Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2006-01-11 16:05:50 +0000
committerDJ Houghton2006-01-11 16:05:50 +0000
commitc055b44b85e693933f8411558e979922cc3fbb07 (patch)
treed7edf20f9db0f5b3555a7ad8a99937e67845ae0c
parent30febef25fb6f70edf95b30a905d7922621210f2 (diff)
downloadrt.equinox.bundles-c055b44b85e693933f8411558e979922cc3fbb07.tar.gz
rt.equinox.bundles-c055b44b85e693933f8411558e979922cc3fbb07.tar.xz
rt.equinox.bundles-c055b44b85e693933f8411558e979922cc3fbb07.zip
Bug 118931 - [prefs] move Preferences class back to core.runtime
-rw-r--r--bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java6
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java6
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/IPreferencesConstants.java27
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceForwarder.java851
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java10
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/runtime/Preferences.java1284
7 files changed, 39 insertions, 2146 deletions
diff --git a/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF
index 8a4c2a2c4..75a7372a1 100644
--- a/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF
@@ -9,7 +9,6 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.equinox.common,
system.bundle
Export-Package: org.eclipse.core.internal.preferences;x-friends:="org.eclipse.core.resources,org.eclipse.core.runtime",
- org.eclipse.core.runtime,
org.eclipse.core.runtime.preferences,
org.osgi.service.prefs;version="1.1"
Eclipse-LazyStart: true
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java
index cacf87cbc..60a89f6d5 100644
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java
+++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -86,13 +86,13 @@ public class DefaultPreferences extends EclipsePreferences {
Bundle bundle = PreferencesOSGiUtils.getDefault().getBundle(name());
if (bundle == null)
return;
- URL url = BundleFinder.find(bundle, new Path(Preferences.PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME));
+ URL url = BundleFinder.find(bundle, new Path(IPreferencesConstants.PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME));
if (url == null) {
if (EclipsePreferences.DEBUG_PREFERENCE_GENERAL)
PrefsMessages.message("Preference default override file not found for bundle: " + bundle.getSymbolicName()); //$NON-NLS-1$
return;
}
- URL transURL = BundleFinder.find(bundle, NL_DIR.append(Preferences.PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME).addFileExtension(PROPERTIES_FILE_EXTENSION));
+ URL transURL = BundleFinder.find(bundle, NL_DIR.append(IPreferencesConstants.PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME).addFileExtension(PROPERTIES_FILE_EXTENSION));
if (transURL == null && EclipsePreferences.DEBUG_PREFERENCE_GENERAL)
PrefsMessages.message("Preference translation file not found for bundle: " + bundle.getSymbolicName()); //$NON-NLS-1$
applyDefaults(name(), loadProperties(url), loadProperties(transURL));
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java
index b7b4169e9..f89fd6060 100644
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java
+++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -644,6 +644,10 @@ public class EclipsePreferences implements IEclipsePreferences, IScope {
}
}
+ public boolean isDirty() {
+ return dirty;
+ }
+
/*
* @see org.osgi.service.prefs.Preferences#name()
*/
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/IPreferencesConstants.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/IPreferencesConstants.java
index be4799d84..dfd4868eb 100644
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/IPreferencesConstants.java
+++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/IPreferencesConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -30,4 +30,29 @@ public interface IPreferencesConstants {
*/
public static final String PLUGIN_CUSTOMIZATION = "-plugincustomization"; //$NON-NLS-1$
+ /**
+ * This is the base filename used to construct the name of the preference
+ * file and the name of the preference translation file.
+ */
+ public static final String PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME = "preferences"; //$NON-NLS-1$
+
+ /**
+ * The name of the file (value <code>"preferences.ini"</code>) in a
+ * plug-in's (read-only) directory that, when present, contains values that
+ * override the normal default values for this plug-in's preferences.
+ * <p>
+ * The format of the file is as per <code>java.io.Properties</code> where
+ * the keys are property names and values are strings.
+ * </p>
+ */
+ public static final String PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME = PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME + ".ini"; //$NON-NLS-1$
+
+ /**
+ * The simple identifier constant (value "<code>preferences</code>") of
+ * the extension point of the Core Runtime plug-in where plug-ins declare
+ * extensions to the preference facility. A plug-in may define any number
+ * of preference extensions.
+ */
+ public static final String PT_PREFERENCES = "preferences"; //$NON-NLS-1$
+
}
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceForwarder.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceForwarder.java
deleted file mode 100644
index c0ee012ab..000000000
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceForwarder.java
+++ /dev/null
@@ -1,851 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.internal.preferences;
-
-import java.io.*;
-import java.util.Iterator;
-import java.util.Properties;
-import org.eclipse.core.internal.runtime.RuntimeLog;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.osgi.service.prefs.BackingStoreException;
-
-/**
- * This class represents a convenience layer between the Eclipse 3.0
- * preferences and pre-3.0 preferences. It acts as a bridge between the
- * org.eclipse.core.runtime.Preferences object associated with a particular plug-in
- * object, and its corresponding preference node in the 3.0 preference node
- * hierarchy.
- *
- * @since 3.0
- */
-public class PreferenceForwarder extends Preferences implements IEclipsePreferences.IPreferenceChangeListener, IEclipsePreferences.INodeChangeListener {
-
- private static final byte[] BYTE_ARRAY_DEFAULT_DEFAULT = new byte[0];
-
- PreferencesService a;
-
- private IEclipsePreferences pluginRoot = (IEclipsePreferences) PreferencesService.getDefault().getRootNode().node(InstanceScope.SCOPE);
- private DefaultPreferences defaultsRoot = (DefaultPreferences) PreferencesService.getDefault().getRootNode().node(DefaultScope.SCOPE);
- private String pluginID;
- private Object plugin;
- // boolean to check to see if we should re-wrap and forward change
- // events coming from the new runtime APIs.
- private boolean notify = true;
-
- /*
- * Used for test suites only.
- */
- public PreferenceForwarder(String pluginID) {
- this(null, pluginID);
- }
-
- public PreferenceForwarder(Object plugin, String pluginID) {
- super();
- this.plugin = plugin;
- this.pluginID = pluginID;
- pluginRoot.addNodeChangeListener(this);
- }
-
- /*
- * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
- */
- public void added(IEclipsePreferences.NodeChangeEvent event) {
- if (listeners.size() > 0 && pluginID.equals(event.getChild().name()))
- getPluginPreferences(true).addPreferenceChangeListener(this);
- }
-
- /*
- * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
- */
- public void removed(IEclipsePreferences.NodeChangeEvent event) {
- // don't worry about removing the preference change listener since
- // we won't get any notification from a removed node anyways.
- }
-
- /**
- * Adds a property change listener to this preference object.
- * Has no affect if the identical listener is already registered.
- *
- * @param listener a property change listener
- */
- public void addPropertyChangeListener(IPropertyChangeListener listener) {
- getPluginPreferences(true).addPreferenceChangeListener(this);
- listeners.add(listener);
- }
-
- /*
- * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
- */
- public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
- // if we are the ones making this change, then don't broadcast
- if (!notify)
- return;
- Object oldValue = event.getOldValue();
- Object newValue = event.getNewValue();
- String key = event.getKey();
- if (newValue == null)
- newValue = getDefault(key, oldValue);
- else if (oldValue == null)
- oldValue = getDefault(key, newValue);
- firePropertyChangeEvent(key, oldValue, newValue);
- }
-
- private EclipsePreferences getPluginPreferences(boolean create) {
- try {
- if (!create && !pluginRoot.nodeExists(pluginID))
- return null;
- } catch (BackingStoreException e) {
- return null;
- }
- try {
- return (EclipsePreferences) pluginRoot.node(pluginID);
- } catch (ClassCastException e) {
- throw new RuntimeException("Plug-in preferences must be instances of EclipsePreferences: " + e.getMessage()); //$NON-NLS-1$
- }
- }
-
- private IEclipsePreferences getDefaultPreferences() {
- return defaultsRoot.node(pluginID, plugin);
- }
-
- /**
- * Removes the given listener from this preference object.
- * Has no affect if the listener is not registered.
- *
- * @param listener a property change listener
- */
- public void removePropertyChangeListener(IPropertyChangeListener listener) {
- listeners.remove(listener);
- }
-
- /**
- * Does its best at determining the default value for the given key. Checks the
- * given object's type and then looks in the list of defaults to see if a value
- * exists. If not or if there is a problem converting the value, the default default
- * value for that type is returned.
- */
- private Object getDefault(String key, Object obj) {
- IEclipsePreferences defaults = getDefaultPreferences();
- if (obj instanceof String)
- return defaults.get(key, STRING_DEFAULT_DEFAULT);
- else if (obj instanceof Integer)
- return new Integer(defaults.getInt(key, INT_DEFAULT_DEFAULT));
- else if (obj instanceof Double)
- return new Double(defaults.getDouble(key, DOUBLE_DEFAULT_DEFAULT));
- else if (obj instanceof Float)
- return new Float(defaults.getFloat(key, FLOAT_DEFAULT_DEFAULT));
- else if (obj instanceof Long)
- return new Long(defaults.getLong(key, LONG_DEFAULT_DEFAULT));
- else if (obj instanceof byte[])
- return defaults.getByteArray(key, BYTE_ARRAY_DEFAULT_DEFAULT);
- else if (obj instanceof Boolean)
- return defaults.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT) ? Boolean.TRUE : Boolean.FALSE;
- else
- return null;
- }
-
- /**
- * Returns whether the given property is known to this preference object,
- * either by having an explicit setting or by having a default
- * setting.
- *
- * @param name the name of the property
- * @return <code>true</code> if either a current value or a default
- * value is known for the named property, and <code>false</code>otherwise
- */
- public boolean contains(String name) {
- if (name == null)
- return false;
- String value = getPluginPreferences(true).get(name, null);
- if (value != null)
- return true;
- return getDefaultPreferences().get(name, null) != null;
- }
-
- /**
- * Returns the current value of the boolean-valued property with the
- * given name.
- * Returns the default-default value (<code>false</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a boolean.
- *
- * @param name the name of the property
- * @return the boolean-valued property
- */
- public boolean getBoolean(String name) {
- return getPluginPreferences(true).getBoolean(name, getDefaultPreferences().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT));
- }
-
- /**
- * Sets the current value of the boolean-valued property with the
- * given name.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, boolean value) {
- Boolean oldValue = getBoolean(name) ? Boolean.TRUE : Boolean.FALSE;
- Boolean newValue = value ? Boolean.TRUE : Boolean.FALSE;
- if (newValue == oldValue)
- return;
- try {
- notify = false;
- if (getDefaultBoolean(name) == value)
- getPluginPreferences(true).remove(name);
- else
- getPluginPreferences(true).putBoolean(name, value);
- firePropertyChangeEvent(name, oldValue, newValue);
- } finally {
- notify = true;
- }
- }
-
- /**
- * Returns the default value for the boolean-valued property
- * with the given name.
- * Returns the default-default value (<code>false</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a boolean.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public boolean getDefaultBoolean(String name) {
- return getDefaultPreferences().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the boolean-valued property with the
- * given name.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, boolean value) {
- getDefaultPreferences().putBoolean(name, value);
- }
-
- /**
- * Returns the current value of the double-valued property with the
- * given name.
- * Returns the default-default value (<code>0.0</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a double.
- *
- * @param name the name of the property
- * @return the double-valued property
- */
- public double getDouble(String name) {
- return getPluginPreferences(true).getDouble(name, getDefaultPreferences().getDouble(name, DOUBLE_DEFAULT_DEFAULT));
- }
-
- /**
- * Sets the current value of the double-valued property with the
- * given name.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property; must be
- * a number (not a NaN)
- */
- public void setValue(String name, double value) {
- if (Double.isNaN(value))
- throw new IllegalArgumentException();
- final double doubleValue = getDouble(name);
- if (value == doubleValue)
- return;
- Double oldValue = new Double(doubleValue);
- Double newValue = new Double(value);
- try {
- notify = false;
- if (getDefaultDouble(name) == value)
- getPluginPreferences(true).remove(name);
- else
- getPluginPreferences(true).putDouble(name, value);
- firePropertyChangeEvent(name, oldValue, newValue);
- } finally {
- notify = true;
- }
- }
-
- /**
- * Returns the default value for the double-valued property
- * with the given name.
- * Returns the default-default value (<code>0.0</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a double.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public double getDefaultDouble(String name) {
- return getDefaultPreferences().getDouble(name, DOUBLE_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the double-valued property with the
- * given name.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property; must be
- * a number (not a NaN)
- */
- public void setDefault(String name, double value) {
- if (Double.isNaN(value))
- throw new IllegalArgumentException();
- getDefaultPreferences().putDouble(name, value);
- }
-
- /**
- * Returns the current value of the float-valued property with the
- * given name.
- * Returns the default-default value (<code>0.0f</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a float.
- *
- * @param name the name of the property
- * @return the float-valued property
- */
- public float getFloat(String name) {
- return getPluginPreferences(true).getFloat(name, getDefaultPreferences().getFloat(name, FLOAT_DEFAULT_DEFAULT));
- }
-
- /**
- * Sets the current value of the float-valued property with the
- * given name.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property; must be
- * a number (not a NaN)
- */
- public void setValue(String name, float value) {
- if (Float.isNaN(value))
- throw new IllegalArgumentException();
- final float floatValue = getFloat(name);
- if (value == floatValue)
- return;
- Float oldValue = new Float(floatValue);
- Float newValue = new Float(value);
- try {
- notify = false;
- if (getDefaultFloat(name) == value)
- getPluginPreferences(true).remove(name);
- else
- getPluginPreferences(true).putFloat(name, value);
- firePropertyChangeEvent(name, oldValue, newValue);
- } finally {
- notify = true;
- }
- }
-
- /**
- * Returns the default value for the float-valued property
- * with the given name.
- * Returns the default-default value (<code>0.0f</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a float.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public float getDefaultFloat(String name) {
- return getDefaultPreferences().getFloat(name, FLOAT_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the float-valued property with the
- * given name.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property; must be
- * a number (not a NaN)
- */
- public void setDefault(String name, float value) {
- if (Float.isNaN(value))
- throw new IllegalArgumentException();
- getDefaultPreferences().putFloat(name, value);
- }
-
- /**
- * Returns the current value of the integer-valued property with the
- * given name.
- * Returns the default-default value (<code>0</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as an integter.
- *
- * @param name the name of the property
- * @return the int-valued property
- */
- public int getInt(String name) {
- return getPluginPreferences(true).getInt(name, getDefaultPreferences().getInt(name, INT_DEFAULT_DEFAULT));
- }
-
- /**
- * Sets the current value of the integer-valued property with the
- * given name.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, int value) {
- final int intValue = getInt(name);
- if (value == intValue)
- return;
- Integer oldValue = new Integer(intValue);
- Integer newValue = new Integer(value);
- try {
- notify = false;
- if (getDefaultInt(name) == value)
- getPluginPreferences(true).remove(name);
- else
- getPluginPreferences(true).putInt(name, value);
- firePropertyChangeEvent(name, oldValue, newValue);
- } finally {
- notify = true;
- }
- }
-
- /**
- * Returns the default value for the integer-valued property
- * with the given name.
- * Returns the default-default value (<code>0</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as an integer.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public int getDefaultInt(String name) {
- return getDefaultPreferences().getInt(name, INT_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the integer-valued property with the
- * given name.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, int value) {
- getDefaultPreferences().putInt(name, value);
- }
-
- /**
- * Returns the current value of the long-valued property with the
- * given name.
- * Returns the default-default value (<code>0L</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a long.
- *
- * @param name the name of the property
- * @return the long-valued property
- */
- public long getLong(String name) {
- return getPluginPreferences(true).getLong(name, getDefaultPreferences().getLong(name, LONG_DEFAULT_DEFAULT));
- }
-
- /**
- * Sets the current value of the long-valued property with the
- * given name.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, long value) {
- final long longValue = getLong(name);
- if (value == longValue)
- return;
- Long oldValue = new Long(longValue);
- Long newValue = new Long(value);
- try {
- notify = false;
- if (getDefaultLong(name) == value)
- getPluginPreferences(true).remove(name);
- else
- getPluginPreferences(true).putLong(name, value);
- firePropertyChangeEvent(name, oldValue, newValue);
- } finally {
- notify = true;
- }
- }
-
- /**
- * Returns the default value for the long-valued property
- * with the given name.
- * Returns the default-default value (<code>0L</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a long.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public long getDefaultLong(String name) {
- return getDefaultPreferences().getLong(name, LONG_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the long-valued property with the
- * given name.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, long value) {
- getDefaultPreferences().putLong(name, value);
- }
-
- /**
- * Returns the current value of the string-valued property with the
- * given name.
- * Returns the default-default value (the empty string <code>""</code>)
- * if there is no property with the given name.
- *
- * @param name the name of the property
- * @return the string-valued property
- */
- public String getString(String name) {
- return getPluginPreferences(true).get(name, getDefaultPreferences().get(name, STRING_DEFAULT_DEFAULT));
- }
-
- /**
- * Sets the current value of the string-valued property with the
- * given name.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, String value) {
- if (value == null)
- throw new IllegalArgumentException();
- String oldValue = getString(name);
- if (value.equals(oldValue))
- return;
- try {
- notify = false;
- if (getDefaultString(name).equals(value))
- getPluginPreferences(true).remove(name);
- else
- getPluginPreferences(true).put(name, value);
- firePropertyChangeEvent(name, oldValue, value);
- } finally {
- notify = true;
- }
- }
-
- /**
- * Returns the default value for the string-valued property
- * with the given name.
- * Returns the default-default value (the empty string <code>""</code>)
- * is no default property with the given name, or if the default
- * value cannot be treated as a string.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public String getDefaultString(String name) {
- return getDefaultPreferences().get(name, STRING_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the string-valued property with the
- * given name.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, String value) {
- if (value == null)
- throw new IllegalArgumentException();
- getDefaultPreferences().put(name, value);
- }
-
- /**
- * Returns whether the property with the given name has the default value in
- * virtue of having no explicitly set value.
- *
- * @param name the name of the property
- * @return <code>true</code> if the property has no explicitly set value,
- * and <code>false</code> otherwise (including the case where the property
- * is unknown to this object)
- */
- public boolean isDefault(String name) {
- if (name == null)
- return false;
- return getPluginPreferences(true).get(name, null) == null;
- }
-
- /**
- * Sets the current value of the property with the given name back
- * to its default value. Has no effect if the property does not have
- * its own current value.
- * <p>
- * Note that the recommended way of re-initializing a property to the
- * appropriate default value is to call <code>setToDefault</code>.
- * This is implemented by removing the named value from the object,
- * thereby exposing the default value.
- * </p>
- * <p>
- * A property change event is always reported. In the event
- * object, the property name is the name of the property, and the
- * old and new values are either strings, or <code>null</code>
- * indicating the default-default value.
- * </p>
- *
- * @param name the name of the property
- */
- public void setToDefault(String name) {
- IEclipsePreferences preferences = getPluginPreferences(true);
- Object oldValue = preferences.get(name, null);
- if (oldValue != null)
- preferences.remove(name);
- }
-
- /**
- * Returns a list of all properties known to this preference object which
- * have current values other than their default value.
- *
- * @return an array of property names
- */
- public String[] propertyNames() {
- return getPluginPreferences(true).keys();
- }
-
- /**
- * Returns a list of all properties known to this preference object which
- * have default values other than their default-default value.
- *
- * @return an array of property names
- */
- public String[] defaultPropertyNames() {
- try {
- return getDefaultPreferences().keys();
- } catch (BackingStoreException e) {
- logError(e.getMessage(), e);
- return new String[0];
- }
- }
-
- /**
- * Returns whether the current values in this preference object
- * require saving.
- *
- * @return <code>true</code> if at least one of the properties
- * known to this preference object has a current value different from its
- * default value, and <code>false</code> otherwise
- */
- public boolean needsSaving() {
- return getPluginPreferences(true).dirty;
- }
-
- /**
- * Flush the values of these plug-in preferences to disk.
- *
- * @throws BackingStoreException
- */
- public void flush() throws BackingStoreException {
- IEclipsePreferences node = getPluginPreferences(false);
- if (node != null)
- node.flush();
- }
-
- /*
- * Something bad happened so log it.
- */
- private void logError(String message, Exception e) {
- IStatus status = new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, IStatus.ERROR, message, e);
- RuntimeLog.log(status);
- }
-
- /*
- * @see org.eclipse.core.runtime.Preferences#load(java.io.InputStream)
- */
- public void load(InputStream in) throws IOException {
- Properties result = new Properties();
- result.load(in);
- convertFromProperties(result);
- // We loaded the prefs from a non-default location so now
- // store them to disk. This also clears the dirty flag
- // and therefore sets the #needsSaving() state correctly.
- try {
- flush();
- } catch (BackingStoreException e) {
- throw new IOException(e.getMessage());
- }
- }
-
- /*
- * @see org.eclipse.core.runtime.Preferences#store(java.io.OutputStream, java.lang.String)
- */
- public void store(OutputStream out, String header) throws IOException {
- Properties result = convertToProperties();
- result.store(out, header);
- // We stored the prefs to a non-default location but the spec
- // says that the dirty state is cleared so we want to store
- // them to disk at the default location as well.
- try {
- flush();
- } catch (BackingStoreException e) {
- throw new IOException(e.getMessage());
- }
- }
-
- private void convertFromProperties(Properties props) {
- IEclipsePreferences preferences = getPluginPreferences(true);
- for (Iterator i = props.keySet().iterator(); i.hasNext();) {
- String key = (String) i.next();
- String value = props.getProperty(key);
- if (value != null)
- preferences.put(key, value);
- }
- }
-
- public String toString() {
- return "PreferenceForwarder(" + pluginID + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /*
- * Convert the preferences in this node to a properties file
- * suitable for persistence.
- */
- private Properties convertToProperties() {
- Properties result = new Properties();
- String[] keys = propertyNames();
- for (int i = 0; i < keys.length; i++) {
- String key = keys[i];
- String value = getString(key);
- if (!Preferences.STRING_DEFAULT_DEFAULT.equals(value))
- result.put(key, value);
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java
index 7b25977cc..d2a76ab19 100644
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java
+++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -693,8 +693,8 @@ public class PreferencesService implements IPreferencesService, IRegistryChangeL
}
public void registryChanged(IRegistryChangeEvent event) {
- IExtensionDelta[] deltasOld = event.getExtensionDeltas(IPreferencesConstants.RUNTIME_NAME, org.eclipse.core.runtime.Preferences.PT_PREFERENCES);
- IExtensionDelta[] deltasNew = event.getExtensionDeltas(IPreferencesConstants.PREFERS_NAME, org.eclipse.core.runtime.Preferences.PT_PREFERENCES);
+ IExtensionDelta[] deltasOld = event.getExtensionDeltas(IPreferencesConstants.RUNTIME_NAME, IPreferencesConstants.PT_PREFERENCES);
+ IExtensionDelta[] deltasNew = event.getExtensionDeltas(IPreferencesConstants.PREFERS_NAME, IPreferencesConstants.PT_PREFERENCES);
IExtensionDelta[] deltas = new IExtensionDelta[deltasOld.length + deltasNew.length];
System.arraycopy(deltasOld, 0, deltas, 0, deltasOld.length);
System.arraycopy(deltasNew, 0, deltas, deltasOld.length, deltasNew.length);
@@ -1131,11 +1131,11 @@ public class PreferencesService implements IPreferencesService, IRegistryChangeL
IExtension[] extensionsOld = emptyExtensionArray;
IExtension[] extensionsNew = emptyExtensionArray;
// "old"
- IExtensionPoint pointOld = registry.getExtensionPoint(IPreferencesConstants.RUNTIME_NAME, org.eclipse.core.runtime.Preferences.PT_PREFERENCES);
+ IExtensionPoint pointOld = registry.getExtensionPoint(IPreferencesConstants.RUNTIME_NAME, IPreferencesConstants.PT_PREFERENCES);
if (pointOld != null)
extensionsOld = pointOld.getExtensions();
// "new"
- IExtensionPoint pointNew = registry.getExtensionPoint(IPreferencesConstants.PREFERS_NAME, org.eclipse.core.runtime.Preferences.PT_PREFERENCES);
+ IExtensionPoint pointNew = registry.getExtensionPoint(IPreferencesConstants.PREFERS_NAME, IPreferencesConstants.PT_PREFERENCES);
if (pointNew != null)
extensionsNew = pointNew.getExtensions();
// combine
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/runtime/Preferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/runtime/Preferences.java
deleted file mode 100644
index 8d882ce97..000000000
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/runtime/Preferences.java
+++ /dev/null
@@ -1,1284 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.runtime;
-
-import java.io.*;
-import java.util.*;
-import org.eclipse.core.internal.preferences.PreferencesService;
-import org.eclipse.core.internal.preferences.PrefsMessages;
-import org.eclipse.core.runtime.preferences.*;
-import org.eclipse.osgi.util.NLS;
-
-/**
- * A table of preference settings, mapping named properties to values. Property
- * names are non-empty strings; property values can be either booleans,
- * non-null strings, or values of one of the primitive number types.
- * The table consists of two, sparse, layers: the lower layer holds default values
- * for properties, and the upper layer holds explicitly set values for properties.
- * Normal retrieval looks for an explicitly set value for the given property in
- * the upper layer; if there is nothing for that property in the upper layer, it
- * next looks for a default value for the given property in the lower layer; if
- * there is nothing for that property in the lower layer, it returns a standard
- * default-default value. The default-default values for the primitive types are
- * as follows:
- * <ul>
- * <li><code>boolean</code> = <code>false</code></li>
- * <li><code>double</code> = <code>0.0</code></li>
- * <li><code>float</code> = <code>0.0f</code></li>
- * <li><code>int</code> = <code>0</code></li>
- * <li><code>long</code> = <code>0L</code></li>
- * <li><code>String</code> = <code>""</code> (the empty string)</li>
- * </ul>
- * <p>
- * Internally, all properties values (in both layers) are stored as strings.
- * Standard conversions to and from numeric and boolean types are performed on
- * demand.
- * </p>
- * <p>
- * The typical usage is to establish the defaults for all known properties
- * and then restore previously stored values for properties whose values
- * were explicitly set. The existing settings can be changed and new properties
- * can be set (<code>setValue</code>). If the values specified is the same as
- * the default value, the explicit setting is deleted from the top layer.
- * It is also possible to reset a property value back to the default value
- * using <code>setToDefault</code>. After the properties have been modified,
- * the properties with explicit settings are written to disk. The default values
- * are never saved. This two-tiered approach
- * to saving and restoring property setting minimizes the number of properties
- * that need to be persisted; indeed, the normal starting state does not require
- * storing any properties at all. It also makes it easy to use different
- * default settings in different environments while maintaining just those
- * property settings the user has adjusted.
- * </p>
- * <p>
- * A property change event is reported whenever a property's value actually
- * changes (either through <code>setValue</code>, <code>setToDefault</code>).
- * Note, however, that manipulating default values (with <code>setDefault</code>)
- * does not cause any events to be reported.
- * </p>
- * <p>
- * Clients may instantiate this class. This class was not designed to be
- * subclassed.
- * </p>
- * <p>
- * The implementation is based on a pair of internal
- * <code>java.util.Properties</code> objects, one holding explicitly set values
- * (set using <code>setValue</code>), the other holding the default values
- * (set using <code>setDefaultValue</code>). The <code>load</code> and
- * <code>store</code> methods persist the non-default property values to
- * streams (the default values are not saved).
- * </p>
- * <p>
- * If a client sets a default value to be equivalent to the default-default for that
- * type, the value is still known to the preference store as having a default value.
- * That is, the name will still be returned in the result of the <code>defaultPropertyNames</code>
- * and <code>contains</code> methods.
- * </p>
- *
- * @since 2.0
- */
-public class Preferences {
-
- /**
- * The default-default value for boolean properties (<code>false</code>).
- */
- public static final boolean BOOLEAN_DEFAULT_DEFAULT = false;
-
- /**
- * The default-default value for double properties (<code>0.0</code>).
- */
- public static final double DOUBLE_DEFAULT_DEFAULT = 0.0;
-
- /**
- * The default-default value for float properties (<code>0.0f</code>).
- */
- public static final float FLOAT_DEFAULT_DEFAULT = 0.0f;
-
- /**
- * The default-default value for int properties (<code>0</code>).
- */
- public static final int INT_DEFAULT_DEFAULT = 0;
-
- /**
- * The default-default value for long properties (<code>0L</code>).
- */
- public static final long LONG_DEFAULT_DEFAULT = 0L;
-
- /**
- * The default-default value for String properties (<code>""</code>).
- */
- public static final String STRING_DEFAULT_DEFAULT = ""; //$NON-NLS-1$
-
- /**
- * The string representation used for <code>true</code>
- * (<code>"true"</code>).
- */
- protected static final String TRUE = "true"; //$NON-NLS-1$
-
- /**
- * The string representation used for <code>false</code>
- * (<code>"false"</code>).
- */
- protected static final String FALSE = "false"; //$NON-NLS-1$
-
- /**
- * Singleton empty string array (optimization)
- */
- private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
- /**
- * The simple identifier constant (value "<code>preferences</code>") of
- * the extension point of the Core Runtime plug-in where plug-ins declare
- * extensions to the preference facility. A plug-in may define any number
- * of preference extensions.
- *
- * @since org.eclipse.equinox.preferences 1.0
- */
- public static final String PT_PREFERENCES = "preferences"; //$NON-NLS-1$
-
- /**
- * The name of the file (value <code>"preferences.ini"</code>) in a
- * plug-in's (read-only) directory that, when present, contains values that
- * override the normal default values for this plug-in's preferences.
- * <p>
- * The format of the file is as per <code>java.io.Properties</code> where
- * the keys are property names and values are strings.
- * </p>
- *
- * @since 3.3
- */
- public static final String PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME = "preferences"; //$NON-NLS-1$
- public static final String PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME = PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME + ".ini"; //$NON-NLS-1$
-
- /**
- * An event object describing a change to a named property.
- * <p>
- * The preferences object reports property change events for internal state
- * changes that may be of interest to external parties. A special listener
- * interface (<code>Preferences.IPropertyChangeListener</code>) is
- * defined for this purpose. Listeners are registered via the
- * <code>Preferences.addPropertyChangeListener</code> method.
- * </p>
- * <p>
- * Clients cannot instantiate or subclass this class.
- * </p>
- *
- * @see Preferences#addPropertyChangeListener(Preferences.IPropertyChangeListener)
- * @see Preferences.IPropertyChangeListener
- */
- public static class PropertyChangeEvent extends EventObject {
- /**
- * All serializable objects should have a stable serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * The name of the changed property.
- */
- private String propertyName;
-
- /**
- * The old value of the changed property, or <code>null</code> if
- * not known or not relevant.
- */
- private Object oldValue;
-
- /**
- * The new value of the changed property, or <code>null</code> if
- * not known or not relevant.
- */
- private Object newValue;
-
- /**
- * Creates a new property change event.
- *
- * @param source the object whose property has changed
- * @param property the property that has changed (must not be
- * <code>null</code>)
- * @param oldValue the old value of the property, or
- * <code>null</code> if none
- * @param newValue the new value of the property, or
- * <code>null</code> if none
- */
- protected PropertyChangeEvent(Object source, String property, Object oldValue, Object newValue) {
-
- super(source);
- if (property == null) {
- throw new IllegalArgumentException();
- }
- this.propertyName = property;
- this.oldValue = oldValue;
- this.newValue = newValue;
- }
-
- /**
- * Returns the name of the property that changed.
- * <p>
- * Warning: there is no guarantee that the property name returned
- * is a constant string. Callers must compare property names using
- * <code>equals</code>, not ==.
- *</p>
- *
- * @return the name of the property that changed
- */
- public String getProperty() {
- return propertyName;
- }
-
- /**
- * Returns the new value of the property.
- *
- * @return the new value, or <code>null</code> if not known
- * or not relevant
- */
- public Object getNewValue() {
- return newValue;
- }
-
- /**
- * Returns the old value of the property.
- *
- * @return the old value, or <code>null</code> if not known
- * or not relevant
- */
- public Object getOldValue() {
- return oldValue;
- }
- }
-
- /**
- * Listener for property changes.
- * <p>
- * Usage:
- * <pre>
- * Preferences.IPropertyChangeListener listener =
- * new Preferences.IPropertyChangeListener() {
- * public void propertyChange(Preferences.PropertyChangeEvent event) {
- * ... // code to deal with occurrence of property change
- * }
- * };
- * emitter.addPropertyChangeListener(listener);
- * ...
- * emitter.removePropertyChangeListener(listener);
- * </pre>
- * </p>
- * <p>
- * <em>Note:</em> Depending on the means in which the property
- * values changed, the old and new values for the property can
- * be either typed, a string representation of the value, or <code>null</code>.
- * Clients who wish to behave properly in all cases should all
- * three cases in their implementation of the property change listener.
- * </p>
- */
- public interface IPropertyChangeListener extends EventListener {
-
- /**
- * Notification that a property has changed.
- * <p>
- * This method gets called when the observed object fires a property
- * change event.
- * </p>
- *
- * @param event the property change event object describing which
- * property changed and how
- */
- public void propertyChange(Preferences.PropertyChangeEvent event);
- }
-
- /**
- * List of registered listeners (element type:
- * <code>IPropertyChangeListener</code>).
- * These listeners are to be informed when the current value of a property
- * changes.
- */
- protected ListenerList listeners = new ListenerList();
-
- /**
- * The mapping from property name to
- * property value (represented as strings).
- */
- private Properties properties;
-
- /**
- * The mapping from property name to
- * default property value (represented as strings);
- * <code>null</code> if none.
- */
- private Properties defaultProperties;
-
- /**
- * Indicates whether a value has been changed by <code>setToDefault</code>
- * or <code>setValue</code>; initially <code>false</code>.
- */
- protected boolean dirty = false;
-
- /**
- * Exports all non-default-valued preferences for all installed plugins to the
- * provided file. If a file already exists at the given location, it will be deleted.
- * If there are no preferences to export, no file will be written.
- * <p>
- * The file that is written can be read later using the importPreferences method.
- * </p>
- * @param path The absolute file system path of the file to export preferences to.
- * @exception CoreException if this method fails. Reasons include:
- * <ul>
- * <li> The file could not be written.</li>
- * </ul>
- * @see #importPreferences(IPath)
- * @see #validatePreferenceVersions(IPath)
- */
- public static void exportPreferences(IPath path) throws CoreException {
- File file = path.toFile();
- if (file.exists())
- file.delete();
- file.getParentFile().mkdirs();
- IPreferencesService service = PreferencesService.getDefault();
- OutputStream output = null;
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(file);
- output = new BufferedOutputStream(fos);
- IEclipsePreferences node = (IEclipsePreferences) service.getRootNode().node(InstanceScope.SCOPE);
- service.exportPreferences(node, output, (String[]) null);
- output.flush();
- fos.getFD().sync();
- } catch (IOException e) {
- String message = NLS.bind(PrefsMessages.preferences_errorWriting, file, e.getMessage());
- IStatus status = new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, IStatus.ERROR, message, e);
- throw new CoreException(status);
- } finally {
- if (output != null)
- try {
- output.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
-
- /**
- * Loads the plugin preferences from the given file, and replaces all
- * non-default-valued preferences for all plugins with the values from this file.
- * <p>
- * If the file contains preferences for plug-ins that don't exist in the current
- * install, they are ignored. This method does not validate if the plug-in
- * versions in the preference file match the currently installed plug-ins.
- * Clients should first call validatePreferenceVersions on the file to ensure
- * that the versions are compatible.
- * </p>
- * <p>
- * The file must have been written by the exportPreferences method.
- * </p>
- * @param path The absolute file system path of the file to import preferences from.
- * @exception CoreException if this method fails. Reasons include:
- * <ul>
- * <li> The file does not exist.</li>
- * <li> The file could not be read.</li>
- * </ul>
- * @see #exportPreferences(IPath)
- * @see #validatePreferenceVersions(IPath)
- */
- public static void importPreferences(IPath path) throws CoreException {
- if (!path.toFile().exists()) {
- String msg = NLS.bind(PrefsMessages.preferences_fileNotFound, path.toOSString());
- throw new CoreException(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, 1, msg, null));
- }
- IPreferencesService service = PreferencesService.getDefault();
- InputStream input = null;
- try {
- input = new BufferedInputStream(new FileInputStream(path.toFile()));
- service.importPreferences(input);
- } catch (FileNotFoundException e) {
- String msg = NLS.bind(PrefsMessages.preferences_fileNotFound, path.toOSString());
- throw new CoreException(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, 1, msg, e));
- } finally {
- if (input != null)
- try {
- input.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
-
- /**
- * Validates that the preference versions in the given file match the versions
- * of the currently installed plugins. Returns an OK status if all preferences match
- * the currently installed plugins, otherwise a MultiStatus describing what
- * plugins have preferences that don't match.
- * <p>
- * If the returned status has a <code>IStatus.WARNING</code> severity,
- * it means that some preferences may not be applicable but for the most
- * part they will be compatible. If the returned status has a
- * <code>IStatus.ERROR</code> severity, it means that the preferences
- * will probably not be compatible.
- * <p>
- * If the file contains preferences for plug-ins that don't exist in the current
- * install, they are ignored.
- * </p>
- * <p>
- * The file must have been written by the exportPreferences method.
- * </p>
- * @param file The absolute file system path of the preference file to validate.
- * @see #exportPreferences(IPath)
- * @see #importPreferences(IPath)
- */
- public static IStatus validatePreferenceVersions(IPath file) {
- PreferencesService service = PreferencesService.getDefault();
- return service.validateVersions(file);
- }
-
- /**
- * Creates an empty preference table.
- * <p>
- * Use the methods <code>load(InputStream)</code> and
- * <code>store(InputStream)</code> to load and store these preferences.
- * </p>
- * @see #load(InputStream)
- * @see #store(OutputStream, String)
- */
- public Preferences() {
- defaultProperties = new Properties();
- properties = new Properties(defaultProperties);
- }
-
- /**
- * Adds a property change listener to this preference object.
- * Has no affect if the identical listener is already registered.
- * <p>
- * <em>Note:</em> Depending on the means in which the property
- * values changed, the old and new values for the property can
- * be either typed, a string representation of the value, or <code>null</code>.
- * Clients who wish to behave properly in all cases should all
- * three cases in their implementation of the property change listener.
- * </p>
- * @param listener a property change listener
- */
- public void addPropertyChangeListener(IPropertyChangeListener listener) {
- listeners.add(listener);
- }
-
- /**
- * Removes the given listener from this preference object.
- * Has no affect if the listener is not registered.
- *
- * @param listener a property change listener
- */
- public void removePropertyChangeListener(IPropertyChangeListener listener) {
- listeners.remove(listener);
- }
-
- /**
- * Returns whether the given property is known to this preference object,
- * either by having an explicit setting or by having a default
- * setting. Returns <code>false</code> if the given name is <code>null</code>.
- *
- * @param name the name of the property, or <code>null</code>
- * @return <code>true</code> if either a current value or a default
- * value is known for the named property, and <code>false</code>otherwise
- */
- public boolean contains(String name) {
- return (properties.containsKey(name) || defaultProperties.containsKey(name));
- }
-
- /**
- * Fires a property change event corresponding to a change to the
- * current value of the property with the given name.
- *
- * @param name the name of the property, to be used as the property
- * in the event object
- * @param oldValue the old value, or <code>null</code> if not known or not
- * relevant
- * @param newValue the new value, or <code>null</code> if not known or not
- * relevant
- */
- protected void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
- if (name == null)
- throw new IllegalArgumentException();
- Object[] changeListeners = this.listeners.getListeners();
- // Do we even need to fire an event?
- if (changeListeners.length == 0)
- return;
- final PropertyChangeEvent pe = new PropertyChangeEvent(this, name, oldValue, newValue);
- for (int i = 0; i < changeListeners.length; ++i) {
- final IPropertyChangeListener l = (IPropertyChangeListener) changeListeners[i];
- ISafeRunnable job = new ISafeRunnable() {
- public void handleException(Throwable exception) {
- // already being logged in Platform#run()
- }
-
- public void run() throws Exception {
- l.propertyChange(pe);
- }
- };
- SafeRunner.run(job);
- }
- }
-
- /**
- * Returns the current value of the boolean-valued property with the
- * given name.
- * Returns the default-default value (<code>false</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a boolean.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the boolean-valued property
- */
- public boolean getBoolean(String name) {
- String value = properties.getProperty(name);
- if (value == null) {
- return BOOLEAN_DEFAULT_DEFAULT;
- }
- return value.equals(Preferences.TRUE);
- }
-
- /**
- * Sets the current value of the boolean-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, boolean value) {
- boolean defaultValue = getDefaultBoolean(name);
- boolean oldValue = getBoolean(name);
- if (value == defaultValue) {
- Object removed = properties.remove(name);
- if (removed != null) {
- // removed an explicit setting
- dirty = true;
- }
- } else {
- properties.put(name, value ? Preferences.TRUE : Preferences.FALSE);
- }
- if (oldValue != value) {
- // mark as dirty since value did really change
- dirty = true;
- // report property change if getValue now returns different value
- firePropertyChangeEvent(name, oldValue ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
- }
- }
-
- /**
- * Returns the default value for the boolean-valued property
- * with the given name.
- * Returns the default-default value (<code>false</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a boolean.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public boolean getDefaultBoolean(String name) {
- String value = defaultProperties.getProperty(name);
- if (value == null) {
- return BOOLEAN_DEFAULT_DEFAULT;
- }
- return value.equals(Preferences.TRUE);
- }
-
- /**
- * Sets the default value for the boolean-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, boolean value) {
- defaultProperties.put(name, value ? Preferences.TRUE : Preferences.FALSE);
- }
-
- /**
- * Returns the current value of the double-valued property with the
- * given name.
- * Returns the default-default value (<code>0.0</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a double.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the double-valued property
- */
- public double getDouble(String name) {
- return convertToDouble(properties.getProperty(name), DOUBLE_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the current value of the double-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property; must be
- * a number (not a NaN)
- */
- public void setValue(String name, double value) {
- if (Double.isNaN(value)) {
- throw new IllegalArgumentException();
- }
- double defaultValue = getDefaultDouble(name);
- double oldValue = getDouble(name);
- if (value == defaultValue) {
- Object removed = properties.remove(name);
- if (removed != null) {
- // removed an explicit setting
- dirty = true;
- }
- } else {
- properties.put(name, Double.toString(value));
- }
- if (oldValue != value) {
- // mark as dirty since value did really change
- dirty = true;
- // report property change if getValue now returns different value
- firePropertyChangeEvent(name, new Double(oldValue), new Double(value));
- }
- }
-
- /**
- * Returns the default value for the double-valued property
- * with the given name.
- * Returns the default-default value (<code>0.0</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a double.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public double getDefaultDouble(String name) {
- return convertToDouble(defaultProperties.getProperty(name), DOUBLE_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the double-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property; must be
- * a number (not a NaN)
- */
- public void setDefault(String name, double value) {
- if (Double.isNaN(value)) {
- throw new IllegalArgumentException();
- }
- defaultProperties.put(name, Double.toString(value));
- }
-
- /**
- * Converts the given raw property value string to a double.
- *
- * @param rawPropertyValue the raw property value, or <code>null</code>
- * if none
- * @param defaultValue the default value
- * @return the raw value converted to a double, or the given
- * <code>defaultValue</code> if the raw value is <code>null</code> or
- * cannot be parsed as a double
- */
- private double convertToDouble(String rawPropertyValue, double defaultValue) {
- double result = defaultValue;
- if (rawPropertyValue != null) {
- try {
- result = Double.parseDouble(rawPropertyValue);
- } catch (NumberFormatException e) {
- // raw value cannot be treated as one of these
- }
- }
- return result;
- }
-
- /**
- * Returns the current value of the float-valued property with the
- * given name.
- * Returns the default-default value (<code>0.0f</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a float.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the float-valued property
- */
- public float getFloat(String name) {
- return convertToFloat(properties.getProperty(name), FLOAT_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the current value of the float-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property; must be
- * a number (not a NaN)
- */
- public void setValue(String name, float value) {
- if (Float.isNaN(value)) {
- throw new IllegalArgumentException();
- }
- float defaultValue = getDefaultFloat(name);
- float oldValue = getFloat(name);
- if (value == defaultValue) {
- Object removed = properties.remove(name);
- if (removed != null) {
- // removed an explicit setting
- dirty = true;
- }
- } else {
- properties.put(name, Float.toString(value));
- }
- if (oldValue != value) {
- // mark as dirty since value did really change
- dirty = true;
- // report property change if getValue now returns different value
- firePropertyChangeEvent(name, new Float(oldValue), new Float(value));
- }
- }
-
- /**
- * Returns the default value for the float-valued property
- * with the given name.
- * Returns the default-default value (<code>0.0f</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a float.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public float getDefaultFloat(String name) {
- return convertToFloat(defaultProperties.getProperty(name), FLOAT_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the float-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property; must be
- * a number (not a NaN)
- */
- public void setDefault(String name, float value) {
- if (Float.isNaN(value)) {
- throw new IllegalArgumentException();
- }
- defaultProperties.put(name, Float.toString(value));
- }
-
- /**
- * Converts the given raw property value string to a float.
- *
- * @param rawPropertyValue the raw property value, or <code>null</code>
- * if none
- * @param defaultValue the default value
- * @return the raw value converted to a float, or the given
- * <code>defaultValue</code> if the raw value is <code>null</code> or
- * cannot be parsed as a float
- */
- private float convertToFloat(String rawPropertyValue, float defaultValue) {
- float result = defaultValue;
- if (rawPropertyValue != null) {
- try {
- result = Float.parseFloat(rawPropertyValue);
- } catch (NumberFormatException e) {
- // raw value cannot be treated as one of these
- }
- }
- return result;
- }
-
- /**
- * Returns the current value of the integer-valued property with the
- * given name.
- * Returns the default-default value (<code>0</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as an integer.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the int-valued property
- */
- public int getInt(String name) {
- return convertToInt(properties.getProperty(name), INT_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the current value of the integer-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, int value) {
- int defaultValue = getDefaultInt(name);
- int oldValue = getInt(name);
- if (value == defaultValue) {
- Object removed = properties.remove(name);
- if (removed != null) {
- // removed an explicit setting
- dirty = true;
- }
- } else {
- properties.put(name, Integer.toString(value));
- }
- if (oldValue != value) {
- // mark as dirty since value did really change
- dirty = true;
- // report property change if getValue now returns different value
- firePropertyChangeEvent(name, new Integer(oldValue), new Integer(value));
- }
- }
-
- /**
- * Returns the default value for the integer-valued property
- * with the given name.
- * Returns the default-default value (<code>0</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as an integer.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public int getDefaultInt(String name) {
- return convertToInt(defaultProperties.getProperty(name), INT_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the integer-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, int value) {
- defaultProperties.put(name, Integer.toString(value));
- }
-
- /**
- * Converts the given raw property value string to an int.
- *
- * @param rawPropertyValue the raw property value, or <code>null</code>
- * if none
- * @param defaultValue the default value
- * @return the raw value converted to an int, or the given
- * <code>defaultValue</code> if the raw value is <code>null</code> or
- * cannot be parsed as an int
- */
- private int convertToInt(String rawPropertyValue, int defaultValue) {
- int result = defaultValue;
- if (rawPropertyValue != null) {
- try {
- result = Integer.parseInt(rawPropertyValue);
- } catch (NumberFormatException e) {
- // raw value cannot be treated as one of these
- }
- }
- return result;
- }
-
- /**
- * Returns the current value of the long-valued property with the
- * given name.
- * Returns the default-default value (<code>0L</code>) if there
- * is no property with the given name, or if the current value
- * cannot be treated as a long.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the long-valued property
- */
- public long getLong(String name) {
- return convertToLong(properties.getProperty(name), LONG_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the current value of the long-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, long value) {
- long defaultValue = getDefaultLong(name);
- long oldValue = getLong(name);
- if (value == defaultValue) {
- Object removed = properties.remove(name);
- if (removed != null) {
- // removed an explicit setting
- dirty = true;
- }
- } else {
- properties.put(name, Long.toString(value));
- }
- if (oldValue != value) {
- // mark as dirty since value did really change
- dirty = true;
- // report property change if getValue now returns different value
- firePropertyChangeEvent(name, new Long(oldValue), new Long(value));
- }
- }
-
- /**
- * Returns the default value for the long-valued property
- * with the given name.
- * Returns the default-default value (<code>0L</code>) if there
- * is no default property with the given name, or if the default
- * value cannot be treated as a long.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public long getDefaultLong(String name) {
- return convertToLong(defaultProperties.getProperty(name), LONG_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the long-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, long value) {
- defaultProperties.put(name, Long.toString(value));
- }
-
- /**
- * Converts the given raw property value string to a long.
- *
- * @param rawPropertyValue the raw property value, or <code>null</code>
- * if none
- * @param defaultValue the default value
- * @return the raw value converted to a long, or the given
- * <code>defaultValue</code> if the raw value is <code>null</code> or
- * cannot be parsed as a long
- */
- private long convertToLong(String rawPropertyValue, long defaultValue) {
- long result = defaultValue;
- if (rawPropertyValue != null) {
- try {
- result = Long.parseLong(rawPropertyValue);
- } catch (NumberFormatException e) {
- // raw value cannot be treated as one of these
- }
- }
- return result;
- }
-
- /**
- * Returns the current value of the string-valued property with the
- * given name.
- * Returns the default-default value (the empty string <code>""</code>)
- * if there is no property with the given name.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the string-valued property
- */
- public String getString(String name) {
- String value = properties.getProperty(name);
- return (value != null ? value : STRING_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the current value of the string-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * A property change event is reported if the current value of the
- * property actually changes from its previous value. In the event
- * object, the property name is the name of the property, and the
- * old and new values are wrapped as objects.
- * </p>
- * <p>
- * If the given value is the same as the corresponding default value
- * for the given property, the explicit setting is deleted.
- * Note that the recommended way of re-initializing a property to its
- * default value is to call <code>setToDefault</code>.
- * </p>
- *
- * @param name the name of the property
- * @param value the new current value of the property
- */
- public void setValue(String name, String value) {
- if (value == null) {
- throw new IllegalArgumentException();
- }
- String defaultValue = getDefaultString(name);
- String oldValue = getString(name);
- if (value.equals(defaultValue)) {
- Object removed = properties.remove(name);
- if (removed != null) {
- // removed an explicit setting
- dirty = true;
- }
- } else {
- properties.put(name, value);
- }
- if (!oldValue.equals(value)) {
- // mark as dirty since value did really change
- dirty = true;
- // report property change if getValue now returns different value
- firePropertyChangeEvent(name, oldValue, value);
- }
- }
-
- /**
- * Returns the default value for the string-valued property
- * with the given name.
- * Returns the default-default value (the empty string <code>""</code>)
- * is no default property with the given name, or if the default
- * value cannot be treated as a string.
- * The given name must not be <code>null</code>.
- *
- * @param name the name of the property
- * @return the default value of the named property
- */
- public String getDefaultString(String name) {
- String value = defaultProperties.getProperty(name);
- return (value != null ? value : STRING_DEFAULT_DEFAULT);
- }
-
- /**
- * Sets the default value for the string-valued property with the
- * given name. The given name must not be <code>null</code>.
- * <p>
- * Note that the current value of the property is affected if
- * the property's current value was its old default value, in which
- * case it changes to the new default value. If the property's current
- * is different from its old default value, its current value is
- * unaffected. No property change events are reported by changing default
- * values.
- * </p>
- *
- * @param name the name of the property
- * @param value the new default value for the property
- */
- public void setDefault(String name, String value) {
- if (value == null) {
- throw new IllegalArgumentException();
- }
- defaultProperties.put(name, value);
- }
-
- /**
- * Returns whether the property with the given name has the default value in
- * virtue of having no explicitly set value.
- * Returns <code>false</code> if the given name is <code>null</code>.
- *
- * @param name the name of the property, or <code>null</code>
- * @return <code>true</code> if the property has no explicitly set value,
- * and <code>false</code> otherwise (including the case where the property
- * is unknown to this object)
- */
- public boolean isDefault(String name) {
- return !properties.containsKey(name);
- }
-
- /**
- * Sets the current value of the property with the given name back
- * to its default value. Has no effect if the property does not have
- * its own current value. The given name must not be <code>null</code>.
- * <p>
- * Note that the recommended way of re-initializing a property to the
- * appropriate default value is to call <code>setToDefault</code>.
- * This is implemented by removing the named value from the object,
- * thereby exposing the default value.
- * </p>
- * <p>
- * A property change event is always reported. In the event
- * object, the property name is the name of the property, and the
- * old and new values are either strings, or <code>null</code>
- * indicating the default-default value.
- * </p>
- *
- * @param name the name of the property
- */
- public void setToDefault(String name) {
- Object oldPropertyValue = properties.remove(name);
- if (oldPropertyValue != null) {
- dirty = true;
- }
- String newValue = defaultProperties.getProperty(name, null);
- // n.b. newValue == null if there is no default value
- // can't determine correct default-default without knowing type
- firePropertyChangeEvent(name, oldPropertyValue, newValue);
- }
-
- /**
- * Returns a list of all properties known to this preference object which
- * have current values other than their default value.
- *
- * @return an array of property names
- */
- public String[] propertyNames() {
- return (String[]) properties.keySet().toArray(EMPTY_STRING_ARRAY);
- }
-
- /**
- * Returns a list of all properties known to this preference object which
- * have an explicit default value set.
- *
- * @return an array of property names
- */
- public String[] defaultPropertyNames() {
- return (String[]) defaultProperties.keySet().toArray(EMPTY_STRING_ARRAY);
- }
-
- /**
- * Returns whether the current values in this preference object
- * require saving.
- *
- * @return <code>true</code> if at least one of the properties
- * known to this preference object has a current value different from its
- * default value, and <code>false</code> otherwise
- */
- public boolean needsSaving() {
- return dirty;
- }
-
- /**
- * Saves the non-default-valued properties known to this preference object to
- * the given output stream using
- * <code>Properties.store(OutputStream,String)</code>.
- * <p>
- * Note that the output is unconditionally written, even when
- * <code>needsSaving</code> is <code>false</code>.
- * </p>
- *
- * @param out the output stream
- * @param header a comment to be included in the output, or
- * <code>null</code> if none
- * @exception IOException if there is a problem saving this preference object
- * @see Properties#store(OutputStream,String)
- */
- public void store(OutputStream out, String header) throws IOException {
- properties.store(out, header);
- dirty = false;
- }
-
- /**
- * Loads the non-default-valued properties for this preference object from the
- * given input stream using
- * <code>java.util.Properties.load(InputStream)</code>. Default property
- * values are not affected.
- *
- * @param in the input stream
- * @exception IOException if there is a problem loading this preference
- * object
- * @see java.util.Properties#load(InputStream)
- */
- public void load(InputStream in) throws IOException {
- properties.load(in);
- dirty = false;
- }
-}

Back to the top