]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
New parametrisation of OpenDiagramFromConfigurationAdapter.openEditor 12/2212/2
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 12:53:56 +0000 (12:53 +0000)
The new method allows giving Resource model and RVI arguments for
ResourceEditorInput2 externally.

gitlab #130

Change-Id: I1c70e2e7548047a376b4a8b0f3797a70564f0dc0

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

index 978d1f89595989dc811de829f1051941edec5190..1ba559e563245878643c2aa06927b3471e6640b8 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);
     }
 
 }