\r
import org.eclipse.swt.widgets.Display;\r
import org.eclipse.ui.IEditorPart;\r
+import org.simantics.Simantics;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.UnaryRead;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.request.PossibleModel;\r
import org.simantics.db.layer0.variable.RVI;\r
\r
private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
\r
- private static Collection<Runnable> rs;\r
- \r
public OpenDiagramFromComponentAdapter() {\r
super("Diagram Editor", Activator.COMPOSITE_ICON);\r
}\r
\r
@Override\r
public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {\r
- Resource r = tryGetResource(graph, input);\r
- if (r == null)\r
- return false;\r
- Variable v = AdaptionUtils.adaptToSingle(input, Variable.class);\r
- rs = tryFindDiagram(graph, r, v);\r
+ Collection<Runnable> rs = graph.syncRequest(new DiagramFinderRequest(input));\r
return !rs.isEmpty();\r
}\r
\r
final Display d = Display.getCurrent();\r
if (d == null)\r
return;\r
-\r
+ \r
+ Collection<Runnable> rs = Simantics.getSession().syncRequest(new DiagramFinderRequest(input));\r
for (Runnable runnable : rs) {\r
runnable.run();\r
}\r
}\r
return selectedObjects;\r
}\r
+ \r
+ private class DiagramFinderRequest extends UnaryRead<Object, Collection<Runnable>> {\r
+\r
+ public DiagramFinderRequest(Object parameter) {\r
+ super(parameter);\r
+ }\r
+\r
+ @Override\r
+ public Collection<Runnable> perform(ReadGraph graph) throws DatabaseException {\r
+ Resource r = tryGetResource(graph, parameter);\r
+ if (r == null)\r
+ return Collections.emptyList();\r
+ Variable v = AdaptionUtils.adaptToSingle(parameter, Variable.class);\r
+ return tryFindDiagram(graph, r, v);\r
+ }\r
+ }\r
\r
}\r