Project

General

Profile

Download (24 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
/*******************************************************************************
3
 * Copyright (c) 2014 OPCoach.
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     Eclipse - copy of the implementation coming from jface 
11
 *******************************************************************************/
12

    
13
package com.opcoach.e4.preferences;
14

    
15
import java.io.IOException;
16

    
17
import org.eclipse.core.commands.common.EventManager;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Plugin;
21
import org.eclipse.core.runtime.SafeRunner;
22
import org.eclipse.core.runtime.preferences.DefaultScope;
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24
import org.eclipse.core.runtime.preferences.IScopeContext;
25
import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener;
26
import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
27
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
28
import org.eclipse.jface.preference.IPersistentPreferenceStore;
29
import org.eclipse.jface.preference.IPreferenceStore;
30
import org.eclipse.jface.resource.JFaceResources;
31
import org.eclipse.jface.util.IPropertyChangeListener;
32
import org.eclipse.jface.util.PropertyChangeEvent;
33
import org.eclipse.jface.util.SafeRunnable;
34
import org.osgi.service.prefs.BackingStoreException;
35

    
36
/**
37
 * The ScopedPreferenceStore is an IPreferenceStore that uses the scopes
38
 * provided in org.eclipse.core.runtime.preferences.
39
 * <p>
40
 * A ScopedPreferenceStore does the lookup of a preference based on it's search
41
 * scopes and sets the value of the preference based on its store scope.
42
 * </p>
43
 * <p>
44
 * The default scope is always included in the search scopes when searching for
45
 * preference values.
46
 * </p>
47
 * 
48
 * @see org.eclipse.core.runtime.preferences
49
 * @since 3.1
50
 */
51
public class ScopedPreferenceStore extends EventManager implements
52
		IPreferenceStore, IPersistentPreferenceStore {
53

    
54
	/**
55
	 * The storeContext is the context where values will stored with the
56
	 * setValue methods. If there are no searchContexts this will be the search
57
	 * context. (along with the "default" context)
58
	 */
59
	private IScopeContext storeContext;
60

    
61
	/**
62
	 * The searchContext is the array of contexts that will be used by the get
63
	 * methods for searching for values.
64
	 */
65
	private IScopeContext[] searchContexts;
66

    
67
	/**
68
	 * A boolean to indicate the property changes should not be propagated.
69
	 */
70
	protected boolean silentRunning = false;
71

    
72
	/**
73
	 * The listener on the IEclipsePreferences. This is used to forward updates
74
	 * to the property change listeners on the preference store.
75
	 */
76
	IEclipsePreferences.IPreferenceChangeListener preferencesListener;
77

    
78
	/**
79
	 * The default context is the context where getDefault and setDefault
80
	 * methods will search. This context is also used in the search.
81
	 */
82
	private IScopeContext defaultContext = new DefaultScope();
83

    
84
	/**
85
	 * The nodeQualifer is the string used to look up the node in the contexts.
86
	 */
87
	String nodeQualifier;
88

    
89
	/**
90
	 * The defaultQualifier is the string used to look up the default node.
91
	 */
92
	String defaultQualifier;
93

    
94
	/**
95
	 * Boolean value indicating whether or not this store has changes to be
96
	 * saved.
97
	 */
98
	private boolean dirty;
99

    
100
	/**
101
	 * Create a new instance of the receiver. Store the values in context in the
102
	 * node looked up by qualifier. <strong>NOTE:</strong> Any instance of
103
	 * ScopedPreferenceStore should call
104
	 * 
105
	 * @param context
106
	 *            the scope to store to
107
	 * @param qualifier
108
	 *            the qualifier used to look up the preference node
109
	 * @param defaultQualifierPath
110
	 *            the qualifier used when looking up the defaults
111
	 */
112
	public ScopedPreferenceStore(IScopeContext context, String qualifier,
113
			String defaultQualifierPath) {
114
		this(context, qualifier);
115
		this.defaultQualifier = defaultQualifierPath;
116
	}
117

    
118
	/**
119
	 * Create a new instance of the receiver. Store the values in context in the
120
	 * node looked up by qualifier.
121
	 * 
122
	 * @param context
123
	 *            the scope to store to
124
	 * @param qualifier
125
	 *            the qualifer used to look up the preference node
126
	 */
127
	public ScopedPreferenceStore(IScopeContext context, String qualifier) {
128
		storeContext = context;
129
		this.nodeQualifier = qualifier;
130
		this.defaultQualifier = qualifier;
131

    
132
		((IEclipsePreferences) getStorePreferences().parent())
133
				.addNodeChangeListener(getNodeChangeListener());
134
	}
135

    
136
	/**
137
	 * Return a node change listener that adds a removes the receiver when nodes
138
	 * change.
139
	 * 
140
	 * @return INodeChangeListener
141
	 */
142
	private INodeChangeListener getNodeChangeListener() {
143
		return new IEclipsePreferences.INodeChangeListener() {
144
			/*
145
			 * (non-Javadoc)
146
			 * 
147
			 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
148
			 */
149
			public void added(NodeChangeEvent event) {
150
				if (nodeQualifier.equals(event.getChild().name())
151
						&& isListenerAttached()) {
152
					getStorePreferences().addPreferenceChangeListener(
153
							preferencesListener);
154
				}
155
			}
156

    
157
			/*
158
			 * (non-Javadoc)
159
			 * 
160
			 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
161
			 */
162
			public void removed(NodeChangeEvent event) {
163
				// Do nothing as there are no events from removed node
164
			}
165
		};
166
	}
167

    
168
	/**
169
	 * Initialize the preferences listener.
170
	 */
171
	private void initializePreferencesListener() {
172
		if (preferencesListener == null) {
173
			preferencesListener = new IEclipsePreferences.IPreferenceChangeListener() {
174
				/*
175
				 * (non-Javadoc)
176
				 * 
177
				 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
178
				 */
179
				public void preferenceChange(PreferenceChangeEvent event) {
180

    
181
					if (silentRunning) {
182
						return;
183
					}
184

    
185
					Object oldValue = event.getOldValue();
186
					Object newValue = event.getNewValue();
187
					String key = event.getKey();
188
					if (newValue == null) {
189
						newValue = getDefault(key, oldValue);
190
					} else if (oldValue == null) {
191
						oldValue = getDefault(key, newValue);
192
					}
193
					firePropertyChangeEvent(event.getKey(), oldValue, newValue);
194
				}
195
			};
196
			getStorePreferences().addPreferenceChangeListener(
197
					preferencesListener);
198
		}
199

    
200
	}
201

    
202
	/**
203
	 * Does its best at determining the default value for the given key. Checks
204
	 * the given object's type and then looks in the list of defaults to see if
205
	 * a value exists. If not or if there is a problem converting the value, the
206
	 * default default value for that type is returned.
207
	 * 
208
	 * @param key
209
	 *            the key to search
210
	 * @param obj
211
	 *            the object who default we are looking for
212
	 * @return Object or <code>null</code>
213
	 */
214
	Object getDefault(String key, Object obj) {
215
		IEclipsePreferences defaults = getDefaultPreferences();
216
		if (obj instanceof String) {
217
			return defaults.get(key, STRING_DEFAULT_DEFAULT);
218
		} else if (obj instanceof Integer) {
219
			return new Integer(defaults.getInt(key, INT_DEFAULT_DEFAULT));
220
		} else if (obj instanceof Double) {
221
			return new Double(defaults.getDouble(key, DOUBLE_DEFAULT_DEFAULT));
222
		} else if (obj instanceof Float) {
223
			return new Float(defaults.getFloat(key, FLOAT_DEFAULT_DEFAULT));
224
		} else if (obj instanceof Long) {
225
			return new Long(defaults.getLong(key, LONG_DEFAULT_DEFAULT));
226
		} else if (obj instanceof Boolean) {
227
			return defaults.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT) ? Boolean.TRUE
228
					: Boolean.FALSE;
229
		} else {
230
			return null;
231
		}
232
	}
233

    
234
	/**
235
	 * Return the IEclipsePreferences node associated with this store.
236
	 * 
237
	 * @return the preference node for this store
238
	 */
239
	IEclipsePreferences getStorePreferences() {
240
		return storeContext.getNode(nodeQualifier);
241
	}
242

    
243
	/**
244
	 * Return the default IEclipsePreferences for this store.
245
	 * 
246
	 * @return this store's default preference node
247
	 */
248
	private IEclipsePreferences getDefaultPreferences() {
249
		return defaultContext.getNode(defaultQualifier);
250
	}
251

    
252
	/*
253
	 * (non-Javadoc)
254
	 * 
255
	 * @see org.eclipse.jface.preference.IPreferenceStore#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
256
	 */
257
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
258
		initializePreferencesListener();// Create the preferences listener if it
259
		// does not exist
260
		addListenerObject(listener);
261
	}
