]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Renaming variables, enumerations, and modules in model browser (refs #4152).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 3 Jul 2013 05:40:13 +0000 (05:40 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 3 Jul 2013 05:40:13 +0000 (05:40 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27675 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java

index 32671a806b3e8af1b1bcd1aba14da93298102f15..b375b9eb4c808f82de2ff83a770e23b59af7715b 100644 (file)
                         args="org.simantics.sysdyn.ui.browser.nodes.BarChartNode"\r
                         property="org.simantics.sysdyn.ui.nodeClass">\r
                   </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.VariableNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.EnumerationNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
                   <!--\r
                   <test\r
                         args="org.simantics.document.workbench.browser_old.DocumentationNode"\r
index cc3283efacf4911f5de5ffd2f38ff00a7d0f4162..7d7ee9dcb7f29ac2d45f83d58c21184858e3412a 100644 (file)
@@ -2,7 +2,11 @@ package org.simantics.sysdyn.ui.browser.nodes;
 \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.ObjectsWithType;\r
 import org.simantics.db.common.request.WriteRequest;\r
@@ -13,10 +17,11 @@ import org.simantics.db.layer0.util.RemoverUtil;
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.utils.VariableNameValidator;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
 \r
-public class EnumerationNode extends VariableNode<Resource> implements /*IModifiableNode,*/ IDeletableNode {\r
+public class EnumerationNode extends VariableNode<Resource> implements IModifiableNode, IDeletableNode {\r
 \r
        public EnumerationNode(Resource resource) {\r
                super(resource);\r
@@ -25,11 +30,11 @@ public class EnumerationNode extends VariableNode<Resource> implements /*IModifi
        public EnumerationNode(Variable variable, Resource represents) {\r
         super(variable, represents);\r
        }\r
-    /*\r
+    \r
     @Override\r
     public Modifier getModifier(String columnId) {\r
         \r
-        Session session = SimanticsUI.getSession();\r
+        final Session session = SimanticsUI.getSession();\r
         LabelModifier modifier = new LabelModifier(session, data, session.getService(Layer0.class).HasName) {\r
             @Override\r
             public String isValid(String label) {\r
@@ -38,9 +43,32 @@ public class EnumerationNode extends VariableNode<Resource> implements /*IModifi
                 else\r
                     return null;\r
             }\r
+            \r
+            @Override\r
+            public void modify(final String label) {\r
+                try {\r
+                                       session.syncRequest(new WriteRequest() {\r
+                                               @Override\r
+                                               public void perform(WriteGraph graph)\r
+                                                               throws DatabaseException {\r
+\r
+                                               String originalName = graph.getRelatedValue(data, Layer0.getInstance(graph).HasName);\r
+                                               if(!originalName.equals(label)) {\r
+                                                   Resource configuration = graph.getPossibleObject(data, Layer0.getInstance(graph).PartOf);\r
+                                                   new VariableNameValidator().renameInAllEquations(graph, configuration, originalName, label);\r
+                                                       graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
+                                               }\r
+                                               }\r
+                                       });\r
+                               } catch (DatabaseException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+\r
+               super.modify(label);\r
+            }\r
         };\r
         return modifier;\r
-    }*/\r
+    }\r
 \r
        @Override\r
        public void delete() throws DeleteException {\r
index 2c947be3e95b4d7342d48e061fe3ce24d075abf2..297124a09617dbb6b9fd052855824a318c1de293 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \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.ReadGraph;\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.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\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.sysdyn.ui.utils.VariableNameValidator;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
-public class ModuleNode extends ConfigurationNode<Resource>/* implements IModifiableNode*/ {\r
+public class ModuleNode extends ConfigurationNode<Resource> implements IModifiableNode {\r
 \r
        Resource configuration;\r
        \r
@@ -61,11 +68,12 @@ public class ModuleNode extends ConfigurationNode<Resource>/* implements IModifi
         return super.getAdapter(adapter);\r
     }\r
 \r
-    /*@Override\r
+    @Override\r
     public Modifier getModifier(String columnId) {\r
         try {\r
-            Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;\r
-            LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {\r
+            final Session session = SimanticsUI.getSession();\r
+            Resource hasName = Layer0.getInstance(session).HasName;\r
+            LabelModifier modifier = new LabelModifier(session, data, hasName) {\r
                 @Override\r
                 public String isValid(String label) {\r
                     if (!new VariableNameValidator().isValid(data, label))\r
@@ -73,11 +81,34 @@ public class ModuleNode extends ConfigurationNode<Resource>/* implements IModifi
                     else\r
                         return null;\r
                 }\r
+                \r
+                @Override\r
+                public void modify(final String label) {\r
+                    try {\r
+                                       session.syncRequest(new WriteRequest() {\r
+                                               @Override\r
+                                               public void perform(WriteGraph graph)\r
+                                                               throws DatabaseException {\r
+\r
+                                               String originalName = graph.getRelatedValue(data, Layer0.getInstance(graph).HasName);\r
+                                               if(!originalName.equals(label)) {\r
+                                                   Resource configuration = graph.getPossibleObject(data, Layer0.getInstance(graph).PartOf);\r
+                                                   new VariableNameValidator().renameInAllEquations(graph, configuration, originalName, label);\r
+                                                       graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
+                                               }\r
+                                               }\r
+                                       });\r
+                               } catch (DatabaseException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+\r
+                       super.modify(label);\r
+                }\r
             };\r
             return modifier;\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         }\r
         return null;\r
-    }*/\r
+    }\r
 }\r
index 71973d3414230e5a7e7c5c495a5a8eda233600d5..fdfcb1340b5f72eab9f935a84720282008b4c24e 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.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.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.utils.VariableNameValidator;\r
+import org.simantics.ui.SimanticsUI;\r
 \r
-public class VariableNode<T> extends AbstractNode<Resource>/* implements IModifiableNode*/ {\r
+public class VariableNode<T> extends AbstractNode<Resource> implements IModifiableNode {\r
 \r
        Variable variable;\r
 \r
@@ -32,11 +42,12 @@ public class VariableNode<T> extends AbstractNode<Resource>/* implements IModifi
                return variable;\r
        }\r
 \r
-    /*@Override\r
+    @Override\r
     public Modifier getModifier(String columnId) {\r
         try {\r
-            Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName;\r
-            LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) {\r
+            final Session session = SimanticsUI.getSession();\r
+            Resource hasName = Layer0.getInstance(session).HasName;\r
+            LabelModifier modifier = new LabelModifier(session, data, hasName) {\r
                 @Override\r
                 public String isValid(String label) {\r
                     if (!new VariableNameValidator().isValid(data, label))\r
@@ -44,11 +55,34 @@ public class VariableNode<T> extends AbstractNode<Resource>/* implements IModifi
                     else\r
                         return null;\r
                 }\r
+                \r
+                @Override\r
+                public void modify(final String label) {\r
+                    try {\r
+                                       session.syncRequest(new WriteRequest() {\r
+                                               @Override\r
+                                               public void perform(WriteGraph graph)\r
+                                                               throws DatabaseException {\r
+\r
+                                               String originalName = graph.getRelatedValue(data, Layer0.getInstance(graph).HasName);\r
+                                               if(!originalName.equals(label)) {\r
+                                                   Resource configuration = graph.getPossibleObject(data, Layer0.getInstance(graph).PartOf);\r
+                                                   new VariableNameValidator().renameInAllEquations(graph, configuration, originalName, label);\r
+                                                       graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
+                                               }\r
+                                               }\r
+                                       });\r
+                               } catch (DatabaseException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+\r
+                       super.modify(label);\r
+                }\r
             };\r
             return modifier;\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         }\r
         return null;\r
-    }*/\r
+    }\r
 }\r
index 265325a285493a3c24a92c97690555ef15068238..b9f246ce9e56e51d2e99c8845dfd4425e9f28127 100644 (file)
@@ -300,7 +300,7 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
 \r
                                                        @Override\r
                                                        public void run() {\r
-                                                           if(result != null)\r
+                                                           if(result != null && !showAll.getWidget().isDisposed())\r
                                                                showAll.getWidget().setSelection(result.booleanValue());\r
                                                        }\r
                                                });\r