From 08f4d03f521f01e2482c9dda8b314571ea8c35c3 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 20 Sep 2018 15:53:35 +0300 Subject: [PATCH] New parametrisation of OpenDiagramFromConfigurationAdapter.openEditor The new method allows giving Resource model and RVI arguments for ResourceEditorInput2 externally. gitlab #130 Change-Id: I1c70e2e7548047a376b4a8b0f3797a70564f0dc0 --- .../OpenDiagramFromConfigurationAdapter.java | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java index 978d1f895..1ba559e56 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java @@ -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 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 modelAndRVI = getModelAndRVI(g, configurationComposite); + public static boolean openEditor(ReadGraph g, Resource r, String editorId, Collection selectedObjects) throws DatabaseException { + Resource diagram = getDiagram(g, r, selectedObjects); + Resource configurationComposite = diagram != null ? ComponentUtils.getPossibleDiagramComposite(g, diagram) : null; + Pair 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 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 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); } } -- 2.47.1