Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2017-11-22 13:10:48 +0000
committerChristian W. Damus2017-11-29 19:26:43 +0000
commite883122a241111735fd03e77128a7b25a21f3ec8 (patch)
tree7f473360ab1410d5b7ff69124dfd8d0c19b0a2f4 /plugins/infra
parent1fc9aedc20221172af1dbfd78a347a48638c9328 (diff)
downloadorg.eclipse.papyrus-e883122a241111735fd03e77128a7b25a21f3ec8.tar.gz
org.eclipse.papyrus-e883122a241111735fd03e77128a7b25a21f3ec8.tar.xz
org.eclipse.papyrus-e883122a241111735fd03e77128a7b25a21f3ec8.zip
Bug 527580: Integration issues with view-type helpers
Factor out common partial implementation of view-type helpers for consistency and add - overridable determination of PolicyChecker for the view - priority ordering of view-type helper extensions https://bugs.eclipse.org/bugs/show_bug.cgi?id=527580 (cherry-picked and expanded from Oxygen) Change-Id: I6e276ca639f4ac664206511b24bc2246472a3fa2
Diffstat (limited to 'plugins/infra')
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF5
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml2
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java68
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java34
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/META-INF/MANIFEST.MF4
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/pom.xml2
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/helper/TableCommandHelper.java55
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/pom.xml2
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/schema/viewType.exsd216
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/AbstractViewTypeHelper.java124
-rw-r--r--plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java77
12 files changed, 378 insertions, 213 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
index 5b2bec5d729..0d00ad4024c 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF
@@ -71,11 +71,12 @@ Require-Bundle: org.eclipse.emf.ecore.edit;bundle-version="[2.9.0,3.0.0)",
org.eclipse.papyrus.infra.gmfdiag.representation;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.gmfdiag.style;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.papyrus.infra.filters;bundle-version="1.2.0"
+ org.eclipse.papyrus.infra.filters;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[2.100.0,3.0.0)"; visibility:=reexport
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
-Bundle-Version: 3.1.0.qualifier
+Bundle-Version: 3.100.0.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.common.Activator
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml
index 4dcd3082aad..76b10551e2f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.gmfdiag.common</artifactId>
- <version>3.1.0-SNAPSHOT</version>
+ <version>3.100.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java
index da27db3b9b6..dd125d52f6e 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/GMFDiagramViewTypeHelper.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
+ * Copyright (c) 2013, 2017 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,24 +8,19 @@
*
* Contributors:
* Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
+ * Christian W. Damus - bug 527580
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.helper;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind;
import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram;
-import org.eclipse.papyrus.infra.gmfdiag.representation.RepresentationPackage;
-import org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper;
+import org.eclipse.papyrus.infra.viewpoints.policy.AbstractViewTypeHelper;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
/**
@@ -34,44 +28,27 @@ import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
*
* @author Laurent Wouters
*/
-public class GMFDiagramViewTypeHelper implements IViewTypeHelper {
+public class GMFDiagramViewTypeHelper extends AbstractViewTypeHelper<PapyrusDiagram> {
/**
- * The cache of prototypes
+ * Initializes me.
*/
- private Map<PapyrusDiagram, DiagramPrototype> cache;
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#isSupported(org.eclipse.emf.ecore.EClass)
- */
- @Override
- public boolean isSupported(EClass type) {
- return EcoreUtil.equals(type, RepresentationPackage.eINSTANCE.getPapyrusDiagram());
+ public GMFDiagramViewTypeHelper() {
+ super(PapyrusDiagram.class);
}
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#isSupported(org.eclipse.emf.ecore.EObject)
- */
@Override
public boolean isSupported(EObject view) {
return (view instanceof Diagram);
}
/**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#getPrototypeFor(org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusRepresentationKind)
+ * {@inheritDoc}
+ *
+ * @since 3.2
*/
@Override
- public ViewPrototype getPrototypeFor(PapyrusRepresentationKind kind) {
- if (!(kind instanceof PapyrusDiagram)) {
- return null;
- }
- PapyrusDiagram diagramKind = (PapyrusDiagram) kind;
- if (cache == null) {
- cache = new HashMap<PapyrusDiagram, DiagramPrototype>();
- }
- if (cache.containsKey(diagramKind)) {
- return cache.get(diagramKind);
- }
+ protected ViewPrototype doGetPrototypeFor(PapyrusDiagram diagramKind) {
String language = diagramKind.getLanguage().getId();
AbstractPapyrusGmfCreateDiagramCommandHandler command;
try {
@@ -81,20 +58,19 @@ public class GMFDiagramViewTypeHelper implements IViewTypeHelper {
Activator.log.error(e);
return null;
}
- DiagramPrototype proto = new DiagramPrototype(diagramKind, language, command);
- cache.put(diagramKind, proto);
- return proto;
+ return new DiagramPrototype(diagramKind, language, command);
}
/**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper#getPrototypeOf(org.eclipse.emf.ecore.EObject)
+ * {@inheritDoc}
+ *
+ * @since 3.2
*/
@Override
- public ViewPrototype getPrototypeOf(EObject view) {
- if (!isSupported(view)) {
- return null;
- }
- return DiagramUtils.getPrototype((Diagram) view);
- }
+ protected ViewPrototype doGetPrototypeOf(EObject view) {
+ Diagram diagram = (Diagram) view;
+ PolicyChecker checker = getPolicyChecker(diagram);
+ return DiagramUtils.getPrototype(diagram, checker);
+ }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
index c2be66e004d..f918e830dbc 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramUtils.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013,2017 CEA LIST.
- *
+ * Copyright (c) 2013, 2017 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,6 +10,7 @@
* Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
* Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
* Benoit Maggi (Cea) benoit.maggi@cea.fr - Add utility to get the containing diagram
+ * Christian W. Damus - bug 527580
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.utils;
@@ -171,21 +171,35 @@ public class DiagramUtils {
*/
public static ViewPrototype getPrototype(Diagram diagram) {
PolicyChecker checker = PolicyChecker.getFor(diagram);
+ return getPrototype(diagram, checker);
+ }
+
+ /**
+ * Gets the prototype of a {@code diagram} according to a given policy {@code checker}.
+ *
+ * @param diagram
+ * a diagram
+ * @param checker
+ * a policy checker
+ * @return the policy {@code checker}'s prototype for the {@code diagram}
+ *
+ * @since 3.2
+ */
+ public static ViewPrototype getPrototype(Diagram diagram, PolicyChecker checker) {
PapyrusDiagramStyle pvs = getPapyrusDiagramStyle(diagram);
- if (pvs != null) {
+ if (pvs != null) {
ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
PapyrusDiagram repKind = null;
String diagramKindId = pvs.getDiagramKindId();
if (manager.getRepresentationKindById(diagramKindId) instanceof PapyrusDiagram) {
repKind = (PapyrusDiagram) manager.getRepresentationKindById(diagramKindId);
- }
- else {
- Activator.log.info("Unexpected diagram kind: "+diagramKindId+" Your notation file might be broken or created with a previous version of the architecture framework."); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ Activator.log.info("Unexpected diagram kind: " + diagramKindId + " Your notation file might be broken or created with a previous version of the architecture framework."); //$NON-NLS-1$ //$NON-NLS-2$
}
// Check if the selected viewpoint contains the diagram model kind
if (repKind != null) {
-
+
if (checker.isInViewpoint(repKind)) {
return ViewPrototype.get(repKind);
}
@@ -206,11 +220,11 @@ public class DiagramUtils {
for (RepresentationKind representationKind : viewpoint.getRepresentationKinds()) {
if (representationKind instanceof PapyrusRepresentationKind) {
PapyrusRepresentationKind papyrusRepresentationKind = (PapyrusRepresentationKind) representationKind;
-
+
if (diagramConfigName.equals(papyrusRepresentationKind.getName())) {
ViewPrototype.get(papyrusRepresentationKind);
}
-
+
PapyrusRepresentationKind parentPapyrusRepresentationKind = papyrusRepresentationKind.getParent();
while (parentPapyrusRepresentationKind != null && !diagramConfigName.equals(parentPapyrusRepresentationKind.getName())) {
parentPapyrusRepresentationKind = parentPapyrusRepresentationKind.getParent();
@@ -228,7 +242,7 @@ public class DiagramUtils {
}
return ViewPrototype.get(checker, diagram.getType(), diagram.getElement(), diagram.getElement());
}
-
+
/**
* Sets the prototype of a diagram
*
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/META-INF/MANIFEST.MF b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/META-INF/MANIFEST.MF
index 7c3d7656aca..01387f51e3d 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/META-INF/MANIFEST.MF
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/META-INF/MANIFEST.MF
@@ -14,7 +14,7 @@ Require-Bundle: org.eclipse.papyrus.infra.nattable;bundle-version="[5.0.0,6.0.0)
org.eclipse.papyrus.infra.nattable.model;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.emf;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)",
- org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[2.100.0,3.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.emf.nattable;bundle-version="[4.0.0,5.0.0)",
org.eclipse.papyrus.infra.services.edit;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
@@ -24,7 +24,7 @@ Require-Bundle: org.eclipse.papyrus.infra.nattable;bundle-version="[5.0.0,6.0.0)
org.eclipse.papyrus.infra.nattable.representation;bundle-version="[1.0.0,2.0.0)";visibility:=reexport
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 4.0.0.qualifier
+Bundle-Version: 4.100.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Activator: org.eclipse.papyrus.infra.nattable.common.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/pom.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/pom.xml
index 0371ffb272d..b2d306df55a 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/pom.xml
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/pom.xml
@@ -8,6 +8,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.nattable.common</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.100.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/helper/TableCommandHelper.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/helper/TableCommandHelper.java
index ba1cae00d88..a3418936b6b 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/helper/TableCommandHelper.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/helper/TableCommandHelper.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2017 CEA LIST.
- *
+ * Copyright (c) 2013, 2017 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,20 +9,17 @@
* Contributors:
* Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 516882
+ * Christian W. Damus - bug 527580
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.common.helper;
-import java.util.HashMap;
-import java.util.Map;
-
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;
-import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.representation.PapyrusTable;
import org.eclipse.papyrus.infra.nattable.representation.RepresentationPackage;
-import org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper;
+import org.eclipse.papyrus.infra.viewpoints.policy.AbstractViewTypeHelper;
import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
@@ -33,27 +29,10 @@ import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
* @author Laurent Wouters
* @since 3.0
*/
-public class TableCommandHelper implements IViewTypeHelper {
-
- /**
- * The cache of prototypes
- */
- private Map<PapyrusRepresentationKind, TableViewPrototype> cache;
+public class TableCommandHelper extends AbstractViewTypeHelper<PapyrusTable> {
- @Override
- public ViewPrototype getPrototypeFor(PapyrusRepresentationKind configuration) {
- if (!(configuration instanceof PapyrusTable)) {
- return null;
- }
- if (cache == null) {
- cache = new HashMap<PapyrusRepresentationKind, TableViewPrototype>();
- }
- if (cache.containsKey(configuration)) {
- return cache.get(configuration);
- }
- TableViewPrototype proto = new TableViewPrototype((PapyrusTable) configuration);
- cache.put(configuration, proto);
- return proto;
+ public TableCommandHelper() {
+ super(PapyrusTable.class);
}
@Override
@@ -74,12 +53,24 @@ public class TableCommandHelper implements IViewTypeHelper {
return (table.getTableKindId() != null || table.getTableConfiguration() != null);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @since 4.1
+ */
@Override
- public ViewPrototype getPrototypeOf(EObject view) {
- if (!isSupported(view)) {
- return null;
- }
- PolicyChecker checker = PolicyChecker.getFor(view);
+ protected ViewPrototype doGetPrototypeFor(PapyrusTable papyrusTable) {
+ return new TableViewPrototype(papyrusTable);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @since 4.1
+ */
+ @Override
+ protected ViewPrototype doGetPrototypeOf(EObject view) {
+ PolicyChecker checker = getPolicyChecker(view);
ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
PapyrusTable repKind = (PapyrusTable) manager.getRepresentationKindById(((Table) view).getTableKindId());
if (null != repKind && checker.isInViewpoint(repKind)) // null when we are destroying the table (undo after a creation for example), bug 516882
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
index 59a2c7f40e5..39d19bed8b3 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/META-INF/MANIFEST.MF
@@ -28,7 +28,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)";visibility:=reex
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 2.100.0.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-ManifestVersion: 2
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/pom.xml b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/pom.xml
index 239c493dd58..9d3c9c9276a 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/pom.xml
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/pom.xml
@@ -6,6 +6,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.viewpoints.policy</artifactId>
- <version>2.0.0-SNAPSHOT</version>
+ <version>2.100.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/schema/viewType.exsd b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/schema/viewType.exsd
index ac27b1583da..27436bd7770 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/schema/viewType.exsd
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/schema/viewType.exsd
@@ -1,102 +1,114 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.papyrus.infra.viewpoints.policy" xmlns="http://www.w3.org/2001/XMLSchema">
-<annotation>
- <appinfo>
- <meta.schema plugin="org.eclipse.papyrus.infra.viewpoints.policy" id="org.eclipse.papyrus.infra.viewpoints.policy.viewType" name="View Type Definition"/>
- </appinfo>
- <documentation>
- Definition of a type of view
- </documentation>
- </annotation>
-
- <element name="extension">
- <annotation>
- <appinfo>
- <meta.element />
- </appinfo>
- </annotation>
- <complexType>
- <sequence>
- <element ref="helper"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute translatable="true"/>
- </appinfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="helper">
- <complexType>
- <attribute name="class" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper"/>
- </appinfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appinfo>
- <meta.section type="since"/>
- </appinfo>
- <documentation>
- [Enter the first release in which this extension point appears.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="examples"/>
- </appinfo>
- <documentation>
- [Enter extension point usage example here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="apiinfo"/>
- </appinfo>
- <documentation>
- [Enter API information here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="implementation"/>
- </appinfo>
- <documentation>
- [Enter information about supplied implementation of this extension point.]
- </documentation>
- </annotation>
-
-
-</schema>
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.infra.viewpoints.policy" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.infra.viewpoints.policy" id="org.eclipse.papyrus.infra.viewpoints.policy.viewType" name="View Type Definition"/>
+ </appinfo>
+ <documentation>
+ Definition of a type of view
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="helper"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="helper">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.viewpoints.policy.IViewTypeHelper"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="priority" type="string" use="default" value="0">
+ <annotation>
+ <documentation>
+ The priority rank, as an integer, of the extension relative to others.
+&lt;p&gt;
+The default priority is zero and higher priorities precede lower priorities in matching helpers against views in the notation model.
+&lt;/p&gt;&lt;p&gt;
+Since version 2.1.
+&lt;/p&gt;
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/AbstractViewTypeHelper.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/AbstractViewTypeHelper.java
new file mode 100644
index 00000000000..7e6ae4c8079
--- /dev/null
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/AbstractViewTypeHelper.java
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 527580
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.viewpoints.policy;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind;
+
+/**
+ * Partial implementation of a view-type helper.
+ *
+ * @author Laurent Wouters
+ *
+ * @since 2.1
+ */
+public abstract class AbstractViewTypeHelper<T extends PapyrusRepresentationKind> implements IViewTypeHelper {
+
+ private final Class<T> representationType;
+
+ /**
+ * The cache of prototypes.
+ */
+ private final Map<T, ViewPrototype> cache = new HashMap<>();
+
+ protected AbstractViewTypeHelper(Class<T> representationType) {
+ super();
+
+ this.representationType = representationType;
+ }
+
+ /**
+ * Queries the type of representation kind that I support.
+ *
+ * @return my representation type
+ */
+ protected final Class<T> getRepresentationType() {
+ return representationType;
+ }
+
+ @Override
+ public boolean isSupported(EClass type) {
+ return getRepresentationType().isAssignableFrom(type.getInstanceClass());
+ }
+
+ @Override
+ public ViewPrototype getPrototypeFor(PapyrusRepresentationKind kind) {
+ if (!isSupported(kind.eClass())) {
+ return null;
+ }
+
+ T specificKind = getRepresentationType().cast(kind);
+ ViewPrototype result = cache.get(specificKind);
+ if (result != null) {
+ // The unavailable type records an explicit null result in the cache
+ if (result.isUnavailable()) {
+ result = null;
+ }
+ return result;
+ }
+
+ result = doGetPrototypeFor(specificKind);
+
+ if (result == null) {
+ // Record the explicit null result
+ cache.put(specificKind, ViewPrototype.UNAVAILABLE_VIEW);
+ } else {
+ cache.put(specificKind, result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Determines the view prototype type for the given specific representation {@code kind}.
+ *
+ * @param kind
+ * the specific representation kind
+ * @return the view prototype, or {@code null} if there is none for the {@code kind}
+ * or somehow it failed to be determined
+ */
+ protected abstract ViewPrototype doGetPrototypeFor(T kind);
+
+ @Override
+ public ViewPrototype getPrototypeOf(EObject view) {
+ if (!isSupported(view)) {
+ return null;
+ }
+ return doGetPrototypeOf(view);
+ }
+
+ /**
+ * Determines the view prototype for the given supported {@code view} object.
+ *
+ * @param view
+ * a view known to the {@linkplain #isSupported(EObject) supported} by this helper
+ * @return its view prototype
+ */
+ protected abstract ViewPrototype doGetPrototypeOf(EObject view);
+
+ /**
+ * Obtains the most appropriate policy-checker for a {@code view}.
+ *
+ * @param view
+ * a view object
+ * @return its policy-checker
+ */
+ protected PolicyChecker getPolicyChecker(EObject view) {
+ return PolicyChecker.getFor(view);
+ }
+}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
index 7a65223d882..b7ac8b6b91c 100644
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2013, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,7 +8,7 @@
*
* Contributors:
* Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- * Christian W. Damus - bugs 474467, 493375
+ * Christian W. Damus - bugs 474467, 493375, 527580
*
*****************************************************************************/
package org.eclipse.papyrus.infra.viewpoints.policy;
@@ -16,16 +16,18 @@ package org.eclipse.papyrus.infra.viewpoints.policy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.IdentityHashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.Command;
@@ -67,22 +69,30 @@ public abstract class ViewPrototype {
*/
private static Collection<IViewTypeHelper> getCommandHelpers() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint point = registry.getExtensionPoint(EXTENSION_ID);
- IExtension[] extensions = point.getExtensions();
+ List<IConfigurationElement> elements = new ArrayList<>(Arrays.asList(registry.getConfigurationElementsFor(EXTENSION_ID)));
+
+ // Only the view helper elements
+ for (Iterator<IConfigurationElement> iter = elements.iterator(); iter.hasNext();) {
+ if (!"helper".equals(iter.next().getName())) {
+ iter.remove();
+ }
+ }
+
+ // Sort by priority
+ Collections.sort(elements, helperConfigComparator());
Collection<IViewTypeHelper> result = new ArrayList<IViewTypeHelper>();
- for (int i = 0; i != extensions.length; i++) {
- IConfigurationElement[] elements = extensions[i].getConfigurationElements();
- for (int j = 0; j != elements.length; j++) {
- try {
- IViewTypeHelper instance = (IViewTypeHelper) elements[j].createExecutableExtension("class");
- if (instance != null) {
- result.add(instance);
- }
- } catch (CoreException e) {
+ for (IConfigurationElement element : elements) {
+ try {
+ IViewTypeHelper instance = (IViewTypeHelper) element.createExecutableExtension("class");
+ if (instance != null) {
+ result.add(instance);
}
+ } catch (CoreException e) {
+ Activator.log.log(e.getStatus());
}
}
+
return result;
}
@@ -446,4 +456,41 @@ public abstract class ViewPrototype {
}
return count;
}
+
+ /**
+ * Comparator to order view-type helper configurations from highest to
+ * lowest priority.
+ *
+ * @return the descending priority comparator
+ */
+ private static Comparator<IConfigurationElement> helperConfigComparator() {
+ return new Comparator<IConfigurationElement>() {
+ private Map<IConfigurationElement, Integer> priorities = new IdentityHashMap<>();
+
+ @Override
+ public int compare(IConfigurationElement o1, IConfigurationElement o2) {
+ // Sort from highest priority to lowest
+ return getPriority(o2) - getPriority(o1);
+ }
+
+ int getPriority(IConfigurationElement element) {
+ Integer result = priorities.get(element);
+
+ if (result == null) {
+ result = 0;
+ String priorityString = element.getAttribute("priority");
+ if (priorityString != null) {
+ try {
+ result = Integer.parseInt(priorityString);
+ } catch (Exception e) {
+ result = 0;
+ }
+ }
+ priorities.put(element, result);
+ }
+
+ return result;
+ }
+ };
+ }
}

Back to the top