From cf2bd5503b4f727a507022459b3ee8e0c9247d70 Mon Sep 17 00:00:00 2001 From: miettinen Date: Wed, 13 Nov 2013 08:51:44 +0000 Subject: [PATCH] Activate variable save when the respective EquationTab is disposed. Save variable also when only the type of variable is changed. (refs #4544). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28247 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 4 ++-- .../sysdyn/ui/properties/EquationTab.java | 6 ++++++ .../widgets/expressions/BasicExpression.java | 21 ++++++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 2ea9023a..51ec0515 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -197,8 +197,8 @@ targetID="org.simantics.sysdyn.ui.perspective.equation"> 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 238a21b2..2f9e4380 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 @@ -73,6 +73,7 @@ import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget; import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget; import org.simantics.sysdyn.ui.properties.widgets.ShortcutTabWidget; import org.simantics.sysdyn.ui.properties.widgets.arrays.NameAndArrayRangeModifyListener; +import org.simantics.sysdyn.ui.properties.widgets.expressions.DelayExpression; import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionComposite; import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionWidgetInput; import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameInputValidator; @@ -779,6 +780,11 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { @Override public void dispose() { + if(expressionWidget != null && !(expressionWidget.getExpression() instanceof DelayExpression)) { + // For delay expression this doesn't work, + // but it doesn't matter since the saving is succeeded elsewhere. + expressionWidget.save(); + } if(focusLostListener != null && site != null) site.getPage().removePartListener(focusLostListener); super.dispose(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java index 0ddbebc5..b5226951 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java @@ -131,10 +131,7 @@ public class BasicExpression implements IExpression { public void save(final Resource expression, Map data) { final String currentText = this.expression.getExpression(); final String oldEquation = (String)data.get("equation"); - - if(currentText != null && oldEquation != null && currentText.equals(oldEquation)) - return; // Nothing is changed, no need to save - + if(oldEquation == null || (currentText != null && expressionType != null)) { data.put("equation", currentText); @@ -145,14 +142,6 @@ public class BasicExpression implements IExpression { SysdynResource sr = SysdynResource.getInstance(g); Layer0 l0 = Layer0.getInstance(g); - // Force change to parameter, if the equation is a parameter - if(ExpressionUtils.isParameter(currentText)) { - if(!expressionType.equals(sr.ConstantExpression)) - expressionType = sr.ParameterExpression; - } else { - expressionType = sr.NormalExpression; - } - // If nothing has changed, do nothing if (oldEquation != null && expression != null @@ -161,6 +150,14 @@ public class BasicExpression implements IExpression { return; } + // Force change to parameter, if the equation is a parameter + if(ExpressionUtils.isParameter(currentText)) { + if(!expressionType.equals(sr.ConstantExpression)) + expressionType = sr.ParameterExpression; + } else { + expressionType = sr.NormalExpression; + } + // If the current expression type is different than the target expression type, create a new expression if(!g.isInstanceOf(expression, expressionType)) { -- 2.47.1