Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2014-01-16 13:20:34 +0000
committervlorenzo2014-01-16 13:20:34 +0000
commit8827db18d0f8ebbf2e6076411aa3cfca47baf7b9 (patch)
tree49e4cca55eae6586d1c392848f85001327add9e3 /plugins
parent3a2bb8601d70fb36947a0e86d9c47b90cfd5676e (diff)
downloadorg.eclipse.papyrus-8827db18d0f8ebbf2e6076411aa3cfca47baf7b9.tar.gz
org.eclipse.papyrus-8827db18d0f8ebbf2e6076411aa3cfca47baf7b9.tar.xz
org.eclipse.papyrus-8827db18d0f8ebbf2e6076411aa3cfca47baf7b9.zip
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusPreferenceStore.java213
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusScopedPreferenceStore.java786
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/Messages.java4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/messages.properties2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/AbstractPreferenceKeyDialog.java1
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/ApplyValueOnPreferenceKeyDialog.java174
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java8
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties4
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/AbstractPapyrusPreferenceStore.java291
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/PapyrusScopedPreferenceStore.java859
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractApplyValueOnPreferenceKeyDialog.java71
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractPreferenceKeyDialog.java103
14 files changed, 1509 insertions, 1012 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/META-INF/MANIFEST.MF
index ddd4da4ec3f..0e16460ab91 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/META-INF/MANIFEST.MF
@@ -3,7 +3,8 @@ Require-Bundle: org.eclipse.gmf.runtime.diagram.ui.properties,
org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
org.eclipse.jface,
com.ibm.icu,
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1"
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1",
+ org.eclipse.papyrus.infra.tools;bundle-version="0.10.1"
Export-Package: org.eclipse.papyrus.infra.gmfdiag.preferences,
org.eclipse.papyrus.infra.gmfdiag.preferences.initializer,
org.eclipse.papyrus.infra.gmfdiag.preferences.jface.preference;x-internal:=true,
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusPreferenceStore.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusPreferenceStore.java
index 9aa7376e7c5..4b982b4cf8d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusPreferenceStore.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusPreferenceStore.java
@@ -13,239 +13,58 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.preferences;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper;
import org.eclipse.papyrus.infra.gmfdiag.preferences.ui.dialog.ApplyValueOnPreferenceKeyDialog;
+import org.eclipse.papyrus.infra.tools.preferences.AbstractPapyrusPreferenceStore;
+import org.eclipse.papyrus.infra.tools.preferences.ui.dialog.AbstractApplyValueOnPreferenceKeyDialog;
/**
* this class is a specific store that is used to look for value of element
* by taking account the structure of preferences : papyrus editor-> Diagram -> Elements of Diagram
*
*/
-public class PapyrusPreferenceStore extends PapyrusScopedPreferenceStore {
+public class PapyrusPreferenceStore extends AbstractPapyrusPreferenceStore {
/**
- * this method is used to overload all value under a level of preferences.
- * In order to overload a pop-up is opened, and the user can choose value to overload
*
- * @param level
- * of preference: Editor or diagram
- */
-
- public void deleteAllSubPreference(String level) {
- //remove all sub value diagram+ element
- ArrayList<String> keytoRemove = new ArrayList<String>();
- //key to collect
- ArrayList<String> elementKey = new ArrayList<String>();
- try {
- for(int i = 0; i < getStorePreferences().keys().length; i++) {
- //level diagram collect only element
- if(level.startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
- if(getStorePreferences().keys()[i].startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) {
- elementKey.add(getStorePreferences().keys()[i]);
- }
- }
- //editor level, collect all element+diagram
- else if(level.startsWith(PreferencesConstantsHelper.PAPYRUS_EDITOR_PREFERENCE_PREFIX)) {
- if((getStorePreferences().keys()[i].startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) || (getStorePreferences().keys()[i].startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX))) {
- elementKey.add(getStorePreferences().keys()[i]);
- }
- }
-
- }
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
- if(elementKey.size() > 0) {
- String[] keyRoconsult = new String[elementKey.size()];
- ApplyValueOnPreferenceKeyDialog dialog = new ApplyValueOnPreferenceKeyDialog(elementKey.toArray(keyRoconsult));
- dialog.open();
- keytoRemove = dialog.getKeyToRemove();
-
- //remove key
- Iterator<String> iterator = keytoRemove.iterator();
- while(iterator.hasNext()) {
- String key = (String)iterator.next();
- getStorePreferences().remove(key);
- }
- }
- }
-
-
- /**
- * constructor
+ * Constructor.
*
* @param context
- * the scope to store to
* @param qualifier
- * the qualifier used to look up the preference node
- */
- public PapyrusPreferenceStore(IScopeContext context, String qualifier) {
- super(context, qualifier);
- }
-
- /**
- * constructor
- *
- * @param context
- * the scope to store to
- * @param qualifier
- * the qualifier used to look up the preference node
* @param defaultQualifierPath
- * the qualifier used when looking up the defaults
*/
public PapyrusPreferenceStore(IScopeContext context, String qualifier, String defaultQualifierPath) {
- super(context, qualifier, defaultQualifierPath);
+ super(context, qualifier, defaultQualifierPath, PreferencesConstantsHelper.PAPYRUS_EDITOR_PREFERENCE_PREFIX, PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX, PreferencesConstantsHelper.DIAGRAM_ELEMENT);
}
- // each get value will be overloaded
- //if not value is found for an element, a value is look for in DIAGRAM
- // if a the value is not find for Diagram a value is find for Papyrus editor
-
/**
- * this method is used to find a key that a got a value:
- * if the key is an element. The method look for if this key exist. If no value exists, it look for the key for diagram
- * if the key for diagram do not exist it look for key for papyrus Editor
- * the structure of Key is:
- * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
- * Diagram : DIAGRAM_DiagramKind.preferenceKind
- * Editor: PAPYRUS_EDITOR.preferenceKind
*
- */
- protected String findKeyWithAValue(String initialKey) {
- String foundedKey = null;
- //first look for in value stack
- foundedKey = findKeyAStoreValue(initialKey);
- //then look for in default stack
- if(foundedKey == null) {
- foundedKey = findKeyWithADefaultValue(initialKey);
- }
- if(foundedKey == null) {
- foundedKey = initialKey;
- }
- return foundedKey;
-
- }
-
- /**
- * look for a key with a value in the store stack
+ * Constructor.
*
- * @param initialKey
- * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
- * Diagram : DIAGRAM_DiagramKind.preferenceKind
- * Editor: PAPYRUS_EDITOR.preferenceKind
- * @return the key that returns a value or null if there is no value
+ * @param context
+ * @param qualifier
*/
- protected String findKeyAStoreValue(String initialKey) {
- String foundedKey = null;
- if(getStorePreferences().get(initialKey, null) != null) {
- foundedKey = initialKey;
- }
-
- if(foundedKey == null && hasPrefix(initialKey)) {
- foundedKey = findKeyAStoreValue(getUpperKey(initialKey));
- }
- return foundedKey;
+ public PapyrusPreferenceStore(IScopeContext context, String qualifier) {
+ super(context, qualifier, PreferencesConstantsHelper.PAPYRUS_EDITOR_PREFERENCE_PREFIX, PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX, PreferencesConstantsHelper.DIAGRAM_ELEMENT);
}
- /**
- * this method is used to find a key that a got a value:
- * if the key is an element. The method look for if this key exist. If no value exists, it look for the key for diagram
- * if the key for diagram do not exist it look for key for papyrus Editor
- * the structure of Key is:
- * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
- * Diagram : DIAGRAM_DiagramKind.preferenceKind
- * Editor: PAPYRUS_EDITOR.preferenceKind
- *
- */
- protected String findKeyWithADefaultValue(String initialKey) {
- String foundedKey = null;
-
- if(getDefaultPreferences().get(initialKey, null) != null) {
- foundedKey = initialKey;
- }
-
- if(foundedKey == null && hasPrefix(initialKey)) {
- return findKeyWithADefaultValue(getUpperKey(initialKey));
- } else {
- foundedKey = initialKey;
- }
- return foundedKey;
-
- }
/**
- * get the upper Key from the initial Key
- * * the structure of Key is:
- * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
- * Diagram : DIAGRAM_DiagramKind.preferenceKind
- * Editor: PAPYRUS_EDITOR.preferenceKind
*
- * @param initialKey
- * @return the upperKey
+ * @see org.eclipse.papyrus.infra.tools.preferences.AbstractPapyrusPreferenceStore#createPreferenceKeyDialog(java.lang.String[])
*
+ * @param keys
+ * @return
*/
- protected String getUpperKey(String initialKey) {
-
- String out = initialKey.toString();
- if(initialKey.startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) {
- out = initialKey.toString().replaceAll(PreferencesConstantsHelper.DIAGRAM_ELEMENT, PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX);
- out = out.substring(0, out.lastIndexOf("_")) + out.substring(out.indexOf("."), out.length());
- }
- if(initialKey.startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
- // out=initialKey.toString().replaceAll(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX, PreferencesConstantsHelper.PAPYRUS_EDITOR_PREFERENCE_PREFIX);
- out = PreferencesConstantsHelper.PAPYRUS_EDITOR_PREFERENCE_PREFIX + out.substring(out.indexOf("."), out.length());
- }
- return out;
+ @Override
+ protected AbstractApplyValueOnPreferenceKeyDialog createPreferenceKeyDialog(String[] keys) {
+ return new ApplyValueOnPreferenceKeyDialog(keys);
}
- protected boolean hasPrefix(String key) {
- if(key.startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT) || key.startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
- return true;
- }
- return false;
- }
- /**
- * get the value from a key
- *
- * @param key
- * @return the value
- */
- protected String internalGet(String key) {
- String newKey = findKeyWithAValue(key);
- //System.err.println("-->Initial Key "+key+"--> "+ newKey);
- return Platform.getPreferencesService().get(newKey, null, getPreferenceNodes(true));
- }
-
- public boolean getDefaultBoolean(String name) {
-
- return super.getDefaultBoolean(findKeyWithADefaultValue(name));
- }
- public double getDefaultDouble(String name) {
- return super.getDefaultDouble(findKeyWithADefaultValue(name));
- }
-
- public float getDefaultFloat(String name) {
- return super.getDefaultFloat(findKeyWithADefaultValue(name));
- };
-
- public int getDefaultInt(String name) {
- return super.getDefaultInt(findKeyWithADefaultValue(name));
- }
- public long getDefaultLong(String name) {
- return super.getDefaultLong(findKeyWithADefaultValue(name));
- }
- public String getDefaultString(String name) {
- return super.getDefaultString(findKeyWithADefaultValue(name));
- }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusScopedPreferenceStore.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusScopedPreferenceStore.java
index f64d6a84c30..1d2311f99cd 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusScopedPreferenceStore.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/PapyrusScopedPreferenceStore.java
@@ -32,27 +32,7 @@ package org.eclipse.papyrus.infra.gmfdiag.preferences;
*
*******************************************************************************/
-import java.io.IOException;
-
-import org.eclipse.core.commands.common.EventManager;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.IScopeContext;
-import org.eclipse.jface.preference.IPersistentPreferenceStore;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.ui.internal.WorkbenchMessages;
-import org.osgi.service.prefs.BackingStoreException;
/**
* The ScopedPreferenceStore is an IPreferenceStore that uses the scopes
@@ -67,53 +47,10 @@ import org.osgi.service.prefs.BackingStoreException;
* @see org.eclipse.core.runtime.preferences
* @since 3.1
*/
-public class PapyrusScopedPreferenceStore extends EventManager implements IPreferenceStore, IPersistentPreferenceStore {
-
- /**
- * The storeContext is the context where values will stored with the
- * setValue methods. If there are no searchContexts this will be the search
- * context. (along with the "default" context)
- */
- protected IScopeContext storeContext;
-
- /**
- * The searchContext is the array of contexts that will be used by the get
- * methods for searching for values.
- */
- protected IScopeContext[] searchContexts;
+@Deprecated
+//replaced by PapyrusScopedPreferenceStore from org.eclipse.papyrus.infra.tools
+public class PapyrusScopedPreferenceStore extends org.eclipse.papyrus.infra.tools.preferences.PapyrusScopedPreferenceStore {
- /**
- * A boolean to indicate the property changes should not be propagated.
- */
- protected boolean silentRunning = false;
-
- /**
- * The listener on the IEclipsePreferences. This is used to forward updates
- * to the property change listeners on the preference store.
- */
- protected IEclipsePreferences.IPreferenceChangeListener preferencesListener;
-
- /**
- * The default context is the context where getDefault and setDefault
- * methods will search. This context is also used in the search.
- */
- protected IScopeContext defaultContext = new DefaultScope();
-
- /**
- * The nodeQualifer is the string used to look up the node in the contexts.
- */
- protected String nodeQualifier;
-
- /**
- * The defaultQualifier is the string used to look up the default node.
- */
- protected String defaultQualifier;
-
- /**
- * Boolean value indicating whether or not this store has changes to be
- * saved.
- */
- private boolean dirty;
/**
* Create a new instance of the receiver. Store the values in context in the
@@ -128,8 +65,7 @@ public class PapyrusScopedPreferenceStore extends EventManager implements IPrefe
* the qualifier used when looking up the defaults
*/
public PapyrusScopedPreferenceStore(IScopeContext context, String qualifier, String defaultQualifierPath) {
- this(context, qualifier);
- this.defaultQualifier = defaultQualifierPath;
+ super(context, qualifier, defaultQualifierPath);
}
/**
@@ -142,718 +78,6 @@ public class PapyrusScopedPreferenceStore extends EventManager implements IPrefe
* the qualifer used to look up the preference node
*/
public PapyrusScopedPreferenceStore(IScopeContext context, String qualifier) {
- storeContext = context;
- this.nodeQualifier = qualifier;
- this.defaultQualifier = qualifier;
-
- ((IEclipsePreferences)getStorePreferences().parent()).addNodeChangeListener(getNodeChangeListener());
- }
-
- /**
- * Return a node change listener that adds a removes the receiver when nodes
- * change.
- *
- * @return INodeChangeListener
- */
- private INodeChangeListener getNodeChangeListener() {
- return new IEclipsePreferences.INodeChangeListener() {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences
- * .NodeChangeEvent)
- */
- public void added(NodeChangeEvent event) {
- if(nodeQualifier.equals(event.getChild().name()) && isListenerAttached()) {
- getStorePreferences().addPreferenceChangeListener(preferencesListener);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.
- * IEclipsePreferences.NodeChangeEvent)
- */
- public void removed(NodeChangeEvent event) {
- // Do nothing as there are no events from removed node
- }
- };
- }
-
- /**
- * Initialize the preferences listener.
- */
- private void initializePreferencesListener() {
- if(preferencesListener == null) {
- preferencesListener = new IEclipsePreferences.IPreferenceChangeListener() {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.
- * preferences.IEclipsePreferences.PreferenceChangeEvent)
- */
- public void preferenceChange(PreferenceChangeEvent event) {
-
- if(silentRunning) {
- 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(event.getKey(), oldValue, newValue);
- }
- };
- getStorePreferences().addPreferenceChangeListener(preferencesListener);
- }
-
- }
-
- /**
- * 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.
- *
- * @param key
- * the key to search
- * @param obj
- * the object who default we are looking for
- * @return Object or <code>null</code>
- */
- protected 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 Boolean) {
- return defaults.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT) ? Boolean.TRUE : Boolean.FALSE;
- } else {
- return null;
- }
- }
-
- /**
- * Return the IEclipsePreferences node associated with this store.
- *
- * @return the preference node for this store
- */
- protected IEclipsePreferences getStorePreferences() {
- return storeContext.getNode(nodeQualifier);
- }
-
- /**
- * Return the default IEclipsePreferences for this store.
- *
- * @return this store's default preference node
- */
- protected IEclipsePreferences getDefaultPreferences() {
- return defaultContext.getNode(defaultQualifier);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
- */
- public void addPropertyChangeListener(IPropertyChangeListener listener) {
- initializePreferencesListener();// Create the preferences listener if it
- // does not exist
- addListenerObject(listener);
- }
-
- /**
- * Return the preference path to search preferences on. This is the list of
- * preference nodes based on the scope contexts for this store. If there are
- * no search contexts set, then return this store's context.
- * <p>
- * Whether or not the default context should be included in the resulting list is specified by the <code>includeDefault</code> parameter.
- * </p>
- *
- * @param includeDefault
- * <code>true</code> if the default context should be included
- * and <code>false</code> otherwise
- * @return IEclipsePreferences[]
- * @since 3.4 public, was added in 3.1 as private method
- */
- public IEclipsePreferences[] getPreferenceNodes(boolean includeDefault) {
- // if the user didn't specify a search order, then return the scope that
- // this store was created on. (and optionally the default)
- if(searchContexts == null) {
- if(includeDefault) {
- return new IEclipsePreferences[]{ getStorePreferences(), getDefaultPreferences() };
- }
- return new IEclipsePreferences[]{ getStorePreferences() };
- }
- // otherwise the user specified a search order so return the appropriate
- // nodes based on it
- int length = searchContexts.length;
- if(includeDefault) {
- length++;
- }
- IEclipsePreferences[] preferences = new IEclipsePreferences[length];
- for(int i = 0; i < searchContexts.length; i++) {
- preferences[i] = searchContexts[i].getNode(nodeQualifier);
- }
- if(includeDefault) {
- preferences[length - 1] = getDefaultPreferences();
- }
- return preferences;
- }
-
- /**
- * Set the search contexts to scopes. When searching for a value the seach
- * will be done in the order of scope contexts and will not search the
- * storeContext unless it is in this list.
- * <p>
- * If the given list is <code>null</code>, then clear this store's search contexts. This means that only this store's scope context and default
- * scope will be used during preference value searching.
- * </p>
- * <p>
- * The defaultContext will be added to the end of this list automatically and <em>MUST NOT</em> be included by the user.
- * </p>
- *
- * @param scopes
- * a list of scope contexts to use when searching, or <code>null</code>
- */
- public void setSearchContexts(IScopeContext[] scopes) {
- this.searchContexts = scopes;
- if(scopes == null) {
- return;
- }
-
- // Assert that the default was not included (we automatically add it to
- // the end)
- for(int i = 0; i < scopes.length; i++) {
- if(scopes[i].equals(defaultContext)) {
- Assert.isTrue(false, WorkbenchMessages.ScopedPreferenceStore_DefaultAddedError);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
- */
- public boolean contains(String name) {
- if(name == null) {
- return false;
- }
- return (Platform.getPreferencesService().get(name, null, getPreferenceNodes(true))) != null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#firePropertyChangeEvent(java.lang.String,
- * java.lang.Object, java.lang.Object)
- */
- public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
- // important: create intermediate array to protect against listeners
- // being added/removed during the notification
- final Object[] list = getListeners();
- if(list.length == 0) {
- return;
- }
- final PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
- for(int i = 0; i < list.length; i++) {
- final IPropertyChangeListener listener = (IPropertyChangeListener)list[i];
- SafeRunner.run(new SafeRunnable(JFaceResources.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
-
- public void run() {
- listener.propertyChange(event);
- }
- });
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
- */
- public boolean getBoolean(String name) {
- String value = internalGet(name);
- return value == null ? BOOLEAN_DEFAULT_DEFAULT : Boolean.valueOf(value).booleanValue();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java.lang.String)
- */
- public boolean getDefaultBoolean(String name) {
- return getDefaultPreferences().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang.String)
- */
- public double getDefaultDouble(String name) {
- return getDefaultPreferences().getDouble(name, DOUBLE_DEFAULT_DEFAULT);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang.String)
- */
- public float getDefaultFloat(String name) {
- return getDefaultPreferences().getFloat(name, FLOAT_DEFAULT_DEFAULT);
+ super(context, qualifier);
}
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang.String)
- */
- public int getDefaultInt(String name) {
- return getDefaultPreferences().getInt(name, INT_DEFAULT_DEFAULT);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang.String)
- */
- public long getDefaultLong(String name) {
- return getDefaultPreferences().getLong(name, LONG_DEFAULT_DEFAULT);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang.String)
- */
- public String getDefaultString(String name) {
- return getDefaultPreferences().get(name, STRING_DEFAULT_DEFAULT);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String)
- */
- public double getDouble(String name) {
- String value = internalGet(name);
- if(value == null) {
- return DOUBLE_DEFAULT_DEFAULT;
- }
- try {
- return Double.parseDouble(value);
- } catch (NumberFormatException e) {
- return DOUBLE_DEFAULT_DEFAULT;
- }
- }
-
- /**
- * Return the string value for the specified key. Look in the nodes which
- * are specified by this object's list of search scopes. If the value does
- * not exist then return <code>null</code>.
- *
- * @param key
- * the key to search with
- * @return String or <code>null</code> if the value does not exist.
- */
- protected String internalGet(String key) {
- return Platform.getPreferencesService().get(key, null, getPreferenceNodes(true));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String)
- */
- public float getFloat(String name) {
- String value = internalGet(name);
- if(value == null) {
- return FLOAT_DEFAULT_DEFAULT;
- }
- try {
- return Float.parseFloat(value);
- } catch (NumberFormatException e) {
- return FLOAT_DEFAULT_DEFAULT;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String)
- */
- public int getInt(String name) {
- String value = internalGet(name);
- if(value == null) {
- return INT_DEFAULT_DEFAULT;
- }
- try {
- return Integer.parseInt(value);
- } catch (NumberFormatException e) {
- return INT_DEFAULT_DEFAULT;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String)
- */
- public long getLong(String name) {
- String value = internalGet(name);
- if(value == null) {
- return LONG_DEFAULT_DEFAULT;
- }
- try {
- return Long.parseLong(value);
- } catch (NumberFormatException e) {
- return LONG_DEFAULT_DEFAULT;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
- */
- public String getString(String name) {
- String value = internalGet(name);
- return value == null ? STRING_DEFAULT_DEFAULT : value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
- */
- public boolean isDefault(String name) {
- if(name == null) {
- return false;
- }
- return (Platform.getPreferencesService().get(name, null, getPreferenceNodes(false))) == null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#needsSaving()
- */
- public boolean needsSaving() {
- return dirty;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#putValue(java.lang.String,
- * java.lang.String)
- */
- public void putValue(String name, String value) {
- try {
- // Do not notify listeners
- silentRunning = true;
- getStorePreferences().put(name, value);
- } finally {
- // Be sure that an exception does not stop property updates
- silentRunning = false;
- dirty = true;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
- */
- public void removePropertyChangeListener(IPropertyChangeListener listener) {
- removeListenerObject(listener);
- if(!isListenerAttached()) {
- disposePreferenceStoreListener();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
- * double)
- */
- public void setDefault(String name, double value) {
- getDefaultPreferences().putDouble(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
- * float)
- */
- public void setDefault(String name, float value) {
- getDefaultPreferences().putFloat(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
- * int)
- */
- public void setDefault(String name, int value) {
- getDefaultPreferences().putInt(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
- * long)
- */
- public void setDefault(String name, long value) {
- getDefaultPreferences().putLong(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
- * java.lang.String)
- */
- public void setDefault(String name, String defaultObject) {
- getDefaultPreferences().put(name, defaultObject);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
- * boolean)
- */
- public void setDefault(String name, boolean value) {
- getDefaultPreferences().putBoolean(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang.String)
- */
- public void setToDefault(String name) {
-
- String oldValue = getString(name);
- String defaultValue = getDefaultString(name);
- try {
- silentRunning = true;// Turn off updates from the store
- // removing a non-existing preference is a no-op so call the Core
- // API directly
- getStorePreferences().remove(name);
- if(oldValue != defaultValue) {
- dirty = true;
- firePropertyChangeEvent(name, oldValue, defaultValue);
- }
-
- } finally {
- silentRunning = false;// Restart listening to preferences
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
- * double)
- */
- public void setValue(String name, double value) {
- double oldValue = getDouble(name);
- if(oldValue == value) {
- return;
- }
- try {
- silentRunning = true;// Turn off updates from the store
- if(getDefaultDouble(name) == value) {
- getStorePreferences().remove(name);
- } else {
- getStorePreferences().putDouble(name, value);
- }
- dirty = true;
- firePropertyChangeEvent(name, new Double(oldValue), new Double(value));
- } finally {
- silentRunning = false;// Restart listening to preferences
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
- * float)
- */
- public void setValue(String name, float value) {
- float oldValue = getFloat(name);
- if(oldValue == value) {
- return;
- }
- try {
- silentRunning = true;// Turn off updates from the store
- if(getDefaultFloat(name) == value) {
- getStorePreferences().remove(name);
- } else {
- getStorePreferences().putFloat(name, value);
- }
- dirty = true;
- firePropertyChangeEvent(name, new Float(oldValue), new Float(value));
- } finally {
- silentRunning = false;// Restart listening to preferences
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
- * int)
- */
- public void setValue(String name, int value) {
- int oldValue = getInt(name);
- if(oldValue == value) {
- return;
- }
- try {
- silentRunning = true;// Turn off updates from the store
- if(getDefaultInt(name) == value) {
- getStorePreferences().remove(name);
- } else {
- getStorePreferences().putInt(name, value);
- }
- dirty = true;
- firePropertyChangeEvent(name, new Integer(oldValue), new Integer(value));
- } finally {
- silentRunning = false;// Restart listening to preferences
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
- * long)
- */
- public void setValue(String name, long value) {
- long oldValue = getLong(name);
- if(oldValue == value) {
- return;
- }
- try {
- silentRunning = true;// Turn off updates from the store
- if(getDefaultLong(name) == value) {
- getStorePreferences().remove(name);
- } else {
- getStorePreferences().putLong(name, value);
- }
- dirty = true;
- firePropertyChangeEvent(name, new Long(oldValue), new Long(value));
- } finally {
- silentRunning = false;// Restart listening to preferences
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
- * java.lang.String)
- */
- public void setValue(String name, String value) {
- // Do not turn on silent running here as Strings are propagated
- if(getDefaultString(name).equals(value)) {
- getStorePreferences().remove(name);
- } else {
- getStorePreferences().put(name, value);
- }
- dirty = true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
- * boolean)
- */
- public void setValue(String name, boolean value) {
- boolean oldValue = getBoolean(name);
- if(oldValue == value) {
- return;
- }
- try {
- silentRunning = true;// Turn off updates from the store
- if(getDefaultBoolean(name) == value) {
- getStorePreferences().remove(name);
- } else {
- getStorePreferences().putBoolean(name, value);
- }
- dirty = true;
- firePropertyChangeEvent(name, oldValue ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
- } finally {
- silentRunning = false;// Restart listening to preferences
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
- */
- public void save() throws IOException {
- try {
- getStorePreferences().flush();
- dirty = false;
- } catch (BackingStoreException e) {
- throw new IOException(e.getMessage());
- }
-
- }
-
- /**
- * Dispose the receiver.
- */
- private void disposePreferenceStoreListener() {
-
- IEclipsePreferences root = (IEclipsePreferences)Platform.getPreferencesService().getRootNode().node(Plugin.PLUGIN_PREFERENCE_SCOPE);
- try {
- if(!(root.nodeExists(nodeQualifier))) {
- return;
- }
- } catch (BackingStoreException e) {
- return;// No need to report here as the node won't have the
- // listener
- }
-
- IEclipsePreferences preferences = getStorePreferences();
- if(preferences == null) {
- return;
- }
- if(preferencesListener != null) {
- preferences.removePreferenceChangeListener(preferencesListener);
- preferencesListener = null;
- }
- }
-
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/Messages.java
index acc65fa6ca2..41f771744d9 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/Messages.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/Messages.java
@@ -19,6 +19,10 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.gmfdiag.preferences.messages.messages"; //$NON-NLS-1$
+ public static String ApplyValueOnPreferenceKeyDialog_DIAGRAM;
+
+ public static String ApplyValueOnPreferenceKeyDialog_ELEMENT;
+
public static String LabelGroup_Labels_To_Display;
public static String RulersAndGridGroup_GridColor;
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/messages.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/messages.properties
index c8b32c626d8..fffa0ad0ec3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/messages.properties
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/messages/messages.properties
@@ -2,3 +2,5 @@ LabelGroup_Labels_To_Display=Labels to display
RulersAndGridGroup_GridColor=Grid Color
RulersAndGridGroup_GridInFront=Grid In Front
RulersAndGridGroup_GridStyle=Grid Style
+ApplyValueOnPreferenceKeyDialog_DIAGRAM=DIAGRAM
+ApplyValueOnPreferenceKeyDialog_ELEMENT=ELEMENT
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/AbstractPreferenceKeyDialog.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/AbstractPreferenceKeyDialog.java
index 6f44dee5bdb..f6b2c874e79 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/AbstractPreferenceKeyDialog.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/AbstractPreferenceKeyDialog.java
@@ -37,6 +37,7 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* The Class AbstractPreferenceKeyDialog display all preference key that are given in parameters
*/
+@Deprecated
public class AbstractPreferenceKeyDialog extends org.eclipse.jface.dialogs.StatusDialog {
/** The key table. */
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/ApplyValueOnPreferenceKeyDialog.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/ApplyValueOnPreferenceKeyDialog.java
index 8587f0f91e5..ae47a3bce47 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/ApplyValueOnPreferenceKeyDialog.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.preferences/src/org/eclipse/papyrus/infra/gmfdiag/preferences/ui/dialog/ApplyValueOnPreferenceKeyDialog.java
@@ -15,61 +15,169 @@ package org.eclipse.papyrus.infra.gmfdiag.preferences.ui.dialog;
import java.util.ArrayList;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper;
+import org.eclipse.papyrus.infra.gmfdiag.preferences.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.preferences.messages.Messages;
+import org.eclipse.papyrus.infra.tools.preferences.ui.dialog.AbstractApplyValueOnPreferenceKeyDialog;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+
/**
* The Class ApplyValueOnPreferenceKeyDialog display all the preference key and give all selected keys
*/
-public class ApplyValueOnPreferenceKeyDialog extends AbstractPreferenceKeyDialog {
-
- /** The checked key. */
- protected ArrayList<String> checkedKey;
+public class ApplyValueOnPreferenceKeyDialog extends AbstractApplyValueOnPreferenceKeyDialog {
- /**
- * Instantiates a new apply value on preference key dialog.
- *
- * @param keys
- * the keys
- */
public ApplyValueOnPreferenceKeyDialog(String[] keys) {
super(keys);
- checkedKey = new ArrayList<String>();
- // TODO Auto-generated constructor stub
}
/**
- * Gets the key to remove.
- *
- * @return the key to remove
+ *
*/
- public ArrayList<String> getKeyToRemove() {
- return checkedKey;
+ @Override
+ protected IBaseLabelProvider createLabelProvider() {
+ return new KeyLabelProvider();
}
- /*
- * (non-Javadoc)
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.tools.preferences.ui.dialog.AbstractPreferenceKeyDialog#createContentProvider()
*
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ * @return
*/
@Override
- protected void okPressed() {
+ protected IContentProvider createContentProvider() {
+ return new KeyContentProvider();
+ }
+
+ /**
+ * The Class KeyLabelProvider.
+ */
+ protected class KeyLabelProvider extends LabelProvider implements ITableLabelProvider, ITableColorProvider {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.ITableColorProvider#getForeground(java.lang.Object, int)
+ */
+ public Color getForeground(Object element, int columnIndex) {
+ //nothing to do
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.ITableColorProvider#getBackground(java.lang.Object, int)
+ */
+ public Color getBackground(Object element, int columnIndex) {
+ //nothing to do
+ return null;
+ }
- for(int i = 0; i < keyTable.getItems().length; i++) {
- if(keyTable.getItems()[i].getChecked()) {
- checkedKey.add((String)keyTable.getItems()[i].getData());
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+ */
+ public Image getColumnImage(Object element, int columnIndex) {
+ if(columnIndex == 0) {
+ if(element.toString().startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) {
+ return Activator.getPluginIconImage(Activator.PLUGIN_ID, "/icons/pref.gif"); //$NON-NLS-1$
+ }
+ if(element.toString().startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
+ return Activator.getPluginIconImage(Activator.PLUGIN_ID, "/icons/diag.gif"); //$NON-NLS-1$
+ }
}
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ public String getColumnText(Object element, int columnIndex) {
+ String initialKey = element.toString();
+ String out = initialKey.toString();
+ if(columnIndex == 0) {
+ out = out.substring(out.indexOf(".") + 1, out.length()).toUpperCase(); //$NON-NLS-1$
+ }
+ if(columnIndex == 1) {
+ if(element.toString().startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) {
+ return Messages.ApplyValueOnPreferenceKeyDialog_ELEMENT;
+ }
+ if(element.toString().startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
+ return Messages.ApplyValueOnPreferenceKeyDialog_DIAGRAM;
+ }
+ }
+ if(columnIndex == 2) {
+ if(initialKey.startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) {
+ out = initialKey.toString().replaceAll(PreferencesConstantsHelper.DIAGRAM_ELEMENT, ""); //$NON-NLS-1$
+ // Reorganize display
+ if(out.indexOf(".") > 0) { //$NON-NLS-1$
+ String beforePoint = out.substring(0, out.indexOf(".")); //$NON-NLS-1$
+ if(beforePoint.lastIndexOf("_") > 0) { //$NON-NLS-1$
+ out = out.substring(beforePoint.lastIndexOf("_") + 1, out.indexOf(".")) + " (" + beforePoint.substring(0, beforePoint.lastIndexOf("_")) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+ }
+ }
+ if(initialKey.startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
+ out = initialKey.toString().replaceAll(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX, ""); //$NON-NLS-1$
+ out = out.substring(0, out.indexOf(".")); //$NON-NLS-1$
+ }
+ }
+ return out;
}
- super.okPressed();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
+
+ /**
+ * The Class KeyContentProvider.
*/
- @Override
- protected void cancelPressed() {
- super.cancelPressed();
- checkedKey = new ArrayList<String>();
+ protected class KeyContentProvider implements IStructuredContentProvider {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements(Object inputElement) {
+ ArrayList<String> result = new ArrayList<String>();
+ for(int i = 0; i < keys.length; i++) {
+ if(keys[i].startsWith(PreferencesConstantsHelper.DIAGRAM_PREFERENCE_PREFIX)) {
+ result.add(keys[i]);
+ }
+ if(keys[i].startsWith(PreferencesConstantsHelper.DIAGRAM_ELEMENT)) {
+ result.add(keys[i]);
+ }
+ }
+ return result.toArray();
+ }
+
}
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF b/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
index 35cdb0e921d..801952c6808 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
@@ -11,6 +11,8 @@ Require-Bundle: org.eclipse.ui,
Export-Package: org.eclipse.papyrus.infra.tools.comparator,
org.eclipse.papyrus.infra.tools.converter,
org.eclipse.papyrus.infra.tools.databinding,
+ org.eclipse.papyrus.infra.tools.preferences,
+ org.eclipse.papyrus.infra.tools.preferences.ui.dialog,
org.eclipse.papyrus.infra.tools.util
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java
index 77a155d1a10..79e543913ce 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java
@@ -19,6 +19,14 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.tools.messages.messages"; //$NON-NLS-1$
+ public static String AbstractPreferenceKeyDialog_Level;
+
+ public static String AbstractPreferenceKeyDialog_Localization;
+
+ public static String AbstractPreferenceKeyDialog_Pref_Kind;
+
+ public static String AbstractPreferenceKeyDialog_WouldYouLikeOverloadPreferences;
+
public static String AbstractStringValueConverter_NoXReprensentedByYHaveBeenFound;
public static String AbstractStringValueConverter_SomeStringsAreNotValidToCreateY;
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties
index dea12a89919..aae5ef667df 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties
@@ -1,3 +1,7 @@
+AbstractPreferenceKeyDialog_Level=Level
+AbstractPreferenceKeyDialog_Localization=Localization
+AbstractPreferenceKeyDialog_Pref_Kind=Pref. kind
+AbstractPreferenceKeyDialog_WouldYouLikeOverloadPreferences=Would you like to overload those preferences?
AbstractStringValueConverter_NoXReprensentedByYHaveBeenFound=No {0} represented by {1} have been found
AbstractStringValueConverter_SomeStringsAreNotValidToCreateY=Some Strings are not valid to create {0}
AbstractStringValueConverter_SomeStringsCantBeResolvedToFindY=Some Strings can't be resolved to find {0}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/AbstractPapyrusPreferenceStore.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/AbstractPapyrusPreferenceStore.java
new file mode 100644
index 00000000000..840e851caf0
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/AbstractPapyrusPreferenceStore.java
@@ -0,0 +1,291 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.preferences;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.papyrus.infra.tools.Activator;
+import org.eclipse.papyrus.infra.tools.preferences.ui.dialog.AbstractApplyValueOnPreferenceKeyDialog;
+
+public abstract class AbstractPapyrusPreferenceStore extends PapyrusScopedPreferenceStore {
+
+ /**
+ * key for element level
+ */
+ private final String elementLevelPrefix;
+
+ /**
+ * key for editor level
+ */
+ private final String instanceEditorLevelPrefix;
+
+ /**
+ * key for all editor of the same kind
+ */
+ private final String editorLevelPrefix;
+
+ /**
+ * constructor
+ *
+ * @param context
+ * the scope to store to
+ * @param qualifier
+ * the qualifier used to look up the preference node
+ * @param key
+ * for all editor of the same kind (all diagrams, all tables, ...)
+ * @param key
+ * for an instance of this editor
+ * @param key
+ * for an element
+ */
+ public AbstractPapyrusPreferenceStore(IScopeContext context, String qualifier, String editorLevelPrefix, String instanceEditorLevelPrefix, String elementLevelPrefix) {
+ super(context, qualifier);
+ this.editorLevelPrefix = editorLevelPrefix;
+ this.instanceEditorLevelPrefix = instanceEditorLevelPrefix;
+ this.elementLevelPrefix = elementLevelPrefix;
+ }
+
+ /**
+ * constructor
+ *
+ * @param context
+ * the scope to store to
+ * @param qualifier
+ * the qualifier used to look up the preference node
+ * @param defaultQualifierPath
+ * the qualifier used when looking up the defaults
+ * @param key
+ * for all editor of the same kind (all diagrams, all tables, ...)
+ * @param key
+ * for an instance of this editor
+ * @param key
+ * for an element
+ */
+ public AbstractPapyrusPreferenceStore(IScopeContext context, String qualifier, String defaultQualifierPath, String editorLevelPrefix, String instanceEditorLevelPrefix, String elementLevelPrefix) {
+ super(context, qualifier, defaultQualifierPath);
+ this.editorLevelPrefix = editorLevelPrefix;
+ this.instanceEditorLevelPrefix = instanceEditorLevelPrefix;
+ this.elementLevelPrefix = elementLevelPrefix;
+ }
+
+
+
+
+ /**
+ * this method is used to overload all value under a level of preferences.
+ * In order to overload a pop-up is opened, and the user can choose value to overload
+ *
+ * @param level
+ * of preference: Editor or diagram
+ */
+
+ public void deleteAllSubPreference(String level) {
+ //remove all sub value diagram+ element
+ ArrayList<String> keytoRemove = new ArrayList<String>();
+ //key to collect
+ ArrayList<String> elementKey = new ArrayList<String>();
+ try {
+ for(int i = 0; i < getStorePreferences().keys().length; i++) {
+ //level diagram collect only element
+ if(level.startsWith(instanceEditorLevelPrefix)) {
+ if(getStorePreferences().keys()[i].startsWith(elementLevelPrefix)) {
+ elementKey.add(getStorePreferences().keys()[i]);
+ }
+ }
+ //editor level, collect all element+diagram
+ else if(level.startsWith(editorLevelPrefix)) {
+ if((getStorePreferences().keys()[i].startsWith(elementLevelPrefix)) || (getStorePreferences().keys()[i].startsWith(instanceEditorLevelPrefix))) {
+ elementKey.add(getStorePreferences().keys()[i]);
+ }
+ }
+
+ }
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ if(elementKey.size() > 0) {
+ String[] keyRoconsult = new String[elementKey.size()];
+ AbstractApplyValueOnPreferenceKeyDialog dialog = createPreferenceKeyDialog(elementKey.toArray(keyRoconsult));
+ dialog.open();
+ keytoRemove = dialog.getKeyToRemove();
+
+ //remove key
+ Iterator<String> iterator = keytoRemove.iterator();
+ while(iterator.hasNext()) {
+ String key = (String)iterator.next();
+ getStorePreferences().remove(key);
+ }
+ }
+ }
+
+ /**
+ *
+ * @param keys
+ * @return
+ * the dialog to apply values
+ */
+ protected abstract AbstractApplyValueOnPreferenceKeyDialog createPreferenceKeyDialog(String[] keys);
+
+
+
+ // each get value will be overloaded
+ //if not value is found for an element, a value is look for in DIAGRAM
+ // if a the value is not find for Diagram a value is find for Papyrus editor
+
+
+ /**
+ * this method is used to find a key that a got a value:
+ * if the key is an element. The method look for if this key exist. If no value exists, it look for the key for diagram
+ * if the key for diagram do not exist it look for key for papyrus Editor
+ * the structure of Key is:
+ * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
+ * Diagram : DIAGRAM_DiagramKind.preferenceKind
+ * Editor: PAPYRUS_EDITOR.preferenceKind
+ *
+ */
+ protected String findKeyWithAValue(String initialKey) {
+ String foundedKey = null;
+ //first look for in value stack
+ foundedKey = findKeyAStoreValue(initialKey);
+ //then look for in default stack
+ if(foundedKey == null) {
+ foundedKey = findKeyWithADefaultValue(initialKey);
+ }
+ if(foundedKey == null) {
+ foundedKey = initialKey;
+ }
+ return foundedKey;
+
+ }
+
+ /**
+ * look for a key with a value in the store stack
+ *
+ * @param initialKey
+ * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
+ * Diagram : DIAGRAM_DiagramKind.preferenceKind
+ * Editor: PAPYRUS_EDITOR.preferenceKind
+ * @return the key that returns a value or null if there is no value
+ */
+ protected String findKeyAStoreValue(String initialKey) {
+ String foundedKey = null;
+ if(getStorePreferences().get(initialKey, null) != null) {
+ foundedKey = initialKey;
+ }
+
+ if(foundedKey == null && hasPrefix(initialKey)) {
+ foundedKey = findKeyAStoreValue(getUpperKey(initialKey));
+ }
+ return foundedKey;
+ }
+
+ /**
+ * this method is used to find a key that a got a value:
+ * if the key is an element. The method look for if this key exist. If no value exists, it look for the key for diagram
+ * if the key for diagram do not exist it look for key for papyrus Editor
+ * the structure of Key is:
+ * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
+ * Diagram : DIAGRAM_DiagramKind.preferenceKind
+ * Editor: PAPYRUS_EDITOR.preferenceKind
+ *
+ */
+ protected String findKeyWithADefaultValue(String initialKey) {
+ String foundedKey = null;
+
+ if(getDefaultPreferences().get(initialKey, null) != null) {
+ foundedKey = initialKey;
+ }
+
+ if(foundedKey == null && hasPrefix(initialKey)) {
+ return findKeyWithADefaultValue(getUpperKey(initialKey));
+ } else {
+ foundedKey = initialKey;
+ }
+ return foundedKey;
+
+ }
+
+ /**
+ * get the upper Key from the initial Key
+ * * the structure of Key is:
+ * element : ELEMENT_DiagramKind_ElementKind.preferenceKind
+ * Diagram : DIAGRAM_DiagramKind.preferenceKind
+ * Editor: PAPYRUS_EDITOR.preferenceKind
+ *
+ * @param initialKey
+ * @return the upperKey
+ *
+ */
+ protected String getUpperKey(String initialKey) {
+
+ String out = initialKey.toString();
+ if(initialKey.startsWith(elementLevelPrefix)) {
+ out = initialKey.toString().replaceAll(elementLevelPrefix, instanceEditorLevelPrefix);
+ out = out.substring(0, out.lastIndexOf("_")) + out.substring(out.indexOf("."), out.length());
+ }
+ if(initialKey.startsWith(instanceEditorLevelPrefix)) {
+ // out=initialKey.toString().replaceAll(instanceEditorLevelPrefix, editorLevelPrefix);
+ out = editorLevelPrefix + out.substring(out.indexOf("."), out.length());
+ }
+ return out;
+ }
+
+ protected boolean hasPrefix(String key) {
+ if(key.startsWith(elementLevelPrefix) || key.startsWith(instanceEditorLevelPrefix)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * get the value from a key
+ *
+ * @param key
+ * @return the value
+ */
+ protected String internalGet(String key) {
+ String newKey = findKeyWithAValue(key);
+ //System.err.println("-->Initial Key "+key+"--> "+ newKey);
+ return Platform.getPreferencesService().get(newKey, null, getPreferenceNodes(true));
+ }
+
+ public boolean getDefaultBoolean(String name) {
+
+ return super.getDefaultBoolean(findKeyWithADefaultValue(name));
+ }
+
+ public double getDefaultDouble(String name) {
+ return super.getDefaultDouble(findKeyWithADefaultValue(name));
+ }
+
+ public float getDefaultFloat(String name) {
+ return super.getDefaultFloat(findKeyWithADefaultValue(name));
+ };
+
+ public int getDefaultInt(String name) {
+ return super.getDefaultInt(findKeyWithADefaultValue(name));
+ }
+
+ public long getDefaultLong(String name) {
+ return super.getDefaultLong(findKeyWithADefaultValue(name));
+ }
+
+ public String getDefaultString(String name) {
+ return super.getDefaultString(findKeyWithADefaultValue(name));
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/PapyrusScopedPreferenceStore.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/PapyrusScopedPreferenceStore.java
new file mode 100644
index 00000000000..18abc8a69e2
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/PapyrusScopedPreferenceStore.java
@@ -0,0 +1,859 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.preferences;
+
+/***************************************************************************
+ Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * the code is copy from ScopedPreferenceStore but I have open some methods in order to be
+ * available for the overload
+ *
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *
+ *******************************************************************************/
+
+import java.io.IOException;
+
+import org.eclipse.core.commands.common.EventManager;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.ui.internal.WorkbenchMessages;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * The ScopedPreferenceStore is an IPreferenceStore that uses the scopes
+ * provided in org.eclipse.core.runtime.preferences.
+ * <p>
+ * A ScopedPreferenceStore does the lookup of a preference based on it's search scopes and sets the value of the preference based on its store scope.
+ * </p>
+ * <p>
+ * The default scope is always included in the search scopes when searching for preference values.
+ * </p>
+ *
+ * @see org.eclipse.core.runtime.preferences
+ * @since 3.1
+ */
+public class PapyrusScopedPreferenceStore extends EventManager implements IPreferenceStore, IPersistentPreferenceStore {
+
+ /**
+ * The storeContext is the context where values will stored with the
+ * setValue methods. If there are no searchContexts this will be the search
+ * context. (along with the "default" context)
+ */
+ protected IScopeContext storeContext;
+
+ /**
+ * The searchContext is the array of contexts that will be used by the get
+ * methods for searching for values.
+ */
+ protected IScopeContext[] searchContexts;
+
+ /**
+ * A boolean to indicate the property changes should not be propagated.
+ */
+ protected boolean silentRunning = false;
+
+ /**
+ * The listener on the IEclipsePreferences. This is used to forward updates
+ * to the property change listeners on the preference store.
+ */
+ protected IEclipsePreferences.IPreferenceChangeListener preferencesListener;
+
+ /**
+ * The default context is the context where getDefault and setDefault
+ * methods will search. This context is also used in the search.
+ */
+ protected IScopeContext defaultContext = new DefaultScope();
+
+ /**
+ * The nodeQualifer is the string used to look up the node in the contexts.
+ */
+ protected String nodeQualifier;
+
+ /**
+ * The defaultQualifier is the string used to look up the default node.
+ */
+ protected String defaultQualifier;
+
+ /**
+ * Boolean value indicating whether or not this store has changes to be
+ * saved.
+ */
+ private boolean dirty;
+
+ /**
+ * Create a new instance of the receiver. Store the values in context in the
+ * node looked up by qualifier. <strong>NOTE:</strong> Any instance of
+ * ScopedPreferenceStore should call
+ *
+ * @param context
+ * the scope to store to
+ * @param qualifier
+ * the qualifier used to look up the preference node
+ * @param defaultQualifierPath
+ * the qualifier used when looking up the defaults
+ */
+ public PapyrusScopedPreferenceStore(IScopeContext context, String qualifier, String defaultQualifierPath) {
+ this(context, qualifier);
+ this.defaultQualifier = defaultQualifierPath;
+ }
+
+ /**
+ * Create a new instance of the receiver. Store the values in context in the
+ * node looked up by qualifier.
+ *
+ * @param context
+ * the scope to store to
+ * @param qualifier
+ * the qualifer used to look up the preference node
+ */
+ public PapyrusScopedPreferenceStore(IScopeContext context, String qualifier) {
+ storeContext = context;
+ this.nodeQualifier = qualifier;
+ this.defaultQualifier = qualifier;
+
+ ((IEclipsePreferences)getStorePreferences().parent()).addNodeChangeListener(getNodeChangeListener());
+ }
+
+ /**
+ * Return a node change listener that adds a removes the receiver when nodes
+ * change.
+ *
+ * @return INodeChangeListener
+ */
+ private INodeChangeListener getNodeChangeListener() {
+ return new IEclipsePreferences.INodeChangeListener() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences
+ * .NodeChangeEvent)
+ */
+ public void added(NodeChangeEvent event) {
+ if(nodeQualifier.equals(event.getChild().name()) && isListenerAttached()) {
+ getStorePreferences().addPreferenceChangeListener(preferencesListener);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.
+ * IEclipsePreferences.NodeChangeEvent)
+ */
+ public void removed(NodeChangeEvent event) {
+ // Do nothing as there are no events from removed node
+ }
+ };
+ }
+
+ /**
+ * Initialize the preferences listener.
+ */
+ private void initializePreferencesListener() {
+ if(preferencesListener == null) {
+ preferencesListener = new IEclipsePreferences.IPreferenceChangeListener() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.
+ * preferences.IEclipsePreferences.PreferenceChangeEvent)
+ */
+ public void preferenceChange(PreferenceChangeEvent event) {
+
+ if(silentRunning) {
+ 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(event.getKey(), oldValue, newValue);
+ }
+ };
+ getStorePreferences().addPreferenceChangeListener(preferencesListener);
+ }
+
+ }
+
+ /**
+ * 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.
+ *
+ * @param key
+ * the key to search
+ * @param obj
+ * the object who default we are looking for
+ * @return Object or <code>null</code>
+ */
+ protected 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 Boolean) {
+ return defaults.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT) ? Boolean.TRUE : Boolean.FALSE;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Return the IEclipsePreferences node associated with this store.
+ *
+ * @return the preference node for this store
+ */
+ protected IEclipsePreferences getStorePreferences() {
+ return storeContext.getNode(nodeQualifier);
+ }
+
+ /**
+ * Return the default IEclipsePreferences for this store.
+ *
+ * @return this store's default preference node
+ */
+ protected IEclipsePreferences getDefaultPreferences() {
+ return defaultContext.getNode(defaultQualifier);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
+ */
+ public void addPropertyChangeListener(IPropertyChangeListener listener) {
+ initializePreferencesListener();// Create the preferences listener if it
+ // does not exist
+ addListenerObject(listener);
+ }
+
+ /**
+ * Return the preference path to search preferences on. This is the list of
+ * preference nodes based on the scope contexts for this store. If there are
+ * no search contexts set, then return this store's context.
+ * <p>
+ * Whether or not the default context should be included in the resulting list is specified by the <code>includeDefault</code> parameter.
+ * </p>
+ *
+ * @param includeDefault
+ * <code>true</code> if the default context should be included
+ * and <code>false</code> otherwise
+ * @return IEclipsePreferences[]
+ * @since 3.4 public, was added in 3.1 as private method
+ */
+ public IEclipsePreferences[] getPreferenceNodes(boolean includeDefault) {
+ // if the user didn't specify a search order, then return the scope that
+ // this store was created on. (and optionally the default)
+ if(searchContexts == null) {
+ if(includeDefault) {
+ return new IEclipsePreferences[]{ getStorePreferences(), getDefaultPreferences() };
+ }
+ return new IEclipsePreferences[]{ getStorePreferences() };
+ }
+ // otherwise the user specified a search order so return the appropriate
+ // nodes based on it
+ int length = searchContexts.length;
+ if(includeDefault) {
+ length++;
+ }
+ IEclipsePreferences[] preferences = new IEclipsePreferences[length];
+ for(int i = 0; i < searchContexts.length; i++) {
+ preferences[i] = searchContexts[i].getNode(nodeQualifier);
+ }
+ if(includeDefault) {
+ preferences[length - 1] = getDefaultPreferences();
+ }
+ return preferences;
+ }
+
+ /**
+ * Set the search contexts to scopes. When searching for a value the seach
+ * will be done in the order of scope contexts and will not search the
+ * storeContext unless it is in this list.
+ * <p>
+ * If the given list is <code>null</code>, then clear this store's search contexts. This means that only this store's scope context and default
+ * scope will be used during preference value searching.
+ * </p>
+ * <p>
+ * The defaultContext will be added to the end of this list automatically and <em>MUST NOT</em> be included by the user.
+ * </p>
+ *
+ * @param scopes
+ * a list of scope contexts to use when searching, or <code>null</code>
+ */
+ public void setSearchContexts(IScopeContext[] scopes) {
+ this.searchContexts = scopes;
+ if(scopes == null) {
+ return;
+ }
+
+ // Assert that the default was not included (we automatically add it to
+ // the end)
+ for(int i = 0; i < scopes.length; i++) {
+ if(scopes[i].equals(defaultContext)) {
+ Assert.isTrue(false, WorkbenchMessages.ScopedPreferenceStore_DefaultAddedError);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#contains(java.lang.String)
+ */
+ public boolean contains(String name) {
+ if(name == null) {
+ return false;
+ }
+ return (Platform.getPreferencesService().get(name, null, getPreferenceNodes(true))) != null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#firePropertyChangeEvent(java.lang.String,
+ * java.lang.Object, java.lang.Object)
+ */
+ public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
+ // important: create intermediate array to protect against listeners
+ // being added/removed during the notification
+ final Object[] list = getListeners();
+ if(list.length == 0) {
+ return;
+ }
+ final PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
+ for(int i = 0; i < list.length; i++) {
+ final IPropertyChangeListener listener = (IPropertyChangeListener)list[i];
+ SafeRunner.run(new SafeRunnable(JFaceResources.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
+
+ public void run() {
+ listener.propertyChange(event);
+ }
+ });
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getBoolean(java.lang.String)
+ */
+ public boolean getBoolean(String name) {
+ String value = internalGet(name);
+ return value == null ? BOOLEAN_DEFAULT_DEFAULT : Boolean.valueOf(value).booleanValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultBoolean(java.lang.String)
+ */
+ public boolean getDefaultBoolean(String name) {
+ return getDefaultPreferences().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultDouble(java.lang.String)
+ */
+ public double getDefaultDouble(String name) {
+ return getDefaultPreferences().getDouble(name, DOUBLE_DEFAULT_DEFAULT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultFloat(java.lang.String)
+ */
+ public float getDefaultFloat(String name) {
+ return getDefaultPreferences().getFloat(name, FLOAT_DEFAULT_DEFAULT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultInt(java.lang.String)
+ */
+ public int getDefaultInt(String name) {
+ return getDefaultPreferences().getInt(name, INT_DEFAULT_DEFAULT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultLong(java.lang.String)
+ */
+ public long getDefaultLong(String name) {
+ return getDefaultPreferences().getLong(name, LONG_DEFAULT_DEFAULT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDefaultString(java.lang.String)
+ */
+ public String getDefaultString(String name) {
+ return getDefaultPreferences().get(name, STRING_DEFAULT_DEFAULT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getDouble(java.lang.String)
+ */
+ public double getDouble(String name) {
+ String value = internalGet(name);
+ if(value == null) {
+ return DOUBLE_DEFAULT_DEFAULT;
+ }
+ try {
+ return Double.parseDouble(value);
+ } catch (NumberFormatException e) {
+ return DOUBLE_DEFAULT_DEFAULT;
+ }
+ }
+
+ /**
+ * Return the string value for the specified key. Look in the nodes which
+ * are specified by this object's list of search scopes. If the value does
+ * not exist then return <code>null</code>.
+ *
+ * @param key
+ * the key to search with
+ * @return String or <code>null</code> if the value does not exist.
+ */
+ protected String internalGet(String key) {
+ return Platform.getPreferencesService().get(key, null, getPreferenceNodes(true));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getFloat(java.lang.String)
+ */
+ public float getFloat(String name) {
+ String value = internalGet(name);
+ if(value == null) {
+ return FLOAT_DEFAULT_DEFAULT;
+ }
+ try {
+ return Float.parseFloat(value);
+ } catch (NumberFormatException e) {
+ return FLOAT_DEFAULT_DEFAULT;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getInt(java.lang.String)
+ */
+ public int getInt(String name) {
+ String value = internalGet(name);
+ if(value == null) {
+ return INT_DEFAULT_DEFAULT;
+ }
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return INT_DEFAULT_DEFAULT;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getLong(java.lang.String)
+ */
+ public long getLong(String name) {
+ String value = internalGet(name);
+ if(value == null) {
+ return LONG_DEFAULT_DEFAULT;
+ }
+ try {
+ return Long.parseLong(value);
+ } catch (NumberFormatException e) {
+ return LONG_DEFAULT_DEFAULT;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#getString(java.lang.String)
+ */
+ public String getString(String name) {
+ String value = internalGet(name);
+ return value == null ? STRING_DEFAULT_DEFAULT : value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#isDefault(java.lang.String)
+ */
+ public boolean isDefault(String name) {
+ if(name == null) {
+ return false;
+ }
+ return (Platform.getPreferencesService().get(name, null, getPreferenceNodes(false))) == null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#needsSaving()
+ */
+ public boolean needsSaving() {
+ return dirty;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#putValue(java.lang.String,
+ * java.lang.String)
+ */
+ public void putValue(String name, String value) {
+ try {
+ // Do not notify listeners
+ silentRunning = true;
+ getStorePreferences().put(name, value);
+ } finally {
+ // Be sure that an exception does not stop property updates
+ silentRunning = false;
+ dirty = true;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
+ */
+ public void removePropertyChangeListener(IPropertyChangeListener listener) {
+ removeListenerObject(listener);
+ if(!isListenerAttached()) {
+ disposePreferenceStoreListener();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
+ * double)
+ */
+ public void setDefault(String name, double value) {
+ getDefaultPreferences().putDouble(name, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
+ * float)
+ */
+ public void setDefault(String name, float value) {
+ getDefaultPreferences().putFloat(name, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
+ * int)
+ */
+ public void setDefault(String name, int value) {
+ getDefaultPreferences().putInt(name, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
+ * long)
+ */
+ public void setDefault(String name, long value) {
+ getDefaultPreferences().putLong(name, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
+ * java.lang.String)
+ */
+ public void setDefault(String name, String defaultObject) {
+ getDefaultPreferences().put(name, defaultObject);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setDefault(java.lang.String,
+ * boolean)
+ */
+ public void setDefault(String name, boolean value) {
+ getDefaultPreferences().putBoolean(name, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setToDefault(java.lang.String)
+ */
+ public void setToDefault(String name) {
+
+ String oldValue = getString(name);
+ String defaultValue = getDefaultString(name);
+ try {
+ silentRunning = true;// Turn off updates from the store
+ // removing a non-existing preference is a no-op so call the Core
+ // API directly
+ getStorePreferences().remove(name);
+ if(oldValue != defaultValue) {
+ dirty = true;
+ firePropertyChangeEvent(name, oldValue, defaultValue);
+ }
+
+ } finally {
+ silentRunning = false;// Restart listening to preferences
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
+ * double)
+ */
+ public void setValue(String name, double value) {
+ double oldValue = getDouble(name);
+ if(oldValue == value) {
+ return;
+ }
+ try {
+ silentRunning = true;// Turn off updates from the store
+ if(getDefaultDouble(name) == value) {
+ getStorePreferences().remove(name);
+ } else {
+ getStorePreferences().putDouble(name, value);
+ }
+ dirty = true;
+ firePropertyChangeEvent(name, new Double(oldValue), new Double(value));
+ } finally {
+ silentRunning = false;// Restart listening to preferences
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
+ * float)
+ */
+ public void setValue(String name, float value) {
+ float oldValue = getFloat(name);
+ if(oldValue == value) {
+ return;
+ }
+ try {
+ silentRunning = true;// Turn off updates from the store
+ if(getDefaultFloat(name) == value) {
+ getStorePreferences().remove(name);
+ } else {
+ getStorePreferences().putFloat(name, value);
+ }
+ dirty = true;
+ firePropertyChangeEvent(name, new Float(oldValue), new Float(value));
+ } finally {
+ silentRunning = false;// Restart listening to preferences
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
+ * int)
+ */
+ public void setValue(String name, int value) {
+ int oldValue = getInt(name);
+ if(oldValue == value) {
+ return;
+ }
+ try {
+ silentRunning = true;// Turn off updates from the store
+ if(getDefaultInt(name) == value) {
+ getStorePreferences().remove(name);
+ } else {
+ getStorePreferences().putInt(name, value);
+ }
+ dirty = true;
+ firePropertyChangeEvent(name, new Integer(oldValue), new Integer(value));
+ } finally {
+ silentRunning = false;// Restart listening to preferences
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
+ * long)
+ */
+ public void setValue(String name, long value) {
+ long oldValue = getLong(name);
+ if(oldValue == value) {
+ return;
+ }
+ try {
+ silentRunning = true;// Turn off updates from the store
+ if(getDefaultLong(name) == value) {
+ getStorePreferences().remove(name);
+ } else {
+ getStorePreferences().putLong(name, value);
+ }
+ dirty = true;
+ firePropertyChangeEvent(name, new Long(oldValue), new Long(value));
+ } finally {
+ silentRunning = false;// Restart listening to preferences
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
+ * java.lang.String)
+ */
+ public void setValue(String name, String value) {
+ // Do not turn on silent running here as Strings are propagated
+ if(getDefaultString(name).equals(value)) {
+ getStorePreferences().remove(name);
+ } else {
+ getStorePreferences().put(name, value);
+ }
+ dirty = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferenceStore#setValue(java.lang.String,
+ * boolean)
+ */
+ public void setValue(String name, boolean value) {
+ boolean oldValue = getBoolean(name);
+ if(oldValue == value) {
+ return;
+ }
+ try {
+ silentRunning = true;// Turn off updates from the store
+ if(getDefaultBoolean(name) == value) {
+ getStorePreferences().remove(name);
+ } else {
+ getStorePreferences().putBoolean(name, value);
+ }
+ dirty = true;
+ firePropertyChangeEvent(name, oldValue ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
+ } finally {
+ silentRunning = false;// Restart listening to preferences
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPersistentPreferenceStore#save()
+ */
+ public void save() throws IOException {
+ try {
+ getStorePreferences().flush();
+ dirty = false;
+ } catch (BackingStoreException e) {
+ throw new IOException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Dispose the receiver.
+ */
+ private void disposePreferenceStoreListener() {
+
+ IEclipsePreferences root = (IEclipsePreferences)Platform.getPreferencesService().getRootNode().node(Plugin.PLUGIN_PREFERENCE_SCOPE);
+ try {
+ if(!(root.nodeExists(nodeQualifier))) {
+ return;
+ }
+ } catch (BackingStoreException e) {
+ return;// No need to report here as the node won't have the
+ // listener
+ }
+
+ IEclipsePreferences preferences = getStorePreferences();
+ if(preferences == null) {
+ return;
+ }
+ if(preferencesListener != null) {
+ preferences.removePreferenceChangeListener(preferencesListener);
+ preferencesListener = null;
+ }
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractApplyValueOnPreferenceKeyDialog.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractApplyValueOnPreferenceKeyDialog.java
new file mode 100644
index 00000000000..ea08721e158
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractApplyValueOnPreferenceKeyDialog.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.preferences.ui.dialog;
+
+import java.util.ArrayList;
+
+/**
+ * The Class ApplyValueOnPreferenceKeyDialog display all the preference key and give all selected keys
+ */
+public abstract class AbstractApplyValueOnPreferenceKeyDialog extends AbstractPreferenceKeyDialog {
+
+ /** The checked key. */
+ protected ArrayList<String> checkedKey;
+
+ /**
+ * Instantiates a new apply value on preference key dialog.
+ *
+ * @param keys
+ * the keys
+ */
+ public AbstractApplyValueOnPreferenceKeyDialog(String[] keys) {
+ super(keys);
+ checkedKey = new ArrayList<String>();
+ }
+
+ /**
+ * Gets the key to remove.
+ *
+ * @return the key to remove
+ */
+ public ArrayList<String> getKeyToRemove() {
+ return checkedKey;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ @Override
+ protected void okPressed() {
+ for(int i = 0; i < keyTable.getItems().length; i++) {
+ if(keyTable.getItems()[i].getChecked()) {
+ checkedKey.add((String)keyTable.getItems()[i].getData());
+ }
+ }
+ super.okPressed();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
+ */
+ @Override
+ protected void cancelPressed() {
+ super.cancelPressed();
+ checkedKey = new ArrayList<String>();
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractPreferenceKeyDialog.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractPreferenceKeyDialog.java
new file mode 100644
index 00000000000..ebf9eeb5cbf
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/preferences/ui/dialog/AbstractPreferenceKeyDialog.java
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.preferences.ui.dialog;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.infra.tools.Activator;
+import org.eclipse.papyrus.infra.tools.messages.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ * The Class AbstractPreferenceKeyDialog display all preference key that are given in parameters
+ */
+public abstract class AbstractPreferenceKeyDialog extends org.eclipse.jface.dialogs.StatusDialog {
+
+ /** The key table. */
+ protected Table keyTable;
+
+ /** The table viewer. */
+ protected TableViewer tableViewer;
+
+ /** The keys. */
+ protected String[] keys;
+
+ /**
+ * Instantiates a new abstract preference key dialog.
+ *
+ * @param keys
+ * the array of preference jy to display
+ */
+ public AbstractPreferenceKeyDialog(String[] keys) {
+ super(new Shell());
+ this.keys = keys;
+ setStatusLineAboveButtons(true);
+ updateStatus(new Status(IStatus.INFO, Activator.PLUGIN_ID, Messages.AbstractPreferenceKeyDialog_WouldYouLikeOverloadPreferences));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ keyTable = new Table(composite, SWT.CHECK | SWT.BORDER);
+ tableViewer = new TableViewer(keyTable);
+ tableViewer.setLabelProvider(createLabelProvider());
+ tableViewer.setContentProvider(createContentProvider());
+
+ TableColumn column = new TableColumn(keyTable, SWT.NONE);
+ column.setWidth(150);
+ column.setText(Messages.AbstractPreferenceKeyDialog_Pref_Kind);
+
+ column = new TableColumn(keyTable, SWT.NONE);
+ column.setWidth(90);
+ column.setText(Messages.AbstractPreferenceKeyDialog_Level);
+
+ column = new TableColumn(keyTable, SWT.NONE);
+ column.setWidth(200);
+ column.setText(Messages.AbstractPreferenceKeyDialog_Localization);
+ tableViewer.setInput(keys);
+ keyTable.setHeaderVisible(true);
+
+
+ return composite;
+
+ }
+
+ /**
+ *
+ * @return
+ * the label provider for the table viewer
+ */
+ protected abstract IBaseLabelProvider createLabelProvider();
+
+ /**
+ *
+ * @return
+ * the content provider for the table viewer
+ */
+ protected abstract IContentProvider createContentProvider();
+
+}

Back to the top