From 454ee72c0ebf08d5c5466fd4f396d45d922cd03a Mon Sep 17 00:00:00 2001 From: miettinen Date: Tue, 2 Jul 2013 05:18:22 +0000 Subject: [PATCH] Improved the sensitivity analysis property view so that the buttons and are shown without scrolling by default (refs #4334). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27671 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../jfreechart/chart/ChartUtils.java | 5 +- ...sitivityAnalysisExperimentNodeHandler.java | 3 +- .../SensitivityAnalysisExperimentTab.java | 111 +++++++++--------- .../NormalDistributionProperties.java | 56 ++++----- .../SensitivityExperimentParameter.java | 52 ++++---- .../SysdynSensitivityAnalysisExperiment.java | 5 +- 6 files changed, 119 insertions(+), 113 deletions(-) diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartUtils.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartUtils.java index ae9a23c4..78b36e62 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartUtils.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartUtils.java @@ -32,10 +32,13 @@ import org.w3c.dom.Document; * Utilities for handling charts * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public class ChartUtils { + public static final String emptyVariableName = ""; + /** * Creates a new range axis of type jfree.NumberAxis to a plot * @@ -116,7 +119,7 @@ public class ChartUtils { // Create series Resource series = GraphUtils.create2(graph, jfree.Series, l0.HasName, "Series" + UUID.randomUUID().toString(), - jfree.variableRVI, rvi == null ? " " : rvi, + jfree.variableRVI, rvi == null ? " " + emptyVariableName : rvi, l0.PartOf, dataset); // Add series to the dataset's series list diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java index ac823f5b..05f53002 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java @@ -18,6 +18,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.jfreechart.chart.ChartUtils; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; @@ -41,7 +42,7 @@ public class NewSensitivityAnalysisExperimentNodeHandler extends NewExperimentNo Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter, sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution, - sr.SensitivityAnalysisExperiment_Parameter_variable, "", + sr.SensitivityAnalysisExperiment_Parameter_variable, ChartUtils.emptyVariableName, L0.PartOf, experiment); ArrayList parameterList = new ArrayList(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java index ae039710..12d743f8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java @@ -68,6 +68,7 @@ import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.db.request.Read; +import org.simantics.jfreechart.chart.ChartUtils; import org.simantics.jfreechart.chart.properties.RangeComposite; import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite; import org.simantics.layer0.Layer0; @@ -224,6 +225,60 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); + Composite buttonComposite = new Composite(explorer, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(buttonComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + + Button addVariable = new Button(buttonComposite, support, SWT.NONE); + addVariable.setText("Add parameter"); + addVariable.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + + Resource distribution = GraphUtils.create2(graph, sr.UniformDistribution, + sr.UniformDistribution_minValue, 0.0, + sr.UniformDistribution_maxValue, 10.0); + + Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter, + sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution, + sr.SensitivityAnalysisExperiment_Parameter_variable, ChartUtils.emptyVariableName, + L0.PartOf, input); + + Resource parameterList = graph.getPossibleObject(input, sr.SensitivityAnalysisExperiment_parameterList); + ListUtils.insertBack(graph, parameterList, Collections.singleton(parameter)); + } + }); + + remove = new Button(buttonComposite, parameterSupport, SWT.NONE); + remove.setText("Remove"); + remove.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if(input == null) + return; + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + + Resource experiment = graph.getPossibleObject(input, L0.PartOf); + Resource parameterList = graph.getPossibleObject(experiment, sr.SensitivityAnalysisExperiment_parameterList); + + if(ListUtils.toList(graph, parameterList).size() > 1) + ListUtils.removeElement(graph, parameterList, input); + + } + + }); + + propertyContainer.setContent(content); + Point tsize = content.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(tsize); + + Group parameterPropertyGroup = new Group(content, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterPropertyGroup); GridLayoutFactory.fillDefaults().applyTo(parameterPropertyGroup); @@ -349,62 +404,6 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo DistributionPropertyWidget dpw = new DistributionPropertyWidget(parameterProperties, context, parameterSupport, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(dpw); - - Composite buttonComposite = new Composite(content, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(buttonComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); - - - Button addVariable = new Button(buttonComposite, support, SWT.NONE); - addVariable.setText("Add parameter"); - addVariable.addSelectionListener(new SelectionListenerImpl(context) { - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 L0 = Layer0.getInstance(graph); - - Resource distribution = GraphUtils.create2(graph, sr.UniformDistribution, - sr.UniformDistribution_minValue, 0.0, - sr.UniformDistribution_maxValue, 10.0); - - Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter, - sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution, - sr.SensitivityAnalysisExperiment_Parameter_variable, "", - L0.PartOf, input); - - Resource parameterList = graph.getPossibleObject(input, sr.SensitivityAnalysisExperiment_parameterList); - ListUtils.insertBack(graph, parameterList, Collections.singleton(parameter)); - } - }); - - remove = new Button(buttonComposite, parameterSupport, SWT.NONE); - remove.setText("Remove"); - remove.addSelectionListener(new SelectionListenerImpl(context) { - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - if(input == null) - return; - - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 L0 = Layer0.getInstance(graph); - - Resource experiment = graph.getPossibleObject(input, L0.PartOf); - Resource parameterList = graph.getPossibleObject(experiment, sr.SensitivityAnalysisExperiment_parameterList); - - if(ListUtils.toList(graph, parameterList).size() > 1) - ListUtils.removeElement(graph, parameterList, input); - - } - - }); - - - propertyContainer.setContent(content); - Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT); - propertyContainer.setMinSize(size); - } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/NormalDistributionProperties.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/NormalDistributionProperties.java index 20c3f76f..ccb5fb2a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/NormalDistributionProperties.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/NormalDistributionProperties.java @@ -48,12 +48,24 @@ public class NormalDistributionProperties implements IDistributionProperties { @Override public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) { Composite composite = new Composite(parent, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite); - // minValue + // mean Label label = new Label(composite, SWT.NONE); + label.setText("Mean (\u03BC)"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + mean = new TrackedText(composite, support, SWT.BORDER); + mean.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_mean)); + mean.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_mean)); + mean.setInputValidator(new DoubleValidator(true)); + mean.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), mean.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(mean.getWidget()); + + // minValue + label = new Label(composite, SWT.NONE); label.setText("Min value"); - GridDataFactory.fillDefaults().applyTo(label); + GridDataFactory.fillDefaults().indent(15, 0).align(SWT.END, SWT.CENTER).applyTo(label); minValue = new TrackedText(composite, support, SWT.BORDER); minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_minValue)); @@ -62,10 +74,22 @@ public class NormalDistributionProperties implements IDistributionProperties { minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget()))); GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget()); + // stdDeviation + label = new Label(composite, SWT.NONE); + label.setText("Standard deviation (\u03C3)"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + stdDeviation = new TrackedText(composite, support, SWT.BORDER); + stdDeviation.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_stdDeviation)); + stdDeviation.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_stdDeviation)); + stdDeviation.setInputValidator(new DoubleValidator(true)); + stdDeviation.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stdDeviation.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(stdDeviation.getWidget()); + // maxValue label = new Label(composite, SWT.NONE); label.setText("Max value"); - GridDataFactory.fillDefaults().applyTo(label); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); maxValue = new TrackedText(composite, support, SWT.BORDER); maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_maxValue)); @@ -74,30 +98,6 @@ public class NormalDistributionProperties implements IDistributionProperties { maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget()))); GridDataFactory.fillDefaults().grab(true, false).applyTo(maxValue.getWidget()); - // mean - label = new Label(composite, SWT.NONE); - label.setText("Mean"); - GridDataFactory.fillDefaults().applyTo(label); - - mean = new TrackedText(composite, support, SWT.BORDER); - mean.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_mean)); - mean.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_mean)); - mean.setInputValidator(new DoubleValidator(true)); - mean.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), mean.getWidget()))); - GridDataFactory.fillDefaults().grab(true, false).applyTo(mean.getWidget()); - - // stdDeviation - label = new Label(composite, SWT.NONE); - label.setText("Standard deviation"); - GridDataFactory.fillDefaults().applyTo(label); - - stdDeviation = new TrackedText(composite, support, SWT.BORDER); - stdDeviation.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_stdDeviation)); - stdDeviation.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_stdDeviation)); - stdDeviation.setInputValidator(new DoubleValidator(true)); - stdDeviation.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stdDeviation.getWidget()))); - GridDataFactory.fillDefaults().grab(true, false).applyTo(stdDeviation.getWidget()); - return composite; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SensitivityExperimentParameter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SensitivityExperimentParameter.java index 09852189..8dc6bdd1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SensitivityExperimentParameter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SensitivityExperimentParameter.java @@ -47,31 +47,33 @@ public class SensitivityExperimentParameter { SysdynModel sm = smm.getModel(graph, graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration)); Variable variable = RepresentationUtils.getVariable(sm.getConfiguration(), variableName); - - if(indexes == null && (variable.getArrayIndexes() != null & variable.getArrayIndexes().size() > 0)) { - indexes = new String[variable.getArrayIndexes().size()]; - - for(int i = 0; i < variable.getArrayIndexes().size(); i++) { - Enumeration e = variable.getArrayIndexes().get(i); - indexes[i] = e.getEnumerationIndexes().get(0).getName(); - } - } - - if(indexes != null) { - StringBuilder sb = new StringBuilder(); - sb.append("["); - for(int i = 0; i < indexes.length; i++) { - if(i > 0) - sb.append(","); - - String index = indexes[i]; - sb.append(index); - } - sb.append("]"); - String result = IndexUtils.rangeToIndexes(variable, sb.toString()); - fullName = variableName + result; - } else { - fullName = variableName; + + if (variable != null) { + if(indexes == null && (variable.getArrayIndexes() != null & variable.getArrayIndexes().size() > 0)) { + indexes = new String[variable.getArrayIndexes().size()]; + + for(int i = 0; i < variable.getArrayIndexes().size(); i++) { + Enumeration e = variable.getArrayIndexes().get(i); + indexes[i] = e.getEnumerationIndexes().get(0).getName(); + } + } + + if(indexes != null) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for(int i = 0; i < indexes.length; i++) { + if(i > 0) + sb.append(","); + + String index = indexes[i]; + sb.append(index); + } + sb.append("]"); + String result = IndexUtils.rangeToIndexes(variable, sb.toString()); + fullName = variableName + result; + } else { + fullName = variableName; + } } } catch (DatabaseException e) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java index e139e379..ea5f7990 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java @@ -184,8 +184,9 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment { if(parameters != null) { parameters.clear(); for(Resource p : parameterResources) { - SensitivityExperimentParameter parameter = graph.adapt(p, SensitivityExperimentParameter.class); - parameters.add(parameter); + SensitivityExperimentParameter parameter = graph.adapt(p, SensitivityExperimentParameter.class); + if (parameter.getFullName() != null) + parameters.add(parameter); } } } -- 2.47.1