]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5093
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 14 Jul 2014 06:01:25 +0000 (06:01 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 14 Jul 2014 06:01:25 +0000 (06:01 +0000)
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

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityChartHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java

index 61eb18506df1b89b88cb3e24727940c9f17c31bb..0d17007c6574bb27be30efff6c1ec68e9eb40362 100644 (file)
@@ -19,13 +19,16 @@ import org.simantics.browsing.ui.common.node.AbstractNode;
 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
+import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.CancelTransactionException;\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.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
 \r
@@ -67,7 +70,10 @@ public abstract class AbstractChartNode<T> extends AbstractNode<Resource> implem
             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                 @Override\r
                 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    graph.markUndoPoint();\r
+                    String chartName = graph.getRelatedValue2(data, Layer0.getInstance(graph).HasName, Bindings.STRING);\r
                     RemoverUtil.remove(graph, data);\r
+                    Layer0Utils.addCommentMetadata(graph, "Removed chart '" + chartName +"' " + data);\r
                 }\r
             });\r
         } catch (DatabaseException e) {\r
index 88aa7eb72e68837fd5c5c2db8fde7b8784d538d6..1e3421421dd517bf8d00549c964d9d66b420b6af 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.ListUtils;\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.diagram.stubs.G2DResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
@@ -55,13 +56,16 @@ public class NewBarChartHandler extends AbstractHandler {
 \r
             @Override\r
             public void perform(WriteGraph g) throws DatabaseException {\r
+                g.markUndoPoint();\r
                 Layer0 l0 = Layer0.getInstance(g);\r
                 JFreeChartResource jfree = JFreeChartResource.getInstance(g);\r
                 G2DResource g2d = G2DResource.getInstance(g);\r
 \r
+                String label = NameUtils.findFreshLabel(g, "Bar Chart", model);\r
+                \r
                 Resource jfreechart = GraphUtils.create2(g, jfree.Chart,\r
                         l0.HasName, "BarChart" + UUID.randomUUID().toString(),\r
-                        l0.HasLabel, NameUtils.findFreshLabel(g, "Bar Chart", model),\r
+                        l0.HasLabel, label,\r
                         l0.PartOf, model,\r
                         jfree.Chart_visibleBorder, true,\r
                         jfree.Chart_borderWidth, 3,\r
@@ -100,6 +104,7 @@ public class NewBarChartHandler extends AbstractHandler {
                         l0.ConsistsOf, dataset,\r
                         l0.ConsistsOf, domainAxis,\r
                         l0.ConsistsOf, rangeAxis);\r
+                Layer0Utils.addCommentMetadata(g, "Created new Bar Chart " +  label + " " + jfreechart);\r
             }\r
 \r
         });\r
index 7acab21ed23d06b97e2f3693b2e9cedd7f441ba3..e048657cf762ae801d725503c2bce2807558cfcb 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.db.WriteGraph;
 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.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -55,6 +56,7 @@ public class NewFunctionHandler extends AbstractHandler {
 \r
             @Override\r
             public void perform(WriteGraph g) throws DatabaseException {\r
+                g.markUndoPoint();\r
                Layer0 l0 = Layer0.getInstance(g);\r
                 SysdynResource sr = SysdynResource.getInstance(g);\r
 \r
@@ -71,11 +73,13 @@ public class NewFunctionHandler extends AbstractHandler {
                 \r
                 String name = NameUtils.findFreshName(g, "Function", library, l0.ConsistsOf, "%s%d");\r
 \r
-                GraphUtils.create2(g, sr.SysdynModelicaFunction,\r
+                Resource func = GraphUtils.create2(g, sr.SysdynModelicaFunction,\r
                         l0.HasName, name,\r
                         l0.HasDescription, "",\r
                         sr.SysdynModelicaFunction_modelicaFunctionCode, "",\r
                         l0.PartOf, library);\r
+                \r
+                Layer0Utils.addCommentMetadata(g, "Created new Function " + name + " " + func.toString());\r
             }\r
         });\r
         \r
index 3f17f995c7bbaf5e9457bec76e12c6845988a069..0d386c7bd8aecf6ee0842500414790c524598a2c 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.ListUtils;\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.diagram.stubs.G2DResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
@@ -55,13 +56,16 @@ public class NewPieChartHandler extends AbstractHandler {
 \r
             @Override\r
             public void perform(WriteGraph g) throws DatabaseException {\r
+                g.markUndoPoint();\r
                 Layer0 l0 = Layer0.getInstance(g);\r
                 JFreeChartResource jfree = JFreeChartResource.getInstance(g);\r
                 G2DResource g2d = G2DResource.getInstance(g);\r
 \r
+                String label = NameUtils.findFreshLabel(g, "Pie Chart", model);\r
+                \r
                 Resource jfreechart = GraphUtils.create2(g, jfree.Chart,\r
                         l0.HasName, "PieChart" + UUID.randomUUID().toString(),\r
-                        l0.HasLabel, NameUtils.findFreshLabel(g, "Pie Chart", model),\r
+                        l0.HasLabel, label,\r
                         l0.PartOf, model,\r
                         jfree.Chart_visibleBorder, true,\r
                         jfree.Chart_borderWidth, 3);\r
@@ -83,6 +87,8 @@ public class NewPieChartHandler extends AbstractHandler {
                         l0.PartOf, jfreechart,\r
                         l0.ConsistsOf, dataset\r
                         );\r
+                Layer0Utils.addCommentMetadata(g, "Created new Pie Chart " +  label + " " + jfreechart);\r
+                \r
             }\r
 \r
         });\r
index 013c56023179ebf46d8da60b6ed0354ee7f2eb7b..7bc7a370a57fd0699ffbf4d4630c55c88e7c2d2d 100644 (file)
@@ -27,6 +27,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.ListUtils;\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.diagram.stubs.G2DResource;\r
 import org.simantics.jfreechart.chart.ChartUtils;\r
 import org.simantics.layer0.Layer0;\r
@@ -54,14 +55,17 @@ public class NewSensitivityChartHandler extends AbstractHandler {
 \r
             @Override\r
             public void perform(WriteGraph g) throws DatabaseException {\r
+                g.markUndoPoint();\r
                 Layer0 l0 = Layer0.getInstance(g);\r
                 JFreeChartResource jfree = JFreeChartResource.getInstance(g);\r
                 G2DResource g2d = G2DResource.getInstance(g);\r
                 SysdynResource SR = SysdynResource.getInstance(g);\r
 \r
+                String label = NameUtils.findFreshLabel(g, "SensitivityChart", model);\r
+                \r
                 Resource jfreechart = GraphUtils.create2(g, jfree.Chart,\r
                         l0.HasName, "SensitivityChart" + UUID.randomUUID().toString(),\r
-                        l0.HasLabel, NameUtils.findFreshLabel(g, "SensitivityChart", model),\r
+                        l0.HasLabel, label,\r
                         l0.PartOf, model,\r
                         jfree.Chart_visibleBorder, true,\r
                         jfree.Chart_borderWidth, 3);\r
@@ -143,6 +147,7 @@ public class NewSensitivityChartHandler extends AbstractHandler {
                         l0.ConsistsOf, dataset,\r
                         l0.ConsistsOf, domainAxis,\r
                         l0.ConsistsOf, rangeAxis);\r
+                Layer0Utils.addCommentMetadata(g, "Created new Sensitivity Chart " +  label + " " + jfreechart);\r
             }\r
 \r
         });\r