262

    
263
	/**
264
	 * Return the preference path to search preferences on. This is the list of
265
	 * preference nodes based on the scope contexts for this store. If there are
266
	 * no search contexts set, then return this store's context.
267
	 * <p>
268
	 * Whether or not the default context should be included in the resulting
269
	 * list is specified by the <code>includeDefault</code> parameter.
270
	 * </p>
271
	 * 
272
	 * @param includeDefault
273
	 *            <code>true</code> if the default context should be included
274
	 *            and <code>false</code> otherwise
275
	 * @return IEclipsePreferences[]
276
	 * @since 3.4 public, was added in 3.1 as private method
277
	 */
278
	public IEclipsePreferences[] getPreferenceNodes(boolean includeDefault) {
279
		// if the user didn't specify a search order, then return the scope that
280
		// this store was created on. (and optionally the default)
281
		if (searchContexts == null) {
282
			if (includeDefault) {
283
				return new IEclipsePreferences[] { getStorePreferences(),
284
						getDefaultPreferences() };
285
			}
286
			return new IEclipsePreferences[] { getStorePreferences() };
287
		}
288
		// otherwise the user specified a search order so return the appropriate
289
		// nodes based on it
290
		int length = searchContexts.length;
291
		if (includeDefault) {
292
			length++;
293
		}
294
		IEclipsePreferences[] preferences = new IEclipsePreferences[length];
295
		for (int i = 0; i < searchContexts.length; i++) {
296
			preferences[i] = searchContexts[i].getNode(nodeQualifier);
297
		}
298
		if (includeDefault) {
299
			preferences[length - 1] = getDefaultPreferences();
300
		}
301
		return preferences;
302
	}
