From b2132af3ac764d549bafdd77a9da427ea0b75680 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 15 Jul 2014 08:03:06 +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@29887 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/properties/DependencyTab.java | 12 +++++++++++- .../simantics/sysdyn/ui/properties/EquationTab.java | 5 +++++ .../ui/properties/widgets/DelayMarkWidget.java | 5 +++++ .../sysdyn/ui/properties/widgets/IsOutputWidget.java | 5 +++++ .../ui/trend/SensitivitySeriesPropertyComposite.java | 7 +++++-- .../sysdyn/representation/utils/UnitUtils.java | 3 ++- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java index 194c0df1..666d1008 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java @@ -31,8 +31,10 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; import org.simantics.jfreechart.chart.properties.AdjustableTab; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.connections.DependencyEdgeClass; import org.simantics.sysdyn.ui.elements.connections.DependencyNode; @@ -83,6 +85,7 @@ public class DependencyTab extends AdjustableTab { SysdynResource sr = SysdynResource.getInstance(graph); float width = ((float)selection) / 10.0f; graph.claimLiteral(connectionElement, sr.DependencyConnection_strokeWidth, width); + Layer0Utils.addCommentMetadata(graph, "Modified Line thickness for connection " + graph.getPossibleRelatedValue2(connectionElement, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to " + width); } } @@ -114,9 +117,12 @@ public class DependencyTab extends AdjustableTab { @Override public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); + String currentLocation = graph.getPossibleRelatedValue2(connectionElement, sr.DependencyConnection_polarityLocation, Bindings.STRING); + if (currentLocation != null && currentLocation.equals(location)) + return; graph.claimLiteral(connectionElement, sr.DependencyConnection_polarityLocation, location); + Layer0Utils.addCommentMetadata(graph, "Modified Location for connection " + graph.getPossibleRelatedValue2(connectionElement, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to " + location); } - } class PolarityLocationRadioSelectionFactory extends ReadFactoryImpl { @@ -157,7 +163,11 @@ public class DependencyTab extends AdjustableTab { @Override public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); + String currentPolarity = graph.getPossibleRelatedValue2(connectionElement, sr.DependencyConnection_polarity, Bindings.STRING); + if (currentPolarity != null && currentPolarity.equals(polarity)) + return; graph.claimLiteral(connectionElement, sr.DependencyConnection_polarity, polarity.trim()); + Layer0Utils.addCommentMetadata(graph, "Modified Polarity for connection " + graph.getPossibleRelatedValue2(connectionElement, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to " + polarity.trim()); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index 429014df..4d45a5cb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -46,6 +46,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.databoard.Bindings; import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -56,6 +57,7 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.AsyncListener; @@ -472,6 +474,7 @@ public class EquationTab extends AdjustableTab implements Widget { ); } }); + Layer0Utils.addCommentMetadata(graph, "Deleted Expression " + activeExpression + " from " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING)); } }); @@ -496,10 +499,12 @@ public class EquationTab extends AdjustableTab implements Widget { graph.claim(newExpression, l0.InstanceOf, graph.getSingleObject(activeExpression, l0.InstanceOf)); if(graph.isInstanceOf(newExpression, sr.StockExpression)) { graph.claimLiteral(newExpression, sr.StockExpression_initialEquation, ""); + Layer0Utils.addCommentMetadata(graph, "Created new Stock Expression " + newExpression + " for " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING)); } } else { // If there was no active expression, create a normal expression graph.claim(newExpression, l0.InstanceOf, sr.NormalExpression); + Layer0Utils.addCommentMetadata(graph, "Created new Normal Expression " + newExpression + " for " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING)); } ArrayList addition = new ArrayList(1); addition.add(newExpression); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/DelayMarkWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/DelayMarkWidget.java index e5d4e0ec..d13f3e6b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/DelayMarkWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/DelayMarkWidget.java @@ -22,12 +22,15 @@ import org.eclipse.swt.widgets.Composite; import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.utils.ui.ISelectionUtils; @@ -155,8 +158,10 @@ public class DelayMarkWidget implements Widget{ final SysdynResource sr = SysdynResource.getInstance(graph); if(graph.hasStatement(input, sr.DependencyConnection_delayMark)) { graph.deny(input, sr.DependencyConnection_delayMark); + Layer0Utils.addCommentMetadata(graph, "Modified Delay mark for connection " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to False"); } else { graph.claim(input, SysdynResource.getInstance(graph).DependencyConnection_delayMark, null, input); + Layer0Utils.addCommentMetadata(graph, "Modified Delay mark for connection " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to True"); } } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java index 5297182d..db9a513f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java @@ -19,12 +19,15 @@ import org.eclipse.swt.widgets.Composite; import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; import org.simantics.utils.ui.ISelectionUtils; @@ -88,8 +91,10 @@ public class IsOutputWidget implements Widget{ SysdynResource sr = SysdynResource.getInstance(graph); if(graph.hasStatement(input, sr.IsOutput)) { graph.deny(input, sr.IsOutput); + Layer0Utils.addCommentMetadata(graph, "Modified Is Output for " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to False"); } else { graph.claim(input, SysdynResource.getInstance(graph).IsOutput, null, input); + Layer0Utils.addCommentMetadata(graph, "Modified Is Output for " + graph.getPossibleRelatedValue2(input, Layer0.getInstance(graph).HasName, Bindings.STRING) + " to True"); } } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java index 4be6de7f..b6c5aed9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivitySeriesPropertyComposite.java @@ -23,7 +23,9 @@ import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +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.jfreechart.chart.properties.xyline.SeriesPropertyComposite; import org.simantics.layer0.Layer0; @@ -81,9 +83,10 @@ public class SensitivitySeriesPropertyComposite extends SeriesPropertyComposite Boolean result = graph.getPossibleRelatedValue(dataset, SR.Charts_SensitivityDataset_median, Bindings.BOOLEAN); if(result == null) result = false; - graph.claimLiteral(dataset, SR.Charts_SensitivityDataset_median, Boolean.FALSE.equals(result)); + boolean newValue = Boolean.FALSE.equals(result); + graph.claimLiteral(dataset, SR.Charts_SensitivityDataset_median, newValue); + Layer0Utils.addCommentMetadata(graph, "Display Median for " + NameUtils.getSafeName(graph, series) + " to " + newValue); } - }); Composite c = new Composite(this, SWT.NONE); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java index 5b630875..8418b14f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java @@ -94,7 +94,8 @@ public class UnitUtils { public static String matchUnits(ReadGraph graph, SysdynModel model, Configuration configuration, String unit, String expression) { if(unit == null) return "Unit not defined"; - + if (expression == null) + return "Expression not defined"; try { StringReader rightReader = new StringReader(expression); UnitParser rightParser = new UnitParser(rightReader); -- 2.47.1