Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/preferences/ExtendedTypesPreferences.java')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/preferences/ExtendedTypesPreferences.java116
1 files changed, 109 insertions, 7 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/preferences/ExtendedTypesPreferences.java b/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/preferences/ExtendedTypesPreferences.java
index caccc00c2bf..e02c87e3752 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/preferences/ExtendedTypesPreferences.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.extendedtypes/src/org/eclipse/papyrus/infra/extendedtypes/preferences/ExtendedTypesPreferences.java
@@ -16,6 +16,10 @@ package org.eclipse.papyrus.infra.extendedtypes.preferences;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.io.ObjectOutputStream.PutField;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.infra.extendedtypes.Activator;
@@ -23,7 +27,6 @@ import org.eclipse.ui.IMemento;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.XMLMemento;
-
/**
* Preferences management for extended types
*/
@@ -35,6 +38,8 @@ public class ExtendedTypesPreferences {
/** id for the node: extended types redefinition */
public final static String EXTENDED_TYPES_REDEFINITION = "extendedTypesRedefinition"; //$NON-NLS-1$
+ public static final String EXTENDED_TYPES_SET_WORKSPACE_DEFINITION = "extendedTypeSetsWorkspaceDefinition";
+
/** name of the ID attribute */
public final static String ID = "id"; //$NON-NLS-1$
@@ -82,22 +87,17 @@ public class ExtendedTypesPreferences {
*/
public static IMemento registerLocalRedefinition(String extendedTypesID, String path) {
XMLMemento rootMemento = getLocalRedefinitions();
-
// try to find an existing local definition for this extendedTypes
IMemento memento = getExtendedTypesRedefinitionNode(extendedTypesID);
-
// if one exists, remove it from the preferences
if(memento != null) {
unregisterLocalRedefinition(extendedTypesID);
}
-
// then register the new one
IMemento newMemento = rootMemento.createChild(EXTENDED_TYPES_REDEFINITION);
newMemento.putString(ID, extendedTypesID);
newMemento.putString(PATH, path);
-
saveLocalRedefinitions(rootMemento);
-
return newMemento;
}
@@ -122,6 +122,39 @@ public class ExtendedTypesPreferences {
}
/**
+ * Returns the memento associated to the extendedTypes set definition in workspace, or <code>null</code> if none exists
+ *
+ * @return the memento found or <code>null</code> if no customization exists for this extendedTypes
+ */
+ protected static IMemento[] getWorkspaceDefinitions() {
+ XMLMemento rootMemento = getLocalRedefinitions();
+ IMemento[] workspaceDefinitions = rootMemento.getChildren(EXTENDED_TYPES_SET_WORKSPACE_DEFINITION);
+ return workspaceDefinitions;
+ }
+
+ /**
+ * Returns the memento associated to the extendedTypes set definition in workspace, or <code>null</code> if none exists
+ *
+ * @return the memento found or <code>null</code> if no customization exists for this extendedTypes
+ */
+ protected static IMemento getWorkspaceDefinition(String extendedTypeSetsID) {
+ if(extendedTypeSetsID == null) {
+ return null;
+ }
+ IMemento[] workspaceDefinitions = getWorkspaceDefinitions();
+ if(workspaceDefinitions == null || workspaceDefinitions.length == 0) {
+ return null;
+ }
+ for(IMemento memento : workspaceDefinitions) {
+ String id = memento.getString(ID);
+ if(extendedTypeSetsID.equals(id)) {
+ return memento;
+ }
+ }
+ return null;
+ }
+
+ /**
* Returns the path for a given extended type local redefinition
*
* @param extendedTypesID
@@ -158,9 +191,33 @@ public class ExtendedTypesPreferences {
newRootMemento.putMemento(memento);
}
}
+ for(IMemento memento : rootMemento.getChildren(EXTENDED_TYPES_SET_WORKSPACE_DEFINITION)) {
+ newRootMemento.putMemento(memento);
+ }
// save new Memento
saveLocalRedefinitions(newRootMemento);
+ }
+ /**
+ * @param extendedTypesID
+ */
+ public static void unregisterWorkspaceDefinition(String extendedTypesID) {
+ XMLMemento rootMemento = getLocalRedefinitions();
+ // no remove method...
+ // so, creation of a new root memento, then, duplicate all entries
+ // except the one to
+ // delete...
+ XMLMemento newRootMemento = XMLMemento.createWriteRoot(EXTENDED_TYPES_REDEFINITIONS);
+ for(IMemento memento : rootMemento.getChildren(EXTENDED_TYPES_REDEFINITION)) {
+ newRootMemento.putMemento(memento);
+ }
+ for(IMemento memento : rootMemento.getChildren(EXTENDED_TYPES_SET_WORKSPACE_DEFINITION)) {
+ if(!memento.getString(ID).equals(extendedTypesID)) {
+ newRootMemento.putMemento(memento);
+ }
+ }
+ // save new Memento
+ saveLocalRedefinitions(newRootMemento);
}
/**
@@ -176,7 +233,6 @@ public class ExtendedTypesPreferences {
StringWriter writer = new StringWriter();
try {
xmlMemento.save(writer);
-
if(getPreferenceStore() != null) {
getPreferenceStore().setValue(key, writer.toString());
}
@@ -194,4 +250,50 @@ public class ExtendedTypesPreferences {
public static void saveLocalRedefinitions(XMLMemento rootMemento) {
saveMemento(rootMemento, EXTENDED_TYPES_REDEFINITIONS);
}
+
+ /**
+ * Returns all the paths in the workspace that should be an extended type set to load, with the id as a key
+ *
+ * @return
+ */
+ public static Map<String, String> getLocalExtendedTypesDefinitions() {
+ IMemento[] mementos = getWorkspaceDefinitions();
+ if(mementos != null && mementos.length > 0) {
+ Map<String, String> idToPath = new HashMap<String, String>();
+ for(IMemento memento : mementos) {
+ String id = memento.getString(ID);
+ String path = memento.getString(PATH);
+ if(id != null && !"".equals(id) && path != null && !"".equals(PATH)) {
+ idToPath.put(id, path);
+ }
+ }
+ return idToPath;
+ }
+ return null;
+ }
+
+ /**
+ * Register a new local redefinition of a extendedTypes.
+ *
+ * @param extendedTypesID
+ * the id of the extendedTypes to register
+ * @param path
+ * the path to the configuration of the extendedTypes
+ * @return the memento that has been registered
+ */
+ public static IMemento registerWorkspaceDefinition(String extendedTypesID, String path) {
+ XMLMemento rootMemento = getLocalRedefinitions();
+ // try to find an existing local definition for this extendedTypes
+ IMemento memento = getWorkspaceDefinition(extendedTypesID);
+ // if one exists, remove it from the preferences
+ if(memento != null) {
+ unregisterWorkspaceDefinition(extendedTypesID);
+ }
+ // then register the new one
+ IMemento newMemento = rootMemento.createChild(EXTENDED_TYPES_SET_WORKSPACE_DEFINITION);
+ newMemento.putString(ID, extendedTypesID);
+ newMemento.putString(PATH, path);
+ saveLocalRedefinitions(rootMemento);
+ return newMemento;
+ }
}

Back to the top