303

    
304
	/**
305
	 * Set the search contexts to scopes. When searching for a value the seach
306
	 * will be done in the order of scope contexts and will not search the
307
	 * storeContext unless it is in this list.
308
	 * <p>
309
	 * If the given list is <code>null</code>, then clear this store's search
310
	 * contexts. This means that only this store's scope context and default
311
	 * scope will be used during preference value searching.
312
	 * </p>
313
	 * <p>
314
	 * The defaultContext will be added to the end of this list automatically
315
	 * and <em>MUST NOT</em> be included by the user.
316
	 * </p>
317
	 * 
318
	 * @param scopes
319
	 *            a list of scope contexts to use when searching, or
320
	 *            <code>null</code>
321
	 */
322
	public void setSearchContexts(IScopeContext[] scopes) {
323
		this.searchContexts = scopes;
324
		if (scopes == null) {
325
			return;
326
		}
327

    
328
		// Assert that the default was not included (we automatically add it to
329
		// the end)
330
		for (int i = 0; i < scopes.length; i++) {
331
			if (scopes[i].equals(defaultContext)) {
332
				Assert
333
						.isTrue(
334
								false,
335
								"Do not add the default to the search contexts");
336
			}
337
		}
338
	}
339

    
340
	/*
341
	 * (non-Javadoc)
342
	 * 
343
	 * @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
344
	 */
