From 65c4cda86f5e513114288e58228c2a0b5847f5a8 Mon Sep 17 00:00:00 2001 From: jplaine Date: Fri, 3 Sep 2010 09:45:59 +0000 Subject: [PATCH] git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17791 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../OpenDiagramFromConfigurationAdapter.java | 119 +++++++++++------- .../sysdyn/ui/project/HistoryVariable.java | 3 +- 2 files changed, 75 insertions(+), 47 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java index e82c0b6b..854a3410 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java @@ -1,32 +1,38 @@ package org.simantics.sysdyn.ui.editor; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.modeling.ComponentUtils; import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ui.Activator; import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.StructuralVariables; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter; +import org.simantics.utils.ui.workbench.WorkbenchUtils; - -public class OpenDiagramFromConfigurationAdapter extends org.simantics.modeling.ui.diagramEditor.OpenDiagramFromConfigurationAdapter { +public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorAdapter { private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; - public OpenDiagramFromConfigurationAdapter() { - super(); - } + public OpenDiagramFromConfigurationAdapter() { + super("Diagram Editor", Activator.COMPOSITE_ICON); + } - @Override - protected String getEditorId() { - return EDITOR_ID; - } + protected String getEditorId() { + return EDITOR_ID; + } - @Override - public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException { + @Override + public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(g); if(g.isInheritedFrom(r, sr.ModuleSymbol)) { ModelingResources mr = ModelingResources.getInstance(g); @@ -42,41 +48,62 @@ public class OpenDiagramFromConfigurationAdapter extends org.simantics.modeling. } } return ComponentUtils.compositeHasDiagram(g, r) /*|| ComponentUtils.componentHasDiagram(g, r)*/; - } - - @Override - public void openEditor(final Resource r) throws Exception { - Resource configuration = null; - try { - configuration = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).ModuleSymbol)) { - ModelingResources mr = ModelingResources.getInstance(graph); - StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - Resource componentType = graph.getSingleObject(r, mr.SymbolToComponentType); - Resource configuration = graph.getSingleObject(componentType, sr2.IsDefinedBy); - return configuration; - } else { - Resource represents = graph.getPossibleObject(r, l0.Represents); - if(represents != null && graph.isInstanceOf(represents, SysdynResource.getInstance(graph).Configuration)){ - return represents; - } - else { - return null; - } + } + + @Override + public void openEditor(final Resource r) throws Exception { + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource cr = r; + Layer0 l0 = Layer0.getInstance(g); + if(g.isInheritedFrom(r, SysdynResource.getInstance(g).ModuleSymbol)) { + ModelingResources mr = ModelingResources.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + Resource componentType = g.getSingleObject(r, mr.SymbolToComponentType); + Resource configuration = g.getSingleObject(componentType, sr2.IsDefinedBy); + cr = configuration; + } else { + Resource represents = g.getPossibleObject(r, l0.Represents); + if(represents != null && g.isInstanceOf(represents, SysdynResource.getInstance(g).Configuration)){ + cr = represents; + } else { + cr = r; } } - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - if (configuration != null) - super.openEditor(configuration); - else - super.openEditor(r); - } + + final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(g, r); + if(diagram == null) return; + final ResourceArray compositePath = StructuralVariables.getCompositeArray(g, r); + final ResourceArray variablePath = compositePath.removeFromBeginning(1); + + Resource model = StructuralVariables.getModel(g, compositePath.head()); + if(model == null) return; + final String modelURI = g.getURI(model); + + final String rvi = StructuralVariables.getRVI(g, variablePath); + if(rvi == null) return; + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + try { + String editorId = getEditorId(); +// System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'"); + WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, diagram, modelURI, rvi)); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); + + } + + }); + + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java index d0054c04..427b1939 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java @@ -65,7 +65,8 @@ public class HistoryVariable extends ResourceVariable { System.out.println("HistoryVariable rvi='" + tmp + "'"); final String rvi = tmp.substring(1).replace("/", "."); SysdynDataSet ds = sr.getDataSet(rvi); - assert(ds != null); + if(ds == null) return null; +// assert(ds != null); try { final RecordAccessor ac = (RecordAccessor)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds); -- 2.47.1