From: lempinen Date: Wed, 22 May 2013 11:31:52 +0000 (+0000) Subject: Sensitivity analysis with a better configuration UI. The UI is not perfect, but enabl... X-Git-Tag: 1.8.1~305 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b045519ddec0e7ca90b3f02454c594d9623acf32;p=simantics%2Fsysdyn.git Sensitivity analysis with a better configuration UI. The UI is not perfect, but enables defining variables, indexes and distributions. Multiple parameters are supported. (refs #4239) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27438 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RVIModifier.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RVIModifier.java index 81edb2b9..6a863802 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RVIModifier.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RVIModifier.java @@ -23,6 +23,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; 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.exception.DatabaseException; @@ -39,6 +40,8 @@ public class RVIModifier extends TextModifyListenerImpl { private boolean active; private Control control; + private String rviUri; + private String indexUri; private char[] alphaNumericCharacters = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö', @@ -51,6 +54,14 @@ public class RVIModifier extends TextModifyListenerImpl { * @param support */ public RVIModifier(Control control, WidgetSupport support) { + this(control, support, JFreeChartResource.URIs.variableRVI, JFreeChartResource.URIs.variableFilter); + } + + + public RVIModifier(Control control, WidgetSupport support, String rviRelationUri, String indexUri) { + this.rviUri = rviRelationUri; + this.indexUri = indexUri; + this.control = control; this.active = true; @@ -101,11 +112,18 @@ public class RVIModifier extends TextModifyListenerImpl { public void applyText(WriteGraph graph, Resource resource, String text) throws DatabaseException { if(active) { text = "/" + text.replace('.', '/'); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - graph.claimLiteral(resource, jfree.variableRVI, text, Bindings.STRING); - graph.deny(resource, jfree.variableFilter); + graph.claimLiteral(resource, getRVIRelation(graph), text, Bindings.STRING); + graph.deny(resource, getIndexRelation(graph)); } } + + private Resource getRVIRelation(ReadGraph graph) throws DatabaseException { + return graph.getResource(rviUri); + } + + private Resource getIndexRelation(ReadGraph graph) throws DatabaseException { + return graph.getResource(indexUri); + } public void deactivate() { active = false; diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RangeComposite.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RangeComposite.java index cbb2f51a..b3d95473 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RangeComposite.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/RangeComposite.java @@ -13,6 +13,7 @@ package org.simantics.jfreechart.chart.properties; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.Map; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -41,7 +42,6 @@ import org.simantics.sysdyn.JFreeChartResource; import org.simantics.utils.RunnableWithObject; import org.simantics.utils.datastructures.Triple; import org.simantics.utils.ui.AdaptionUtils; -import org.simantics.utils.ui.ExceptionUtils; /** * Composite for range controls in chart series properties @@ -51,7 +51,7 @@ import org.simantics.utils.ui.ExceptionUtils; public class RangeComposite extends Composite implements Widget { private Composite composite; - + public RangeComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { super(parent, style); support.register(this); @@ -69,21 +69,21 @@ public class RangeComposite extends Composite implements Widget { RangeHandlerFactory f; try { - f = context.getSession().syncRequest(new Read() { - @Override - public RangeHandlerFactory perform(ReadGraph graph) - throws DatabaseException { - return graph.adapt(series, RangeHandlerFactory.class); - } - }); - + f = context.getSession().syncRequest(new Read() { + @Override + public RangeHandlerFactory perform(ReadGraph graph) + throws DatabaseException { + return graph.adapt(series, RangeHandlerFactory.class); + } + }); + } catch (DatabaseException e) { - //ExceptionUtils.logAndShowError("Insert something intelligent here.", e); - return; + //ExceptionUtils.logAndShowError("Insert something intelligent here.", e); + return; } - + final RangeHandlerFactory factory = f; - + /* * Listen to the enumerations assigned to the variable in this series. * Listener is needed because the user can change the variableRVI for the series @@ -106,6 +106,8 @@ public class RangeComposite extends Composite implements Widget { // Remove all content (even with null result) for(Control child : composite.getChildren()) child.dispose(); + + composite.layout(); if(getObject() == null) return; @@ -117,6 +119,10 @@ public class RangeComposite extends Composite implements Widget { TrackedCombo combo; LinkedHashMap result = (LinkedHashMap)getObject(); Iterator iterator = result.keySet().iterator(); + + // Set the width of the combo + GridLayout gl = (GridLayout)composite.getLayout(); + gl.numColumns = result.size(); // For each array index (enumeration), create a label and a combo int index = 0; @@ -125,7 +131,7 @@ public class RangeComposite extends Composite implements Widget { Composite c = new Composite(composite, SWT.NONE); GridDataFactory.fillDefaults().applyTo(c); GridLayoutFactory.fillDefaults().applyTo(c); - + label = new Label(c, SWT.NONE); label.setText((String)key); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(label); @@ -137,22 +143,19 @@ public class RangeComposite extends Composite implements Widget { GridDataFactory.fillDefaults().applyTo(combo.getWidget()); index++; } - - // Set the width of the combo - GridLayout gl = (GridLayout)composite.getLayout(); - gl.numColumns = index; - + // Set input for the combos support.fireInput(context, input); - + /* * Find out if this composite is located in a scrolled composite. * If it is, resize the scrolled composite */ + composite.layout(); Composite previousParent = composite.getParent(); - for(int i = 0; i < 5; i++) { + for(int i = 0; i < 7 && previousParent != null; i++) { + previousParent.layout(); if(previousParent.getParent() instanceof ScrolledComposite) { - previousParent.layout(); ScrolledComposite sc = (ScrolledComposite) previousParent.getParent(); Point size = previousParent.computeSize(SWT.DEFAULT, SWT.DEFAULT); sc.setMinSize(size); @@ -199,18 +202,21 @@ public class RangeComposite extends Composite implements Widget { @Override public String perform(ReadGraph graph, Resource series) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - String[] filter = graph.getPossibleRelatedValue(series, jfree.variableFilter, Bindings.STRING_ARRAY); - + String[] filter = graph.getPossibleRelatedValue(series, getIndexRelation(graph), Bindings.STRING_ARRAY); + + /* - * If no filter was found or the index is not applicable, return "All" + * If no filter was found or the index is not applicable, return the first index */ + String result = null; if(filter == null) - return "All"; + result = getFirstIndex(graph, series, index); else if(filter.length < index) - return "All"; + result = getFirstIndex(graph, series, index); else - return filter[index]; + result = filter[index]; + + return result; } } @@ -223,7 +229,7 @@ public class RangeComposite extends Composite implements Widget { * */ private class RangeModifyListener extends ComboModifyListenerImpl { - + private int index, size; /** @@ -238,20 +244,46 @@ public class RangeComposite extends Composite implements Widget { @Override public void applyText(WriteGraph graph, Resource series, String text) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - String[] filter = graph.getPossibleRelatedValue(series, jfree.variableFilter, Bindings.STRING_ARRAY); - + Resource filterRelation = getIndexRelation(graph); + String[] filter = graph.getPossibleRelatedValue(series, filterRelation, Bindings.STRING_ARRAY); + // If there is no filter, create a default filter with all indexes "All" if(filter == null) { filter = new String[size]; for(int i = 0; i < filter.length; i++) { - filter[i] = "All"; + filter[i] = getFirstIndex(graph, series, i); } } - + // Modify the filter index filter[index] = text; - graph.claimLiteral(series, jfree.variableFilter, filter, Bindings.STRING_ARRAY); + graph.claimLiteral(series, filterRelation, filter, Bindings.STRING_ARRAY); } } + + protected Resource getIndexRelation(ReadGraph graph) { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + return jfree.variableFilter; + } + + private static String getFirstIndex(ReadGraph graph, Resource series, int index) throws DatabaseException { + RangeHandlerFactory f = graph.adapt(series, RangeHandlerFactory.class); + LinkedHashMap map = graph.syncRequest(f.getRequest(series)); + if(map == null) + return null; + else { + Resource enumeration = null; + Iterator iterator = map.values().iterator(); + for(int i = 0; i <= index && iterator.hasNext(); i++) { + enumeration = iterator.next(); + } + if(enumeration != null) { + Map indexmap = f.getRangeItemFactory(index, enumeration).perform(graph, null); + if(indexmap != null) + return indexmap.values().iterator().next().toString(); + } + } + + return null; + } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java index aa19d6de..c3229747 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java @@ -25,7 +25,7 @@ import org.simantics.db.Resource; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.ui.AdaptionUtils; /** * @@ -67,7 +67,8 @@ public class VariableProposalProvider implements IContentProposalProvider, Widge @SuppressWarnings("unchecked") public IContentProposal[] getProposals(String contents, int position) { if (filterProposals) { - ArrayList list = new ArrayList(); + @SuppressWarnings("rawtypes") + ArrayList list = new ArrayList(); if (compareRVI) { for (ChartVariable proposal : proposals) { if (proposal.getRvi().length() >= contents.length() && proposal.getRvi().substring(0, contents.length()).equalsIgnoreCase(contents)) { diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 87734e26..66e2ea9e 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph b/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph index c7d1d53b..f9f52469 100644 --- a/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph +++ b/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph @@ -57,4 +57,30 @@ POBC VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution VP.VisualsContribution.HasNodeType L0.Entity VP.VisualsContribution.HasRule POBC.ParameterSorterRule - \ No newline at end of file + +///////////////////////////////////////////// +/// Sensitivity experiment parameters +///////////////////////////////////////////// +SPBC = SYSDYN.SensitivityAnalysisExperiment.ParameterBrowseContext : VP.BrowseContext +SPAC = SYSDYN.SensitivityAnalysisExperiment.ParameterActionContext : VP.BrowseContext + +SPBC.ParameterChildRule : VP.ChildRule +SPBC.ParameterLabelRule : VP.LabelRule +//SPBC.ParameterLabelDecorationRule : VP.LabelDecorationRule + +SPBC + @VP.customChildRule SYSDYN.SensitivityAnalysisExperiment SPBC.ParameterChildRule + SYSDYN.SensitivityAnalysisExperiment.Parameter + +SPBC + @VP.customLabelRule SYSDYN.SensitivityAnalysisExperiment.Parameter SPBC.ParameterLabelRule + +//SPBC +// @VP.customLabelDecorationRule SYSDYN.SensitivityAnalysisExperiment.Parameter SPBC.ParameterLabelDecorationRule + +SPBC + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType SYSDYN.SensitivityAnalysisExperiment + VP.VisualsContribution.HasRule VP.PassThruSorterRule + +SPAC.Actions : L0.Library diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 54d927db..9fa3788b 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -349,14 +349,38 @@ SYSDYN.SimulateOnChangeExperiment -- SYSDYN.SensitivityAnalysisExperiment.propabilityDistribution --> L0.String -- SYSDYN.SensitivityAnalysisExperiment.variedParameter --> SYSDYN.Auxiliary -- SYSDYN.SensitivityAnalysisExperiment.variedParameter --> L0.String -- SYSDYN.SensitivityAnalysisExperiment.minValue --> L0.Double -- SYSDYN.SensitivityAnalysisExperiment.maxValue --> L0.Double -- SYSDYN.SensitivityAnalysisExperiment.numValues --> L0.Integer -- SYSDYN.SensitivityAnalysisExperiment.mean --> L0.Double -- SYSDYN.SensitivityAnalysisExperiment.stdDeviation --> L0.Double -- SYSDYN.SensitivityAnalysisExperiment.parameterList --> L0.List -- SYSDYN.SensitivityAnalysisExperiment.randomSeed --> L0.Integer -- SYSDYN.SensitivityAnalysisExperiment.resultRefreshRate --> L0.Integer -- SYSDYN.SensitivityAnalysisExperiment.Parameter.propabilityDistribution --> SYSDYN.ProbabilityDistribution -- SYSDYN.SensitivityAnalysisExperiment.Parameter.variable --> L0.String -- SYSDYN.SensitivityAnalysisExperiment.Parameter.indexes --> L0.StringArray -- SYSDYN.SensitivityAnalysisExperiment.Parameter.numberOfValues --> L0.Integer -- SYSDYN.UniformDistribution.minValue --> L0.Double -- SYSDYN.UniformDistribution.maxValue --> L0.Double -- SYSDYN.NormalDistribution.minValue --> L0.Double -- SYSDYN.NormalDistribution.maxValue --> L0.Double -- SYSDYN.NormalDistribution.mean --> L0.Double -- SYSDYN.NormalDistribution.stdDeviation --> L0.Double -- SYSDYN.Interval.minValue --> L0.Double -- SYSDYN.Interval.maxValue --> L0.Double - none 0 fill 1 + none 0 fill 1 \ No newline at end of file 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 8c8c00b6..c1be4933 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 @@ -11,12 +11,16 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.handlers.newComponents; +import java.util.ArrayList; + import org.simantics.db.ReadGraph; 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.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.manager.SysdynSensitivityAnalysisExperiment; /** * Creates a new sensitivity analysis experiment. @@ -29,12 +33,22 @@ public class NewSensitivityAnalysisExperimentNodeHandler extends NewExperimentNo @Override protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); - graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_minValue, SysdynSensitivityAnalysisExperiment.DEFAULT_MIN_VALUE); - graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_maxValue, SysdynSensitivityAnalysisExperiment.DEFAULT_MAX_VALUE); - graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_numValues, SysdynSensitivityAnalysisExperiment.DEFAULT_NUM_VALUES); - graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_mean, SysdynSensitivityAnalysisExperiment.DEFAULT_MEAN); - graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_stdDeviation, SysdynSensitivityAnalysisExperiment.DEFAULT_STD_DEVIATION); - graph.claimLiteral(experiment, sr.SensitivityAnalysisExperiment_propabilityDistribution, "uniform"); + 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, "", + sr.SensitivityAnalysisExperiment_Parameter_numberOfValues, 10, + L0.PartOf, experiment); + + ArrayList parameterList = new ArrayList(); + parameterList.add(parameter); + + graph.claim(experiment, sr.SensitivityAnalysisExperiment_parameterList, ListUtils.create(graph, parameterList)); } @Override 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 b334ec2e..68ae677c 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 @@ -1,26 +1,66 @@ package org.simantics.sysdyn.ui.properties; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; +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.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.DisposableListener; +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.properties.RangeComposite; +import org.simantics.jfreechart.chart.properties.VariableExistsValidator; +import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite; import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.properties.widgets.factories.IntegerPropertyFactory; import org.simantics.sysdyn.ui.properties.widgets.factories.IntegerPropertyModifier; -import org.simantics.utils.ui.validators.DoubleValidator; +import org.simantics.sysdyn.ui.properties.widgets.sensitivity.DistributionPropertyWidget; +import org.simantics.sysdyn.ui.properties.widgets.sensitivity.ParameterChildRule; +import org.simantics.sysdyn.ui.properties.widgets.sensitivity.VariableNameModifier; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.RunnableWithObject; +import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.ui.AdaptionUtils; import org.simantics.utils.ui.validators.IntegerValidator; /** @@ -29,107 +69,350 @@ import org.simantics.utils.ui.validators.IntegerValidator; * @author Tuomas Miettinen * */ -public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributor { +public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributor implements Widget { - @Override - public void createControls(Composite body, IWorkbenchSite site, - ISessionContext context, WidgetSupport support) { - - ScrolledComposite sc = new ScrolledComposite(body, SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); - GridLayoutFactory.fillDefaults().applyTo(sc); - - Composite composite = new RemoveFocusBeforeExperimentComposite(sc, SWT.NONE); + private GraphExplorerComposite explorer; + private WidgetSupportImpl parameterSupport = new WidgetSupportImpl(); + private ScrolledComposite propertyContainer; + private Composite parameterProperties; + private Composite content; + private Button remove; + private Resource experiment; + + private boolean dirty = false; + + private DisposableListener> contentListener; + + @Override + public void createControls(Composite body, IWorkbenchSite site, + final ISessionContext context, WidgetSupport support) { + support.register(this); + + Composite composite = new RemoveFocusBeforeExperimentComposite(body, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + + // Scrolled composite for displaying properties of a selection in explorer + propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyContainer); + GridLayoutFactory.fillDefaults().applyTo(propertyContainer); + propertyContainer.setExpandHorizontal(true); + propertyContainer.setExpandVertical(true); + content = new Composite(propertyContainer, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(content); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(content); + // Label - Label label = new Label(composite, SWT.NONE); + Composite labelComposite = new Composite(content, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(labelComposite); + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(labelComposite); + Label label = new Label(labelComposite, SWT.NONE); label.setText("Name"); - - TrackedText name = new TrackedText(composite, support, SWT.BORDER); + + TrackedText name = new TrackedText(labelComposite, support, SWT.BORDER); name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName)); name.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), name.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); + + label = new Label(labelComposite, SWT.NONE); + label.setText("Seed"); + + TrackedText seed = new TrackedText(labelComposite, support, SWT.BORDER); + seed.setTextFactory(new IntegerPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_randomSeed)); + seed.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_randomSeed)); + seed.setInputValidator(new IntegerValidator()); + seed.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), seed.getWidget()))); + GridDataFactory.fillDefaults().hint(80, SWT.DEFAULT).applyTo(seed.getWidget()); + + + // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis + explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, content, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); + explorer.setBrowseContexts(SysdynResource.URIs.SensitivityAnalysisExperiment_ParameterBrowseContext); + explorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning + explorer.finish(); + + ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateSelection(context); + } + }); + + + + explorer.addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + if(contentListener != null) + contentListener.dispose(); + } + }); + + + GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); - // The propability distribution - label = new Label(composite, SWT.NONE); - label.setText("Propability distribution"); - - TrackedText propabilityDistributionName = new TrackedText(composite, support, SWT.BORDER); - propabilityDistributionName.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_propabilityDistribution)); - propabilityDistributionName.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_propabilityDistribution)); - //parameterName.setInputValidator(new DoubleValidator()); - propabilityDistributionName.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), propabilityDistributionName.getWidget()))); - - // Parameter the value of which is varied - label = new Label(composite, SWT.NONE); - label.setText("Varied parameter name"); - - TrackedText parameterName = new TrackedText(composite, support, SWT.BORDER); - parameterName.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_variedParameter)); - parameterName.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_variedParameter)); - //parameterName.setInputValidator(new DoubleValidator()); - parameterName.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), parameterName.getWidget()))); - - // minValue - label = new Label(composite, SWT.NONE); - label.setText("Min value"); - - TrackedText minValue = new TrackedText(composite, support, SWT.BORDER); - minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_minValue)); - minValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_minValue)); - minValue.setInputValidator(new DoubleValidator()); - minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget()))); - GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).applyTo(name.getWidget()); - - // maxValue - label = new Label(composite, SWT.NONE); - label.setText("Max value"); - - TrackedText maxValue = new TrackedText(composite, support, SWT.BORDER); - maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_maxValue)); - maxValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_maxValue)); - maxValue.setInputValidator(new DoubleValidator()); - maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget()))); - - // number of values - label = new Label(composite, SWT.NONE); - label.setText("Number of values"); - - TrackedText numValues = new TrackedText(composite, support, SWT.BORDER); - numValues.setTextFactory(new IntegerPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_numValues)); - numValues.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_numValues)); + Group parameterPropertyGroup = new Group(content, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterPropertyGroup); + GridLayoutFactory.fillDefaults().applyTo(parameterPropertyGroup); + + parameterProperties = new Composite(parameterPropertyGroup, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterProperties); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parameterProperties); + + // Label + label = new Label(parameterProperties, SWT.NONE); + label.setText("Variable:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + TrackedText variable = new TrackedText(parameterProperties, parameterSupport, SWT.BORDER); + variable.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable)); + variable.addModifyListener(new VariableNameModifier(variable.getWidget(), parameterSupport, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_indexes)); + variable.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), variable.getWidget()))); + variable.setInputValidator(new VariableExistsValidator(parameterSupport, variable)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(variable.getWidget()); + + label = new Label(parameterProperties, SWT.NONE); + label.setText("Range:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + RangeComposite rangeComposite = new RangeComposite(parameterProperties, context, parameterSupport, SWT.NONE) { + @Override + protected Resource getIndexRelation(ReadGraph graph) { + return SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_indexes; + } + }; + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); + +// TrackedText variable = new TrackedText(parameterProperties, parameterSupport, SWT.BORDER); +// variable.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable)); +// variable.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable)); +// variable.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), variable.getWidget()))); +// GridDataFactory.fillDefaults().grab(true, false).applyTo(variable.getWidget()); + + label = new Label(parameterProperties, SWT.NONE); + label.setText("Number of values:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + + TrackedText numValues = new TrackedText(parameterProperties, parameterSupport, SWT.BORDER); + numValues.setTextFactory(new IntegerPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_numberOfValues)); + numValues.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_numberOfValues)); numValues.setInputValidator(new IntegerValidator()); numValues.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), numValues.getWidget()))); + GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).hint(80, SWT.DEFAULT).applyTo(numValues.getWidget()); + + label = new Label(parameterProperties, SWT.NONE); + label.setText("Distribution:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + TrackedCombo distributionSelector = new TrackedCombo(parameterProperties, parameterSupport, SWT.DROP_DOWN); + distributionSelector.setItemFactory(new ReadFactoryImpl>() { + + @Override + public Map perform(ReadGraph graph, Resource input) throws DatabaseException { + SysdynResource SR = SysdynResource.getInstance(graph); + Map items = new HashMap(); + + items.put("Normal", SR.NormalDistribution); + items.put("Uniform", SR.UniformDistribution); + items.put("Interval", SR.Interval); + + return items; + } + + }); + + distributionSelector.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public String perform(ReadGraph graph, Resource parameter) throws DatabaseException { + SysdynResource SR = SysdynResource.getInstance(graph); + Resource distribution = graph.getPossibleObject(parameter, SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution); + if(distribution == null) + return null; + + if(graph.isInstanceOf(distribution, SR.UniformDistribution)) + return "Uniform"; + else if(graph.isInstanceOf(distribution, SR.NormalDistribution)) + return "Normal"; + else if(graph.isInstanceOf(distribution, SR.Interval)) + return "Interval"; + else + return ""; + + } + }); + + distributionSelector.addModifyListener(new ComboModifyListenerImpl() { + + @Override + public void applyText(WriteGraph graph, Resource input, String text) + throws DatabaseException { + if(text == null || text.isEmpty()) + return; + + SysdynResource SR = SysdynResource.getInstance(graph); + + Resource type = SR.UniformDistribution; + + if("Normal".equals(text)) + type = SR.NormalDistribution; + else if("Interval".equals(text)) + type = SR.Interval; + + graph.deny(input, SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution); + + GraphUtils.create2(graph, type, + SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse, input); + + dirty = true; + } + }); + + distributionSelector.addModifyListener(new TextModifyListener() { + + @Override + public void modifyText(TrackedModifyEvent e) { + if(dirty) { + parameterSupport.update(); + dirty = false; + propertyContainer.setContent(content); + Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + } + } + }); + + label = new Label(parameterProperties, SWT.NONE); + + 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, "", + sr.SensitivityAnalysisExperiment_Parameter_numberOfValues, 10, + 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); + + } + + + /** + * Updates the content of propertyContainer + * @param context + */ + private void updateSelection(ISessionContext context) { + ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); + IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + parameterSupport.fireInput(context, selection); + + propertyContainer.setContent(content); + Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + } + + + @Override + public void setInput(ISessionContext context, Object input) { + experiment = AdaptionUtils.adaptToSingle(input, Resource.class); + if(contentListener == null) { + contentListener = new DisposableListener>() { + + @Override + public void execute(Collection result) { + if(remove != null && !remove.getWidget().isDisposed() && result != null) { + remove.getWidget().getDisplay().asyncExec(new RunnableWithObject(result) { + @Override + public void run() { + if(!remove.getWidget().isDisposed()) { + @SuppressWarnings("unchecked") + Collection result = (Collection) getObject(); + if(result.size() > 1) + remove.getWidget().setEnabled(true); + else + remove.getWidget().setEnabled(false); + } + } + }); + + } + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + }; + + SimanticsUI.getSession().asyncRequest(new Read> () { + + @SuppressWarnings("unchecked") + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + return (Collection) new ParameterChildRule().getChildren(graph, experiment); + } + + }, contentListener); + } + - // mean - label = new Label(composite, SWT.NONE); - label.setText("Mean"); - - TrackedText mean = new TrackedText(composite, support, SWT.BORDER); - mean.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_mean)); - mean.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_mean)); - mean.setInputValidator(new DoubleValidator()); - mean.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), mean.getWidget()))); - - // standard deviation - label = new Label(composite, SWT.NONE); - label.setText("Standard deviation"); - - TrackedText stdDeviation = new TrackedText(composite, support, SWT.BORDER); - stdDeviation.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_stdDeviation)); - stdDeviation.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_stdDeviation)); - stdDeviation.setInputValidator(new DoubleValidator()); - stdDeviation.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stdDeviation.getWidget()))); - - // Scrolled composite settings - sc.setContent(composite); - sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - - } + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/DistributionPropertyWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/DistributionPropertyWidget.java new file mode 100644 index 00000000..93a62b2d --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/DistributionPropertyWidget.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.HashMap; + +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +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.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.AdaptionUtils; + +public class DistributionPropertyWidget extends Composite implements Widget { + + private IDistributionProperties distributionProperties = null; + private WidgetSupportImpl distributionSupport = new WidgetSupportImpl(); + private HashMap cache = new HashMap(); + private Resource oldInput; + + public DistributionPropertyWidget(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + GridLayoutFactory.fillDefaults().applyTo(this); + support.register(this); + } + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class); + if(resource == null) + return; + + IDistributionProperties newProperties = null; + Resource distribution = null; + try { + distribution = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + Resource distribution = graph.getPossibleObject( + resource, + SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_propabilityDistribution + ); + + return distribution; + } + + }); + + newProperties = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public IDistributionProperties perform(ReadGraph graph) throws DatabaseException { + Resource distribution = graph.getPossibleObject( + resource, + SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_propabilityDistribution + ); + + return graph.adapt(distribution, IDistributionProperties.class); + } + + }); + + // Create a PropertyComposite for the selected node + if(newProperties != null) { + + if(distributionProperties != null) + distributionProperties.getCachedValues(cache); + + if(oldInput != null && !oldInput.equals(resource)) + cache.clear(); + + oldInput = resource; + + for(Control child : this.getChildren()) { + child.dispose(); + } + + newProperties.createContent(this, context, distributionSupport); + distributionProperties = newProperties; + + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + distributionProperties.applyCache(graph, cache); + + } + }); + + distributionSupport.fireInput(context, new StructuredSelection(distribution)); + } + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/IDistributionProperties.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/IDistributionProperties.java new file mode 100644 index 00000000..0c628e95 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/IDistributionProperties.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.HashMap; + +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; + +public interface IDistributionProperties { + + public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support); + + public void getCachedValues(HashMap cachedValues); + + public void applyCache(WriteGraph graph, HashMap cachedValues) throws DatabaseException; + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/IntervalProperties.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/IntervalProperties.java new file mode 100644 index 00000000..9f3b7bc4 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/IntervalProperties.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.HashMap; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.jfreechart.chart.properties.DoubleValidator; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; + +public class IntervalProperties implements IDistributionProperties { + + private Resource resource; + private TrackedText minValue; + private TrackedText maxValue; + + public IntervalProperties(Resource resource) { + this.resource = resource; + } + + @Override + public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); + + // minValue + Label label = new Label(composite, SWT.NONE); + label.setText("Min value"); + GridDataFactory.fillDefaults().applyTo(label); + + minValue = new TrackedText(composite, support, SWT.BORDER); + minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.Interval_minValue)); + minValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.Interval_minValue)); + minValue.setInputValidator(new DoubleValidator(false)); + minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget()); + + // maxValue + label = new Label(composite, SWT.NONE); + label.setText("Max value"); + GridDataFactory.fillDefaults().applyTo(label); + + maxValue = new TrackedText(composite, support, SWT.BORDER); + maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.Interval_maxValue)); + maxValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.Interval_maxValue)); + maxValue.setInputValidator(new DoubleValidator(false)); + maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(maxValue.getWidget()); + + return composite; + } + + + @Override + public void getCachedValues(HashMap cahcedValues) { + if(!minValue.isDisposed()) + cahcedValues.put(SensitivityDistributionKeys.MIN, minValue.getText()); + if(!maxValue.isDisposed()) + cahcedValues.put(SensitivityDistributionKeys.MAX, maxValue.getText()); + } + + + + @Override + public void applyCache(WriteGraph graph, HashMap cachedValues) throws DatabaseException { + if(resource == null) + return; + + SysdynResource SR = SysdynResource.getInstance(graph); + + String min = cachedValues.get(SensitivityDistributionKeys.MIN); + if(min != null) { + try { + Double d = Double.parseDouble(min); + graph.claimLiteral(resource, SR.Interval_minValue, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + + String max = cachedValues.get(SensitivityDistributionKeys.MAX); + if(max != null) { + try { + Double d = Double.parseDouble(max); + graph.claimLiteral(resource, SR.Interval_maxValue, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + } + + + +} 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 new file mode 100644 index 00000000..20c3f76f --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/NormalDistributionProperties.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.HashMap; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.jfreechart.chart.properties.DoubleValidator; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; + +public class NormalDistributionProperties implements IDistributionProperties { + + private TrackedText minValue; + private TrackedText maxValue; + private TrackedText mean; + private TrackedText stdDeviation; + private Resource resource; + + public NormalDistributionProperties(Resource resource) { + this.resource = resource; + } + + @Override + public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); + + // minValue + Label label = new Label(composite, SWT.NONE); + label.setText("Min value"); + GridDataFactory.fillDefaults().applyTo(label); + + minValue = new TrackedText(composite, support, SWT.BORDER); + minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_minValue)); + minValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_minValue)); + minValue.setInputValidator(new DoubleValidator(true)); + minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget()); + + // maxValue + label = new Label(composite, SWT.NONE); + label.setText("Max value"); + GridDataFactory.fillDefaults().applyTo(label); + + maxValue = new TrackedText(composite, support, SWT.BORDER); + maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_maxValue)); + maxValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_maxValue)); + maxValue.setInputValidator(new DoubleValidator(true)); + 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; + } + + @Override + public void getCachedValues(HashMap cahcedValues) { + if(!minValue.isDisposed()) + cahcedValues.put(SensitivityDistributionKeys.MIN, minValue.getText()); + if(!maxValue.isDisposed()) + cahcedValues.put(SensitivityDistributionKeys.MAX, maxValue.getText()); + if(!mean.isDisposed()) + cahcedValues.put(SensitivityDistributionKeys.MEAN, mean.getText()); + if(!stdDeviation.isDisposed()) + cahcedValues.put(SensitivityDistributionKeys.STD_DEVIATION, stdDeviation.getText()); + } + + + + @Override + public void applyCache(WriteGraph graph, HashMap cachedValues) throws DatabaseException { + if(resource == null) + return; + + SysdynResource SR = SysdynResource.getInstance(graph); + + String min = cachedValues.get(SensitivityDistributionKeys.MIN); + if(min != null) { + try { + Double d = Double.parseDouble(min); + graph.claimLiteral(resource, SR.NormalDistribution_minValue, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + + String max = cachedValues.get(SensitivityDistributionKeys.MAX); + if(max != null) { + try { + Double d = Double.parseDouble(max); + graph.claimLiteral(resource, SR.NormalDistribution_maxValue, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + + String mean = cachedValues.get(SensitivityDistributionKeys.MEAN); + if(mean != null) { + try { + Double d = Double.parseDouble(mean); + graph.claimLiteral(resource, SR.NormalDistribution_mean, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + + String stdDeviation = cachedValues.get(SensitivityDistributionKeys.STD_DEVIATION); + if(stdDeviation != null) { + try { + Double d = Double.parseDouble(stdDeviation); + graph.claimLiteral(resource, SR.NormalDistribution_stdDeviation, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterChildRule.java new file mode 100644 index 00000000..30274d60 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterChildRule.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.Collection; +import java.util.Collections; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class ParameterChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + SysdynResource SR = SysdynResource.getInstance(graph); + + Resource experiment = (Resource) parent; + Resource parameterList = graph.getPossibleObject(experiment, SR.SensitivityAnalysisExperiment_parameterList); + + if(parameterList != null) + return ListUtils.toList(graph, parameterList); + else + return Collections.emptyList(); + } + + @Override + public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { + return Collections.emptyList(); + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterLabelRule.java new file mode 100644 index 00000000..87984f7e --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterLabelRule.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.HashMap; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class ParameterLabelRule implements LabelRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + HashMap result = new HashMap(); + + String variable = graph.getPossibleRelatedValue((Resource)content, SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_variable); + Integer n = graph.getPossibleRelatedValue((Resource)content, SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_numberOfValues); + + StringBuilder sb = new StringBuilder(); + + if(variable != null) + sb.append(variable); + else + sb.append("No variable"); + + sb.append(" (n="); + + if(n != null) + sb.append(n); + else + sb.append("undefined"); + + sb.append(")"); + + result.put(ColumnKeys.SINGLE, sb.toString()) ; + + return result; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterProposalProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterProposalProvider.java new file mode 100644 index 00000000..84b0c212 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/ParameterProposalProvider.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +public class ParameterProposalProvider { + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/SensitivityDistributionKeys.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/SensitivityDistributionKeys.java new file mode 100644 index 00000000..d1019b2c --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/SensitivityDistributionKeys.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +public class SensitivityDistributionKeys { + + public static String MAX = "MAX"; + public static String MIN = "MIN"; + public static String STD_DEVIATION = "STD_DEVIATION"; + public static String MEAN = "MEAN"; + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/SensitivityRangeHandlerFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/SensitivityRangeHandlerFactory.java new file mode 100644 index 00000000..aca7931c --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/SensitivityRangeHandlerFactory.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.Map; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.trend.SysdynRangeHandlerFactory; + +public class SensitivityRangeHandlerFactory extends SysdynRangeHandlerFactory { + + @Override + protected Resource getRVIRelation(ReadGraph graph) { + return SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_variable; + } + + @Override + public ReadFactoryImpl> getRangeItemFactory(int index, Resource res) { + return new RangeItemFactory(index, res, false); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/UniformDistributionProperties.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/UniformDistributionProperties.java new file mode 100644 index 00000000..2b78a9db --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/UniformDistributionProperties.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import java.util.HashMap; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.jfreechart.chart.properties.DoubleValidator; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; + +public class UniformDistributionProperties implements IDistributionProperties{ + + private TrackedText minValue; + private TrackedText maxValue; + private Resource resource; + + public UniformDistributionProperties(Resource resource) { + this.resource = resource; + } + + @Override + public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); + + // minValue + Label label = new Label(composite, SWT.NONE); + label.setText("Min value"); + GridDataFactory.fillDefaults().applyTo(label); + + minValue = new TrackedText(composite, support, SWT.BORDER); + minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.UniformDistribution_minValue)); + minValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.UniformDistribution_minValue)); + minValue.setInputValidator(new DoubleValidator(false)); + minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget()); + + // maxValue + label = new Label(composite, SWT.NONE); + label.setText("Max value"); + GridDataFactory.fillDefaults().applyTo(label); + + maxValue = new TrackedText(composite, support, SWT.BORDER); + maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.UniformDistribution_maxValue)); + maxValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.UniformDistribution_maxValue)); + maxValue.setInputValidator(new DoubleValidator(false)); + maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget()))); + GridDataFactory.fillDefaults().grab(true, false).applyTo(maxValue.getWidget()); + + return composite; + } + + @Override + public void getCachedValues(HashMap cahcedValues) { + cahcedValues.put(SensitivityDistributionKeys.MIN, minValue.getText()); + cahcedValues.put(SensitivityDistributionKeys.MAX, maxValue.getText()); + } + + + + @Override + public void applyCache(WriteGraph graph, HashMap cachedValues) throws DatabaseException { + if(resource == null) + return; + + SysdynResource SR = SysdynResource.getInstance(graph); + + String min = cachedValues.get(SensitivityDistributionKeys.MIN); + if(min != null) { + try { + Double d = Double.parseDouble(min); + graph.claimLiteral(resource, SR.UniformDistribution_minValue, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + + String max = cachedValues.get(SensitivityDistributionKeys.MAX); + if(max != null) { + try { + Double d = Double.parseDouble(max); + graph.claimLiteral(resource, SR.UniformDistribution_maxValue, d, Bindings.DOUBLE); + } catch (NumberFormatException e) {} + } + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/VariableNameModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/VariableNameModifier.java new file mode 100644 index 00000000..1b04c098 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/sensitivity/VariableNameModifier.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.sensitivity; + +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.fieldassist.IContentProposalListener; +import org.eclipse.jface.fieldassist.IContentProposalListener2; +import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.swt.widgets.Control; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +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.exception.DatabaseException; +import org.simantics.jfreechart.chart.properties.VariableProposalProvider; + +public class VariableNameModifier extends TextModifyListenerImpl { + + private boolean active; + private Control control; + private String variableNameRelationUri; + private String indexUri; + + private char[] alphaNumericCharacters = { + 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö', + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö', + '1','2','3','4','5','6','7','8','9','0','.','_'}; + + + public VariableNameModifier(Control control, WidgetSupport support, String variableNameRelationUri, String indexUri) { + this.variableNameRelationUri = variableNameRelationUri; + this.indexUri = indexUri; + + this.control = control; + this.active = true; + + KeyStroke keyStroke = null; + try { + keyStroke = KeyStroke.getInstance("Ctrl+Space"); + } catch (ParseException e1) { + e1.printStackTrace(); + } + + //SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support); + VariableProposalProvider scpp = new VariableProposalProvider(control, support); + scpp.setFiltering(true); + + ContentProposalAdapter adapter = new ContentProposalAdapter( + control, new TextContentAdapter(), scpp, keyStroke, alphaNumericCharacters); + adapter.setAutoActivationDelay(0); + adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + adapter.addContentProposalListener(new IContentProposalListener2() { + + @Override + public void proposalPopupOpened(ContentProposalAdapter adapter) { + if(VariableNameModifier.this != null) + VariableNameModifier.this.deactivate(); + } + + @Override + public void proposalPopupClosed(ContentProposalAdapter adapter) { + if(VariableNameModifier.this != null) + VariableNameModifier.this.activate(); + } + }); + + adapter.addContentProposalListener(new IContentProposalListener() { + + @Override + public void proposalAccepted(IContentProposal proposal) { + if(VariableNameModifier.this.control != null && !VariableNameModifier.this.control.isDisposed()) + VariableNameModifier.this.modifyText(new TrackedModifyEvent(VariableNameModifier.this.control, proposal.getContent())); + } + }); + + + } + + + @Override + public void applyText(WriteGraph graph, Resource resource, String text) throws DatabaseException { + if(active) { + graph.claimLiteral(resource, getVariableNameRelation(graph), text, Bindings.STRING); + graph.deny(resource, getIndexRelation(graph)); + } else { + System.out.println("NÄHÄÄ"); + } + } + + private Resource getVariableNameRelation(ReadGraph graph) throws DatabaseException { + return graph.getResource(variableNameRelationUri); + } + + private Resource getIndexRelation(ReadGraph graph) throws DatabaseException { + return graph.getResource(indexUri); + } + + public void deactivate() { + active = false; + } + + public void activate() { + active = 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 28dc7d34..c05d1ae4 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 @@ -74,7 +74,7 @@ public class SensitivitySeriesPropertyComposite extends SeriesPropertyComposite public void apply(WriteGraph graph, Resource series) throws DatabaseException { SysdynResource SR = SysdynResource.getInstance(graph); Resource dataset = graph.getPossibleObject(series, Layer0.getInstance(graph).PartOf); - if(dataset != null) + if(dataset == null) return; Boolean result = graph.getPossibleRelatedValue(dataset, SR.Charts_SensitivityDataset_median, Bindings.BOOLEAN); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SysdynRangeHandlerFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SysdynRangeHandlerFactory.java index 74bbee09..9f804e55 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SysdynRangeHandlerFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SysdynRangeHandlerFactory.java @@ -22,6 +22,11 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.utils.datastructures.Quad; public class SysdynRangeHandlerFactory implements RangeHandlerFactory { + + protected Resource getRVIRelation(ReadGraph graph) { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + return jfree.variableRVI; + } @Override public Read> getRequest(final Resource series) { @@ -30,14 +35,18 @@ public class SysdynRangeHandlerFactory implements RangeHandlerFactory { @Override public LinkedHashMap perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); SysdynResource sr = SysdynResource.getInstance(graph); String realizationURI = ChartUtils.getCurrentRealizationURI(graph, series); - String rvi = graph.getPossibleRelatedValue(series, jfree.variableRVI); + String rvi = graph.getPossibleRelatedValue(series, getRVIRelation(graph)); if(rvi == null) return null; + rvi = rvi.replace(".", "/"); + + if(!rvi.startsWith("/")) + rvi = "/" + rvi; + try { // Find the variable for the current variableRVI Variable v = Variables.getVariable(graph, realizationURI + rvi.trim()); @@ -103,19 +112,32 @@ public class SysdynRangeHandlerFactory implements RangeHandlerFactory { * @author Teemu Lempinen * */ - private class RangeItemFactory extends ReadFactoryImpl> { + public class RangeItemFactory extends ReadFactoryImpl> { private int index; private Resource enumeration; + private boolean addCollections; + /** * * @param index Index of the enumeration in the variable * @param enumeration The enumeration */ public RangeItemFactory(int index, Resource enumeration) { + this(index, enumeration, true); + } + + /** + * + * @param index Index of the enumeration in the variable + * @param enumeration The enumeration + * @param addCollections add "Sum" and "All" + */ + public RangeItemFactory(int index, Resource enumeration, boolean addCollections) { this.index = index; this.enumeration = enumeration; + this.addCollections = addCollections; } public Object getIdentity(Object inputContents) { @@ -127,13 +149,16 @@ public class SysdynRangeHandlerFactory implements RangeHandlerFactory { LinkedHashMap result = new LinkedHashMap(); Resource enumerationIndexes = graph.getPossibleObject(enumeration, sr.Enumeration_enumerationIndexList); List indexes = ListUtils.toList(graph, enumerationIndexes); - // First add "All" and "Sum", then all of the enumeration indexes in order - result.put("All", "All"); - result.put("Sum", "Sum"); + if(addCollections) { + // First add "All" and "Sum", then all of the enumeration indexes in order + result.put("All", "All"); + result.put("Sum", "Sum"); + } for(Resource index : indexes) { String name = NameUtils.getSafeName(graph, index); result.put(name, name); } + return result; } } diff --git a/org.simantics.sysdyn/adapters.xml b/org.simantics.sysdyn/adapters.xml index 74013f11..e370bc2c 100644 --- a/org.simantics.sysdyn/adapters.xml +++ b/org.simantics.sysdyn/adapters.xml @@ -21,6 +21,38 @@ + + + + + + + + + + + + + + + + + + + + + +