1 /*******************************************************************************
\r
2 * Copyright (c) 2013 Association for Decentralized Information Management in
\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
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.properties.widgets.sensitivity;
\r
14 import java.util.HashMap;
\r
16 import org.eclipse.jface.layout.GridDataFactory;
\r
17 import org.eclipse.jface.layout.GridLayoutFactory;
\r
18 import org.eclipse.jface.resource.JFaceResources;
\r
19 import org.eclipse.jface.resource.LocalResourceManager;
\r
20 import org.eclipse.swt.SWT;
\r
21 import org.eclipse.swt.widgets.Composite;
\r
22 import org.eclipse.swt.widgets.Label;
\r
23 import org.simantics.browsing.ui.swt.widgets.TrackedText;
\r
24 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
25 import org.simantics.databoard.Bindings;
\r
26 import org.simantics.db.Resource;
\r
27 import org.simantics.db.WriteGraph;
\r
28 import org.simantics.db.exception.DatabaseException;
\r
29 import org.simantics.db.management.ISessionContext;
\r
30 import org.simantics.jfreechart.chart.properties.DoubleValidator;
\r
31 import org.simantics.sysdyn.SysdynResource;
\r
32 import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider;
\r
33 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;
\r
34 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;
\r
36 public class IntervalProperties implements IDistributionProperties {
\r
38 private Resource resource;
\r
39 private TrackedText minValue;
\r
40 private TrackedText maxValue;
\r
42 public IntervalProperties(Resource resource) {
\r
43 this.resource = resource;
\r
47 public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) {
\r
48 Composite composite = new Composite(parent, SWT.NONE);
\r
49 GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
\r
52 Label label = new Label(composite, SWT.NONE);
\r
53 label.setText("Min value");
\r
54 GridDataFactory.fillDefaults().applyTo(label);
\r
56 minValue = new TrackedText(composite, support, SWT.BORDER);
\r
57 minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.Interval_minValue));
\r
58 minValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.Interval_minValue));
\r
59 minValue.setInputValidator(new DoubleValidator(false));
\r
60 minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget())));
\r
61 GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget());
\r
64 label = new Label(composite, SWT.NONE);
\r
65 label.setText("Max value");
\r
66 GridDataFactory.fillDefaults().applyTo(label);
\r
68 maxValue = new TrackedText(composite, support, SWT.BORDER);
\r
69 maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.Interval_maxValue));
\r
70 maxValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.Interval_maxValue));
\r
71 maxValue.setInputValidator(new DoubleValidator(false));
\r
72 maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget())));
\r
73 GridDataFactory.fillDefaults().grab(true, false).applyTo(maxValue.getWidget());
\r
80 public void getCachedValues(HashMap<String, String> cahcedValues) {
\r
81 if(!minValue.isDisposed())
\r
82 cahcedValues.put(SensitivityDistributionKeys.MIN, minValue.getText());
\r
83 if(!maxValue.isDisposed())
\r
84 cahcedValues.put(SensitivityDistributionKeys.MAX, maxValue.getText());
\r
90 public void applyCache(WriteGraph graph, HashMap<String, String> cachedValues) throws DatabaseException {
\r
91 if(resource == null)
\r
94 SysdynResource SR = SysdynResource.getInstance(graph);
\r
96 String min = cachedValues.get(SensitivityDistributionKeys.MIN);
\r
99 Double d = Double.parseDouble(min);
\r
100 graph.claimLiteral(resource, SR.Interval_minValue, d, Bindings.DOUBLE);
\r
101 } catch (NumberFormatException e) {}
\r
104 String max = cachedValues.get(SensitivityDistributionKeys.MAX);
\r
107 Double d = Double.parseDouble(max);
\r
108 graph.claimLiteral(resource, SR.Interval_maxValue, d, Bindings.DOUBLE);
\r
109 } catch (NumberFormatException e) {}
\r