From 960e83d8440375aacefd12be71bdb898adc1cf0a Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 16 Sep 2014 07:10:13 +0000 Subject: [PATCH] refs #5314 Modify the OpenDiagramFromComponentAdapter optimizations to obey the EditorAdapter API rules (don't cache the runnables between canHandle and openEditor) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30283 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../OpenDiagramFromComponentAdapter.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromComponentAdapter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromComponentAdapter.java index 20c7ab19..1ff6f174 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromComponentAdapter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromComponentAdapter.java @@ -6,8 +6,10 @@ import java.util.Collections; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; +import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.PossibleModel; import org.simantics.db.layer0.variable.RVI; @@ -37,19 +39,13 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; - private static Collection rs; - public OpenDiagramFromComponentAdapter() { super("Diagram Editor", Activator.COMPOSITE_ICON); } @Override public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException { - Resource r = tryGetResource(graph, input); - if (r == null) - return false; - Variable v = AdaptionUtils.adaptToSingle(input, Variable.class); - rs = tryFindDiagram(graph, r, v); + Collection rs = graph.syncRequest(new DiagramFinderRequest(input)); return !rs.isEmpty(); } @@ -77,7 +73,8 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt final Display d = Display.getCurrent(); if (d == null) return; - + + Collection rs = Simantics.getSession().syncRequest(new DiagramFinderRequest(input)); for (Runnable runnable : rs) { runnable.run(); } @@ -179,5 +176,21 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt } return selectedObjects; } + + private class DiagramFinderRequest extends UnaryRead> { + + public DiagramFinderRequest(Object parameter) { + super(parameter); + } + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + Resource r = tryGetResource(graph, parameter); + if (r == null) + return Collections.emptyList(); + Variable v = AdaptionUtils.adaptToSingle(parameter, Variable.class); + return tryFindDiagram(graph, r, v); + } + } } -- 2.47.1