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