345
	public boolean contains(String name) {
346
		if (name == null) {
347
			return false;
348
		}
349
		return (Platform.getPreferencesService().get(name, null,
350
				getPreferenceNodes(true))) != null;
351
	}
352

    
353
	/*
354
	 * (non-Javadoc)
355
	 * 
356
	 * @see org.eclipse.jface.preference.IPreferenceStore#firePropertyChangeEvent(java.lang.String,
357
	 *      java.lang.Object, java.lang.Object)
358
	 */
359
	public void firePropertyChangeEvent(String name, Object oldValue,
360
			Object newValue) {
361
		// important: create intermediate array to protect against listeners
362
		// being added/removed during the notification
363
		final Object[] list = getListeners();
364
		if (list.length == 0) {
365
			return;
366
		}
367
		final PropertyChangeEvent event = new PropertyChangeEvent(this, name,
368
				oldValue, newValue);
369
		for (int i = 0; i < list.length; i++) {
370
			final IPropertyChangeListener listener = (IPropertyChangeListener) list[i];
371
			SafeRunner.run(new SafeRunnable(JFaceResources
372
					.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
373
						public void run() {
374
							listener.propertyChange(event);
375
						}
376
					});
377
		}
378
	}
379

    
380
	/*
381
	 * (non-Javadoc)
382
	 * 
383
	 * @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
384
	 */
385
	public boolean getBoolean(String name) {
386
		String value = internalGet(name);
387
		return value == null ? BOOLEAN_DEFAULT_DEFAULT : Boolean.valueOf(value)
388
				.booleanValue();
389
	}
390

    
391
	/*
392
	 * (non-Javadoc)
393
	 * 
394
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java.lang.String)
395
	 */
396
	public boolean getDefaultBoolean(String name) {
397
		return getDefaultPreferences()
398
				.getBoolean(name, BOOLEAN_DEFAULT_DEFAULT);
399
	}
400

    
401
	/*
402
	 * (non-Javadoc)
403
	 * 
404
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang.String)
405
	 */
406
	public double getDefaultDouble(String name) {
407
		return getDefaultPreferences().getDouble(name, DOUBLE_DEFAULT_DEFAULT);
408
	}
409

    
410
	/*
411
	 * (non-Javadoc)
412
	 * 
413
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang.String)
414
	 */
415
	public float getDefaultFloat(String name) {
416
		return getDefaultPreferences().getFloat(name, FLOAT_DEFAULT_DEFAULT);
417
	}
418

    
419
	/*
420
	 * (non-Javadoc)
421
	 * 
422
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang.String)
423
	 */
424
	public int getDefaultInt(String name) {
425
		return getDefaultPreferences().getInt(name, INT_DEFAULT_DEFAULT);
426
	}
427

    
428
	/*
429
	 * (non-Javadoc)
430
	 * 
431
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang.String)
432
	 */
433
	public long getDefaultLong(String name) {
434
		return getDefaultPreferences().getLong(name, LONG_DEFAULT_DEFAULT);
435
	}
436

    
437
	/*
438
	 * (non-Javadoc)
439
	 * 
440
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang.String)
441
	 */
442
	public String getDefaultString(String name) {
443
		return getDefaultPreferences().get(name, STRING_DEFAULT_DEFAULT);
444
	}
445

    
446
	/*
447
	 * (non-Javadoc)
448
	 * 
449
	 * @see org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String)
450
	 */
