]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5196
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 22 Aug 2014 09:17:01 +0000 (09:17 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 22 Aug 2014 09:17:01 +0000 (09:17 +0000)
- Preventing the user to move the function to Built-in functions library
- Changing SimanticsUI.getSession() calls to Simantics.getSession()

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30120 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java

index 00a3dcb5ff87d2240f7211993b6f8c0b798bc00e..8813df952232924589b2670f47289e35740c30d5 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
+import org.simantics.Simantics;\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
@@ -21,7 +22,9 @@ import org.simantics.browsing.ui.graph.impl.LabelModifier;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -62,6 +65,8 @@ public class FunctionLibraryNode<T> extends AbstractNode<Resource> implements ID
 \r
                @Override\r
                public void perform(WriteGraph graph) throws DatabaseException {\r
+                   graph.markUndoPoint();\r
+                   Layer0Utils.addCommentMetadata(graph, "Removed " + NameUtils.getSafeName(graph, data));\r
                    RemoverUtil.remove(graph, data);\r
                }\r
            });\r
@@ -72,12 +77,18 @@ public class FunctionLibraryNode<T> extends AbstractNode<Resource> implements ID
                final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
                final Resource library = this.data;\r
                if(resources.length > 0) {\r
-                       SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                       Simantics.getSession().asyncRequest(new WriteRequest() {\r
                                \r
                                @Override\r
                                public void perform(WriteGraph graph) throws DatabaseException {\r
                                        SysdynResource sr = SysdynResource.getInstance(graph);\r
                                        Layer0 l0 = Layer0.getInstance(graph);\r
+                                       \r
+                                       // Fixing #5196\r
+                                       // Prevent dropping functions to immutable function libraries such as Built-in Functions, Modelica Array Functions etc.\r
+                                       if (graph.isImmutable(library))\r
+                                           return;\r
+                                       \r
                                        for(Resource tobeMoved : resources) {\r
                                                if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
                                                                graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
index 21312513b4c2d206ed87c53098b9bb4bfc8641f9..df983ed1de5790406f10462bcd48543ec05281f3 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
+import org.simantics.Simantics;\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.IDropTargetNode;\r
@@ -20,12 +21,13 @@ import org.simantics.browsing.ui.graph.impl.LabelModifier;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.utils.FunctionNameValidator;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 \r
 public class FunctionNode extends VariableNode<Resource> implements IDeletableNode, IModifiableNode, IDropTargetNode {\r
@@ -37,8 +39,8 @@ public class FunctionNode extends VariableNode<Resource> implements IDeletableNo
        @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
+                       Resource hasName = Layer0.getInstance(Simantics.getSession()).HasName;\r
+                       LabelModifier modifier = new LabelModifier(Simantics.getSession(), data, hasName) {\r
                 @Override\r
                 public String isValid(String label) {\r
                     if (!new FunctionNameValidator().isValid(data, label))\r
@@ -56,10 +58,12 @@ public class FunctionNode extends VariableNode<Resource> implements IDeletableNo
 \r
        @Override\r
        public void delete() throws DeleteException {\r
-           SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+           Simantics.getSession().asyncRequest(new WriteRequest() {\r
 \r
                @Override\r
                public void perform(WriteGraph graph) throws DatabaseException {\r
+                graph.markUndoPoint();\r
+                Layer0Utils.addCommentMetadata(graph, "Removed " + NameUtils.getSafeName(graph, data));\r
                    RemoverUtil.remove(graph, data);\r
                }\r
            });\r
@@ -71,7 +75,7 @@ public class FunctionNode extends VariableNode<Resource> implements IDeletableNo
                final Resource thisFunction = this.data;\r
                \r
                if(resources.length > 0) {\r
-                       SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                       Simantics.getSession().asyncRequest(new WriteRequest() {\r
                                \r
                                @Override\r
                                public void perform(WriteGraph graph) throws DatabaseException {\r
index b508227732e4818dc2c11314bf989653314e2c65..ec8d5f89ecd8912fbf6c8c76957fc2d3e15a2894 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
+import org.simantics.Simantics;\r
 import org.simantics.browsing.ui.common.node.DeleteException;\r
 import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
 import org.simantics.browsing.ui.content.Labeler.Modifier;\r
@@ -25,7 +26,6 @@ import org.simantics.db.layer0.util.RemoverUtil;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.utils.SharedFunctionLibraryNameValidator;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 \r
 public class SharedFunctionLibraryNode extends FunctionLibraryNode<Resource> implements IDropTargetNode {\r
@@ -36,7 +36,7 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode<Resource> imp
 \r
        @Override\r
        public void delete() throws DeleteException {\r
-               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+               Simantics.getSession().asyncRequest(new WriteRequest() {\r
 \r
                        @Override\r
                        public void perform(WriteGraph graph) throws DatabaseException {\r
@@ -50,8 +50,8 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode<Resource> imp
     @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
+            Resource hasName = Layer0.getInstance(Simantics.getSession()).HasName;\r
+            LabelModifier modifier = new LabelModifier(Simantics.getSession(), data, hasName) {\r
                 @Override\r
                 public String isValid(String label) {\r
                     if (!new SharedFunctionLibraryNameValidator().isValid(data, label))\r
@@ -72,7 +72,7 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode<Resource> imp
                final Resource[] resources = ResourceAdaptionUtils.toResources(data);\r
                final Resource library = this.data;\r
                if(resources.length > 0) {\r
-                       SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                       Simantics.getSession().asyncRequest(new WriteRequest() {\r
                                \r
                                @Override\r
                                public void perform(WriteGraph graph) throws DatabaseException {\r