1 11 package org.eclipse.jdt.internal.ui.compare; 12 13 import org.eclipse.core.runtime.ListenerList; 14 import org.eclipse.core.runtime.preferences.IEclipsePreferences; 15 import org.eclipse.core.runtime.preferences.IScopeContext; 16 17 import org.eclipse.jface.util.IPropertyChangeListener; 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 import org.eclipse.swt.widgets.Display; 20 import org.osgi.service.prefs.BackingStoreException; 21 22 import org.eclipse.jface.preference.IPreferenceStore; 23 24 33 class EclipsePreferencesAdapter implements IPreferenceStore { 34 35 40 private class PreferenceChangeListener implements IEclipsePreferences.IPreferenceChangeListener { 41 42 45 public void preferenceChange(final IEclipsePreferences.PreferenceChangeEvent event) { 46 if (Display.getCurrent() == null) { 47 Display.getDefault().asyncExec(new Runnable () { 48 public void run() { 49 firePropertyChangeEvent(event.getKey(), event.getOldValue(), event.getNewValue()); 50 } 51 }); 52 } else { 53 firePropertyChangeEvent(event.getKey(), event.getOldValue(), event.getNewValue()); 54 } 55 } 56 } 57 58 59 private ListenerList fListeners= new ListenerList(ListenerList.IDENTITY); 60 61 62 private IEclipsePreferences.IPreferenceChangeListener fListener= new PreferenceChangeListener(); 63 64 65 private final IScopeContext fContext; 66 private final String fQualifier; 67 68 73 public EclipsePreferencesAdapter(IScopeContext context, String qualifier) { 74 fContext= context; 75 fQualifier= qualifier; 76 } 77 78 private IEclipsePreferences getNode() { 79 return fContext.getNode(fQualifier); 80 } 81 82 85 public void addPropertyChangeListener(IPropertyChangeListener listener) { 86 if (fListeners.size() == 0) 87 getNode().addPreferenceChangeListener(fListener); 88 fListeners.add(listener); 89 } 90 91 94 public void removePropertyChangeListener(IPropertyChangeListener listener) { 95 fListeners.remove(listener); 96 if (fListeners.size() == 0) { 97 getNode().removePreferenceChangeListener(fListener); 98 } 99 } 100 101 104 public boolean contains(String name) { 105 return getNode().get(name, null) != null; 106 } 107 108 111 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) { 112 PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue); 113 Object [] listeners= fListeners.getListeners(); 114 for (int i= 0; i < listeners.length; i++) 115 ((IPropertyChangeListener) listeners[i]).propertyChange(event); 116 } 117 118 121 public boolean getBoolean(String name) { 122 return getNode().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT); 123 } 124 125 128 public boolean getDefaultBoolean(String name) { 129 return BOOLEAN_DEFAULT_DEFAULT; 130 } 131 132 135 public double getDefaultDouble(String name) { 136 return DOUBLE_DEFAULT_DEFAULT; 137 } 138 139 142 public float getDefaultFloat(String name) { 143 return FLOAT_DEFAULT_DEFAULT; 144 } 145 146 149 public int getDefaultInt(String name) { 150 return INT_DEFAULT_DEFAULT; 151 } 152 153 156 public long getDefaultLong(String name) { 157 return LONG_DEFAULT_DEFAULT; 158 } 159 160 163 public String getDefaultString(String name) { 164 return STRING_DEFAULT_DEFAULT; 165 } 166 167 170 public double getDouble(String name) { 171 return getNode().getDouble(name, DOUBLE_DEFAULT_DEFAULT); 172 } 173 174 177 public float getFloat(String name) { 178 return getNode().getFloat(name, FLOAT_DEFAULT_DEFAULT); 179 } 180 181 184 public int getInt(String name) { 185 return getNode().getInt(name, INT_DEFAULT_DEFAULT); 186 } 187 188 191 public long getLong(String name) { 192 return getNode().getLong(name, LONG_DEFAULT_DEFAULT); 193 } 194 195 198 public String getString(String name) { 199 return getNode().get(name, STRING_DEFAULT_DEFAULT); 200 } 201 202 205 public boolean isDefault(String name) { 206 return false; 207 } 208 209 212 public boolean needsSaving() { 213 try { 214 return getNode().keys().length > 0; 215 } catch (BackingStoreException e) { 216 } 218 return true; 219 } 220 221 224 public void putValue(String name, String value) { 225 throw new UnsupportedOperationException (); 226 } 227 228 231 public void setDefault(String name, double value) { 232 throw new UnsupportedOperationException (); 233 } 234 235 238 public void setDefault(String name, float value) { 239 throw new UnsupportedOperationException (); 240 } 241 242 245 public void setDefault(String name, int value) { 246 throw new UnsupportedOperationException (); 247 } 248 249 252 public void setDefault(String name, long value) { 253 throw new UnsupportedOperationException (); 254 } 255 256 259 public void setDefault(String name, String defaultObject) { 260 throw new UnsupportedOperationException (); 261 } 262 263 266 public void setDefault(String name, boolean value) { 267 throw new UnsupportedOperationException (); 268 } 269 270 273 public void setToDefault(String name) { 274 throw new UnsupportedOperationException (); 275 } 276 277 280 public void setValue(String name, double value) { 281 throw new UnsupportedOperationException (); 282 } 283 284 287 public void setValue(String name, float value) { 288 throw new UnsupportedOperationException (); 289 } 290 291 294 public void setValue(String name, int value) { 295 throw new UnsupportedOperationException (); 296 } 297 298 301 public void setValue(String name, long value) { 302 throw new UnsupportedOperationException (); 303 } 304 305 308 public void setValue(String name, String value) { 309 throw new UnsupportedOperationException (); 310 } 311 312 315 public void setValue(String name, boolean value) { 316 throw new UnsupportedOperationException (); 317 } 318 319 } 320 | Popular Tags |