<with\r
variable="selection">\r
<test\r
- args="org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder"\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
</with>\r
class="org.simantics.sysdyn.ui.browser.contributions.LibraryFunctions"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SharedFunctionLibraries"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
<binding browseContext="http://www.simantics.org/Sysdyn-1.0/SysdynOperationBrowser">\r
<implementation class="org.simantics.sysdyn.ui.property.OperationProjectContributor" preference="1.0"/>\r
preference="2.0">\r
</implementation>\r
</binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/AvailableSharedFunctionLibraries">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.properties.widgets.functions.SharedFunctionLibraries"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/SelectedSharedFunctionLibraries">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.properties.widgets.functions.SelectedSharedFunctionLibraries"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.labelerBinding">\r
class="org.simantics.sysdyn.ui.browser.contributions.FunctionLibraryLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SharedFunctionsLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
<binding browseContext="http://www.simantics.org/Sysdyn-1.0/SysdynOperationBrowser">\r
<implementation class="org.simantics.sysdyn.ui.property.OperationModelLabels" preference="1.0"/>\r
preference="2.0">\r
</implementation>\r
</binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/AvailableSharedFunctionLibraries">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.FunctionLibraryLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/SelectedSharedFunctionLibraries">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.FunctionLibraryLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.imagerBinding">\r
preference="2.0">\r
</implementation>\r
</binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/AvailableSharedFunctionLibraries">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.AbstractNodeImager"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/SelectedSharedFunctionLibraries">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.AbstractNodeImager"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
</extension>\r
<extension\r
point="org.simantics.browsing.ui.common.labelDecoratorBinding">\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.SharedFunctionLibraryNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
\r
public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>> {\r
public ImageDescriptor getDescriptor(ReadGraph graph, AbstractNode<Resource> node) throws DatabaseException {\r
\r
String image = null;\r
- if (node instanceof SharedFunctionLibraryNode)\r
+ if (node instanceof SharedFunctionsFolder)\r
image = "icons/folder_link.png";\r
else if (node instanceof ExperimentsFolder || \r
node instanceof ModulesNode || \r
node instanceof FunctionsFolder ||\r
- node instanceof FunctionLibraryNode)\r
+ node instanceof FunctionLibraryNode ||\r
+ node instanceof SharedFunctionLibraryNode)\r
image = "icons/folder.png";\r
else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
image = "icons/bricks.png";\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
-import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
\r
public class FunctionLibraries extends ViewpointContributor<FunctionsFolder> {\r
\r
result.add(new FunctionNode(function));\r
}\r
\r
- // Find shared libraries\r
- Function index = graph.adapt(L0.Dependencies, Function.class);\r
- Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SharedFunctionOntology");\r
- HashSet<Resource> sharedLibraries = new HashSet<Resource>();\r
- for(Map<String, Object> r : results) {\r
- Resource sharedLibrary = (Resource)r.get("Resource");\r
- if(sharedLibrary == null)\r
- continue;\r
- sharedLibraries.add(sharedLibrary);\r
- }\r
- \r
// Find function libraries in model and sysdyn ontology\r
- index = graph.adapt(L0.Dependencies, Function.class);\r
- results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunctionLibrary");\r
+ Function index = graph.adapt(L0.Dependencies, Function.class);\r
+ Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunctionLibrary");\r
HashSet<Resource> modelLibraries = new HashSet<Resource>();\r
for(Map<String, Object> r : results) {\r
Resource library = (Resource)r.get("Resource");\r
}\r
\r
// If the root is not a shared library (it is the model or sysdyn ontology)\r
- if(!sharedLibraries.contains(root))\r
+ if(graph.isInstanceOf(root, sr.SysdynModel))\r
modelLibraries.add(library);\r
}\r
\r
\r
for(Resource modelLibrary : modelLibraries) {\r
- Resource partOf = graph.getPossibleObject(modelLibrary, l0.PartOf);\r
- if(graph.isInstanceOf(partOf, sr.SysdynModel))\r
- // From the model\r
- result.add(new FunctionLibraryNode<Resource>(modelLibrary));\r
- else\r
- // From sysdyn ontology, this is read only\r
- result.add(new FunctionLibraryNode<Resource>(modelLibrary));\r
+ result.add(new FunctionLibraryNode<Resource>(modelLibrary));\r
}\r
\r
- for(Resource sharedLibrary : sharedLibraries)\r
- result.add(new SharedFunctionLibraryNode(sharedLibrary));\r
+ result.add(new SharedFunctionsFolder(functionsFolder.data));\r
\r
return result;\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.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.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
+\r
+public class SharedFunctionLibraries extends ViewpointContributor<SharedFunctionsFolder> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph,\r
+ SharedFunctionsFolder sharedFunctionsFolder) throws DatabaseException {\r
+ \r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+\r
+ \r
+ for(Resource sharedLibrary : graph.syncRequest(new ObjectsWithType(\r
+ sharedFunctionsFolder.data, \r
+ Layer0.getInstance(graph).IsLinkedTo, \r
+ SysdynResource.getInstance(graph).SharedFunctionOntology)))\r
+ {\r
+ result.add(new SharedFunctionLibraryNode(sharedLibrary));\r
+ }\r
+ \r
+ return result;\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
+\r
+public class SharedFunctionsLabeler extends LabelerContributor<SharedFunctionsFolder>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SharedFunctionsFolder input) throws DatabaseException {\r
+ return "Shared Functions";\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\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 SharedFunctionsFolder extends AbstractNode<Resource> {\r
+\r
+ public SharedFunctionsFolder(Resource data) {\r
+ super(data);\r
+ }\r
+\r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if(clazz == adapter) // There is no resource for this node..\r
+ return null;\r
+ return super.getAdapter(adapter);\r
+ }\r
+}\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.exception.MissingVariableException;\r
import org.simantics.db.layer0.variable.Variable;\r
}\r
} else {\r
Resource runtime = diagram.getHint((DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE));\r
- for(Resource r : graph.getPredicates(runtime)) {\r
- System.out.println(NameUtils.getSafeName(graph, r) + " " + graph.getPossibleRelatedValue(runtime, r));\r
- }\r
DiagramResource dr = DiagramResource.getInstance(graph);\r
String variable = (String)graph.getPossibleRelatedValue(runtime, dr.HasVariable);\r
if(variable == null)\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
public class ResourceSelectionProcessor implements SelectionProcessor<Object, ReadGraph> {\r
// Single element\r
Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
\r
- if(r == null) \r
+ if(r == null) {\r
+ SharedFunctionsFolder sff = AdaptionUtils.adaptToSingle(selection, SharedFunctionsFolder.class);\r
+ if (sff != null) {\r
+ return Collections.singleton(new ComparableTabContributor(\r
+ new SharedFunctionLibrariesTab(),\r
+ 2,\r
+ sff.data,\r
+ "Shared Functions"));\r
+ }\r
+ \r
return Collections.emptyList();\r
+ }\r
+\r
\r
if (backend.isInstanceOf(r, dr.Element)) {\r
Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+\r
+public class SharedFunctionLibrariesTab extends PropertyTabContributorImpl implements Widget {\r
+ \r
+ GraphExplorerComposite availableSharedFunctionLibraries;\r
+ GraphExplorerComposite usedSharedFunctionLibraries;\r
+ Resource model;\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+ support.register(this);\r
+ \r
+ GridLayoutFactory.fillDefaults().numColumns(4).applyTo(body);\r
+ \r
+ \r
+ Composite available = new Composite(body, SWT.NONE);\r
+ GridLayoutFactory.fillDefaults().applyTo(available);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(available);\r
+ Label label = new Label(available, SWT.None);\r
+ label.setText("Available Shared Function Libraries");\r
+ availableSharedFunctionLibraries = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), site, available, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI) {\r
+ \r
+ @Override\r
+ protected void handleDrop(Object data, NodeContext target) {\r
+ if (!(data instanceof IStructuredSelection))\r
+ return;\r
+ \r
+ IStructuredSelection iss = (IStructuredSelection)data;\r
+ if (iss == null || iss.isEmpty())\r
+ return;\r
+ \r
+ for (Iterator<?> iterator = iss.iterator(); iterator.hasNext();) {\r
+ Object o = iterator.next();\r
+ if(o instanceof IAdaptable) {\r
+ IAdaptable a = (IAdaptable)o;\r
+ final SharedFunctionLibraryNode node = (SharedFunctionLibraryNode)a.getAdapter(SharedFunctionLibraryNode.class);\r
+ if(node != null) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ if(getModel() != null && node.data != null)\r
+ graph.deny(getModel(), Layer0.getInstance(graph).IsLinkedTo, node.data); \r
+ }\r
+ });\r
+ }\r
+ }\r
+ }\r
+ }\r
+ };\r
+ \r
+ availableSharedFunctionLibraries\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/AvailableSharedFunctionLibraries");\r
+ availableSharedFunctionLibraries.setInputSource(new SingleSelectionInputSource(\r
+ Resource.class));\r
+\r
+ availableSharedFunctionLibraries.finish();\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ availableSharedFunctionLibraries);\r
+ \r
+ Composite middleButtons = new Composite(body, SWT.NONE);\r
+ GridLayoutFactory.fillDefaults().applyTo(middleButtons);\r
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, true).applyTo(middleButtons);\r
+ \r
+ Button add = new Button(middleButtons, support, SWT.NONE);\r
+ add.setText(" -> ");\r
+ \r
+ add.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ List<Resource> selectedLibraries = getSelectedResources(availableSharedFunctionLibraries);\r
+ for(Resource library : selectedLibraries) {\r
+ graph.claim(input, l0.IsLinkedTo, library);\r
+ }\r
+ }\r
+ });\r
+ \r
+ Button remove = new Button(middleButtons, support, SWT.NONE);\r
+ remove.setText(" <- ");\r
+ \r
+ remove.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ List<Resource> selectedLibraries = getSelectedResources(usedSharedFunctionLibraries);\r
+ for(Resource library : selectedLibraries) {\r
+ graph.deny(input, l0.IsLinkedTo, library);\r
+ }\r
+ }\r
+ });\r
+ \r
+ \r
+ Composite used = new Composite(body, SWT.NONE);\r
+ GridLayoutFactory.fillDefaults().applyTo(used);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(used);\r
+ label = new Label(used, SWT.None);\r
+ label.setText("Selected Shared Function Libraries");\r
+ \r
+ usedSharedFunctionLibraries = new GraphExplorerComposite(ArrayMap.keys(\r
+ "displaySelectors", "displayFilter").values(false, false), site, used, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI) {\r
+ \r
+ @Override\r
+ protected void handleDrop(Object data, NodeContext target) {\r
+ if (!(data instanceof IStructuredSelection))\r
+ return;\r
+ \r
+ IStructuredSelection iss = (IStructuredSelection)data;\r
+ if (iss == null || iss.isEmpty())\r
+ return;\r
+ \r
+ for (Iterator<?> iterator = iss.iterator(); iterator.hasNext();) {\r
+ Object o = iterator.next();\r
+ if(o instanceof IAdaptable) {\r
+ IAdaptable a = (IAdaptable)o;\r
+ final SharedFunctionLibraryNode node = (SharedFunctionLibraryNode)a.getAdapter(SharedFunctionLibraryNode.class);\r
+ if(node != null) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ if(getModel() != null && node.data != null)\r
+ graph.claim(getModel(), Layer0.getInstance(graph).IsLinkedTo, node.data); \r
+ }\r
+ });\r
+ }\r
+ }\r
+ }\r
+ }\r
+ };\r
+ \r
+ usedSharedFunctionLibraries\r
+ .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/SelectedSharedFunctionLibraries");\r
+ usedSharedFunctionLibraries.setInputSource(new SingleSelectionInputSource(\r
+ Resource.class));\r
+\r
+ usedSharedFunctionLibraries.finish();\r
+\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+ usedSharedFunctionLibraries);\r
+ }\r
+ \r
+ \r
+ private List<Resource> getSelectedResources(GraphExplorerComposite explorer) {\r
+ List<Resource> result = new ArrayList<Resource>();\r
+ \r
+ ISelection selection = ((ISelectionProvider) explorer\r
+ .getAdapter(ISelectionProvider.class)).getSelection();\r
+ if (selection == null)\r
+ return result;\r
+ IStructuredSelection iss = (IStructuredSelection) selection;\r
+ @SuppressWarnings("unchecked")\r
+ List<AdaptableHintContext> selections = iss.toList();\r
+ for(AdaptableHintContext ahc : selections) {\r
+ Resource resource = (Resource) ahc.getAdapter(Resource.class);\r
+ result.add(resource);\r
+ }\r
+ return result;\r
+ }\r
+\r
+ private Resource getModel() {\r
+ return model;\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object input) {\r
+ availableSharedFunctionLibraries.setInput(context, input);\r
+ usedSharedFunctionLibraries.setInput(context, input);\r
+ this.model = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+ }\r
+\r
+}\r
+\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties.widgets.functions;\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.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.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class SelectedSharedFunctionLibraries extends ViewpointContributor<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+\r
+ \r
+ for(Resource sharedLibrary : graph.syncRequest(new ObjectsWithType(\r
+ input, \r
+ Layer0.getInstance(graph).IsLinkedTo, \r
+ SysdynResource.getInstance(graph).SharedFunctionOntology)))\r
+ {\r
+ result.add(new SharedFunctionLibraryNode(sharedLibrary));\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.properties.widgets.functions;\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.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
+\r
+public class SharedFunctionLibraries extends ViewpointContributor<Resource> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+ throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ \r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+\r
+ // Find shared ontologies. graph.getPossibleResource("http://SharedOntologies") does not update if it was null for the first time.\r
+ Resource sharedOntologies = null;\r
+ Resource root = input;\r
+ while(graph.getPossibleObject(root, l0.PartOf) != null)\r
+ root = graph.getPossibleObject(root, l0.PartOf);\r
+ \r
+ for(Resource r : graph.getObjects(root, l0.ConsistsOf)) {\r
+ if("SharedOntologies".equals(NameUtils.getSafeName(graph, r))) {\r
+ sharedOntologies = r;\r
+ break;\r
+ }\r
+ }\r
+ \r
+ if(sharedOntologies == null) {\r
+ return result;\r
+ }\r
+ \r
+ // Find all shared function ontologies. \r
+ // (Don't know why ObjectsWithType works only the first time, then gives nothing) \r
+ ArrayList<Resource> sharedFunctionLibraries = new ArrayList<Resource>();\r
+ for(Resource r : graph.getObjects(sharedOntologies, l0.ConsistsOf)) {\r
+ if(graph.isInstanceOf(r, sr.SharedFunctionOntology))\r
+ sharedFunctionLibraries.add(r);\r
+ }\r
+\r
+ // Find all shared function ontologies that have already been selected\r
+ Collection<Resource> selectedSharedFunctionLibraries = graph.syncRequest(new ObjectsWithType(\r
+ input, l0.IsLinkedTo, sr.SharedFunctionOntology));\r
+\r
+ // Remove all selected ontologies from the shared function ontologies\r
+ sharedFunctionLibraries.removeAll(selectedSharedFunctionLibraries);\r
+\r
+ for(Resource ontology : sharedFunctionLibraries) {\r
+ result.add(new SharedFunctionLibraryNode(ontology));\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+}\r
HashSet<SysdynModel> models = new HashSet<SysdynModel>(); \r
for(Variable variable : variables) {\r
Resource model = Variables.getModel(graph, variable);\r
- System.out.println("MODEL: " + model);\r
if(model != null) {\r
models.add(getSysdynModel(graph, model));\r
}\r
ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
HashMap<String, String> rvis = new HashMap<String, String>();\r
\r
- String rvi = Variables.getRVI(g, variable).substring(1).replace("/", "."); \r
+ String rvi = Variables.getRVI(g, variable).replace("/", "."); \r
+ if(rvi.length() > 1)\r
+ rvi = rvi.substring(1);\r
\r
Resource r = variable.getPropertyValue(g, Variables.REPRESENTS);\r
\r
import java.util.Collection;\r
import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
import java.util.Set;\r
\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.util.Simantics;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.scl.runtime.function.Function;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.Activator;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
private static Set<Resource> getParents(ReadGraph graph, SysdynModel model) throws DatabaseException{\r
HashSet<Resource> parents = new HashSet<Resource>();\r
- HashSet<Resource> checked = new HashSet<Resource>();\r
- ArrayList<Resource> toCheck = new ArrayList<Resource>();\r
\r
Layer0 l0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf);\r
\r
+ parents.add(modelResource);\r
\r
- // add model to parents and all the model libraries to checked\r
- if(!graph.syncRequest(new ObjectsWithType(modelResource, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() ||\r
- !graph.syncRequest(new ObjectsWithType(modelResource, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty()) {\r
- parents.add(modelResource);\r
- toCheck.clear();\r
- toCheck.add(modelResource);\r
- while(!toCheck.isEmpty()){\r
- Resource checkedLibrary = toCheck.get(0);\r
- checked.add(checkedLibrary);\r
- toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)));\r
- toCheck.remove(checkedLibrary);\r
- }\r
- }\r
- \r
- // add all linked function ontologies to parents and their children ontologies to checked \r
- Function index = graph.adapt(l0.Dependencies, Function.class);\r
- Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, modelResource, "Types:SharedFunctionOntology");\r
- for(Map<String, Object> r : results) {\r
- Resource sharedLibrary = (Resource)r.get("Resource");\r
- if(sharedLibrary == null)\r
- continue;\r
- if(graph.syncRequest(new ObjectsWithType(sharedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() &&\r
- graph.syncRequest(new ObjectsWithType(sharedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty())\r
- continue;\r
- \r
- parents.add(sharedLibrary);\r
- toCheck.clear();\r
- toCheck.add(sharedLibrary);\r
- while(!toCheck.isEmpty()){\r
- Resource checkedLibrary = toCheck.get(0);\r
- checked.add(checkedLibrary);\r
- toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)));\r
- toCheck.remove(checkedLibrary);\r
- }\r
- }\r
+ Collection<Resource> sharedOntologies = graph.syncRequest(new ObjectsWithType(\r
+ modelResource, l0.IsLinkedTo, sr.SharedFunctionOntology));\r
+ parents.addAll(sharedOntologies);\r
\r
- // it is assumed that only built-in function libraries remain\r
- if(modelResource != null) {\r
- index = graph.adapt(l0.Dependencies, Function.class);\r
- results = (Collection<Map<String, Object>>)index.apply(graph, modelResource, "Types:SysdynModelicaFunctionLibrary");\r
- for(Map<String, Object> r : results) {\r
- Resource library = (Resource)r.get("Resource");\r
- if(library != null && !checked.contains(library)) {\r
- \r
- while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) {\r
- library = graph.getPossibleObject(library, l0.PartOf);\r
- }\r
- \r
- if(graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty() &&\r
- graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)).isEmpty())\r
- continue;\r
- \r
- parents.add(library);\r
- \r
- toCheck.clear();\r
- toCheck.add(library);\r
- while(!toCheck.isEmpty()){\r
- Resource checkedLibrary = toCheck.get(0);\r
- checked.add(checkedLibrary);\r
- toCheck.addAll(graph.syncRequest(new ObjectsWithType(checkedLibrary, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)));\r
- toCheck.remove(checkedLibrary);\r
- }\r
- }\r
- }\r
- }\r
return parents;\r
\r
}\r