92b1ef5c9a3b56ad25827d59d8756c5f0ede2fb1
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / spelling / TaskTagDictionary.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.text.spelling;
13
14 import java.net.URL;
15 import java.util.StringTokenizer;
16
17 import net.sourceforge.phpdt.core.JavaCore;
18 import net.sourceforge.phpdt.internal.ui.text.spelling.engine.AbstractSpellDictionary;
19
20 import org.eclipse.core.runtime.Plugin;
21 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
22 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
23
24 /**
25  * Dictionary for task tags.
26  * 
27  * @since 3.0
28  */
29 public class TaskTagDictionary extends AbstractSpellDictionary implements IPropertyChangeListener {
30
31         /*
32          * @see org.eclipse.jdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getName()
33          */
34         protected final URL getURL() {
35                 return null;
36         }
37
38         /*
39          * @see org.eclipse.jdt.ui.text.spelling.engine.AbstractSpellDictionary#load(java.net.URL)
40          */
41         protected boolean load(final URL url) {
42
43                 final Plugin plugin= JavaCore.getPlugin();
44                 if (plugin != null) {
45
46                         plugin.getPluginPreferences().addPropertyChangeListener(this);
47                         return updateTaskTags();
48                 }
49                 return false;
50         }
51
52         /*
53          * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
54          */
55         public void propertyChange(final PropertyChangeEvent event) {
56
57                 if (JavaCore.COMPILER_TASK_TAGS.equals(event.getProperty()))
58                         updateTaskTags();
59         }
60
61         /*
62          * @see org.eclipse.jdt.ui.text.spelling.engine.ISpellDictionary#unload()
63          */
64         public void unload() {
65
66                 final Plugin plugin= JavaCore.getPlugin();
67                 if (plugin != null)
68                         plugin.getPluginPreferences().removePropertyChangeListener(this);
69
70                 super.unload();
71         }
72
73         /**
74          * Handles the compiler task tags property change event.
75          */
76         protected boolean updateTaskTags() {
77
78                 final String tags= JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS);
79                 if (tags != null) {
80
81                         unload();
82
83                         final StringTokenizer tokenizer= new StringTokenizer(tags, ","); //$NON-NLS-1$
84                         while (tokenizer.hasMoreTokens())
85                                 hashWord(tokenizer.nextToken());
86
87                         return true;
88                 }
89                 return false;
90         }
91 }