]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Copy Enumerations to modules and configurations.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 16 May 2011 13:32:50 +0000 (13:32 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 16 May 2011 13:32:50 +0000 (13:32 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20970 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java

index 563a7dd34d3791b8b2b249e615ea1b52ee42be81..c8dec6a2699646932b3828dd8df9f57f4d5e4652 100644 (file)
          <activeWhen>\r
             <with\r
                   variable="selection">\r
-               <and>\r
+               <or>\r
                   <test\r
                         args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
-                  <not>\r
-                     <test\r
-                           args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
-                           property="org.simantics.sysdyn.ui.nodeClass">\r
-                     </test>\r
-                  </not>\r
-               </and>\r
+                  <test\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.ModuleTypeNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
             </with>\r
          </activeWhen>\r
       </handler>\r
index cf69782ad39d2ddae25bb2afcfe4be1d144b4bbc..0f2dc7c5ebfdeb595d9ce6609a3503ad42ebcefe 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
+import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.PasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
 import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.ui.SimanticsUI;\r
 \r
 public class ModuleNode extends ConfigurationNode<Resource> {\r
 \r
+       Resource configuration;\r
+       \r
        public ModuleNode(Resource resource) {\r
                super(resource);\r
+               \r
+\r
+        SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph graph) throws DatabaseException {\r
+                       Resource type =  graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf);\r
+                       configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy);                              \r
+                       }\r
+               });\r
        }\r
        \r
     public ModuleNode(Variable variable, Resource represents) {\r
         super(variable, represents);\r
+        \r
+        SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph graph) throws DatabaseException {\r
+                       Resource type =  graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf);\r
+                       configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy);                              \r
+                       }\r
+               });\r
+    }\r
+    \r
+    @SuppressWarnings("rawtypes")\r
+    @Override\r
+    public Object getAdapter(Class adapter) {\r
+        if(PasteHandler.class == adapter && configuration != null) \r
+            return new DefaultPasteHandler(configuration);\r
+        return super.getAdapter(adapter);\r
     }\r
 }\r
index 95602d5f3c5ef66b8a600ede2f4a0e914c2fa649..b1da3bb26d3d6e70d983a67eedcae69bb93a447b 100644 (file)
@@ -23,10 +23,13 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
 import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.layer0.adapter.PasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
@@ -40,9 +43,21 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
        \r
        Listener<String> configurationNameSynchronizer;\r
        private boolean disposed = false;\r
+       private Resource configuration;\r
        \r
     public ModuleTypeNode(Resource resource) {\r
         super(resource);\r
+\r
+        SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph graph) throws DatabaseException {\r
+                       ModelingResources mr = ModelingResources.getInstance(graph);\r
+                       StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+                       Resource type =  graph.getPossibleObject(data, mr.SymbolToComponentType);\r
+                       configuration = graph.getPossibleObject(type, sr2.IsDefinedBy);                         \r
+                       }\r
+               });\r
         \r
         // Not the best solution for name sync\r
         configurationNameSynchronizer = new Listener<String>() {\r
@@ -53,12 +68,8 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
                                        \r
                                        @Override\r
                                        public void perform(WriteGraph graph) throws DatabaseException {\r
-                                               Layer0 l0 = Layer0.getInstance(graph);\r
-                               ModelingResources mr = ModelingResources.getInstance(graph);\r
-                               StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
-                               Resource type =  graph.getPossibleObject(data, mr.SymbolToComponentType);\r
-                               Resource configuration = graph.getPossibleObject(type, sr2.IsDefinedBy);\r
-                                               graph.claimLiteral(configuration, l0.HasLabel, result);\r
+                                               if(configuration != null)\r
+                                                       graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result);\r
                                        }\r
                                });\r
                        }\r
@@ -154,4 +165,12 @@ public class ModuleTypeNode extends AbstractNode<Resource> implements IDeletable
             e.printStackTrace();\r
         }\r
     }\r
+    \r
+    @SuppressWarnings("rawtypes")\r
+    @Override\r
+    public Object getAdapter(Class adapter) {\r
+        if(PasteHandler.class == adapter && configuration != null) \r
+            return new DefaultPasteHandler(configuration);\r
+        return super.getAdapter(adapter);\r
+    }\r
 }\r
index 15bc5fd672cceb91dbc34a492ce833effb2ae39f..e616b0a7fabbce8cae956d59cc088af31a6330d2 100644 (file)
@@ -25,17 +25,24 @@ public class UnlinkNodeHandler2 extends DeleteNodeHandler {
 \r
     @Override\r
     public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        //TODO: deletenodehandler for all resources\r
+\r
         Shell shell = HandlerUtil.getActiveShellChecked(event);\r
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
         Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
-        if (resources.length == 0)\r
+        if (resources.length != 1) {\r
+               // Quick fix to provide some feedback to users. Removing many items should be allowed.\r
+            MessageDialog dialog = new MessageDialog(shell, "Too many items", null, "Please select only one item to remove.", 0,\r
+                    new String[] { "OK" }, 0);\r
+            dialog.create();\r
+            dialog.open();\r
             return null;\r
+        }\r
 \r
         MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0,\r
                 new String[] { "OK", "Cancel" }, 0);\r
         dialog.create();\r
         if (dialog.open() == 0) {\r
-            //TODO: deletenodehandler for all resources\r
             super.execute(event);\r
         }\r
         return null;\r