From: jsimomaa Date: Fri, 22 Aug 2014 09:17:01 +0000 (+0000) Subject: refs #5196 X-Git-Tag: v1.29.0~218 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=afa1274d49a45dc2e8a95602d18b2bda43628b29;p=simantics%2Fsysdyn.git refs #5196 - 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 --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java index 00a3dcb5..8813df95 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.browser.nodes; +import org.simantics.Simantics; import org.simantics.browsing.ui.common.node.AbstractNode; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; @@ -21,7 +22,9 @@ import org.simantics.browsing.ui.graph.impl.LabelModifier; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; @@ -62,6 +65,8 @@ public class FunctionLibraryNode extends AbstractNode implements ID @Override public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0Utils.addCommentMetadata(graph, "Removed " + NameUtils.getSafeName(graph, data)); RemoverUtil.remove(graph, data); } }); @@ -72,12 +77,18 @@ public class FunctionLibraryNode extends AbstractNode implements ID final Resource[] resources = ResourceAdaptionUtils.toResources(data); final Resource library = this.data; if(resources.length > 0) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); + + // Fixing #5196 + // Prevent dropping functions to immutable function libraries such as Built-in Functions, Modelica Array Functions etc. + if (graph.isImmutable(library)) + return; + for(Resource tobeMoved : resources) { if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) || graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java index 21312513..df983ed1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.browser.nodes; +import org.simantics.Simantics; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IDropTargetNode; @@ -20,12 +21,13 @@ import org.simantics.browsing.ui.graph.impl.LabelModifier; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.utils.FunctionNameValidator; -import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; public class FunctionNode extends VariableNode implements IDeletableNode, IModifiableNode, IDropTargetNode { @@ -37,8 +39,8 @@ public class FunctionNode extends VariableNode implements IDeletableNo @Override public Modifier getModifier(String columnId) { try { - Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName; - LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) { + Resource hasName = Layer0.getInstance(Simantics.getSession()).HasName; + LabelModifier modifier = new LabelModifier(Simantics.getSession(), data, hasName) { @Override public String isValid(String label) { if (!new FunctionNameValidator().isValid(data, label)) @@ -56,10 +58,12 @@ public class FunctionNode extends VariableNode implements IDeletableNo @Override public void delete() throws DeleteException { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0Utils.addCommentMetadata(graph, "Removed " + NameUtils.getSafeName(graph, data)); RemoverUtil.remove(graph, data); } }); @@ -71,7 +75,7 @@ public class FunctionNode extends VariableNode implements IDeletableNo final Resource thisFunction = this.data; if(resources.length > 0) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java index b5082277..ec8d5f89 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.browser.nodes; +import org.simantics.Simantics; import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDropTargetNode; import org.simantics.browsing.ui.content.Labeler.Modifier; @@ -25,7 +26,6 @@ import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.utils.SharedFunctionLibraryNameValidator; -import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; public class SharedFunctionLibraryNode extends FunctionLibraryNode implements IDropTargetNode { @@ -36,7 +36,7 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode imp @Override public void delete() throws DeleteException { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { @@ -50,8 +50,8 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode imp @Override public Modifier getModifier(String columnId) { try { - Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName; - LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) { + Resource hasName = Layer0.getInstance(Simantics.getSession()).HasName; + LabelModifier modifier = new LabelModifier(Simantics.getSession(), data, hasName) { @Override public String isValid(String label) { if (!new SharedFunctionLibraryNameValidator().isValid(data, label)) @@ -72,7 +72,7 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode imp final Resource[] resources = ResourceAdaptionUtils.toResources(data); final Resource library = this.data; if(resources.length > 0) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException {