Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java170
1 files changed, 151 insertions, 19 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java
index bf9fbdab2fd..9997e9f82b1 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2013 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
@@ -16,6 +16,8 @@ import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
import org.eclipse.papyrus.infra.tools.util.StringHelper;
@@ -32,9 +34,13 @@ public class NotationTypesMap {
public static final String EXTENSION_ID = Activator.ID + ".notationTypesMapping"; //$NON-NLS-1$
- private final Map<String, String> computerToHumanTypeMapping = new HashMap<String, String>();
+ public static final String DIAGRAM_CATEGORY = "diagramMappings"; //$NON-NLS-1$
+
+ public static final String ALL_DIAGRAMS = "Papyrus.AllDiagrams"; //$NON-NLS-1$
+
+ public static final String MAPPING = "mapping";
- private final Map<String, String> humanToComputerTypeMapping = new HashMap<String, String>();
+ private final Map<String, TypeMap> typeMaps = new HashMap<String, TypeMap>(); //DiagramID -> TypeMap
private NotationTypesMap() {
readExtensionPoint();
@@ -42,34 +48,160 @@ public class NotationTypesMap {
private void readExtensionPoint() {
IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
- for(IConfigurationElement mappingDefinition : configurationElements) {
+ for(IConfigurationElement diagramMappingsDefinition : configurationElements) {
+
+ if(DIAGRAM_CATEGORY.equals(diagramMappingsDefinition.getName())) {
+ String diagramID = diagramMappingsDefinition.getAttribute("diagramID");
+
+ TypeMap typeMap = getOrCreateTypeMap(diagramID);
+
+ for(IConfigurationElement mappingDefinition : diagramMappingsDefinition.getChildren()) {
+
+ final String notationType = mappingDefinition.getAttribute("type");
+ final String humanReadableType = StringHelper.toJavaIdentifier(mappingDefinition.getAttribute("humanReadableType"));
- final String notationType = mappingDefinition.getAttribute("type");
- final String humanReadableType = StringHelper.toJavaIdentifier(mappingDefinition.getAttribute("humanReadableType"));
+ if(notationType == null || humanReadableType == null) {
+ Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", mappingDefinition.getContributor().getName()));
+ continue;
+ }
- if(notationType == null || humanReadableType == null) {
- Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", mappingDefinition.getContributor().getName()));
- continue;
+
+ typeMap.getComputerToHumanTypeMapping().put(notationType, humanReadableType);
+ typeMap.getHumanToComputerTypeMapping().put(humanReadableType, notationType);
+ }
+ } else if(MAPPING.equals(diagramMappingsDefinition.getName())) {
+
+ TypeMap typeMap = TypeMap.defaultMap;
+
+ final String notationType = diagramMappingsDefinition.getAttribute("type");
+ final String humanReadableType = StringHelper.toJavaIdentifier(diagramMappingsDefinition.getAttribute("humanReadableType"));
+
+ if(notationType == null || humanReadableType == null) {
+ Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", diagramMappingsDefinition.getContributor().getName()));
+ continue;
+ }
+
+
+ typeMap.getComputerToHumanTypeMapping().put(notationType, humanReadableType);
+ typeMap.getHumanToComputerTypeMapping().put(humanReadableType, notationType);
}
+ }
+ }
+
+ //Never null.
+ //Used at runtime. Do not fill the map if the diagramID doesn't exist.
+ private TypeMap getTypeMap(String diagramID) {
+ if(typeMaps.containsKey(diagramID)) {
+ return typeMaps.get(diagramID);
+ }
+
+ return TypeMap.defaultMap;
+ }
+
+ private TypeMap getTypeMap(View view) {
+ if(view.getDiagram() == null) {
+ return TypeMap.defaultMap;
+ }
+
+ return getTypeMap(view.getDiagram().getType());
+ }
+
+ //Never null.
+ //Used during parsing of extension point. Fills the map if the diagramID doesn't exist
+ private TypeMap getOrCreateTypeMap(String diagramID) {
+ if(!typeMaps.containsKey(diagramID)) {
+ TypeMap typeMap = new TypeMap();
+ typeMaps.put(diagramID, typeMap);
+ }
+
+ return typeMaps.get(diagramID);
+ }
+
+ //////////////////////
+
+ public String getNotationType(String humanReadableType, String diagramID) {
+ return getTypeMap(diagramID).getNotationType(humanReadableType);
+ }
- computerToHumanTypeMapping.put(notationType, humanReadableType);
- humanToComputerTypeMapping.put(humanReadableType, notationType);
+ public String getHumanReadableType(String notationType, String diagramID) {
+ return getTypeMap(diagramID).getHumanReadableType(notationType);
+ }
+
+ public Map<String, String> getComputerToHumanTypeMapping(String diagramID) {
+ return getTypeMap(diagramID).getComputerToHumanTypeMapping();
+ }
+
+ public Map<String, String> getHumanToComputerTypeMapping(String diagramID) {
+ return getTypeMap(diagramID).getHumanToComputerTypeMapping();
+ }
+
+ //////////////////////
+
+ public String getNotationType(View view) {
+ if(view == null) {
+ return null;
}
+
+ return getTypeMap(view).getNotationType(view.getType());
}
- public String getNotationType(String humanReadableType) {
- return humanToComputerTypeMapping.get(humanReadableType);
+ public String getHumanReadableType(View view) {
+ if(view == null) {
+ return null;
+ }
+
+ return getTypeMap(view).getHumanReadableType(view.getType());
}
- public String getHumanReadableType(String notationType) {
- return computerToHumanTypeMapping.get(notationType);
+
+ public Map<String, String> getComputerToHumanTypeMapping(Diagram diagram) {
+ if(diagram == null) {
+ return TypeMap.defaultMap.getComputerToHumanTypeMapping();
+ }
+
+ return getComputerToHumanTypeMapping(diagram.getType());
}
- public Map<String, String> getComputerToHumanTypeMapping() {
- return computerToHumanTypeMapping;
+ public Map<String, String> getHumanToComputerTypeMapping(Diagram diagram) {
+ if(diagram == null) {
+ return TypeMap.defaultMap.getHumanToComputerTypeMapping();
+ }
+
+ return getHumanToComputerTypeMapping(diagram.getType());
}
- public Map<String, String> getHumanToComputerTypeMapping() {
- return humanToComputerTypeMapping;
+ //////////////////////
+
+ private static class TypeMap {
+
+ public static final TypeMap defaultMap = new TypeMap();
+
+ private final Map<String, String> computerToHumanTypeMapping = new HashMap<String, String>(); //GMF Type -> Human-readable Type
+
+ private final Map<String, String> humanToComputerTypeMapping = new HashMap<String, String>(); //Human-readable Type -> GMF Type
+
+ public String getNotationType(String humanReadableType) {
+ if(humanToComputerTypeMapping.containsKey(humanReadableType) || defaultMap == this) {
+ return humanToComputerTypeMapping.get(humanReadableType);
+ }
+
+ return defaultMap.getNotationType(humanReadableType);
+ }
+
+ public String getHumanReadableType(String notationType) {
+ if(computerToHumanTypeMapping.containsKey(notationType) || defaultMap == this) {
+ return computerToHumanTypeMapping.get(notationType);
+ }
+
+ return defaultMap.getHumanReadableType(notationType);
+ }
+
+ public Map<String, String> getComputerToHumanTypeMapping() {
+ return computerToHumanTypeMapping;
+ }
+
+ public Map<String, String> getHumanToComputerTypeMapping() {
+ return humanToComputerTypeMapping;
+ }
}
}

Back to the top