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