From: lempinen Date: Thu, 7 Oct 2010 12:13:44 +0000 (+0000) Subject: Model browser enter and double-click handling X-Git-Tag: simantics-1.2.0~3 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ae921a46e2582fe430efc9231f9c493fcdadcc2e;p=simantics%2Fsysdyn.git Model browser enter and double-click handling git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18300 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 9fdc3437..bcde8c4b 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -749,4 +749,18 @@ label="System Dynamics ontology dependencies"> + + + + + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java new file mode 100644 index 00000000..6cd51681 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java @@ -0,0 +1,48 @@ +package org.simantics.sysdyn.ui.actions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.project.IProject; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.action.PriorityAction; + +public class ActivateExperimentAction implements IDoubleClickAction { + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + ReadGraph g = e.getGraph(); + final Resource experiment = ResourceAdaptionUtils.toSingleResource(e.getResource()); + if (experiment == null) + return; + + if (g.isInstanceOf(experiment, SimulationResource.getInstance(g).Experiment)) { + final IProject project = SimanticsUI.getProject(); + if (project == null) + return; + + final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + if (experimentManager == null) { + ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception()); + return; + } + + e.add(new PriorityAction(PriorityAction.HIGH+20) { + @Override + public void run() { + SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, experiment); + } + }); + e.consume(); + } + + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java new file mode 100644 index 00000000..cff7e26a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java @@ -0,0 +1,44 @@ +package org.simantics.sysdyn.ui.actions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.action.PriorityAction; + +public class ConsumeUnnecessaryEntersAction implements IDoubleClickAction { + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + ReadGraph g = e.getGraph(); + Layer0 l0 = Layer0.getInstance(g); + final Resource resource = ResourceAdaptionUtils.toSingleResource(e.getResource()); + if(resource == null) + return; + SysdynResource sr = SysdynResource.getInstance(g); + + if(g.isInstanceOf(resource, sr.SysdynModel) || g.isInstanceOf(resource, sr.Variable)) { + consume(e); + } else if(g.hasStatement(resource, l0.Represents)){ + Resource represents = g.getSingleObject(resource, l0.Represents); + if (g.isInstanceOf(represents, sr.Variable)) { + consume(e); + } + } + } + + private void consume(DoubleClickEvent e) { + e.add(new PriorityAction(PriorityAction.HIGH) { + @Override + public void run() { + + } + }); + e.consume(); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java new file mode 100644 index 00000000..b3c8d6c4 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java @@ -0,0 +1,94 @@ +package org.simantics.sysdyn.ui.actions; + +import java.util.Set; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PartInitException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.BrowserSelection; +import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.action.PriorityAction; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class ShowInstantiatedModuleAction implements IDoubleClickAction { + + private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + + ReadGraph g = e.getGraph(); + + if(e.getResource() instanceof IStructuredSelection) { + Set bss = ISelectionUtils.filterSetSelection(e.getResource(), BrowserSelection.class); + + if(!bss.isEmpty()) { + Layer0 l0 = Layer0.getInstance(g); + for(BrowserSelection bs : bss) { + Resource instanceOf = g.getSingleObject((Resource)bs.getAdapter(Resource.class), l0.InstanceOf); + SysdynResource sr = SysdynResource.getInstance(g); + if(g.isInheritedFrom(instanceOf, sr.Module)) { + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy); + addShowModuleAction(e, getResourceEditorInput(g, bs.getModel(), conf, bs.getURI())); + } + } + } else { + ModuleNode moduleNode = ISelectionUtils.filterSingleSelection(e.getResource(), ModuleNode.class); + if(moduleNode != null) { + Layer0 l0 = Layer0.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + String rvi = moduleNode.getURI(g); + Resource instanceOf = g.getSingleObject(moduleNode.getResource() != null ? moduleNode.getResource() : moduleNode.data, l0.InstanceOf); + Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy); + addShowModuleAction(e, getResourceEditorInput(g, moduleNode.getModel(), conf, rvi)); + } + } + } + } + + private ResourceEditorInput2 getResourceEditorInput(ReadGraph g, Resource model, Resource configuration, String rvi) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + + String modelURI; + if(model != null) { + modelURI = g.getURI(model); + } else { + Resource parent = configuration; + do { + parent = g.getPossibleObject(parent, l0.PartOf); + } while (parent != null && !g.isInstanceOf(parent, sr.SysdynModel)); + modelURI = g.getURI(parent); + rvi = null; + } + + Resource diagram = g.getSingleObject(configuration, ModelingResources.getInstance(g).CompositeToDiagram); + return new ResourceEditorInput2(EDITOR_ID, diagram, modelURI, rvi == null ? "" : "/" + rvi); + } + + private void addShowModuleAction(DoubleClickEvent e, final ResourceEditorInput2 editorInput) { + e.add(new PriorityAction(PriorityAction.HIGH) { + @Override + public void run() { + try { + WorkbenchUtils.openEditor(EDITOR_ID, editorInput); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + e.consume(); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java index 286f57cb..b2d10d61 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java @@ -16,12 +16,14 @@ public class InputLabeler extends LabelerContributor{ StringBuilder sb = new StringBuilder(); for(Resource r : graph.getObjects(varres, l0.HasName)) sb.append(graph.getValue(r)); - sb.append(" : "); - Resource represents = graph.getPossibleObject(varres, l0.Represents); - if(represents == null) return sb.toString(); - for(Resource t : graph.getObjects(represents, l0.InstanceOf)) - for(Resource r : graph.getObjects(t, l0.HasName)) - sb.append(graph.getValue(r)); + if(graph.isInstanceOf(varres, l0.Realization)) { + varres = graph.getPossibleObject(varres, l0.Represents); + if(varres == null) return sb.toString(); + } + sb.append(" : "); + for(Resource t : graph.getObjects(varres, l0.InstanceOf)) + for(Resource r : graph.getObjects(t, l0.HasName)) + sb.append(graph.getValue(r)); return sb.toString(); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java index 51f47eae..94cedeb8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java @@ -27,12 +27,14 @@ public class ModuleLabeler extends LabelerContributor{ StringBuilder sb = new StringBuilder(); for(Resource r : graph.getObjects(resource, l0.HasName)) sb.append(graph.getValue(r)); - sb.append(" : "); - Resource represents = graph.getPossibleObject(resource, l0.Represents); - if(represents == null) return sb.toString(); - for(Resource t : graph.getObjects(represents, l0.InstanceOf)) - for(Resource r : graph.getObjects(t, l0.HasName)) - sb.append(graph.getValue(r)); + if(graph.isInstanceOf(resource, l0.Realization)) { + resource = graph.getPossibleObject(resource, l0.Represents); + if(resource == null) return sb.toString(); + } + sb.append(" : "); + for(Resource t : graph.getObjects(resource, l0.InstanceOf)) + for(Resource r : graph.getObjects(t, l0.HasName)) + sb.append(graph.getValue(r)); return sb.toString(); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java index ac92c4b9..a75cfe49 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java @@ -20,20 +20,22 @@ import org.simantics.sysdyn.ui.browser.nodes.VariableNode; public class VariableLabeler extends LabelerContributor>{ - @Override - public String getLabel(ReadGraph graph, VariableNode var) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - Resource varres = var.data; - StringBuilder sb = new StringBuilder(); - for(Resource r : graph.getObjects(varres, l0.HasName)) - sb.append(graph.getValue(r)); - sb.append(" : "); - Resource represents = graph.getPossibleObject(varres, l0.Represents); - if(represents == null) return sb.toString(); - for(Resource t : graph.getObjects(represents, l0.InstanceOf)) - for(Resource r : graph.getObjects(t, l0.HasName)) - sb.append(graph.getValue(r)); - return sb.toString(); - } + @Override + public String getLabel(ReadGraph graph, VariableNode var) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource varres = var.data; + StringBuilder sb = new StringBuilder(); + for(Resource r : graph.getObjects(varres, l0.HasName)) + sb.append(graph.getValue(r)); + if(graph.isInstanceOf(varres, l0.Realization)) { + varres = graph.getPossibleObject(varres, l0.Represents); + if(varres == null) return sb.toString(); + } + sb.append(" : "); + for(Resource t : graph.getObjects(varres, l0.InstanceOf)) + for(Resource r : graph.getObjects(t, l0.HasName)) + sb.append(graph.getValue(r)); + return sb.toString(); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java index db67c36b..00117ddc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java @@ -1,16 +1,10 @@ package org.simantics.sysdyn.ui.browser.nodes; -import org.simantics.browsing.ui.common.node.IDoubleClickableNode; import org.simantics.db.Resource; -public class ModuleNode extends ConfigurationNode implements IDoubleClickableNode { +public class ModuleNode extends ConfigurationNode { public ModuleNode(Resource resource) { super(resource); } - - @Override - public boolean handleDoubleClick() { - return true; - } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java index ce7b2d77..4d5b141d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java @@ -66,23 +66,7 @@ public class VariableNode extends AbstractNode { @Override public String perform(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - String uri = getName(graph); - - // don't search for a parent if the resource is not part of a realization - if(!graph.isInheritedFrom(graph.getSingleObject(data, l0.InstanceOf), l0.Realization)) - return "NOT PART OF REALIZATION"; - - // search for the model parent and build the uri - Resource parent = graph.getSingleObject(data, l0.PartOf); - while (!graph.isInstanceOf(parent, sr.SysdynModel)) { - uri = graph.getRelatedValue(parent, l0.HasName) + "/" + uri; - parent = graph.getSingleObject(parent, l0.PartOf); - } - // cut out the realization name - uri = uri.substring(uri.indexOf("/") + 1); - return uri; + return getURI(graph); } }); @@ -91,6 +75,26 @@ public class VariableNode extends AbstractNode { } return null; } + + public String getURI(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + String uri = getName(graph); + + // don't search for a parent if the resource is not part of a realization + if(!graph.isInheritedFrom(graph.getSingleObject(data, l0.InstanceOf), l0.Realization)) + return null; + + // search for the model parent and build the uri + Resource parent = graph.getSingleObject(data, l0.PartOf); + while (!graph.isInstanceOf(parent, sr.SysdynModel)) { + uri = graph.getRelatedValue(parent, l0.HasName) + "/" + uri; + parent = graph.getSingleObject(parent, l0.PartOf); + } + // cut out the realization name + uri = uri.substring(uri.indexOf("/") + 1); + return uri; + } public Resource getModel() { return model; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java index 45d8d893..90fff3aa 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java @@ -85,8 +85,15 @@ public class ShowModuleHandler extends AbstractHandler { if(diagram == null) return; - final String rvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, l0.HasName, StringBindingDefault.INSTANCE); - + String finalRvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, l0.HasName, StringBindingDefault.INSTANCE); + + Variable rootVariable = graph.adapt(model, Variable.class); + Variable var = rootVariable.browsePossible(graph, finalRvi); + if(var == null) { + finalRvi = ""; + } + final String rvi = finalRvi; + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override @@ -94,7 +101,7 @@ public class ShowModuleHandler extends AbstractHandler { // for (Triple in : ins) { try { String editorId = EDITOR_ID; - System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'"); +// 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