]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
20c3f76f48e82dec48802defed8facef8a8e4b76
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.properties.widgets.sensitivity;\r
13 \r
14 import java.util.HashMap;\r
15 \r
16 import org.eclipse.jface.layout.GridDataFactory;\r
17 import org.eclipse.jface.layout.GridLayoutFactory;\r
18 import org.eclipse.jface.resource.JFaceResources;\r
19 import org.eclipse.jface.resource.LocalResourceManager;\r
20 import org.eclipse.swt.SWT;\r
21 import org.eclipse.swt.widgets.Composite;\r
22 import org.eclipse.swt.widgets.Label;\r
23 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
24 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
25 import org.simantics.databoard.Bindings;\r
26 import org.simantics.db.Resource;\r
27 import org.simantics.db.WriteGraph;\r
28 import org.simantics.db.exception.DatabaseException;\r
29 import org.simantics.db.management.ISessionContext;\r
30 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
31 import org.simantics.sysdyn.SysdynResource;\r
32 import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider;\r
33 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
34 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
35 \r
36 public class NormalDistributionProperties implements IDistributionProperties {\r
37 \r
38     private TrackedText minValue; \r
39     private TrackedText maxValue;\r
40     private TrackedText mean;\r
41     private TrackedText stdDeviation;\r
42     private Resource resource;\r
43     \r
44     public NormalDistributionProperties(Resource resource) {\r
45         this.resource = resource;\r
46     }\r
47     \r
48     @Override\r
49     public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) {\r
50         Composite composite = new Composite(parent, SWT.NONE);\r
51         GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);\r
52         \r
53         // minValue\r
54         Label label = new Label(composite, SWT.NONE);\r
55         label.setText("Min value");\r
56         GridDataFactory.fillDefaults().applyTo(label);\r
57         \r
58         minValue = new TrackedText(composite, support, SWT.BORDER);\r
59         minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_minValue));\r
60         minValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_minValue));\r
61         minValue.setInputValidator(new DoubleValidator(true));\r
62         minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget())));\r
63         GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget());\r
64 \r
65         // maxValue\r
66         label = new Label(composite, SWT.NONE);\r
67         label.setText("Max value");\r
68         GridDataFactory.fillDefaults().applyTo(label);\r
69         \r
70         maxValue = new TrackedText(composite, support, SWT.BORDER);\r
71         maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_maxValue));\r
72         maxValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_maxValue));\r
73         maxValue.setInputValidator(new DoubleValidator(true));\r
74         maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget())));\r
75         GridDataFactory.fillDefaults().grab(true, false).applyTo(maxValue.getWidget());\r
76         \r
77         // mean\r
78         label = new Label(composite, SWT.NONE);\r
79         label.setText("Mean");\r
80         GridDataFactory.fillDefaults().applyTo(label);\r
81         \r
82         mean = new TrackedText(composite, support, SWT.BORDER);\r
83         mean.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_mean));\r
84         mean.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_mean));\r
85         mean.setInputValidator(new DoubleValidator(true));\r
86         mean.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), mean.getWidget())));\r
87         GridDataFactory.fillDefaults().grab(true, false).applyTo(mean.getWidget());\r
88         \r
89         // stdDeviation\r
90         label = new Label(composite, SWT.NONE);\r
91         label.setText("Standard deviation");\r
92         GridDataFactory.fillDefaults().applyTo(label);\r
93         \r
94         stdDeviation = new TrackedText(composite, support, SWT.BORDER);\r
95         stdDeviation.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_stdDeviation));\r
96         stdDeviation.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_stdDeviation));\r
97         stdDeviation.setInputValidator(new DoubleValidator(true));\r
98         stdDeviation.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stdDeviation.getWidget())));\r
99         GridDataFactory.fillDefaults().grab(true, false).applyTo(stdDeviation.getWidget());\r
100         \r
101         return composite;\r
102     }\r
103 \r
104     @Override\r
105     public void getCachedValues(HashMap<String, String> cahcedValues) {\r
106         if(!minValue.isDisposed())\r
107             cahcedValues.put(SensitivityDistributionKeys.MIN, minValue.getText());\r
108         if(!maxValue.isDisposed())\r
109             cahcedValues.put(SensitivityDistributionKeys.MAX, maxValue.getText());\r
110         if(!mean.isDisposed())\r
111             cahcedValues.put(SensitivityDistributionKeys.MEAN, mean.getText());\r
112         if(!stdDeviation.isDisposed())\r
113             cahcedValues.put(SensitivityDistributionKeys.STD_DEVIATION, stdDeviation.getText());\r
114     }\r
115 \r
116 \r
117 \r
118     @Override\r
119     public void applyCache(WriteGraph graph, HashMap<String, String> cachedValues) throws DatabaseException {\r
120         if(resource == null)\r
121             return;\r
122         \r
123         SysdynResource SR = SysdynResource.getInstance(graph);\r
124         \r
125         String min = cachedValues.get(SensitivityDistributionKeys.MIN);\r
126         if(min != null) {\r
127             try {\r
128                 Double d = Double.parseDouble(min);\r
129                 graph.claimLiteral(resource, SR.NormalDistribution_minValue, d, Bindings.DOUBLE);\r
130             } catch (NumberFormatException e) {}\r
131         }\r
132         \r
133         String max = cachedValues.get(SensitivityDistributionKeys.MAX);\r
134         if(max != null) {\r
135             try {\r
136                 Double d = Double.parseDouble(max);\r
137                 graph.claimLiteral(resource, SR.NormalDistribution_maxValue, d, Bindings.DOUBLE);\r
138             } catch (NumberFormatException e) {}\r
139         }\r
140         \r
141         String mean = cachedValues.get(SensitivityDistributionKeys.MEAN);\r
142         if(mean != null) {\r
143             try {\r
144                 Double d = Double.parseDouble(mean);\r
145                 graph.claimLiteral(resource, SR.NormalDistribution_mean, d, Bindings.DOUBLE);\r
146             } catch (NumberFormatException e) {}\r
147         }\r
148         \r
149         String stdDeviation = cachedValues.get(SensitivityDistributionKeys.STD_DEVIATION);\r
150         if(stdDeviation != null) {\r
151             try {\r
152                 Double d = Double.parseDouble(stdDeviation);\r
153                 graph.claimLiteral(resource, SR.NormalDistribution_stdDeviation, d, Bindings.DOUBLE);\r
154             } catch (NumberFormatException e) {}\r
155         }\r
156     }\r
157 \r
158 }\r