From 98f3c4bac9b5c83fbb2ddc2981c96ff2d89db115 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Mon, 15 Sep 2014 18:22:21 +0000 Subject: [PATCH] refs #5314 Optimize OpenDiagramFromComponentAdapter to speed up diagram opening when e.g. double clicking a component under configuration folder in model browser git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30282 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../OpenDiagramFromComponentAdapter.java | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 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 fb89ccc3..20c7ab19 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 @@ -8,7 +8,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.PossibleModel; import org.simantics.db.layer0.variable.RVI; @@ -25,11 +24,9 @@ import org.simantics.modeling.ModelingResources; import org.simantics.modeling.actions.NavigateToTarget; import org.simantics.modeling.ui.Activator; import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter; import org.simantics.utils.datastructures.Callback; -import org.simantics.utils.threads.SWTThread; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.AdaptionUtils; @@ -40,6 +37,8 @@ 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); } @@ -50,7 +49,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt if (r == null) return false; Variable v = AdaptionUtils.adaptToSingle(input, Variable.class); - Collection rs = tryFindDiagram(graph, r, v); + rs = tryFindDiagram(graph, r, v); return !rs.isEmpty(); } @@ -79,29 +78,9 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt if (d == null) return; - SimanticsUI.getSession().syncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - Resource r = tryGetResource(graph, input); - if (r == null) - return; - - Variable v = AdaptionUtils.adaptToSingle(input, Variable.class); - - final Collection rs = tryFindDiagram(graph, r, v); - if (rs.isEmpty()) - return; - - SWTThread.getThreadAccess(d).asyncExec(new Runnable() { - @Override - public void run() { - for (Runnable runnable : rs) { - runnable.run(); - } - } - }); - } - }); + for (Runnable runnable : rs) { + runnable.run(); + } } private Collection tryFindDiagram(ReadGraph g, Resource module, Variable variable) throws DatabaseException { -- 2.47.1