From 47093a185608cfa2e4e841cf53c37691b58775f4 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Fri, 11 Jul 2014 11:18:05 +0000 Subject: [PATCH] refs #5093 Fixing undo problems in Sysdyn by adding graph.markUndoPoint() calls in write transactions git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29865 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/browser/nodes/EnumerationNode.java | 6 ++++- .../ui/browser/nodes/ExperimentNode.java | 5 ++++ .../sysdyn/ui/browser/nodes/ModelNode.java | 23 ++++++++++++++++++- .../ui/browser/nodes/ModuleTypeNode.java | 12 ++++++++-- .../sysdyn/ui/browser/nodes/SCLModule.java | 4 ++++ .../nodes/SharedFunctionLibraryNode.java | 12 +++++----- .../ui/browser/nodes/SharedOntologyNode.java | 10 ++++++-- .../participant/SysdynConnectionBuilder.java | 12 ++++++++++ .../NewEnumerationNodeHandler.java | 4 ++++ .../NewExperimentNodeHandler.java | 3 +++ .../NewFunctionLibraryHandler.java | 4 ++++ .../newComponents/NewModuleNodeHandler.java | 6 +++-- .../ui/properties/VariableInformationTab.java | 12 ++++++++-- .../simantics/sysdyn/utils/ModelUtils.java | 5 ++++ 14 files changed, 102 insertions(+), 16 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java index 7d7ee9dc..bfa2943d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java @@ -5,6 +5,7 @@ import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; @@ -13,6 +14,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.variable.Variable; import org.simantics.layer0.Layer0; @@ -76,6 +78,7 @@ public class EnumerationNode extends VariableNode implements IModifiab SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + graph.markUndoPoint(); SysdynResource sr = SysdynResource.getInstance(graph); for(Resource redeclaration : graph.getObjects(data, sr.Redeclaration_replacedEnumeration_Inverse)) { graph.deny(redeclaration, sr.Module_redeclaration_Inverse); @@ -96,8 +99,9 @@ public class EnumerationNode extends VariableNode implements IModifiab } } + String enumerationName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); - + Layer0Utils.addCommentMetadata(graph, "Removed Enumeration " + enumerationName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java index deeb8dd7..e059b644 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java @@ -20,12 +20,15 @@ import org.simantics.browsing.ui.common.node.IDoubleClickableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; 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.project.IProject; import org.simantics.simulation.project.IExperimentManager; import org.simantics.sysdyn.SysdynResource; @@ -81,7 +84,9 @@ public class ExperimentNode extends AbstractNode implements IDoubleCli if(resultSets != null) for(Resource resultSet : resultSets) SimulationResultSetNode.unlinkResultSet(graph, resultSet); + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed experiment " + ontologyName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java index 660fe185..13971866 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.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; @@ -18,6 +19,7 @@ import org.simantics.browsing.ui.common.node.IDoubleClickableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -25,6 +27,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; @@ -49,14 +52,22 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl @Override public void execute(final String result) { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { + if (result == null) + return; + Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { Layer0 l0 = Layer0.getInstance(graph); SimulationResource sim = SimulationResource.getInstance(graph); Resource configuration = graph.getPossibleObject(data, sim.HasConfiguration); + + String label = graph.getPossibleRelatedValue2(configuration, l0.HasLabel, Bindings.STRING); + if (label != null) + return; + graph.claimLiteral(configuration, l0.HasLabel, result); + Layer0Utils.addCommentMetadata(graph, "Created ModelNode to model browser for model " + result); } }); } @@ -98,10 +109,13 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl return new WriteRequest() { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); + String oldName = g.getPossibleRelatedValue2(data, l0.HasLabel, Bindings.STRING); g.claimLiteral(data, l0.HasLabel, label); String safeName = NameUtils.findFreshName(g, label, g.getSingleObject(data, l0.PartOf), l0.ConsistsOf, "%s%d"); g.claimLiteral(data, l0.HasName, safeName); + Layer0Utils.addCommentMetadata(g, "Renamed model " + oldName + " to " + label + " " + data.toString()); } }; } @@ -116,13 +130,20 @@ public class ModelNode extends AbstractNode implements IDoubleClickabl SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + + graph.markUndoPoint(); + Layer0 l0 = Layer0.getInstance(graph); for(Resource r : graph.getObjects(data, l0.ConsistsOf)) if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result)) SimulationResultNode.deleteResultFiles(graph, r); + String modelName = graph.getPossibleRelatedValue2(data, l0.HasName, Bindings.STRING); + String modelResource = data.toString(); RemoverUtil.remove(graph, data); + + Layer0Utils.addCommentMetadata(graph, "Removed model '" + modelName +"' " + modelResource); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java index 6d773446..06e93bd0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java @@ -23,6 +23,7 @@ import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -34,6 +35,7 @@ import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.adapter.PasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; @@ -78,8 +80,12 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable @Override public void perform(WriteGraph graph) throws DatabaseException { - if(configuration != null) - graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result); + if(configuration != null) { + Layer0 L0 = Layer0.getInstance(graph); + String currentLabel = graph.getRelatedValue2(configuration, L0.HasLabel, Bindings.STRING); + if (!currentLabel.equals(result)) + graph.claimLiteral(configuration, L0.HasLabel, result); + } } }); } @@ -150,6 +156,7 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable @Override public void perform(WriteGraph graph) throws DatabaseException{ + graph.markUndoPoint(); Layer0 l0 = Layer0.getInstance(graph); StructuralResource2 st = StructuralResource2.getInstance(graph); ModelingResources mr = ModelingResources.getInstance(graph); @@ -175,6 +182,7 @@ public class ModuleTypeNode extends AbstractNode implements IDeletable RemoverUtil.remove(graph, issue); } } + Layer0Utils.addCommentMetadata(graph, "Removed Module Type " + graph.getRelatedValue2(type, l0.HasName, Bindings.STRING) + " " + type.toString()); RemoverUtil.remove(graph, type); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java index 70815ee4..9307287e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java @@ -17,12 +17,14 @@ import org.simantics.browsing.ui.common.node.IDeletableNode; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; 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.ui.SimanticsUI; @@ -40,7 +42,9 @@ public class SCLModule extends AbstractNode implements IDeletableNode, SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed SCL Module " + ontologyName + " "+ data.toString()); } }); } catch (DatabaseException e) { 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 e2269eba..b5082277 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 @@ -15,10 +15,13 @@ import org.simantics.browsing.ui.common.node.DeleteException; import org.simantics.browsing.ui.common.node.IDropTargetNode; import org.simantics.browsing.ui.content.Labeler.Modifier; import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; 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.SharedFunctionLibraryNameValidator; @@ -37,12 +40,9 @@ public class SharedFunctionLibraryNode extends FunctionLibraryNode imp @Override public void perform(WriteGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - - graph.deny(data, l0.PartOf); - graph.deny(data, l0.IsLinkedTo_Inverse); - - // TODO: remove file + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); + RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed Shared Function Library " + ontologyName + " "+ data.toString()); } }); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java index 6e6d5951..678a4c05 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedOntologyNode.java @@ -1,17 +1,20 @@ 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; import org.simantics.browsing.ui.common.node.IModifiableNode; import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.RemoverUtil; -import org.simantics.ui.SimanticsUI; +import org.simantics.layer0.Layer0; import org.simantics.utils.ui.ExceptionUtils; public class SharedOntologyNode extends AbstractNode implements IDeletableNode, IModifiableNode { @@ -23,10 +26,13 @@ public class SharedOntologyNode extends AbstractNode implements IDelet @Override public void delete() throws DeleteException { try { - SimanticsUI.getSession().syncRequest(new WriteRequest() { + Simantics.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + graph.markUndoPoint(); + String ontologyName = graph.getPossibleRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed Shared Ontology " + ontologyName + " "+ data.toString()); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java index 159abc54..5f3c3259 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java @@ -22,6 +22,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.content.ConnectionUtil; import org.simantics.diagram.participant.ConnectionBuilder; import org.simantics.diagram.participant.ControlPoint; @@ -65,6 +66,9 @@ public class SysdynConnectionBuilder extends ConnectionBuilder{ */ public void create(WriteGraph graph, ConnectionJudgement judgment, Deque controlPoints, TerminalInfo startTerminal, TerminalInfo endTerminal) throws DatabaseException { + + graph.markUndoPoint(); + // If needs a valve, we will create two separate connections if(needsValve(startTerminal, endTerminal)) { createValveAndConnections(graph, judgment, controlPoints, startTerminal, endTerminal); @@ -73,6 +77,14 @@ public class SysdynConnectionBuilder extends ConnectionBuilder{ else { createConnection(graph, judgment, controlPoints, startTerminal, endTerminal, false); } + + String startElementName = startTerminal.e.getHint(ElementHints.KEY_TEXT); + String endElementName = endTerminal.e.getHint(ElementHints.KEY_TEXT); + + String startElementResource = startTerminal.e.getHint(ElementHints.KEY_OBJECT).toString(); + String endElementResource = endTerminal.e.getHint(ElementHints.KEY_OBJECT).toString(); + + Layer0Utils.addCommentMetadata(graph, "Created dependency starting from " + startElementName + " " + startElementResource + " and ending to " + endElementName + " " + endElementResource); } /** * @param graph diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java index 6801225c..81128020 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java @@ -18,12 +18,14 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.modeling.ModelingResources; @@ -51,6 +53,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); @@ -79,6 +82,7 @@ public class NewEnumerationNodeHandler extends AbstractHandler { l0.HasName, name, sr.Enumeration_enumerationIndexList, ListUtils.create(g, new ArrayList()), l0.PartOf, configuration); + Layer0Utils.addCommentMetadata(g, "Created new Enumeration " + name + " to " + g.getRelatedValue2(configuration, l0.HasLabel, Bindings.STRING)); } }); return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java index 0ddf1a3b..ddfc2b1d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java @@ -24,6 +24,7 @@ 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.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; @@ -56,6 +57,7 @@ public class NewExperimentNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); String label = NameUtils.findFreshName(g, getNameSuggestion(), model, l0.ConsistsOf, l0.HasLabel, "%s%d"); Resource experiment = GraphUtils.create2(g, getExperimentType(g), @@ -63,6 +65,7 @@ public class NewExperimentNodeHandler extends AbstractHandler { l0.HasLabel, label, l0.PartOf, model); configureExperiment(g, experiment); + Layer0Utils.addCommentMetadata(g, "Created new experiment " + label + " " + experiment.toString()); } }); return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java index bf62f3ef..62d88a4a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java @@ -23,6 +23,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; @@ -63,6 +64,7 @@ public class NewFunctionLibraryHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); @@ -100,6 +102,8 @@ public class NewFunctionLibraryHandler extends AbstractHandler { if(shared) g.claim(model, l0.IsLinkedTo, functionLibrary); + + Layer0Utils.addCommentMetadata(g, "Created new Function Library " + name + " " + functionLibrary.toString()); } }); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java index 60170f7e..b5939cb7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java @@ -23,6 +23,7 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Template; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -33,8 +34,8 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.actions.newActions.NewModuleTypeAction; import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; import org.simantics.ui.SimanticsUI; -import org.simantics.utils.ui.AdaptionUtils; import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.ui.AdaptionUtils; /** * Creates a new module node for a model. @@ -62,6 +63,7 @@ public class NewModuleNodeHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); Layer0X L0X = Layer0X.getInstance(g); @@ -122,7 +124,7 @@ public class NewModuleNodeHandler extends AbstractHandler { g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); - + Layer0Utils.addCommentMetadata(g, "Created new Module Type " + name + " " + moduleType.toString()); } }); return null; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java index f091b37a..bb66b6e4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java @@ -355,15 +355,23 @@ public class VariableInformationTab extends AdjustableTab implements Widget { @Override public void apply(WriteGraph graph, Resource input) throws DatabaseException { + graph.markUndoPoint(); Resource element = graph.getPossibleObject(input, ModelingResources.getInstance(graph).ComponentToElement); if(element != null) { G2DResource g2d = G2DResource.getInstance(graph); graph.deny(element, g2d.HasFont); - if(f != null) + StringBuilder sb = new StringBuilder(); + if(f != null) { graph.claim(element, g2d.HasFont, G2DUtils.createFont(graph, f)); + sb.append(" font to " + f.getName()); + } graph.deny(element, g2d.HasColor); - if(color != null) + if(color != null) { graph.claim(element, g2d.HasColor, G2DUtils.createColor(graph, color)); + sb.append(" color to " + color.getRGB()); + } + sb.insert(0, "Modified"); + Layer0Utils.addCommentMetadata(graph, sb.toString()); } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java index e3212aba..98fb37c0 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java @@ -11,6 +11,7 @@ import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Template; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.document.DocumentResource; import org.simantics.issues.ontology.IssueResource; import org.simantics.layer0.Layer0; @@ -56,6 +57,8 @@ public class ModelUtils { // TODO: remove this public static Resource createModelAt(WriteGraph g, Resource library) { + + g.markUndoPoint(); try { Layer0 l0 = Layer0.getInstance(g); Layer0X L0X = Layer0X.getInstance(g); @@ -178,6 +181,8 @@ public class ModelUtils { ProfileEntries.createStandardProfiles(g, model); + Layer0Utils.addCommentMetadata(g, "Created new Sysdyn Model '" + modelName + "' " + model.toString()); + return model; } catch (DatabaseException e ) { -- 2.47.1