451
	public double getDouble(String name) {
452
		String value = internalGet(name);
453
		if (value == null) {
454
			return DOUBLE_DEFAULT_DEFAULT;
455
		}
456
		try {
457
			return Double.parseDouble(value);
458
		} catch (NumberFormatException e) {
459
			return DOUBLE_DEFAULT_DEFAULT;
460
		}
461
	}
462

    
463
	/**
464
	 * Return the string value for the specified key. Look in the nodes which
465
	 * are specified by this object's list of search scopes. If the value does
466
	 * not exist then return <code>null</code>.
467
	 * 
468
	 * @param key
469
	 *            the key to search with
470
	 * @return String or <code>null</code> if the value does not exist.
471
	 */
472
	private String internalGet(String key) {
473
		return Platform.getPreferencesService().get(key, null,
474
				getPreferenceNodes(true));
475
	}
476

    
477
	/*
478
	 * (non-Javadoc)
479
	 * 
480
	 * @see org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String)
481
	 */
482
	public float getFloat(String name) {
483
		String value = internalGet(name);
484
		if (value == null) {
485
			return FLOAT_DEFAULT_DEFAULT;
486
		}
487
		try {
488
			return Float.parseFloat(value);
489
		} catch (NumberFormatException e) {
490
			return FLOAT_DEFAULT_DEFAULT;
491
		}
492
	}
493

    
494
	/*
495
	 * (non-Javadoc)
496
	 * 
497
	 * @see org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String)
498
	 */
499
	public int getInt(String name) {
500
		String value = internalGet(name);
501
		if (value == null) {
502
			return INT_DEFAULT_DEFAULT;
503
		}
504
		try {
505
			return Integer.parseInt(value);
506
		} catch (NumberFormatException e) {
507
			return INT_DEFAULT_DEFAULT;
508
		}
509
	}
510

    
511
	/*
512
	 * (non-Javadoc)
513
	 * 
514
	 * @see org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String)
515
	 */
516
	public long getLong(String name) {
517
		String value = internalGet(name);
518
		if (value == null) {
519
			return LONG_DEFAULT_DEFAULT;
520
		}
521
		try {
522
			return Long.parseLong(value);
523
		} catch (NumberFormatException e) {
524
			return LONG_DEFAULT_DEFAULT;
525
		}
526
	}
527

    
528
	/*
529
	 * (non-Javadoc)
530
	 * 
531
	 * @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
532
	 */
533
	public String getString(String name) {
534
		String value = internalGet(name);
535
		return value == null ? STRING_DEFAULT_DEFAULT : value;
536
	}
537

    
538
	/*
539
	 * (non-Javadoc)
540
	 * 
541
	 * @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
542
	 */
543
	public boolean isDefault(String name) {
544
		if (name == null) {
545
			return false;
546
		}
547
		return (Platform.getPreferencesService().get(name, null,
548
				getPreferenceNodes(false))) == null;
549
	}
550

    
551
	/*
552
	 * (non-Javadoc)
553
	 * 
554
	 * @see org.eclipse.jface.preference.IPreferenceStore#needsSaving()
555
	 */
556
	public boolean needsSaving() {
557
		return dirty;
558
	}
559

    
560
	/*
561
	 * (non-Javadoc)
562
	 * 
563
	 * @see org.eclipse.jface.preference.IPreferenceStore#putValue(java.lang.String,
564
	 *      java.lang.String)
565
	 */
566
	public void putValue(String name, String value) {
567
		try {
568
			// Do not notify listeners
569
			silentRunning = true;
570
			getStorePreferences().put(name, value);
571
		} finally {
572
			// Be sure that an exception does not stop property updates
573
			silentRunning = false;
574
			dirty = true;
575
		}
576
	}
577

    
578
	/*
579
	 * (non-Javadoc)
580
	 * 
581
	 * @see org.eclipse.jface.preference.IPreferenceStore#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
582
	 */
583
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
584
		removeListenerObject(listener);
585
		if (!isListenerAttached()) {
586
			disposePreferenceStoreListener();
587
		}