index 2f06ce812f6c41d9929a27a512e9f3f5d95aa453..9c2e675e98a53dc42b48129c44cc2d3606b5ab9f 100644 (file)
@@ -26,6 +26,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.ListUtils;\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.diagram.stubs.G2DResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
@@ -58,13 +59,16 @@ public class NewXYLineChartHandler extends AbstractHandler {
 \r
             @Override\r
             public void perform(WriteGraph g) throws DatabaseException {\r
+                g.markUndoPoint();\r
                 Layer0 l0 = Layer0.getInstance(g);\r
                 JFreeChartResource jfree = JFreeChartResource.getInstance(g);\r
                 G2DResource g2d = G2DResource.getInstance(g);\r
-\r
+                \r
+                String label = NameUtils.findFreshLabel(g, "Chart", model);\r
+                \r
                 Resource jfreechart = GraphUtils.create2(g, jfree.Chart,\r
                         l0.HasName, "Chart" + UUID.randomUUID().toString(),\r
-                        l0.HasLabel, NameUtils.findFreshLabel(g, "Chart", model),\r
+                        l0.HasLabel, label,\r
                         l0.PartOf, model,\r
                         jfree.Chart_visibleBorder, true,\r
                         jfree.Chart_borderWidth, 3);\r
@@ -102,6 +106,7 @@ public class NewXYLineChartHandler extends AbstractHandler {
                         l0.ConsistsOf, dataset,\r
                         l0.ConsistsOf, domainAxis,\r
                         l0.ConsistsOf, rangeAxis);\r
+                Layer0Utils.addCommentMetadata(g, "Created new Line Chart " +  label + " " + jfreechart);\r
             }\r
 \r
         });\r
