Removed temporary file build.xml from CVS for several plugins.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / PreferencesAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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;
13
14 import org.eclipse.core.runtime.Preferences;
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.ListenerList;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19
20 /**
21  * Adapts {@link org.eclipse.core.runtime.Preferences} to
22  * {@link org.eclipse.jface.preference.IPreferenceStore}
23  * 
24  * @since 3.0
25  */
26 public class PreferencesAdapter implements IPreferenceStore {
27
28         /**
29          * Property change listener. Listens for events of type
30          * {@link org.eclipse.core.runtime.Preferences.PropertyChangeEvent} and fires
31          * a {@link org.eclipse.jface.util.PropertyChangeEvent} on the
32          * adapter with arguments from the received event.
33          */
34         private class PropertyChangeListener implements Preferences.IPropertyChangeListener {
35
36                 /*
37                  * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
38                  */
39                 public void propertyChange(Preferences.PropertyChangeEvent event) {
40                         firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
41                 }
42         }
43         
44         /** Listeners on the adapter */
45         private ListenerList fListeners= new ListenerList();
46         
47         /** Listener on the adapted Preferences */
48         private PropertyChangeListener fListener= new PropertyChangeListener();
49         
50         /** Adapted Preferences */
51         private Preferences fPreferences;
52
53         /** True iff no events should be forwarded */
54         private boolean fSilent;
55         
56         /**
57          * Initialize with empty Preferences.
58          */
59         public PreferencesAdapter() {
60                 this(new Preferences());
61         }
62         /**
63          * Initialize with the given Preferences.
64          * 
65          * @param preferences The preferences to wrap.
66          */
67         public PreferencesAdapter(Preferences preferences) {
68                 fPreferences= preferences;
69         }
70         
71         /**
72          * {@inheritDoc}
73          */
74         public void addPropertyChangeListener(IPropertyChangeListener listener) {
75                 if (fListeners.size() == 0)
76                         fPreferences.addPropertyChangeListener(fListener);
77                 fListeners.add(listener);
78         }
79
80         /**
81          * {@inheritDoc}
82          */
83         public void removePropertyChangeListener(IPropertyChangeListener listener) {
84                 fListeners.remove(listener);
85                 if (fListeners.size() == 0)
86                         fPreferences.removePropertyChangeListener(fListener);
87         }
88
89         /**
90          * {@inheritDoc}
91          */
92         public boolean contains(String name) {
93                 return fPreferences.contains(name);
94         }
95
96         /**
97          * {@inheritDoc}
98          */
99         public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
100                 if (!fSilent) {
101                         PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue);
102                         Object[] listeners= fListeners.getListeners();
103                         for (int i= 0; i < listeners.length; i++)
104                                 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
105                 }
106         }
107
108         /**
109          * {@inheritDoc}
110          */
111         public boolean getBoolean(String name) {
112                 return fPreferences.getBoolean(name);
113         }
114
115         /**
116          * {@inheritDoc}
117          */
118         public boolean getDefaultBoolean(String name) {
119                 return fPreferences.getDefaultBoolean(name);
120         }
121
122         /**
123          * {@inheritDoc}
124          */
125         public double getDefaultDouble(String name) {
126                 return fPreferences.getDefaultDouble(name);
127         }
128
129         /**
130          * {@inheritDoc}
131          */
132         public float getDefaultFloat(String name) {
133                 return fPreferences.getDefaultFloat(name);
134         }
135
136         /**
137          * {@inheritDoc}
138          */
139         public int getDefaultInt(String name) {
140                 return fPreferences.getDefaultInt(name);
141         }
142
143         /**
144          * {@inheritDoc}
145          */
146         public long getDefaultLong(String name) {
147                 return fPreferences.getDefaultLong(name);
148         }
149
150         /**
151          * {@inheritDoc}
152          */
153         public String getDefaultString(String name) {
154                 return fPreferences.getDefaultString(name);
155         }
156
157         /**
158          * {@inheritDoc}
159          */
160         public double getDouble(String name) {
161                 return fPreferences.getDouble(name);
162         }
163
164         /**
165          * {@inheritDoc}
166          */
167         public float getFloat(String name) {
168                 return fPreferences.getFloat(name);
169         }
170
171         /**
172          * {@inheritDoc}
173          */
174         public int getInt(String name) {
175                 return fPreferences.getInt(name);
176         }
177
178         /**
179          * {@inheritDoc}
180          */
181         public long getLong(String name) {
182                 return fPreferences.getLong(name);
183         }
184
185         /**
186          * {@inheritDoc}
187          */
188         public String getString(String name) {
189                 return fPreferences.getString(name);
190         }
191
192         /**
193          * {@inheritDoc}
194          */
195         public boolean isDefault(String name) {
196                 return fPreferences.isDefault(name);
197         }
198
199         /**
200          * {@inheritDoc}
201          */
202         public boolean needsSaving() {
203                 return fPreferences.needsSaving();
204         }
205
206         /**
207          * {@inheritDoc}
208          */
209         public void putValue(String name, String value) {
210                 try {
211                         fSilent= true;
212                         fPreferences.setValue(name, value);
213                 } finally {
214                         fSilent= false;
215                 }
216         }
217
218         /**
219          * {@inheritDoc}
220          */
221         public void setDefault(String name, double value) {
222                 fPreferences.setDefault(name, value);
223         }
224
225         /**
226          * {@inheritDoc}
227          */
228         public void setDefault(String name, float value) {
229                 fPreferences.setDefault(name, value);
230         }
231
232         /**
233          * {@inheritDoc}
234          */
235         public void setDefault(String name, int value) {
236                 fPreferences.setDefault(name, value);
237         }
238
239         /**
240          * {@inheritDoc}
241          */
242         public void setDefault(String name, long value) {
243                 fPreferences.setDefault(name, value);
244         }
245
246         /**
247          * {@inheritDoc}
248          */
249         public void setDefault(String name, String defaultObject) {
250                 fPreferences.setDefault(name, defaultObject);
251         }
252
253         /**
254          * {@inheritDoc}
255          */
256         public void setDefault(String name, boolean value) {
257                 fPreferences.setDefault(name, value);
258         }
259
260         /**
261          * {@inheritDoc}
262          */
263         public void setToDefault(String name) {
264                 fPreferences.setToDefault(name);
265         }
266
267         /**
268          * {@inheritDoc}
269          */
270         public void setValue(String name, double value) {
271                 fPreferences.setValue(name, value);
272         }
273
274         /**
275          * {@inheritDoc}
276          */
277         public void setValue(String name, float value) {
278                 fPreferences.setValue(name, value);
279         }
280
281         /**
282          * {@inheritDoc}
283          */
284         public void setValue(String name, int value) {
285                 fPreferences.setValue(name, value);
286         }
287
288         /**
289          * {@inheritDoc}
290          */
291         public void setValue(String name, long value) {
292                 fPreferences.setValue(name, value);
293         }
294
295         /**
296          * {@inheritDoc}
297          */
298         public void setValue(String name, String value) {
299                 fPreferences.setValue(name, value);
300         }
301
302         /**
303          * {@inheritDoc}
304          */
305         public void setValue(String name, boolean value) {
306                 fPreferences.setValue(name, value);
307         }
308 }