588
	}
589

    
590
	/*
591
	 * (non-Javadoc)
592
	 * 
593
	 * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
594
	 *      double)
595
	 */
596
	public void setDefault(String name, double value) {
597
		getDefaultPreferences().putDouble(name, value);
598
	}
599

    
600
	/*
601
	 * (non-Javadoc)
602
	 * 
603
	 * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
604
	 *      float)
605
	 */
606
	public void setDefault(String name, float value) {
607
		getDefaultPreferences().putFloat(name, value);
608
	}
609

    
610
	/*
611
	 * (non-Javadoc)
612
	 * 
613
	 * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
614
	 *      int)
615
	 */
616
	public void setDefault(String name, int value) {
617
		getDefaultPreferences().putInt(name, value);
618
	}
619

    
620
	/*
621
	 * (non-Javadoc)
622
	 * 
623
	 * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
624
	 *      long)
625
	 */
626
	public void setDefault(String name, long value) {
627
		getDefaultPreferences().putLong(name, value);
628
	}
629

    
630
	/*
631
	 * (non-Javadoc)
632
	 * 
633
	 * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
634
	 *      java.lang.String)
635
	 */
636
	public void setDefault(String name, String defaultObject) {
637
		getDefaultPreferences().put(name, defaultObject);
638
	}
639

    
640
	/*
641
	 * (non-Javadoc)
642
	 * 
643
	 * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
644
	 *      boolean)
645
	 */
646
	public void setDefault(String name, boolean value) {
647
		getDefaultPreferences().putBoolean(name, value);
648
	}
649

    
650
	/*
651
	 * (non-Javadoc)
652
	 * 
653
	 * @see org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang.String)
654
	 */
655
	public void setToDefault(String name) {
656

    
657
		String oldValue = getString(name);
658
		String defaultValue = getDefaultString(name);
659
		try {
660
			silentRunning = true;// Turn off updates from the store
661
			// removing a non-existing preference is a no-op so call the Core
662
			// API directly
663
			getStorePreferences().remove(name);
664
			if (oldValue != defaultValue){
665
				dirty = true;
666
				firePropertyChangeEvent(name, oldValue, defaultValue);
667
			}
668
				
669
		} finally {
670
			silentRunning = false;// Restart listening to preferences
671
		}
672

    
673
	}
674

    
675
	/*
676
	 * (non-Javadoc)
677
	 * 
678
	 * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
679
	 *      double)
680
	 */
681
	public void setValue(String name, double value) {
682
		double oldValue = getDouble(name);
683
		if (oldValue == value) {
684
			return;
685
		}
686
		try {
687
			silentRunning = true;// Turn off updates from the store
688
			if (getDefaultDouble(name) == value) {
689
				getStorePreferences().remove(name);
690
			} else {
691
				getStorePreferences().putDouble(name, value);
692
			}
693
			dirty = true;
694
			firePropertyChangeEvent(name, new Double(oldValue), new Double(
695
					value));
696
		} finally {
697
			silentRunning = false;// Restart listening to preferences
698
		}
699
	}
700

    
701
	/*
702
	 * (non-Javadoc)
703
	 * 
704
	 * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
705
	 *      float)
706
	 */
707
	public void setValue(String name, float value) {
708
		float oldValue = getFloat(name);
709
		if (oldValue == value) {
710
			return;
711
		}
712
		try {
713
			silentRunning = true;// Turn off updates from the store
714
			if (getDefaultFloat(name) == value) {
715
				getStorePreferences().remove(name);
716
			} else {
717
				getStorePreferences().putFloat(name, value);
718
			}
719
			dirty = true;
720
			firePropertyChangeEvent(name, new Float(oldValue), new Float(value));
721
		} finally {
722
			silentRunning = false;// Restart listening to preferences
723
		}
724
	}
725

    
726
	/*
727
	 * (non-Javadoc)
728
	 * 
729
	 * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
730
	 *      int)
731
	 */
