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