ee830798eebe417c3916f59732202f4331d8de1d
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / 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
30                 IPropertyChangeListener {
31
32         /*
33          * @see net.sourceforge.phpdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getName()
34          */
35         protected final URL getURL() {
36                 return null;
37         }
38
39         /*
40          * @see net.sourceforge.phpdt.ui.text.spelling.engine.AbstractSpellDictionary#load(java.net.URL)
41          */
42         protected boolean load(final URL url) {
43
44                 final Plugin plugin = JavaCore.getPlugin();
45                 if (plugin != null) {
46
47                         plugin.getPluginPreferences().addPropertyChangeListener(this);
48                         return updateTaskTags();
49                 }
50                 return false;
51         }
52
53         /*
54          * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
55          */
56         public void propertyChange(final PropertyChangeEvent event) {
57
58                 if (JavaCore.COMPILER_TASK_TAGS.equals(event.getProperty()))
59                         updateTaskTags();
60         }
61
62         /*
63          * @see net.sourceforge.phpdt.ui.text.spelling.engine.ISpellDictionary#unload()
64          */
65         public void unload() {
66
67                 final Plugin plugin = JavaCore.getPlugin();
68                 if (plugin != null)
69                         plugin.getPluginPreferences().removePropertyChangeListener(this);
70
71                 super.unload();
72         }
73
74         /**
75          * Handles the compiler task tags property change event.
76          */
77         private boolean updateTaskTags() {
78
79                 final String tags = JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS);
80                 if (tags != null) {
81
82                         unload();
83
84                         final StringTokenizer tokenizer = new StringTokenizer(tags, ","); //$NON-NLS-1$
85                         while (tokenizer.hasMoreTokens())
86                                 hashWord(tokenizer.nextToken());
87
88                         return true;
89                 }
90                 return false;
91         }
92 }