<resource\r
uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r
class="org.simantics.sysdyn.ui.project.SysdynProject" />\r
- <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r class="org.simantics.sysdyn.ui.project.SysdynProject" />\r </target>\r \r <target interface="org.simantics.project.IProjectLifecycle">\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r </target>\r \r <target\r interface="org.simantics.browsing.ui.common.node.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Input"\r class="org.simantics.sysdyn.ui.browser.nodes.InputNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Module"\r class="org.simantics.sysdyn.ui.browser.nodes.ModuleNode">\r <this />\r </type>\r \r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/Module"\r class="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode">\r <this />\r </resource>\r\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r <this />\r </resource>\r\r <type\r uri="http://www.simantics.org/Simulation-1.0/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r \r </target>\r\r <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r <target interface="org.simantics.g2d.diagram.DiagramClass">\r <adapter uri="http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram"\r adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r </target>\r\r <!-- Sysdyn symbols -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" /> \r </target>\r \r <!-- Sysdyn connections -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <!-- Edges -->\r <resource uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <!-- : SYSDYN.Connection-->\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowConnectionFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r </target>\r \r <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r <baseType uri="http://www.simantics.org/Diagram-2.0/HasConnector" />\r <resource uri="http://www.simantics.org/Diagram-2.0/HasPlainConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>none 0</string>\r </resource>\r <resource uri="http://www.simantics.org/Diagram-2.0/HasArrowConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>fill 1</string>\r </resource>\r </target>\r \r
+ <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r class="org.simantics.sysdyn.ui.project.SysdynProject" />\r </target>\r \r <target interface="org.simantics.project.IProjectLifecycle">\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r </target>\r \r <target\r interface="org.simantics.browsing.ui.common.node.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r <this />\r </resource>\r\r <type\r uri="http://www.simantics.org/Simulation-1.0/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r \r </target>\r\r <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r <target interface="org.simantics.g2d.diagram.DiagramClass">\r <adapter uri="http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram"\r adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r </target>\r\r <!-- Sysdyn symbols -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" /> \r </target>\r \r <!-- Sysdyn connections -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <!-- Edges -->\r <resource uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <!-- : SYSDYN.Connection-->\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowConnectionFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r </target>\r \r <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r <baseType uri="http://www.simantics.org/Diagram-2.0/HasConnector" />\r <resource uri="http://www.simantics.org/Diagram-2.0/HasPlainConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>none 0</string>\r </resource>\r <resource uri="http://www.simantics.org/Diagram-2.0/HasArrowConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>fill 1</string>\r </resource>\r </target>\r \r
</adapters>
\ No newline at end of file
<binding\r
browseContext="http://www.simantics.org/Sysdyn-1.0/Browser">\r
<implementation\r
- class="org.simantics.sysdyn.ui.browser.contributions.Configuration"\r
+ class="org.simantics.sysdyn.ui.browser.contributions.ModuleType"\r
preference="1.0">\r
</implementation>\r
<implementation\r
preference="2.0">\r
</implementation>\r
<implementation\r
- class="org.simantics.sysdyn.ui.browser.contributions.Module"\r
- preference="1.0">\r
+ class="org.simantics.sysdyn.ui.browser.contributions.Configuration"\r
+ preference="2.0">\r
</implementation>\r
</binding>\r
</extension>\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser;\r
+\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.simantics.db.Resource;\r
+\r
+public class BrowserSelection implements IAdaptable {\r
+ private Resource resource;\r
+ private Resource model;\r
+ private String URI;\r
+\r
+ public BrowserSelection(Resource resource, String URI, Resource model) {\r
+ this.resource = resource;\r
+ this.URI = URI;\r
+ this.model = model;\r
+ }\r
+\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if (adapter == Resource.class)\r
+ return resource;\r
+ return null;\r
+ }\r
+ \r
+ public Resource getModel() {\r
+ return this.model;\r
+ }\r
+ \r
+ public String getURI() {\r
+ return this.URI;\r
+ }\r
+ \r
+}\r
import java.util.Set;\r
\r
import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.GraphExplorer;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
import org.simantics.browsing.ui.swt.ContextMenuInitializer;\r
+import org.simantics.browsing.ui.swt.DefaultSelectionDataResolver;\r
+import org.simantics.browsing.ui.swt.GraphExplorerFactory;\r
import org.simantics.browsing.ui.swt.GraphExplorerView;\r
import org.simantics.browsing.ui.swt.IContextMenuInitializer;\r
import org.simantics.browsing.ui.swt.IPropertyPage;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.layer0.SelectionHints;\r
import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.utils.datastructures.BinaryFunction;\r
+import org.simantics.utils.datastructures.hints.IHintContext;\r
\r
\r
public class SysdynBrowser extends GraphExplorerView {\r
// private static final Set<String> browseContexts = Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser");\r
private static final Set<String> browseContexts = new HashSet<String>(Arrays.asList("http://www.simantics.org/Sysdyn-1.0/Browser", "http://www.simantics.org/Operating-1.0/Browser")); \r
\r
+ private BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {\r
+\r
+ @Override\r
+ public Object[] call(GraphExplorer explorer, Object[] objects) {\r
+ Object[] result = new Object[objects.length];\r
+ for (int i = 0; i < objects.length; i++) {\r
+ \r
+ NodeContext ctx = (NodeContext)objects[i]; \r
+ @SuppressWarnings("unchecked")\r
+ VariableNode<Resource> vn = (VariableNode<Resource>) ctx.getAdapter(VariableNode.class);\r
+ IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
+ if(vn != null) {\r
+ Resource resource = vn.getResource() == null ? vn.data : vn.getResource();\r
+ context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(resource, vn.getURI(), vn.getModel()));\r
+ } else {\r
+ context.setHint(SelectionHints.KEY_MAIN, objects[i]);\r
+ }\r
+ result[i] = context;\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ };\r
+ \r
+ protected GraphExplorer createExplorerControl(Composite parent) {\r
+ return GraphExplorerFactory.getInstance()\r
+ .selectionDataResolver(new DefaultSelectionDataResolver())\r
+ .selectionTransformation(selectionTransformation)\r
+ .create(parent, getStyle());\r
+ }\r
+ \r
@Override\r
protected IContextMenuInitializer getContextMenuInitializer() {\r
return new ContextMenuInitializer("#SysdynBrowserPopup");\r
//toolBar.add(new HomeAction());\r
}\r
\r
- @SuppressWarnings("unchecked")\r
@Override\r
public Object getAdapter(Class adapter) {\r
if (adapter == IPropertyPage.class)\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.OperatingInterfacesFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
\r
public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>> {\r
\r
String image = null;\r
if (node instanceof ExperimentsFolder || \r
-// node instanceof OperatingInterfacesFolder || \r
node instanceof ModulesNode)\r
image = "icons/folder.png";\r
else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
\r
-public class Configuration extends ViewpointContributor<ConfigurationNode> {\r
+public class Configuration extends ViewpointContributor<ConfigurationNode<Resource>> {\r
\r
- @Override\r
- public Collection<?> getContribution(ReadGraph graph, ConfigurationNode configuration) throws DatabaseException {\r
- ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(configuration.data, b.ConsistsOf, sr.IndependentVariable))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(configuration.data, b.ConsistsOf, sr.Input))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(configuration.data, b.ConsistsOf, sr.Module))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return result;\r
- }\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, ConfigurationNode<Resource> configuration) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ if (!graph.isInheritedFrom(graph.getSingleObject(configuration.data, b.InstanceOf), b.Realization))\r
+ return result;\r
+ \r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ ArrayList<Resource> variables = new ArrayList<Resource>();\r
+ ArrayList<Resource> inputs = new ArrayList<Resource>();\r
+ ArrayList<Resource> modules = new ArrayList<Resource>();\r
+ \r
+ for(Resource r : graph.getObjects(configuration.data, b.ConsistsOf)) {\r
+ Resource represents = graph.getSingleObject(r, b.Represents);\r
+ if(graph.isInstanceOf(represents, sr.IndependentVariable)) {\r
+ variables.add(r);\r
+ } else if (graph.isInstanceOf(represents, sr.Input)) {\r
+ inputs.add(r);\r
+ } else if (graph.isInstanceOf(represents, sr.Module)) {\r
+ modules.add(r);\r
+ }\r
+ }\r
+ \r
+ for (Resource r : variables)\r
+ result.add(new VariableNode<Resource>(r));\r
+ for (Resource r : inputs)\r
+ result.add(new InputNode(r));\r
+ for (Resource r : modules) \r
+ result.add(new ModuleNode(r));\r
+ return result;\r
+ }\r
\r
- @Override\r
- public String getViewpointId() {\r
- return "Standard";\r
- }\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
}\r
\r
import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
\r
-public class ConfigurationLabeler extends LabelerContributor<ConfigurationNode>{\r
+public class ConfigurationLabeler extends LabelerContributor<ConfigurationNode<Resource>>{\r
\r
@Override\r
- public String getLabel(ReadGraph graph, ConfigurationNode conf) throws DatabaseException {\r
+ public String getLabel(ReadGraph graph, ConfigurationNode<Resource> conf) throws DatabaseException {\r
return "Configuration";\r
}\r
\r
\r
public class Experiment extends ViewpointContributor<ExperimentsFolder> {\r
\r
- @Override\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
public Collection<?> getContribution(ReadGraph graph, ExperimentsFolder experimentsFolder) throws DatabaseException {\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
Builtins b = graph.getBuiltins();\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
throws DatabaseException {\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
- result.add(new ConfigurationNode(\r
- graph.getSingleObject(\r
- model.data,\r
- SimulationResource.getInstance(graph).HasConfiguration))\r
- );\r
+ \r
+ Resource baseRealization = graph.syncRequest(new PossibleObjectWithType(model.data, b.ConsistsOf, SysdynResource.getInstance(graph).DefaultRealization));\r
+ if (baseRealization != null) {\r
+ result.add(new ConfigurationNode<Resource>(baseRealization));\r
+ }\r
result.add(new ExperimentsFolder(model.data));\r
result.add(new ModulesNode(model.data));\r
return result;\r
+++ /dev/null
-package org.simantics.sysdyn.ui.browser.contributions;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.browsing.ui.common.node.AbstractNode;\r
-import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
-\r
-public class Module extends ViewpointContributor<ModuleNode> {\r
-\r
- @Override\r
- public Collection<?> getContribution(ReadGraph graph, ModuleNode module) throws DatabaseException {\r
- ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- StructuralResource2 str = StructuralResource2.getInstance(graph);\r
-\r
- // ModuleTypeNode extends ModuleNode, so we get the instance in two different ways\r
- Resource instance = graph.getPossibleObject(module.data, b.InstanceOf);\r
- if(graph.isInheritedFrom(module.data, sr.ModuleSymbol)) {\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- instance = graph.getPossibleObject(module.data, mr.SymbolToComponentType);\r
- }\r
-\r
- if(instance == null) return result;\r
- Resource conf = graph.getSingleObject(instance, str.IsDefinedBy);\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(conf, b.ConsistsOf, sr.IndependentVariable))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(conf, b.ConsistsOf, sr.Input))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(conf, b.ConsistsOf, sr.Module))) {\r
- try {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } catch(DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return result;\r
- }\r
-\r
- @Override\r
- public String getViewpointId() {\r
- return "Standard";\r
- }\r
-\r
-}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
+\r
+public class ModuleType extends ViewpointContributor<ModuleTypeNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, ModuleTypeNode module) throws DatabaseException {\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ StructuralResource2 str = StructuralResource2.getInstance(graph);\r
+ \r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ Resource instance = graph.getPossibleObject(module.data, mr.SymbolToComponentType);\r
+\r
+ if(instance == null) return result;\r
+ Resource conf = graph.getSingleObject(instance, str.IsDefinedBy);\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(conf, b.ConsistsOf, sr.IndependentVariable))) {\r
+ result.add(new VariableNode<Resource>(r));\r
+ }\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(conf, b.ConsistsOf, sr.Input))) {\r
+ result.add(new InputNode(r));\r
+ }\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(conf, b.ConsistsOf, sr.Module))) {\r
+ result.add(new ModuleNode(r));\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
\r
public class Project extends ViewpointContributor<Resource> {\r
\r
- @Override\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
public Collection<?> getContribution(ReadGraph graph, Resource project)\r
throws DatabaseException {\r
\r
\r
public class SimulationResult extends ViewpointContributor<ExperimentNode> {\r
\r
- @Override\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
\r
-public class VariableLabeler extends LabelerContributor<VariableNode>{\r
+public class VariableLabeler extends LabelerContributor<VariableNode<Resource>>{\r
\r
@Override\r
- public String getLabel(ReadGraph graph, VariableNode var) throws DatabaseException {\r
+ public String getLabel(ReadGraph graph, VariableNode<Resource> var) throws DatabaseException {\r
Builtins b = graph.getBuiltins();\r
Resource varres = var.data;\r
StringBuilder sb = new StringBuilder();\r
import org.simantics.browsing.ui.common.node.IDeletable;\r
import org.simantics.db.Resource;\r
\r
-public class ConfigurationNode extends AbstractNode<Resource> implements IDeletable {\r
-\r
- public ConfigurationNode(Resource resource) {\r
- super(resource);\r
+public class ConfigurationNode<T> extends AbstractNode<Resource> implements IDeletable {\r
+ \r
+ public ConfigurationNode(final Resource resource) {\r
+ super(resource);\r
}\r
\r
}\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
-import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.db.Resource;\r
\r
-public class InputNode extends AbstractNode<Resource> {\r
+public class InputNode extends VariableNode<Resource> {\r
\r
public InputNode(Resource resource) {\r
super(resource);\r
\r
public class ModelNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
\r
+ \r
public ModelNode(Resource resource) {\r
super(resource);\r
}\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
-import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.db.Resource;\r
\r
-public class ModuleNode extends AbstractNode<Resource> {\r
+public class ModuleNode extends ConfigurationNode<Resource> {\r
\r
public ModuleNode(Resource resource) {\r
super(resource);\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.ui.SimanticsUI;\r
-// FIXME: should extend ModuleNode\r
+\r
public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
\r
public ModuleTypeNode(Resource resource) {\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
\r
-public class VariableNode extends AbstractNode<Resource> {\r
+public class VariableNode<T> extends AbstractNode<Resource> {\r
\r
- public VariableNode(Resource resource) {\r
- super(resource);\r
- }\r
+ Resource model = null;\r
+ String uri;\r
+ Resource resource;\r
\r
+ public VariableNode(Resource resource) {\r
+ super(resource);\r
+\r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ VariableNode.this.resource = graph.getPossibleObject(data, b.Represents);\r
+ \r
+ if(VariableNode.this.resource == null)\r
+ return;\r
+ \r
+ uri = getName(graph);\r
+ \r
+ // don't search for a parent if the resource is not part of a realization\r
+ if(!graph.isInheritedFrom(graph.getSingleObject(data, b.InstanceOf), b.Realization))\r
+ return;\r
+ \r
+ // search for the model parent and build the uri\r
+ Resource parent = graph.getSingleObject(data, b.PartOf);\r
+ while (!graph.isInstanceOf(parent, sr.SysdynModel)) {\r
+ uri = graph.getRelatedValue(parent, b.HasName) + "/" + uri;\r
+ parent = graph.getSingleObject(parent, b.PartOf);\r
+ }\r
+ // cut out the realization name\r
+ System.out.println(uri);\r
+ uri = uri.substring(uri.indexOf("/") + 1);\r
+ System.out.println(uri);\r
+ model = parent;\r
+ }\r
+ });\r
+ }\r
+\r
+ public String getURI() {\r
+ return uri;\r
+ }\r
+\r
+ public Resource getModel() {\r
+ return model;\r
+ }\r
+\r
+ public String getName(ReadGraph graph) throws DatabaseException {\r
+ return (String)graph.getRelatedValue(data, graph.getBuiltins().HasName);\r
+ }\r
+\r
+ public Resource getParent(ReadGraph graph) throws DatabaseException {\r
+ return graph.getSingleObject(data, graph.getBuiltins().PartOf);\r
+ }\r
+ \r
+ public Resource getResource() {\r
+ return resource;\r
+ }\r
}\r
package org.simantics.sysdyn.ui.editor;\r
\r
+import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
\r
public class OpenDiagramFromConfigurationAdapter extends org.simantics.modeling.ui.diagramEditor.OpenDiagramFromConfigurationAdapter {\r
\r
- private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
+ private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
\r
- public OpenDiagramFromConfigurationAdapter() {\r
- super();\r
- }\r
+ public OpenDiagramFromConfigurationAdapter() {\r
+ super();\r
+ }\r
\r
- @Override\r
- protected String getEditorId() {\r
- return EDITOR_ID;\r
- }\r
+ @Override\r
+ protected String getEditorId() {\r
+ return EDITOR_ID;\r
+ }\r
\r
- @Override\r
- public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {\r
- if(g.isInheritedFrom(r, SysdynResource.getInstance(g).ModuleSymbol)) {\r
- ModelingResources mr = ModelingResources.getInstance(g);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
- Resource componentType = g.getSingleObject(r, mr.SymbolToComponentType);\r
- r = g.getSingleObject(componentType, sr2.IsDefinedBy);\r
- }\r
- return ComponentUtils.compositeHasDiagram(g, r) /*|| ComponentUtils.componentHasDiagram(g, r)*/;\r
- }\r
+ @Override\r
+ public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ if(g.isInheritedFrom(r, sr.ModuleSymbol)) {\r
+ ModelingResources mr = ModelingResources.getInstance(g);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
+ Resource componentType = g.getSingleObject(r, mr.SymbolToComponentType);\r
+ r = g.getSingleObject(componentType, sr2.IsDefinedBy);\r
+ }\r
+ Builtins b = g.getBuiltins();\r
+ Resource represents = g.getPossibleObject(r, b.Represents);\r
+ if(represents != null){\r
+ if(g.isInstanceOf(represents, sr.Configuration)) {\r
+ r = represents;\r
+ }\r
+ }\r
+ return ComponentUtils.compositeHasDiagram(g, r) /*|| ComponentUtils.componentHasDiagram(g, r)*/;\r
+ }\r
\r
- @Override\r
- public void openEditor(final Resource r) throws Exception {\r
- Resource configuration = null;\r
- try {\r
- configuration = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+ @Override\r
+ public void openEditor(final Resource r) throws Exception {\r
+ Resource configuration = null;\r
+ try {\r
+ configuration = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
\r
- @Override\r
- public Resource perform(ReadGraph graph) throws DatabaseException {\r
- if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).ModuleSymbol)) {\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- Resource componentType = graph.getSingleObject(r, mr.SymbolToComponentType);\r
- Resource configuration = graph.getSingleObject(componentType, sr2.IsDefinedBy);\r
- return configuration;\r
- }\r
- else {\r
- return null;\r
- }\r
- }\r
- });\r
- } catch (DatabaseException e1) {\r
- e1.printStackTrace();\r
- }\r
- if (configuration != null)\r
- super.openEditor(configuration);\r
- else\r
- super.openEditor(r);\r
- }\r
+ @Override\r
+ public Resource perform(ReadGraph graph) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).ModuleSymbol)) {\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ Resource componentType = graph.getSingleObject(r, mr.SymbolToComponentType);\r
+ Resource configuration = graph.getSingleObject(componentType, sr2.IsDefinedBy);\r
+ return configuration;\r
+ } else { \r
+ Resource represents = graph.getPossibleObject(r, b.Represents);\r
+ if(represents != null && graph.isInstanceOf(represents, SysdynResource.getInstance(graph).Configuration)){\r
+ return represents;\r
+ }\r
+ else {\r
+ return null;\r
+ }\r
+ }\r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ if (configuration != null)\r
+ super.openEditor(configuration);\r
+ else\r
+ super.openEditor(r);\r
+ }\r
\r
}\r
item = new TableItem(functionTable, SWT.NONE);\r
item.setText("if then else");\r
item.setData("if then else");\r
+ item = new TableItem(functionTable, SWT.NONE);\r
+ item.setText("xidz()");\r
+ item.setData("xidz( number, divisor , x)");\r
+ item = new TableItem(functionTable, SWT.NONE);\r
+ item.setText("interpolate()");\r
+ item.setData("interpolate( x, table)"); \r
functions.setControl(functionTable);\r
}\r
\r
import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.manager.SysdynResult;\r
+import org.simantics.sysdyn.ui.browser.BrowserSelection;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ISelectionUtils;\r
import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
\r
public class TrendView extends ViewPart {\r
\r
- Frame frame;\r
- ChartPanel panel;\r
- SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
-\r
-\r
- @SuppressWarnings("serial")\r
- class SysdynDatasets extends AbstractXYDataset {\r
-\r
- SysdynDataSet[] sets = new SysdynDataSet[0];\r
-\r
- public void setDatasets(SysdynDataSet[] sets) {\r
- this.sets = sets;\r
- fireDatasetChanged();\r
- }\r
-\r
- @Override\r
- public Number getY(int series, int item) {\r
- return sets[series].values[item];\r
- }\r
-\r
- @Override\r
- public Number getX(int series, int item) {\r
- return sets[series].times[item];\r
- }\r
-\r
- @Override\r
- public int getItemCount(int series) {\r
- return sets[series].times.length;\r
- }\r
-\r
- @Override\r
- public Comparable<String> getSeriesKey(int series) {\r
- SysdynDataSet sds = sets[series];\r
- if(sds.result == null)\r
- return sds.name;\r
- else\r
- return sds.name + " : " + sds.result;\r
- }\r
-\r
- @Override\r
- public int getSeriesCount() {\r
- return sets.length;\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
- getSite().setSelectionProvider(selectionProvider);\r
-\r
- final Composite composite = new Composite(parent,\r
- SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
- frame = SWT_AWT.new_Frame(composite);\r
-\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- XYPlot plot = new XYPlot(\r
- sysdynDatasets,\r
- new NumberAxis("time"),\r
- new NumberAxis("x"),\r
- new XYLineAndShapeRenderer(true, false)\r
- );\r
-\r
- JFreeChart chart = new JFreeChart(plot);\r
- panel = new ChartPanel(chart);\r
- frame.add(panel);\r
-\r
- panel.requestFocus();\r
- }\r
-\r
- });\r
-\r
- getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new ISelectionListener() {\r
-\r
- @Override\r
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
- if(selection.isEmpty() || Boolean.TRUE.equals(PinTrend.getState()))\r
- return;\r
- if(selection instanceof IStructuredSelection) {\r
- Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
- List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
- if(runtimes.isEmpty())\r
- return;\r
- Resource runtime = runtimes.get(0);\r
- setSelection(ress.toArray(Resource.NONE), runtime);\r
- }\r
- }\r
- });\r
-\r
- }\r
-\r
- Resource[] resources;\r
- Resource runtime;\r
-\r
- protected void setSelection(Resource[] resources, Resource runtime) {\r
- this.resources = resources;\r
- this.runtime = runtime;\r
- updateView();\r
- }\r
-\r
- public void updateView() {\r
-\r
- Session session = SimanticsUI.peekSession();\r
- if (session == null)\r
- return;\r
-\r
- session.asyncRequest(new ReadRequest() {\r
- @Override\r
- public void run(ReadGraph g) throws DatabaseException {\r
-\r
- final ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
- for(Resource resource : resources) {\r
-// SysdynDataSet set = load(g, resource, runtime);\r
-// if(set == null) {\r
-// return;\r
-// }\r
-// datasets.add(set);\r
- Collection<SysdynDataSet> activeDataSets = loadAllActive(g, resource, runtime);\r
- if(activeDataSets != null && !activeDataSets.isEmpty())\r
- datasets.addAll(activeDataSets);\r
- }
-\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- sysdynDatasets.setDatasets(datasets.toArray(new SysdynDataSet[datasets.size()]));\r
- }\r
-\r
- });\r
-\r
- }\r
- });\r
- }\r
-\r
- /*\r
- protected SysdynDataSet load(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
-\r
- Builtins b = g.getBuiltins();\r
-\r
- SysdynResource sr = SysdynResource.getInstance(g);\r
-\r
- DiagramResource dr = DiagramResource.getInstance(g);\r
-\r
- if(runtime == null) return null;\r
- Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
- if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
-\r
- String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
-\r
- System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
- Variable compositeVariable = Variables.getVariable(g, variableURI);\r
- Variable item = compositeVariable.browsePossible(g, resource);\r
- if(item == null) return null;\r
-\r
- System.out.println("load dataset for '" + item.getURI(g) + "'");\r
-\r
- Accessor accessor = item.getInterface(g, Accessor.class);\r
- if(accessor == null) return null;\r
- try {\r
- return (SysdynDataSet)accessor.getValue(Bindings.getBindingUnchecked(SysdynDataSet.class));\r
- } catch (RuntimeBindingConstructionException e) {\r
- e.printStackTrace();\r
- } catch (AccessorException e) {\r
- e.printStackTrace();\r
- }\r
- return null;\r
+ Frame frame;\r
+ ChartPanel panel;\r
+ SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
+\r
\r
- }\r
- */\r
+ @SuppressWarnings("serial")\r
+ class SysdynDatasets extends AbstractXYDataset {\r
\r
- @Override\r
- public void setFocus() {\r
- if(panel != null)\r
- panel.requestFocus();\r
- }\r
+ SysdynDataSet[] sets = new SysdynDataSet[0];\r
\r
- protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
+ public void setDatasets(SysdynDataSet[] sets) {\r
+ this.sets = sets;\r
+ fireDatasetChanged();\r
+ }\r
+\r
+ @Override\r
+ public Number getY(int series, int item) {\r
+ return sets[series].values[item];\r
+ }\r
\r
- ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
- Builtins b = g.getBuiltins();\r
+ @Override\r
+ public Number getX(int series, int item) {\r
+ return sets[series].times[item];\r
+ }\r
\r
- SysdynResource sr = SysdynResource.getInstance(g);\r
+ @Override\r
+ public int getItemCount(int series) {\r
+ return sets[series].times.length;\r
+ }\r
\r
- DiagramResource dr = DiagramResource.getInstance(g);\r
+ @Override\r
+ public Comparable<String> getSeriesKey(int series) {\r
+ SysdynDataSet sds = sets[series];\r
+ if(sds.result == null)\r
+ return sds.name;\r
+ else\r
+ return sds.name + " : " + sds.result;\r
+ }\r
\r
- if(runtime == null) return null;\r
- Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
- if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
+ @Override\r
+ public int getSeriesCount() {\r
+ return sets.length;\r
+ }\r
\r
- String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
+ }\r
+\r
+ @Override\r
+ public void createPartControl(Composite parent) {\r
+ final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
+ getSite().setSelectionProvider(selectionProvider);\r
+\r
+ final Composite composite = new Composite(parent,\r
+ SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
+ frame = SWT_AWT.new_Frame(composite);\r
+\r
+ SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ XYPlot plot = new XYPlot(\r
+ sysdynDatasets,\r
+ new NumberAxis("time"),\r
+ new NumberAxis("x"),\r
+ new XYLineAndShapeRenderer(true, false)\r
+ );\r
+\r
+ JFreeChart chart = new JFreeChart(plot);\r
+ panel = new ChartPanel(chart);\r
+ frame.add(panel);\r
+\r
+ panel.requestFocus();\r
+ }\r
+\r
+ });\r
+\r
+ getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new ISelectionListener() {\r
+\r
+ @Override\r
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
+ if(selection.isEmpty() || Boolean.TRUE.equals(PinTrend.getState()))\r
+ return;\r
+ if(selection instanceof IStructuredSelection) {\r
+ Set<BrowserSelection> bs = ISelectionUtils.filterSetSelection(selection, BrowserSelection.class);\r
+ if(!bs.isEmpty()) {\r
+ updateDatasets(bs.toArray(new BrowserSelection[bs.size()]));\r
+ } else {\r
+ Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
+ List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
+ if(runtimes.isEmpty())\r
+ return;\r
+ Resource runtime = runtimes.get(0);\r
+ updateDatasets(ress.toArray(Resource.NONE), runtime);\r
+ }\r
+ }\r
+ }\r
+ });\r
\r
- System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
- Variable compositeVariable = Variables.getVariable(g, variableURI);\r
- Variable item = compositeVariable.browsePossible(g, resource);\r
- if(item == null) return null;\r
+ }\r
+\r
+ ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
+\r
+ private void updateDatasets(final Resource[] resources, final Resource runtime) {\r
+ Session session = SimanticsUI.peekSession();\r
+ if (session == null)\r
+ return;\r
+\r
+ session.asyncRequest(new ReadRequest() {\r
+ @Override\r
+ public void run(ReadGraph g) throws DatabaseException {\r
+ datasets.clear();\r
+ for(Resource resource : resources) {\r
+ Collection<SysdynDataSet> activeDataSets = loadAllActive(g, resource, runtime);\r
+ if(activeDataSets != null && !activeDataSets.isEmpty())\r
+ datasets.addAll(activeDataSets);\r
+ }\r
+ updateView();\r
+ }\r
+ });\r
+\r
+ }\r
+\r
+ private void updateDatasets(final BrowserSelection[] browserSelections) {\r
+ Session session = SimanticsUI.peekSession();\r
+ if (session == null)\r
+ return;\r
+\r
+ session.asyncRequest(new ReadRequest() {\r
+ @Override\r
+ public void run(ReadGraph g) throws DatabaseException {\r
+ datasets.clear();\r
+ for(BrowserSelection bs : browserSelections) {\r
+ if(bs.getURI() != null && bs.getModel() != null) {\r
+ Collection<SysdynDataSet> activeDataSets = loadAllActive(g, bs.getURI(), bs.getModel());\r
+ if(activeDataSets != null && !activeDataSets.isEmpty()) \r
+ datasets.addAll(activeDataSets);\r
+ }\r
+\r
+ }\r
+ updateView();\r
+ }\r
+ });\r
+ }\r
+\r
+ private void updateView() {\r
+ SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ sysdynDatasets.setDatasets(datasets.toArray(new SysdynDataSet[datasets.size()]));\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+\r
+ @Override\r
+ public void setFocus() {\r
+ if(panel != null)\r
+ panel.requestFocus();\r
+ }\r
+\r
+ protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
+\r
+ Builtins b = g.getBuiltins();\r
+\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+\r
+ DiagramResource dr = DiagramResource.getInstance(g);\r
+\r
+ if(runtime == null) return null;\r
+ Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
+ if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
+\r
+ String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
+\r
+ System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
+ Variable compositeVariable = Variables.getVariable(g, variableURI);\r
+ Variable item = compositeVariable.browsePossible(g, resource);\r
+ if(item == null) return null;\r
+\r
+ String rvi = Variables.getRVI(g, item);\r
+ System.out.println("HistoryVariable rvi='" + rvi + "'");\r
+\r
+ System.out.println("load dataset for '" + item.getURI(g) + "'");\r
+\r
+ Resource model = Variables.getModel(g, item);\r
+\r
+ return loadAllActive(g, rvi.substring(1), model);\r
\r
- String rvi = Variables.getRVI(g, item);\r
- System.out.println("HistoryVariable rvi='" + rvi + "'");\r
+ }\r
\r
- System.out.println("load dataset for '" + item.getURI(g) + "'");\r
+ protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, String rvi, Resource model) throws DatabaseException {\r
+ ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
\r
- Resource model = Variables.getModel(g, item);\r
- Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration);\r
- SysdynModel sm = SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration);\r
+ Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration);\r
+ SysdynModel sm = SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration);\r
\r
- Collection<SysdynResult> activeResults = sm.getActiveResults(g);\r
- for(SysdynResult sysdynResult : activeResults) {\r
- SysdynDataSet sds = sysdynResult.getDataSet(rvi.substring(1).replace("/", "."));\r
- if(sds != null)\r
- dataSets.add(sds);\r
- }\r
- return dataSets;\r
+ Collection<SysdynResult> activeResults = sm.getActiveResults(g);\r
+ for(SysdynResult sysdynResult : activeResults) {\r
+ SysdynDataSet sds = sysdynResult.getDataSet(rvi.replace("/", "."));\r
+ if(sds != null)\r
+ dataSets.add(sds);\r
+ }\r
+ return dataSets;\r
\r
- }\r
+ }\r
\r
}\r