732
	public void setValue(String name, int value) {
733
		int oldValue = getInt(name);
734
		if (oldValue == value) {
735
			return;
736
		}
737
		try {
738
			silentRunning = true;// Turn off updates from the store
739
			if (getDefaultInt(name) == value) {
740
				getStorePreferences().remove(name);
741
			} else {
742
				getStorePreferences().putInt(name, value);
743
			}
744
			dirty = true;
745
			firePropertyChangeEvent(name, new Integer(oldValue), new Integer(
746
					value));
747
		} finally {
748
			silentRunning = false;// Restart listening to preferences
749
		}
750
	}
751

    
752
	/*
753
	 * (non-Javadoc)
754
	 * 
755
	 * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
756
	 *      long)
757
	 */
758
	public void setValue(String name, long value) {
759
		long oldValue = getLong(name);
760
		if (oldValue == value) {
761
			return;
762
		}
763
		try {
764
			silentRunning = true;// Turn off updates from the store
765
			if (getDefaultLong(name) == value) {
766
				getStorePreferences().remove(name);
767
			} else {
768
				getStorePreferences().putLong(name, value);
769
			}
770
			dirty = true;
771
			firePropertyChangeEvent(name, new Long(oldValue), new Long(value));
772
		} finally {
773
			silentRunning = false;// Restart listening to preferences
774
		}
775
	}
776

    
777
	/*
778
	 * (non-Javadoc)
779
	 * 
780
	 * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
781
	 *      java.lang.String)
782
	 */
783
	public void setValue(String name, String value) {
784
		// Do not turn on silent running here as Strings are propagated
785
		if (getDefaultString(name).equals(value)) {
786
			getStorePreferences().remove(name);
787
		} else {
788
			getStorePreferences().put(name, value);
789
		}
790
		dirty = true;
791
	}
792

    
793
	/*
794
	 * (non-Javadoc)
795
	 * 
796
	 * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
797
	 *      boolean)
798
	 */
799
	public void setValue(String name, boolean value) {
800
		boolean oldValue = getBoolean(name);
801
		if (oldValue == value) {
802
			return;
803
		}
804
		try {
805
			silentRunning = true;// Turn off updates from the store
806
			if (getDefaultBoolean(name) == value) {
807
				getStorePreferences().remove(name);
808
			} else {
809
				getStorePreferences().putBoolean(name, value);
810
			}
811
			dirty = true;
812
			firePropertyChangeEvent(name, oldValue ? Boolean.TRUE
813
					: Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
814
		} finally {
815
			silentRunning = false;// Restart listening to preferences
816
		}
817
	}
818

    
819
	/*
820
	 * (non-Javadoc)
821
	 * 
822
	 * @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
823
	 */
824
	public void save() throws IOException {
825
		try {
826
			getStorePreferences().flush();
827
			dirty = false;
828
		} catch (BackingStoreException e) {
829
			throw new IOException(e.getMessage());
830
		}
831

    
832
	}
833

    
834
	/**
835
	 * Dispose the receiver.
836
	 */
837
	private void disposePreferenceStoreListener() {
838

    
839
		IEclipsePreferences root = (IEclipsePreferences) Platform
840
				.getPreferencesService().getRootNode().node(
841
						Plugin.PLUGIN_PREFERENCE_SCOPE);
842
		try {
843
			if (!(root.nodeExists(nodeQualifier))) {
844
				return;
845
			}
846
		} catch (BackingStoreException e) {
847
			return;// No need to report here as the node won't have the
848
			// listener
849
		}
850

    
851
		IEclipsePreferences preferences = getStorePreferences();
852
		if (preferences == null) {
853
			return;
854
		}
855
		if (preferencesListener != null) {
856
			preferences.removePreferenceChangeListener(preferencesListener);
857
			preferencesListener = null;
858
		}
859
	}
860

    
861
}
(3-3/3)