]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
c05d1ae427434a72a09b269c33bd81f0f004ed8d
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.trend;\r
13 \r
14 import org.eclipse.jface.layout.GridDataFactory;\r
15 import org.eclipse.jface.layout.GridLayoutFactory;\r
16 import org.eclipse.swt.SWT;\r
17 import org.eclipse.swt.widgets.Composite;\r
18 import org.simantics.browsing.ui.swt.widgets.Button;\r
19 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
20 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
21 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
22 import org.simantics.databoard.Bindings;\r
23 import org.simantics.db.ReadGraph;\r
24 import org.simantics.db.Resource;\r
25 import org.simantics.db.WriteGraph;\r
26 import org.simantics.db.exception.DatabaseException;\r
27 import org.simantics.db.management.ISessionContext;\r
28 import org.simantics.jfreechart.chart.properties.xyline.SeriesPropertyComposite;\r
29 import org.simantics.layer0.Layer0;\r
30 import org.simantics.sysdyn.SysdynResource;\r
31 \r
32 /**\r
33  * UI for setting properties for sensitivity analysis series. Sensitivity analysis \r
34  * charts display only one variable as a "fan" chart.\r
35  * @author Teemu Lempinen\r
36  *\r
37  */\r
38 public class SensitivitySeriesPropertyComposite extends SeriesPropertyComposite {\r
39 \r
40     public SensitivitySeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support,\r
41             int style) {\r
42         super(parent, context, support, style);\r
43     }\r
44 \r
45     @Override\r
46     protected void createContent(ISessionContext context, WidgetSupport support) {\r
47         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
48 \r
49         // Variable for the series\r
50         variable(this, context, support);\r
51 \r
52         // Range\r
53         range(this, context, support);\r
54 \r
55         // Label to be displayed in chart for this series \r
56 //        seriesLabel(this, context, support);\r
57         \r
58         Button validateUnits = new Button(this, support, SWT.CHECK);\r
59         validateUnits.setText("Display median");\r
60         GridDataFactory.fillDefaults().span(2, 1).applyTo(validateUnits.getWidget());\r
61         validateUnits.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
62 \r
63             @Override\r
64             public Boolean perform(ReadGraph graph, Resource series) throws DatabaseException {\r
65                 Resource dataset = graph.getPossibleObject(series, Layer0.getInstance(graph).PartOf);\r
66                 Boolean result = graph.getPossibleRelatedValue(dataset, SysdynResource.getInstance(graph).Charts_SensitivityDataset_median, Bindings.BOOLEAN);\r
67                 return Boolean.TRUE.equals(result);\r
68             }\r
69         });\r
70         \r
71         validateUnits.addSelectionListener(new SelectionListenerImpl<Resource>(context){\r
72 \r
73             @Override\r
74             public void apply(WriteGraph graph, Resource series) throws DatabaseException {\r
75                 SysdynResource SR = SysdynResource.getInstance(graph);\r
76                 Resource dataset = graph.getPossibleObject(series, Layer0.getInstance(graph).PartOf);\r
77                 if(dataset == null)\r
78                     return;\r
79                 \r
80                 Boolean result = graph.getPossibleRelatedValue(dataset, SR.Charts_SensitivityDataset_median, Bindings.BOOLEAN);\r
81                 if(result == null)\r
82                     result = false;\r
83                 graph.claimLiteral(dataset, SR.Charts_SensitivityDataset_median, Boolean.FALSE.equals(result));\r
84             }\r
85             \r
86         });\r
87         \r
88         ConfidenceBoundWidget cbWidget = new ConfidenceBoundWidget(this, context, support, SWT.NONE, 0);\r
89         GridDataFactory.fillDefaults().span(2, 1).applyTo(cbWidget);\r
90         cbWidget = new ConfidenceBoundWidget(this, context, support, SWT.NONE, 1);\r
91         GridDataFactory.fillDefaults().span(2, 1).applyTo(cbWidget);\r
92         cbWidget = new ConfidenceBoundWidget(this, context, support, SWT.NONE, 2);\r
93         GridDataFactory.fillDefaults().span(2, 1).applyTo(cbWidget);\r
94         cbWidget = new ConfidenceBoundWidget(this, context, support, SWT.NONE, 3);\r
95         GridDataFactory.fillDefaults().span(2, 1).applyTo(cbWidget);\r
96         cbWidget = new ConfidenceBoundWidget(this, context, support, SWT.NONE, 4);\r
97         GridDataFactory.fillDefaults().span(2, 1).applyTo(cbWidget);\r
98         \r
99     }\r
100     \r
101 \r
102 \r
103 }\r