]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #4833
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 23 Apr 2014 09:21:14 +0000 (09:21 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 23 Apr 2014 09:21:14 +0000 (09:21 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29327 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntology.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyImager.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportSharedOntologyHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSCLModuleHandler.java [new file with mode: 0644]

index d9a5d7eb90b005f10887684dfc26c52a2e578f88..06b1075e85e4e93cf18870f939d43017a790f50d 100644 (file)
                   style="push">\r
             </command>\r
             -->\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.newSCLModule"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/script.png"\r
+                  id="org.simantics.sysdyn.ui.newSCLModule"\r
+                  label="SCL Module"\r
+                  style="push">\r
+               <visibleWhen\r
+                     checkEnabled="true">\r
+                  <with\r
+                        variable="selection">\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newModuleNode"\r
                   id="org.simantics.sysdyn.ui.browser.newModule"\r
          <menu\r
                id="org.simantics.export"\r
                label="Export">\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.exportSharedOntology"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/application_form.png"\r
+                  id="org.simantics.sysdyn.ui.exportSharedOntology"\r
+                  label="Shared Library"\r
+                  style="push">\r
+               <visibleWhen\r
+                     checkEnabled="true">\r
+                  <with\r
+                        variable="selection">\r
+                     <or>\r
+                        <test\r
+                              args="org.simantics.sysdyn.ui.browser.contribution.SharedOntologyNode"\r
+                              property="org.simantics.sysdyn.ui.nodeClass">\r
+                        </test>\r
+                     </or>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.exportModel"\r
                   label="Model"\r
                            property="org.simantics.graph.resourceType"\r
                            value="true">\r
                      </test>\r
+                     <test\r
+                           args="http://www.simantics.org/Layer0-0.0/SCLModule"\r
+                           property="org.simantics.graph.resourceType"\r
+                           value="true">\r
+                     </test>\r
                   </or>\r
                </with>\r
             </visibleWhen>\r
                            property="org.simantics.graph.resourceType"\r
                            value="true">\r
                      </test>\r
+                     <test\r
+                           args="http://www.simantics.org/Layer0-0.0/SCLModule"\r
+                           property="org.simantics.graph.resourceType"\r
+                           value="true">\r
+                     </test>\r
                   </or>\r
                </with>\r
             </visibleWhen>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.commands">\r
+      <command\r
+            id="org.simantics.sysdyn.ui.newSCLModule"\r
+            name="New SCL Module">\r
+      </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.exportSharedOntology"\r
+            name="Export Shared Library">\r
+      </command>\r
       <command\r
             id="org.simantics.sysdyn.ui.trend.view.pin"\r
             name="Pin Trend">\r
             class="org.simantics.sysdyn.ui.trend.TrendToSvg"\r
             commandId="org.simantics.sysdyn.ui.trend.view.svg">\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.NewSCLModuleHandler"\r
+            commandId="org.simantics.sysdyn.ui.newSCLModule">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
       <handler\r
             class="org.simantics.sysdyn.ui.handlers.ShowModuleHandler"\r
             commandId="org.simantics.sysdyn.ui.showModule">\r
                         args="org.simantics.sysdyn.ui.browser.nodes.AbstractChartNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.SCLModule"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
                   <!--\r
                   <test\r
                         args="org.simantics.document.workbench.browser_old.DocumentationNode"\r
                         args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.SCLModule"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
                   <!--\r
                   <test\r
                         args="org.simantics.document.workbench.browser_old.DocumentationNode"\r
             </with>\r
          </activeWhen>\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.ExportSharedOntologyHandler"\r
+            commandId="org.simantics.sysdyn.ui.exportSharedOntology">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.contribution.SharedOntologyNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>      \r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.importWizards">\r
                class="org.simantics.sysdyn.ui.browser.contributions.Model"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SharedOntology"\r
+               preference="2.0">\r
+         </implementation>\r
          <implementation\r
                class="org.simantics.sysdyn.ui.browser.contributions.Experiment"\r
                preference="1.0">\r
          point="org.simantics.browsing.ui.common.labelerBinding">\r
       <binding\r
             browseContext="http://www.simantics.org/Sysdyn-0.0/Browser">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyLabeler"\r
+               preference="3.0">\r
+         </implementation>\r
          <implementation\r
                class="org.simantics.sysdyn.ui.browser.contributions.ConfigurationLabeler"\r
                preference="2.0">\r
          point="org.simantics.browsing.ui.common.imagerBinding">\r
       <binding\r
             browseContext="http://www.simantics.org/Sysdyn-0.0/Browser">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyImager"\r
+               preference="3.0">\r
+         </implementation>\r
          <implementation\r
                class="org.simantics.browsing.ui.swt.ImageDescriptorProviderAdapter"\r
                preference="1.0">\r
index 5506660f0de9eb7c25bb9149ff341c4afbcc48f4..ee58e8e8a704dbc5f0697ef0e082dc2c15a9a765 100644 (file)
@@ -13,7 +13,9 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.Collections;\r
 \r
+import org.simantics.Simantics;\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
@@ -21,6 +23,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.project.ontology.ProjectResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
 \r
 public class Project extends ViewpointContributor<Resource> {\r
@@ -40,6 +43,12 @@ public class Project extends ViewpointContributor<Resource> {
                 e.printStackTrace();\r
             }\r
         }\r
+        \r
+        ProjectResource PROJ = ProjectResource.getInstance(graph);\r
+        if(!graph.isInstanceOf(project, PROJ.Project)) return Collections.emptyList();\r
+        Collection<Resource> ontologies = Simantics.applySCL("Simantics/SharedOntologies", "traverseSharedOntologies", graph, graph.getRootLibrary());\r
+        for(Resource o : ontologies) result.add(new SharedOntologyNode(o));\r
+\r
         return result;\r
 \r
     }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntology.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntology.java
new file mode 100644 (file)
index 0000000..9645b36
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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 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.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder;\r
+\r
+public class SharedOntology  extends ViewpointContributor<SharedOntologyNode> {\r
+\r
+    @Override\r
+    public Collection<?> getContribution(ReadGraph graph, SharedOntologyNode model)\r
+    throws DatabaseException {\r
+        ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+        result.add(new SCLModulesFolder(model.data));\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyImager.java
new file mode 100644 (file)
index 0000000..44155c2
--- /dev/null
@@ -0,0 +1,24 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.swt.ImagerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class SharedOntologyImager extends ImagerContributor<SharedOntologyNode> {\r
+\r
+    @Override\r
+    public ImageDescriptor getDescriptor(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
+       \r
+        try {\r
+               return ImageDescriptor.createFromURL(new URL("platform:/plugin/com.famfamfam.silk/icons/folder.png"));\r
+        } catch (MalformedURLException e) {\r
+               e.printStackTrace();\r
+        }\r
+        return null;\r
+        \r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyLabeler.java
new file mode 100644 (file)
index 0000000..1868c6f
--- /dev/null
@@ -0,0 +1,19 @@
+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
+\r
+public class SharedOntologyLabeler extends LabelerContributor<SharedOntologyNode> {\r
+\r
+    @Override\r
+    public String getLabel(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
+       return graph.getURI(node.data);\r
+    }\r
+    \r
+    @Override\r
+    public int getCategory(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
+       return -1;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedOntologyNode.java
new file mode 100644 (file)
index 0000000..2013ec2
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.Resource;\r
+\r
+public class SharedOntologyNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
+\r
+    public SharedOntologyNode(Resource data) {\r
+        super(data);\r
+    }\r
+    \r
+    @Override\r
+    public void delete() throws DeleteException {\r
+    }\r
+\r
+       @Override\r
+       public Modifier getModifier(String columnId) {\r
+               return null;\r
+       }\r
+\r
+}\r
index 0a102065948c0587600d6a36db8ae93fab7cb16e..c695ca63c248b630796104300e30c0e81a16aff6 100644 (file)
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
 \r
-public class SCLModule extends AbstractNode<Resource> {\r
+public class SCLModule extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
 \r
     public SCLModule(Resource resource) {\r
         super(resource);\r
     }\r
 \r
+    @Override\r
+    public void delete() throws DeleteException {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    RemoverUtil.remove(graph, data);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }    \r
+\r
+    }\r
+\r
+    @Override\r
+    public Modifier getModifier(String columnId) {\r
+        Session session = SimanticsUI.getSession();\r
+        return new LabelModifier(session, data, session.getService(Layer0.class).HasName);\r
+    }\r
+    \r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportSharedOntologyHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportSharedOntologyHandler.java
new file mode 100644 (file)
index 0000000..b322db1
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+\r
+public class ExportSharedOntologyHandler  extends AbstractHandler {\r
+\r
+    /**\r
+     * Assumes to be called from a node with SysdynModel, Library or SysdynModelicaFunction as its resource\r
+     */\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        \r
+        @SuppressWarnings("unchecked")\r
+               SharedOntologyNode node = AdaptionUtils.adaptToSingle(sel, SharedOntologyNode.class);\r
+        if (node == null)\r
+            return null;\r
+\r
+        ModelingUtils.exportSharedOntologyWithUI(node.data);\r
+\r
+        return null;\r
+        \r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSCLModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewSCLModuleHandler.java
new file mode 100644 (file)
index 0000000..f5f58be
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\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.modeling.ModelingUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+\r
+public class NewSCLModuleHandler  extends AbstractHandler {\r
+\r
+    /**\r
+     * Assumes to be called from a node with SysdynModel, Library or SysdynModelicaFunction as its resource\r
+     */\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        \r
+        @SuppressWarnings("unchecked")\r
+               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+        if (node == null)\r
+            return null;\r
+\r
+        final Resource parent = node.data;\r
+        \r
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+               \r
+            @Override\r
+            public void perform(WriteGraph graph) throws DatabaseException {\r
+               ModelingUtils.createSCLModule(graph, parent);\r
+            }\r
+            \r
+        });\r
+        \r
+        return null;\r
+        \r
+       }\r
+\r
+}\r