]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Improved shared function library handling
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 21 Apr 2011 11:04:51 +0000 (11:04 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 21 Apr 2011 11:04:51 +0000 (11:04 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20567 ac1ea38d-2e2b-0410-8846-a27921b304fc

13 files changed:
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java

index c64518a67471ed55ac203bfa9ee9ef67b636dc96..83a652e35b8d044c577ecc6ce1172a89da8dd79b 100644 (file)
                   <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
index d00e9e96eafd4d20ec6d023590ec2b236893aaca..6b447f4d3e4d2be5853ee50624dac14e96eb74cf 100644 (file)
@@ -29,6 +29,7 @@ import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;
 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
@@ -37,12 +38,13 @@ public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>
     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
index a0a250c3455fbfefb3002a28f5a50fd229e37cce..6bebe335f8494be4b9abe52fa8577ca4e04a78a1 100644 (file)
@@ -28,7 +28,7 @@ import org.simantics.sysdyn.SysdynResource;
 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
@@ -47,20 +47,9 @@ public class FunctionLibraries  extends ViewpointContributor<FunctionsFolder> {
                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
@@ -73,23 +62,16 @@ public class FunctionLibraries  extends ViewpointContributor<FunctionsFolder> {
                }\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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java
new file mode 100644 (file)
index 0000000..7d5c736
--- /dev/null
@@ -0,0 +1,36 @@
+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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java
new file mode 100644 (file)
index 0000000..c1c8c0a
--- /dev/null
@@ -0,0 +1,25 @@
+/*******************************************************************************\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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java
new file mode 100644 (file)
index 0000000..0531fd9
--- /dev/null
@@ -0,0 +1,30 @@
+/*******************************************************************************\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
index 9cee6cb4345b5ba09a7f51edbfcac844cc2e1d29..96caea962d42ef166e0e3920fd2b1dfe78bb6c01 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Collection;
 \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
@@ -125,9 +124,6 @@ public class InputFactory extends SysdynElementFactory {
             }\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
index 499ea6e50a641c38154309459573d37497dee697..cf417b6f8061ebe5fdab3784c65dcd5158ad1b38 100644 (file)
@@ -30,6 +30,7 @@ import org.simantics.layer0.Layer0;
 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
@@ -70,8 +71,19 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                        // 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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java
new file mode 100644 (file)
index 0000000..75e3ac1
--- /dev/null
@@ -0,0 +1,224 @@
+/*******************************************************************************\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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java
new file mode 100644 (file)
index 0000000..255555b
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************\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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java
new file mode 100644 (file)
index 0000000..70dbb6f
--- /dev/null
@@ -0,0 +1,77 @@
+/*******************************************************************************\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
index a26c312188ad78614dd706b84fb79a57da5b60cd..b650cd89d294e2e8de36752d5e0cbe45106f1651 100644 (file)
@@ -102,7 +102,6 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
                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
@@ -148,7 +147,9 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
                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
index def1fcbbb1831c27bf7f75e3b8ce45d0ef574d6c..585601dd43939f853399820c0815cc57ab742e3c 100644 (file)
@@ -9,7 +9,6 @@ import java.util.ArrayList;
 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
@@ -21,7 +20,6 @@ import org.simantics.db.common.utils.NameUtils;
 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
@@ -63,80 +61,18 @@ public class FunctionUtils {
        \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