From 4da04e47699ab646f9dd713b8b3fff32f00b2ede Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Mon, 14 Jul 2014 06:01:25 +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@29869 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/browser/nodes/AbstractChartNode.java | 6 ++++++ .../ui/handlers/newComponents/NewBarChartHandler.java | 7 ++++++- .../ui/handlers/newComponents/NewFunctionHandler.java | 6 +++++- .../ui/handlers/newComponents/NewPieChartHandler.java | 8 +++++++- .../newComponents/NewSensitivityChartHandler.java | 7 ++++++- .../handlers/newComponents/NewXYLineChartHandler.java | 9 +++++++-- .../sysdyn/ui/properties/ConfigurationTab.java | 2 ++ .../factories/ComboStringPropertyModifier.java | 3 +-- .../simantics/sysdyn/manager/SysdynExperiments.java | 11 ++++++----- .../src/org/simantics/sysdyn/utils/SheetUtils.java | 5 +++-- 10 files changed, 49 insertions(+), 15 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java index 61eb1850..0d17007c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java @@ -19,13 +19,16 @@ 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.IDropTargetNode; +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.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.ExceptionUtils; @@ -67,7 +70,10 @@ public abstract class AbstractChartNode extends AbstractNode implem SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + graph.markUndoPoint(); + String chartName = graph.getRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING); RemoverUtil.remove(graph, data); + Layer0Utils.addCommentMetadata(graph, "Removed chart '" + chartName +"' " + data); } }); } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java index 88aa7eb7..1e342142 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java @@ -25,6 +25,7 @@ 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.diagram.stubs.G2DResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -55,13 +56,16 @@ public class NewBarChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); + String label = NameUtils.findFreshLabel(g, "Bar Chart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "BarChart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "Bar Chart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3, @@ -100,6 +104,7 @@ public class NewBarChartHandler extends AbstractHandler { l0.ConsistsOf, dataset, l0.ConsistsOf, domainAxis, l0.ConsistsOf, rangeAxis); + Layer0Utils.addCommentMetadata(g, "Created new Bar Chart " + label + " " + jfreechart); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java index 7acab21e..e048657c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java @@ -22,6 +22,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; @@ -55,6 +56,7 @@ public class NewFunctionHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); SysdynResource sr = SysdynResource.getInstance(g); @@ -71,11 +73,13 @@ public class NewFunctionHandler extends AbstractHandler { String name = NameUtils.findFreshName(g, "Function", library, l0.ConsistsOf, "%s%d"); - GraphUtils.create2(g, sr.SysdynModelicaFunction, + Resource func = GraphUtils.create2(g, sr.SysdynModelicaFunction, l0.HasName, name, l0.HasDescription, "", sr.SysdynModelicaFunction_modelicaFunctionCode, "", l0.PartOf, library); + + Layer0Utils.addCommentMetadata(g, "Created new Function " + name + " " + func.toString()); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java index 3f17f995..0d386c7b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java @@ -25,6 +25,7 @@ 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.diagram.stubs.G2DResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -55,13 +56,16 @@ public class NewPieChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); + String label = NameUtils.findFreshLabel(g, "Pie Chart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "PieChart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "Pie Chart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3); @@ -83,6 +87,8 @@ public class NewPieChartHandler extends AbstractHandler { l0.PartOf, jfreechart, l0.ConsistsOf, dataset ); + Layer0Utils.addCommentMetadata(g, "Created new Pie Chart " + label + " " + jfreechart); + } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java index 013c5602..7bc7a370 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java @@ -27,6 +27,7 @@ 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.diagram.stubs.G2DResource; import org.simantics.jfreechart.chart.ChartUtils; import org.simantics.layer0.Layer0; @@ -54,14 +55,17 @@ public class NewSensitivityChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); SysdynResource SR = SysdynResource.getInstance(g); + String label = NameUtils.findFreshLabel(g, "SensitivityChart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "SensitivityChart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "SensitivityChart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3); @@ -143,6 +147,7 @@ public class NewSensitivityChartHandler extends AbstractHandler { l0.ConsistsOf, dataset, l0.ConsistsOf, domainAxis, l0.ConsistsOf, rangeAxis); + Layer0Utils.addCommentMetadata(g, "Created new Sensitivity Chart " + label + " " + jfreechart); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java index 2f06ce81..9c2e675e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java @@ -26,6 +26,7 @@ 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.diagram.stubs.G2DResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -58,13 +59,16 @@ public class NewXYLineChartHandler extends AbstractHandler { @Override public void perform(WriteGraph g) throws DatabaseException { + g.markUndoPoint(); Layer0 l0 = Layer0.getInstance(g); JFreeChartResource jfree = JFreeChartResource.getInstance(g); G2DResource g2d = G2DResource.getInstance(g); - + + String label = NameUtils.findFreshLabel(g, "Chart", model); + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, l0.HasName, "Chart" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(g, "Chart", model), + l0.HasLabel, label, l0.PartOf, model, jfree.Chart_visibleBorder, true, jfree.Chart_borderWidth, 3); @@ -102,6 +106,7 @@ public class NewXYLineChartHandler extends AbstractHandler { l0.ConsistsOf, dataset, l0.ConsistsOf, domainAxis, l0.ConsistsOf, rangeAxis); + Layer0Utils.addCommentMetadata(g, "Created new Line Chart " + label + " " + jfreechart); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java index 31ad9e7a..36e3fa14 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -38,6 +38,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.issues.ontology.IssueResource; import org.simantics.jfreechart.chart.properties.AdjustableTab; @@ -263,6 +264,7 @@ public class ConfigurationTab extends AdjustableTab { public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException { graph.claimLiteral(input, SysdynResource.getInstance(graph).SysdynModel_timeUnit, text); + Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " time unit to " + text); } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java index a029acd3..27b49076 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java @@ -52,10 +52,9 @@ abstract public class ComboStringPropertyModifier implements TextModifyListen @SuppressWarnings("unchecked") @Override public void perform(WriteGraph graph) throws DatabaseException { - + graph.markUndoPoint(); T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz); applyText(graph, single, textValue); - } }); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java index aaa959a5..b48628f2 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java @@ -185,7 +185,7 @@ public class SysdynExperiments { } public static Resource saveIC(WriteGraph graph, Variable input, String name) throws DatabaseException { - + graph.markUndoPoint(); Resource model = Variables.getModel(graph, input); Resource child = Layer0Utils.getPossibleChild(graph, model, name); SysdynResource SYSDYN = SysdynResource.getInstance(graph); @@ -209,12 +209,13 @@ public class SysdynExperiments { graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING); graph.claim(model, L0.ConsistsOf, ic); + Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic); return ic; } public static void assignIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException { - + graph.markUndoPoint(); System.err.println("assignIC " + experiment.getURI(graph)); Layer0 L0 = Layer0.getInstance(graph); @@ -233,7 +234,7 @@ public class SysdynExperiments { graph.deny(exp, SYSDYN.Experiment_ic); graph.claim(exp, SYSDYN.Experiment_ic, ic); - + Layer0Utils.addCommentMetadata(graph, "Assigned Initial Condition " + graph.getRelatedValue2(ic, L0.HasName, Bindings.STRING) + " to experiment " + graph.getRelatedValue2(exp, L0.HasName, Bindings.STRING)); } public static void deassignIC(WriteGraph graph, Variable experiment) throws DatabaseException { @@ -278,14 +279,14 @@ public class SysdynExperiments { } public static void deleteIC(WriteGraph graph, Variable input, String name) throws DatabaseException { - + graph.markUndoPoint(); Resource model = Variables.getModel(graph, input); Resource child = Layer0Utils.getPossibleChild(graph, model, name); SysdynResource SYSDYN = SysdynResource.getInstance(graph); if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition)) RemoverUtil.remove(graph, child); - + Layer0Utils.addCommentMetadata(graph, "Deleted Initial Condition " + graph.getRelatedValue2(child, Layer0.getInstance(graph).HasName, Bindings.STRING)); } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java index 9bda6cab..5e93b99a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java @@ -19,6 +19,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; 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.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.layer0.Layer0; @@ -29,7 +30,7 @@ import org.simantics.spreadsheet.resource.SpreadsheetResource; public class SheetUtils { public static Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException { - + graph.markUndoPoint(); Layer0 L0 = Layer0.getInstance(graph); SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); @@ -75,7 +76,7 @@ public class SheetUtils { // graph.claim(result, L0.HasChildVariables, L0.HasChildVariables_Inverse, newCell); // // } - + Layer0Utils.addCommentMetadata(graph, "Created new Spreadsheet " + name + " " + result.toString()); return result; } -- 2.47.1