]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Use PreferredDiagramEditorID in OpenDiagramEditorFromComponentAdapter 90/3190/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Tue, 3 Sep 2019 10:28:13 +0000 (13:28 +0300)
committerJussi Koskela <jussi.koskela@semantum.fi>
Tue, 3 Sep 2019 10:29:19 +0000 (13:29 +0300)
gitlab #371

Change-Id: Ia2b39d03f346a47c45b3982ec882b9facc9e28eb

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromComponentAdapter.java

index d5071303e4924b22a3f812f05b312141d03a5ed1..6be9f72f92d2939dfafefb7284a36ca2d9d0d87e 100644 (file)
@@ -63,6 +63,15 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
         super(Messages.OpenDiagramFromComponentAdapter_OpenDiagramContainingComponent, Activator.SYMBOL_ICON);
     }
 
+    protected String getEditorId(ReadGraph g, Resource diagram) throws DatabaseException {
+        ModelingResources MOD = ModelingResources.getInstance(g);
+        String preferredEditorId = g.getPossibleRelatedValue(diagram, MOD.PreferredDiagramEditorID);
+        if(preferredEditorId != null)
+            return preferredEditorId;
+        else
+            return EDITOR_ID;
+    }
+
     @Override
     public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {
         Pair<Resource, String> p = tryGetResource(graph, input);
@@ -153,6 +162,8 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
             Resource composite = g.getSingleObject(component, l0.PartOf);
             Resource diagram = ComponentUtils.getPossibleCompositeDiagram(g, composite);
 
+            String editorId = getEditorId(g, composite);
+
             if (LOGGER.isDebugEnabled()) {
                 LOGGER.debug(getClass().getSimpleName() + ".findDiagram: component: " + NameUtils.getURIOrSafeNameInternal(g, component)); //$NON-NLS-1$
                 LOGGER.debug(getClass().getSimpleName() + ".findDiagram: composite: " + NameUtils.getURIOrSafeNameInternal(g, composite)); //$NON-NLS-1$
@@ -213,7 +224,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
                 // Prevent diagram from opening if there's nothing to select
                 // on the diagram based on the received input.
                 if (!selectedObjects.isEmpty())
-                    result.add( NavigateToTarget.editorActivator(EDITOR_ID, diagram, indexRoot, rvi, editorActivationCallback(selectedObjects)) );
+                    result.add( NavigateToTarget.editorActivator(editorId, diagram, indexRoot, rvi, editorActivationCallback(selectedObjects)) );
             } else {
                 final MapSet<NamedResource, Resource> referencingDiagrams = listReferenceDiagrams(g, referenceElements);
                 final Set<NamedResource> diagrams = referencingDiagrams.getKeys();
@@ -238,7 +249,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
                     RVI rvi = getDiagramCompositeRvi(g, singleDiagram.getResource());
                     if (rvi != null) {
                         Collection<Resource> selectedObjects = referencingDiagrams.getValues(singleDiagram);
-                        result.add( NavigateToTarget.editorActivator(EDITOR_ID, singleDiagram.getResource(), indexRoot, rvi, editorActivationCallback(selectedObjects)) );
+                        result.add( NavigateToTarget.editorActivator(editorId, singleDiagram.getResource(), indexRoot, rvi, editorActivationCallback(selectedObjects)) );
                     }
                     break;
 
@@ -254,7 +265,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
                         if (selected != null) {
                             Collection<Resource> selectedObjects = referencingDiagrams.getValues(selected);
                             RVI drvi = diagramToRvi.get(selected);
-                            NavigateToTarget.editorActivator(EDITOR_ID, selected.getResource(), indexRoot, drvi, editorActivationCallback(selectedObjects)).run();
+                            NavigateToTarget.editorActivator(editorId, selected.getResource(), indexRoot, drvi, editorActivationCallback(selectedObjects)).run();
                         }
                     });
                     break;