]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
ee1a45557a907e69313ceeb08fc284ef106804ef
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011, 2014 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  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.properties;\r
13 \r
14 import java.util.Collection;\r
15 import java.util.Collections;\r
16 import java.util.HashMap;\r
17 import java.util.Map;\r
18 \r
19 import org.eclipse.core.runtime.IAdaptable;\r
20 import org.eclipse.jface.layout.GridDataFactory;\r
21 import org.eclipse.jface.layout.GridLayoutFactory;\r
22 import org.eclipse.jface.resource.JFaceResources;\r
23 import org.eclipse.jface.resource.LocalResourceManager;\r
24 import org.eclipse.jface.viewers.ISelectionProvider;\r
25 import org.eclipse.jface.viewers.IStructuredSelection;\r
26 import org.eclipse.jface.viewers.StructuredSelection;\r
27 import org.eclipse.swt.SWT;\r
28 import org.eclipse.swt.custom.ScrolledComposite;\r
29 import org.eclipse.swt.events.DisposeEvent;\r
30 import org.eclipse.swt.events.DisposeListener;\r
31 import org.eclipse.swt.events.SelectionAdapter;\r
32 import org.eclipse.swt.events.SelectionEvent;\r
33 import org.eclipse.swt.graphics.Point;\r
34 import org.eclipse.swt.widgets.Composite;\r
35 import org.eclipse.swt.widgets.Event;\r
36 import org.eclipse.swt.widgets.Group;\r
37 import org.eclipse.swt.widgets.Label;\r
38 import org.eclipse.swt.widgets.Listener;\r
39 import org.eclipse.swt.widgets.Tree;\r
40 import org.eclipse.swt.widgets.TreeItem;\r
41 import org.eclipse.ui.IWorkbenchSite;\r
42 import org.simantics.browsing.ui.BuiltinKeys;\r
43 import org.simantics.browsing.ui.Column;\r
44 import org.simantics.browsing.ui.Column.Align;\r
45 import org.simantics.browsing.ui.NodeContext;\r
46 import org.simantics.browsing.ui.common.ColumnKeys;\r
47 import org.simantics.browsing.ui.common.NodeContextBuilder.MapNodeContext;\r
48 import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
49 import org.simantics.browsing.ui.swt.widgets.Button;\r
50 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
51 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
52 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
53 import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
54 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
55 import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
56 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
57 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
58 import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
59 import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
60 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
61 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
62 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
63 import org.simantics.db.ReadGraph;\r
64 import org.simantics.db.Resource;\r
65 import org.simantics.db.WriteGraph;\r
66 import org.simantics.db.common.procedure.adapter.DisposableListener;\r
67 import org.simantics.db.common.utils.ListUtils;\r
68 import org.simantics.db.exception.DatabaseException;\r
69 import org.simantics.db.management.ISessionContext;\r
70 import org.simantics.db.request.Read;\r
71 import org.simantics.jfreechart.chart.ChartUtils;\r
72 import org.simantics.jfreechart.chart.properties.AdjustableTab;\r
73 import org.simantics.jfreechart.chart.properties.RangeComposite;\r
74 import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
75 import org.simantics.layer0.Layer0;\r
76 import org.simantics.layer0.utils.direct.GraphUtils;\r
77 import org.simantics.sysdyn.SysdynResource;\r
78 import org.simantics.sysdyn.ui.properties.widgets.factories.IntegerPropertyFactory;\r
79 import org.simantics.sysdyn.ui.properties.widgets.factories.IntegerPropertyModifier;\r
80 import org.simantics.sysdyn.ui.properties.widgets.sensitivity.DistributionPropertyWidget;\r
81 import org.simantics.sysdyn.ui.properties.widgets.sensitivity.ParameterChildRule;\r
82 import org.simantics.sysdyn.ui.properties.widgets.sensitivity.VariableNameModifier;\r
83 import org.simantics.sysdyn.ui.validation.ParameterExistsValidator;\r
84 import org.simantics.ui.SimanticsUI;\r
85 import org.simantics.utils.RunnableWithObject;\r
86 import org.simantics.utils.datastructures.ArrayMap;\r
87 import org.simantics.utils.ui.AdaptionUtils;\r
88 import org.simantics.utils.ui.validators.IntegerValidator;\r
89 \r
90 /**\r
91  * Tab for displaying sensitivity analysis experiment properties\r
92  * \r
93  * @author Tuomas Miettinen\r
94  *\r
95  */\r
96 public class SensitivityAnalysisExperimentTab extends AdjustableTab implements Widget {\r
97 \r
98     private GraphExplorerComposite explorer;\r
99     private WidgetSupportImpl parameterSupport = new WidgetSupportImpl();\r
100     private ScrolledComposite propertyContainer;\r
101     private Composite parameterProperties;\r
102     private Composite content;\r
103     private Button remove;\r
104     private Resource experiment;\r
105     \r
106     private boolean dirty = false;\r
107     private boolean dirtyMethod = false;\r
108     \r
109     private DisposableListener<Collection<Resource>> contentListener;\r
110         private Composite labelComposite;\r
111         private Label labelName;\r
112         private Label labelNumber;\r
113         private Label labelMethod;\r
114         private TrackedCombo methodSelector;\r
115         private Label labelSeed;\r
116         private TrackedText seed;\r
117         private Tree tree;\r
118         private Composite buttonComposite;\r
119         private Group parameterPropertyGroup;\r
120         private Label labelVariable;\r
121         private TrackedText variable;\r
122         private Label labelRange;\r
123         private RangeComposite rangeComposite;\r
124         private Label labelDistribution;\r
125         private TrackedCombo distributionSelector;\r
126         private DistributionPropertyWidget dpw;\r
127         private TrackedText name;\r
128         private TrackedText n;\r
129         private Button addVariable;\r
130 \r
131     @Override\r
132     public void createControls(Composite body, IWorkbenchSite site,\r
133             final ISessionContext context, final WidgetSupport support) {\r
134         support.register(this);\r
135         super.createControls(body, site, context, support);\r
136     }\r
137 \r
138     /**\r
139      * Updates the content of propertyContainer  \r
140      * @param context\r
141      */\r
142     private void updateSelection(ISessionContext context) {\r
143         ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class);\r
144         IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();\r
145         parameterSupport.fireInput(context, selection);\r
146 \r
147         propertyContainer.setContent(content);\r
148         Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
149         propertyContainer.setMinSize(size);\r
150     }\r
151 \r
152 \r
153     @Override\r
154     public void setInput(ISessionContext context, Object input) {\r
155         experiment = AdaptionUtils.adaptToSingle(input, Resource.class);\r
156         if(contentListener == null) {\r
157             contentListener = new DisposableListener<Collection<Resource>>() {\r
158 \r
159                 @Override\r
160                 public void execute(Collection<Resource> result) {\r
161                     if(remove != null && !remove.getWidget().isDisposed() && result != null) {\r
162                         remove.getWidget().getDisplay().asyncExec(new RunnableWithObject(result) {\r
163                             @Override\r
164                             public void run() {\r
165                                 if(!remove.getWidget().isDisposed()) {\r
166                                     @SuppressWarnings("unchecked")\r
167                                     Collection<Resource> result = (Collection<Resource>) getObject();\r
168                                     if(result.size() > 1)\r
169                                         remove.getWidget().setEnabled(true);\r
170                                     else\r
171                                         remove.getWidget().setEnabled(false);\r
172                                 }\r
173                             }\r
174                         });\r
175 \r
176                     }\r
177                 }\r
178 \r
179                 @Override\r
180                 public void exception(Throwable t) {\r
181                     t.printStackTrace();\r
182                 }\r
183             };\r
184 \r
185             SimanticsUI.getSession().asyncRequest(new Read<Collection<Resource>> () {\r
186 \r
187                 @SuppressWarnings("unchecked")\r
188                 @Override\r
189                 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
190                     return (Collection<Resource>) new ParameterChildRule().getChildren(graph, experiment);\r
191                 }\r
192 \r
193             }, contentListener);\r
194         }\r
195 \r
196     }\r
197 \r
198 \r
199         @Override\r
200         protected void createAndAddControls(Composite body, IWorkbenchSite site,\r
201                         final ISessionContext context, final WidgetSupport support) {\r
202 \r
203         composite = new RemoveFocusBeforeExperimentComposite(body, SWT.NONE);\r
204         \r
205         // Scrolled composite for displaying properties of a selection in explorer\r
206         propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);\r
207         propertyContainer.setExpandHorizontal(true);\r
208         propertyContainer.setExpandVertical(true);\r
209         \r
210         content = new Composite(propertyContainer, SWT.NONE);\r
211 \r
212         // Label\r
213         labelComposite = new Composite(content, SWT.NONE);\r
214         labelName = new Label(labelComposite, SWT.NONE);\r
215         labelName.setText("Name");\r
216 \r
217         name = new TrackedText(labelComposite, support, SWT.BORDER);\r
218         name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
219         name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
220         name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName));\r
221         name.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), name.getWidget())));\r
222         \r
223         labelNumber = new Label(labelComposite, SWT.NONE);\r
224         labelNumber.setText("Number of runs");\r
225         \r
226         n = new TrackedText(labelComposite, support, SWT.BORDER);\r
227         n.setTextFactory(new IntegerPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_numberOfValues));\r
228         n.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_numberOfValues));\r
229         n.setInputValidator(new IntegerValidator());\r
230         n.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), n.getWidget())));\r
231         \r
232         labelMethod = new Label(labelComposite, SWT.NONE);\r
233         labelMethod.setText("Method");\r
234         \r
235         methodSelector = new TrackedCombo(labelComposite, support, SWT.DROP_DOWN);\r
236         methodSelector.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
237 \r
238             @Override\r
239             public Map<String, Object> perform(ReadGraph graph, Resource input) throws DatabaseException {\r
240                 SysdynResource SR = SysdynResource.getInstance(graph);\r
241                 Map<String, Object> items = new HashMap<String, Object>();\r
242 \r
243                 items.put("Halton", SR.HaltonSequenceGenerator);\r
244                 items.put("Random", SR.RandomGenerator);\r
245                 \r
246                 return items;\r
247             }\r
248 \r
249         });\r
250         methodSelector.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
251 \r
252             @Override\r
253             public String perform(ReadGraph graph, Resource parameter) throws DatabaseException {\r
254                 SysdynResource SR = SysdynResource.getInstance(graph);\r
255                 Resource method = graph.getPossibleObject(parameter, SR.SensitivityAnalysisExperiment_method);\r
256                 if(method == null)\r
257                     return null;\r
258                 \r
259                 if(graph.isInstanceOf(method, SR.RandomGenerator))\r
260                     return "Random";\r
261                 else if(graph.isInstanceOf(method, SR.HaltonSequenceGenerator))\r
262                     return "Halton";\r
263                 else\r
264                     return "";\r
265 \r
266             }\r
267         });\r
268         methodSelector.addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
269 \r
270             @Override\r
271             public void applyText(WriteGraph graph, Resource input, String text)\r
272                     throws DatabaseException {\r
273                 if(text == null || text.isEmpty())\r
274                     return;\r
275 \r
276                 SysdynResource SR = SysdynResource.getInstance(graph);\r
277 \r
278                 Resource type = SR.RandomGenerator;\r
279 \r
280                 if("Halton".equals(text))\r
281                     type = SR.HaltonSequenceGenerator;\r
282                 \r
283                 graph.deny(input, SR.SensitivityAnalysisExperiment_method);\r
284 \r
285                 GraphUtils.create2(graph, type,\r
286                         SR.SensitivityAnalysisExperiment_method_Inverse, input);\r
287 \r
288                 dirtyMethod = true;\r
289             }\r
290         });\r
291         methodSelector.addModifyListener(new TextModifyListener() {\r
292 \r
293             @Override\r
294             public void modifyText(TrackedModifyEvent e) {\r
295                 if(dirtyMethod) {\r
296                     support.update();\r
297                     dirtyMethod = false;\r
298                     propertyContainer.setContent(content);\r
299                     Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
300                     propertyContainer.setMinSize(size);\r
301                 }\r
302             }\r
303         });\r
304         \r
305         labelSeed = new Label(labelComposite, SWT.NONE);\r
306         labelSeed.setText("Seed");\r
307         \r
308         seed = new TrackedText(labelComposite, support, SWT.BORDER);\r
309         seed.setTextFactory(new IntegerPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_randomSeed));\r
310         seed.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_randomSeed));\r
311         seed.setInputValidator(new IntegerValidator());\r
312         seed.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), seed.getWidget())));\r
313 \r
314         // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis\r
315         explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys(\r
316                 "displaySelectors", "displayFilter", "treeView").values(false, false, true), site, content, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE);\r
317         \r
318         explorer.setBrowseContexts(SysdynResource.URIs.SensitivityAnalysisExperiment_ParameterBrowseContext);\r
319         explorer.setInputSource(new SingleSelectionInputSource(\r
320                 Resource.class));\r
321         explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning\r
322         explorer.setColumns( new Column[] { new Column(ColumnKeys.SINGLE, Align.LEFT, 0, "", true) });\r
323         explorer.finish();\r
324         \r
325         \r
326         ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() {\r
327             public void widgetSelected(SelectionEvent e) {\r
328                 updateSelection(context);\r
329             }\r
330         });\r
331 \r
332         /* Listener for displaying information of the first parameter during view initialization\r
333          * The view does not have focus, so normal selection listener mechanisms do not work. \r
334          * Need to do it the hard way. \r
335          */ \r
336         Listener listener = new Listener() {\r
337 \r
338             boolean flag = false;\r
339             @Override\r
340             public void handleEvent(Event event) {\r
341                 switch (event.type) {\r
342                     case SWT.Activate:\r
343                     case SWT.Show:\r
344                     case SWT.Paint:\r
345                     {\r
346                         if(!flag && ((Tree) event.widget).getItems().length > 0) {\r
347                             flag = true;\r
348                             TreeItem item = ((Tree) event.widget).getItems()[0];\r
349                             IAdaptable adaptable = (IAdaptable) item.getData();\r
350                             MapNodeContext nc = (MapNodeContext) adaptable.getAdapter(NodeContext.class);\r
351                             parameterSupport.fireInput(context, new StructuredSelection(nc.getConstant(BuiltinKeys.INPUT)));\r
352                             propertyContainer.setContent(content);\r
353                             Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
354                             propertyContainer.setMinSize(size);\r
355                         }\r
356                     }\r
357                 }\r
358             }\r
359         };\r
360 \r
361         tree = explorer.getExplorerControl();\r
362         tree.addListener(SWT.Activate, listener);\r
363         tree.addListener(SWT.Show, listener);\r
364         tree.addListener(SWT.Paint,listener);\r
365         /* End listener for displaying information for first parameter during view initialization*/\r
366         \r
367         explorer.addDisposeListener(new DisposeListener() {\r
368             \r
369             @Override\r
370             public void widgetDisposed(DisposeEvent e) {\r
371                 if(contentListener != null)\r
372                     contentListener.dispose();              \r
373             }\r
374         });\r
375         \r
376         \r
377         buttonComposite = new Composite(explorer, SWT.NONE);\r
378         \r
379         addVariable = new Button(buttonComposite, support, SWT.NONE);\r
380         addVariable.setText("Add parameter");\r
381         addVariable.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
382 \r
383             @Override\r
384             public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
385                 SysdynResource sr = SysdynResource.getInstance(graph);\r
386                 Layer0 L0 = Layer0.getInstance(graph);\r
387                 \r
388                 Resource distribution = GraphUtils.create2(graph, sr.UniformDistribution,\r
389                         sr.UniformDistribution_minValue, 0.0,\r
390                         sr.UniformDistribution_maxValue, 10.0);\r
391                 \r
392                 Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter,\r
393                         sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution,\r
394                         sr.SensitivityAnalysisExperiment_Parameter_variable, ChartUtils.emptyVariableName,\r
395                         L0.PartOf, input);\r
396                 \r
397                 Resource parameterList = graph.getPossibleObject(input, sr.SensitivityAnalysisExperiment_parameterList);\r
398                 ListUtils.insertBack(graph, parameterList, Collections.singleton(parameter));\r
399             }\r
400         });\r
401 \r
402         remove = new Button(buttonComposite, parameterSupport, SWT.NONE);\r
403         remove.setText("Remove");\r
404         remove.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
405 \r
406             @Override\r
407             public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
408                 if(input == null)\r
409                     return;\r
410                 \r
411                 SysdynResource sr = SysdynResource.getInstance(graph);\r
412                 Layer0 L0 = Layer0.getInstance(graph);\r
413                 \r
414                 Resource experiment = graph.getPossibleObject(input, L0.PartOf);\r
415                 Resource parameterList = graph.getPossibleObject(experiment, sr.SensitivityAnalysisExperiment_parameterList);\r
416                 \r
417                 if(ListUtils.toList(graph, parameterList).size() > 1)\r
418                     ListUtils.removeElement(graph, parameterList, input);\r
419  \r
420             }\r
421             \r
422         });\r
423         propertyContainer.setContent(content);\r
424         \r
425         \r
426         parameterPropertyGroup = new Group(content, SWT.NONE);\r
427         \r
428         parameterProperties = new Composite(parameterPropertyGroup, SWT.NONE);\r
429 \r
430         // Label\r
431         labelVariable = new Label(parameterProperties, SWT.NONE);\r
432         labelVariable.setText("Variable:");\r
433 \r
434         variable = new TrackedText(parameterProperties, parameterSupport, SWT.BORDER);\r
435         variable.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable));\r
436         variable.addModifyListener(new VariableNameModifier(variable.getWidget(), parameterSupport, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_indexes));\r
437         variable.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), variable.getWidget())));\r
438         variable.setInputValidator(new ParameterExistsValidator(parameterSupport, variable));\r
439         \r
440         labelRange = new Label(parameterProperties, SWT.NONE);\r
441         labelRange.setText("Range:");\r
442         \r
443         rangeComposite = new RangeComposite(parameterProperties, context, parameterSupport, SWT.NONE) {\r
444             @Override\r
445             protected Resource getIndexRelation(ReadGraph graph) {\r
446                 return SysdynResource.getInstance(graph).SensitivityAnalysisExperiment_Parameter_indexes;\r
447             }\r
448         };\r
449         \r
450 //        TrackedText variable = new TrackedText(parameterProperties, parameterSupport, SWT.BORDER);\r
451 //        variable.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable));\r
452 //        variable.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_Parameter_variable));\r
453 //        variable.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), variable.getWidget())));\r
454 //        GridDataFactory.fillDefaults().grab(true, false).applyTo(variable.getWidget());\r
455 \r
456         labelDistribution = new Label(parameterProperties, SWT.NONE);\r
457         labelDistribution.setText("Distribution:");\r
458 \r
459         distributionSelector = new TrackedCombo(parameterProperties, parameterSupport, SWT.DROP_DOWN);\r
460         distributionSelector.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
461 \r
462             @Override\r
463             public Map<String, Object> perform(ReadGraph graph, Resource input) throws DatabaseException {\r
464                 SysdynResource SR = SysdynResource.getInstance(graph);\r
465                 Map<String, Object> items = new HashMap<String, Object>();\r
466 \r
467                 items.put("Normal", SR.NormalDistribution);\r
468                 items.put("Uniform", SR.UniformDistribution);\r
469                 items.put("Interval", SR.Interval);\r
470 \r
471                 return items;\r
472             }\r
473 \r
474         });\r
475 \r
476         distributionSelector.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
477 \r
478             @Override\r
479             public String perform(ReadGraph graph, Resource parameter) throws DatabaseException {\r
480                 SysdynResource SR = SysdynResource.getInstance(graph);\r
481                 Resource distribution = graph.getPossibleObject(parameter, SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution);\r
482                 if(distribution == null)\r
483                     return null;\r
484                 \r
485                 if(graph.isInstanceOf(distribution, SR.UniformDistribution))\r
486                     return "Uniform";\r
487                 else if(graph.isInstanceOf(distribution, SR.NormalDistribution))\r
488                     return "Normal";\r
489                 else if(graph.isInstanceOf(distribution, SR.Interval))\r
490                     return "Interval";\r
491                 else\r
492                     return "";\r
493 \r
494             }\r
495         });\r
496 \r
497         distributionSelector.addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
498 \r
499             @Override\r
500             public void applyText(WriteGraph graph, Resource input, String text)\r
501                     throws DatabaseException {\r
502                 if(text == null || text.isEmpty())\r
503                     return;\r
504 \r
505                 SysdynResource SR = SysdynResource.getInstance(graph);\r
506 \r
507                 Resource type = SR.UniformDistribution;\r
508 \r
509                 if("Normal".equals(text))\r
510                     type = SR.NormalDistribution;\r
511                 else if("Interval".equals(text))\r
512                     type = SR.Interval; \r
513 \r
514                 graph.deny(input, SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution);\r
515 \r
516                 GraphUtils.create2(graph, type,\r
517                         SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse, input);\r
518 \r
519                 dirty = true;\r
520             }\r
521         });\r
522 \r
523         distributionSelector.addModifyListener(new TextModifyListener() {\r
524 \r
525             @Override\r
526             public void modifyText(TrackedModifyEvent e) {\r
527                 if(dirty) {\r
528                     parameterSupport.update();\r
529                     dirty = false;\r
530                     propertyContainer.setContent(content);\r
531                     Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
532                     propertyContainer.setMinSize(size);\r
533                 }\r
534             }\r
535         });\r
536 \r
537         dpw = new DistributionPropertyWidget(parameterProperties, context, parameterSupport, SWT.NONE);\r
538     }\r
539 \r
540 \r
541         @Override\r
542         protected void createControlLayoutVertical() {\r
543         \r
544         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
545         GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite);\r
546         \r
547         // Scrolled composite for displaying properties of a selection in explorer\r
548         GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyContainer);\r
549         GridLayoutFactory.fillDefaults().applyTo(propertyContainer);\r
550         \r
551         GridDataFactory.fillDefaults().grab(true, true).applyTo(content);\r
552         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(content);\r
553 \r
554         // Label\r
555         GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(labelComposite);\r
556         GridLayoutFactory.fillDefaults().numColumns(2).applyTo(labelComposite);\r
557         \r
558         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());\r
559         \r
560         GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(n.getWidget());\r
561         \r
562         GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(seed.getWidget());\r
563 \r
564         GridDataFactory.fillDefaults().hint(150, SWT.DEFAULT).grab(false, true).applyTo(explorer);\r
565         \r
566         GridDataFactory.fillDefaults().applyTo(buttonComposite);\r
567         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite);\r
568         \r
569         Point tsize = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
570         propertyContainer.setMinSize(tsize);\r
571         GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterPropertyGroup);\r
572         GridLayoutFactory.fillDefaults().applyTo(parameterPropertyGroup);\r
573         \r
574         GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterProperties);\r
575         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parameterProperties);\r
576 \r
577         // Label\r
578         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(labelVariable);\r
579 \r
580         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(variable.getWidget());\r
581         \r
582         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(labelRange);\r
583         \r
584         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(rangeComposite);\r
585         \r
586         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(labelDistribution);\r
587         \r
588         GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(dpw);\r
589         GridLayoutFactory.fillDefaults().margins(6, 0).applyTo(dpw);\r
590         }\r
591         \r
592         @Override\r
593         protected void createControlLayoutHorizontal(boolean wideScreen) {\r
594                 GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
595         GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite);\r
596         \r
597         // Scrolled composite for displaying properties of a selection in explorer\r
598         GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyContainer);\r
599         GridLayoutFactory.fillDefaults().applyTo(propertyContainer);\r
600         \r
601         GridDataFactory.fillDefaults().grab(true, true).applyTo(content);\r
602         GridLayoutFactory.fillDefaults().numColumns(2).applyTo(content);\r
603 \r
604         // Label\r
605         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(labelComposite);\r
606         GridLayoutFactory.fillDefaults().numColumns(8).applyTo(labelComposite);\r
607         \r
608         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());\r
609         \r
610         GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(n.getWidget());\r
611         \r
612         GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(seed.getWidget());\r
613 \r
614         GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer);\r
615 \r
616         GridDataFactory.fillDefaults().applyTo(buttonComposite);\r
617         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite);\r
618         \r
619         Point tsize = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
620         propertyContainer.setMinSize(tsize);\r
621         GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterPropertyGroup);\r
622         GridLayoutFactory.fillDefaults().applyTo(parameterPropertyGroup);\r
623         \r
624         GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterProperties);\r
625         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parameterProperties);\r
626 \r
627         // Label\r
628         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(labelVariable);\r
629 \r
630         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(variable.getWidget());\r
631         \r
632         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(labelRange);\r
633         \r
634         GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(rangeComposite);\r
635         \r
636         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(labelDistribution);\r
637 \r
638         GridDataFactory.fillDefaults().span(1, 1).grab(true, true).applyTo(dpw);\r
639         GridLayoutFactory.fillDefaults().margins(6, 0).applyTo(dpw);\r
640 \r
641         }\r
642         \r
643 }\r