]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
New parametrisation of OpenDiagramFromConfigurationAdapter.openEditor 17/2217/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Sep 2018 12:53:35 +0000 (15:53 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Sep 2018 15:01:42 +0000 (15:01 +0000)
The new method allows giving Resource model and RVI arguments for
ResourceEditorInput2 externally.

gitlab #130

Change-Id: I1c70e2e7548047a376b4a8b0f3797a70564f0dc0
(cherry picked from commit 08f4d03f521f01e2482c9dda8b314571ea8c35c3)

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

index 2394c490b5a02d117269edc75184e0ee4ab7fbee..82f51feeab1988a150d4bf131eaf95a0d7fda4a5 100644 (file)
@@ -150,42 +150,51 @@ public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorA
      * @param selectedObjects
      * @throws DatabaseException
      */
-    public static boolean openEditor(ReadGraph g, Resource r, final String editorId, final Collection<Object> selectedObjects) throws DatabaseException {
-
-        final Resource diagram = getDiagram(g, r, selectedObjects);
-        if (diagram == null)
-            return false;
-
-        final Resource configurationComposite = ComponentUtils.getPossibleDiagramComposite(g, diagram);
-        if (configurationComposite == null)
-            return false;
-
-        Pair<Resource, RVI> modelAndRVI = getModelAndRVI(g, configurationComposite);
+    public static boolean openEditor(ReadGraph g, Resource r, String editorId, Collection<Object> selectedObjects) throws DatabaseException {
+        Resource diagram = getDiagram(g, r, selectedObjects);
+        Resource configurationComposite = diagram != null ? ComponentUtils.getPossibleDiagramComposite(g, diagram) : null;
+        Pair<Resource, RVI> modelAndRVI = configurationComposite != null ? getModelAndRVI(g, configurationComposite) : null;
         //System.out.println("modelAndRVI: " + modelAndRVI);
         if (modelAndRVI == null)
             return false;
+        scheduleOpenEditor(editorId, diagram, modelAndRVI.first, modelAndRVI.second, selectedObjects);
+        return true;
+    }
+
+    /**
+     * @param g
+     * @param configurationComposite
+     * @param editorId
+     * @param selectedObjects
+     * @throws DatabaseException
+     */
+    public static boolean openEditor(ReadGraph g, Resource r, String editorId, Collection<Object> selectedObjects, Resource model, RVI rvi) throws DatabaseException {
+        Resource diagram = getDiagram(g, r, selectedObjects);
+        if (diagram == null)
+            return false;
+        scheduleOpenEditor(editorId, diagram, model, rvi, selectedObjects);
+        return true;
+    }
 
-        final Runnable editorActivator = NavigateToTarget.editorActivator(editorId, diagram, modelAndRVI.first, modelAndRVI.second, part -> {
+    /**
+     * @param g
+     * @param configurationComposite
+     * @param editorId
+     * @param selectedObjects
+     * @throws DatabaseException
+     */
+    private static void scheduleOpenEditor(String editorId, Resource diagram, Resource model, RVI rvi, Collection<Object> selectedObjects) throws DatabaseException {
+        Runnable editorActivator = NavigateToTarget.editorActivator(editorId, diagram, model, rvi, part -> {
             if (selectedObjects.isEmpty())
                 return;
-
-            final ICanvasContext openedCanvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);
+            ICanvasContext openedCanvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);
             assert openedCanvas != null;
             // CanvasContext-wide denial of initial zoom-to-fit on diagram open.
             openedCanvas.getDefaultHintContext().setHint(DiagramHints.KEY_INITIAL_ZOOM_TO_FIT, Boolean.FALSE);
-            //System.out.println("ASDF: " + element);
             ThreadUtils.asyncExec(openedCanvas.getThreadAccess(),
                     NavigateToTarget.elementSelectorZoomer(openedCanvas, selectedObjects, false));
         });
-
-        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                editorActivator.run();
-            }
-        });
-
-        return true;
+        PlatformUI.getWorkbench().getDisplay().asyncExec(editorActivator);
     }
 
 }