index 31ad9e7a398875b5f9024c016bfad4c79886a7b1..36e3fa14e3aa2d91e25ba839bb44fcbfbf736ed7 100644 (file)
@@ -38,6 +38,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.PossibleObjectWithType;\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.management.ISessionContext;\r
 import org.simantics.issues.ontology.IssueResource;\r
 import org.simantics.jfreechart.chart.properties.AdjustableTab;\r
@@ -263,6 +264,7 @@ public class ConfigurationTab extends AdjustableTab {
             public void applyText(WriteGraph graph, Resource input, String text)\r
                     throws DatabaseException {\r
                 graph.claimLiteral(input, SysdynResource.getInstance(graph).SysdynModel_timeUnit, text);\r
+                Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " time unit to " + text);\r
             }\r
         });\r
         \r
index a029acd377b6b1c556fbe5818fd2d7d7d817ce24..27b49076b190b1cc3475597a4e6ee7b59baa7155 100644 (file)
@@ -52,10 +52,9 @@ abstract public class ComboStringPropertyModifier<T> implements TextModifyListen
                                @SuppressWarnings("unchecked")\r
                 @Override\r
                                public void perform(WriteGraph graph) throws DatabaseException {\r
-\r
+                                   graph.markUndoPoint();\r
                                        T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz);\r
                                        applyText(graph, single, textValue);\r
-                                       \r
                                }\r
                                \r
                        });\r
index aaa959a5960c27a3921ebb800a5a1843c4450a6d..b48628f246cc75b0af86664f346e87c0deb53ede 100644 (file)
@@ -185,7 +185,7 @@ public class SysdynExperiments {
        }\r
 \r
     public static Resource saveIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
-       \r
+        graph.markUndoPoint();\r
                Resource model = Variables.getModel(graph, input);\r
        Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
        SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
@@ -209,12 +209,13 @@ public class SysdynExperiments {
                graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING);\r
                graph.claim(model, L0.ConsistsOf, ic);\r
                \r
+               Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic);\r
                return ic;\r
        \r
     }\r
 \r
     public static void assignIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException {\r
-\r
+        graph.markUndoPoint();\r
        System.err.println("assignIC " + experiment.getURI(graph));\r
 \r
                Layer0 L0 = Layer0.getInstance(graph);\r
@@ -233,7 +234,7 @@ public class SysdynExperiments {
        \r
                graph.deny(exp, SYSDYN.Experiment_ic);\r
                graph.claim(exp, SYSDYN.Experiment_ic, ic);\r
-       \r
+       Layer0Utils.addCommentMetadata(graph, "Assigned Initial Condition " + graph.getRelatedValue2(ic, L0.HasName, Bindings.STRING) + " to experiment " + graph.getRelatedValue2(exp, L0.HasName, Bindings.STRING));\r
     }\r
     \r
     public static void deassignIC(WriteGraph graph, Variable experiment) throws DatabaseException {\r
@@ -278,14 +279,14 @@ public class SysdynExperiments {
     }\r
     \r
     public static void deleteIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
-\r
+        graph.markUndoPoint();\r
        Resource model = Variables.getModel(graph, input);\r
        Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
        SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
 \r
        if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition))\r
                RemoverUtil.remove(graph, child);\r
-       \r
+       Layer0Utils.addCommentMetadata(graph, "Deleted Initial Condition " + graph.getRelatedValue2(child, Layer0.getInstance(graph).HasName, Bindings.STRING));\r
     }\r
     \r
 }\r
index 9bda6cab3deee055fd5af008caf7d285fac5b8ac..5e93b99a16746f2430ffadedf49a06a49206d654 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ObjectsWithType;\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.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.layer0.Layer0;\r
@@ -29,7 +30,7 @@ import org.simantics.spreadsheet.resource.SpreadsheetResource;
 public class SheetUtils {\r
 \r
     public static Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException {\r
-\r
+        graph.markUndoPoint();\r
         Layer0 L0 = Layer0.getInstance(graph);\r
         SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
 \r
@@ -75,7 +76,7 @@ public class SheetUtils {
 //            graph.claim(result, L0.HasChildVariables, L0.HasChildVariables_Inverse, newCell);\r
 //            \r
 //        }\r
-\r
+        Layer0Utils.addCommentMetadata(graph, "Created new Spreadsheet " + name + " " + result.toString());\r
         return result;\r
 \r
     }\r