1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.chart.property;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.jface.dialogs.IInputValidator;
17 import org.eclipse.jface.layout.GridDataFactory;
18 import org.eclipse.jface.layout.GridLayoutFactory;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.SelectionAdapter;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.IWorkbenchSite;
26 import org.simantics.NameLabelUtil;
27 import org.simantics.Simantics;
28 import org.simantics.browsing.ui.swt.widgets.Button;
29 import org.simantics.browsing.ui.swt.widgets.Combo;
30 import org.simantics.browsing.ui.swt.widgets.Label;
31 import org.simantics.browsing.ui.swt.widgets.Scale;
32 import org.simantics.browsing.ui.swt.widgets.TrackedText;
33 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;
34 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
35 import org.simantics.charts.ontology.ChartResource;
36 import org.simantics.databoard.Bindings;
37 import org.simantics.db.ReadGraph;
38 import org.simantics.db.Resource;
39 import org.simantics.db.WriteGraph;
40 import org.simantics.db.common.request.WriteRequest;
41 import org.simantics.db.exception.DatabaseException;
42 import org.simantics.db.management.ISessionContext;
43 import org.simantics.db.request.Read;
44 import org.simantics.modeling.ui.Activator;
45 import org.simantics.selectionview.ConfigurationComposite;
46 import org.simantics.ui.utils.ResourceAdaptionUtils;
47 import org.simantics.utils.ui.ISelectionUtils;
50 * @author Tuukka Lehtonen
52 public class ChartComposite extends ConfigurationComposite {
54 public static final TimeInputValidator LENGTH_VALIDATOR = new TimeInputValidator(1.0);
55 public static final TimeInputValidator START_VALIDATOR = new TimeInputValidator(-Double.MAX_VALUE);
57 public static Read<String> getPartTitleRequest(final ISelection selection) {
58 return new Read<String>() {
60 public String perform(ReadGraph graph) throws DatabaseException {
61 Resource r = ResourceAdaptionUtils.toSingleResource(selection);
64 return NameLabelUtil.modalName(graph, r);
70 public Read<String> getPartNameReadRequest(ISelection forSelection) {
71 return getPartTitleRequest(forSelection);
74 public void create(final Composite body, IWorkbenchSite site, final ISessionContext context, final WidgetSupport support) {
75 final Display display = body.getDisplay();
77 body.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
79 /* Composite buttonComposite = new Composite(body, SWT.NONE);
80 buttonComposite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
81 GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(buttonComposite);
82 GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(4).extendedMargins(5,5,5,5).applyTo(buttonComposite);
84 Label nameHeader = new Label(buttonComposite, support, 0);
85 nameHeader.setText("Name");
86 //nameHeader.setFont(smallFont);
87 nameHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
88 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(nameHeader.getWidget());
90 TrackedText nameText = new TrackedText(buttonComposite, support, SWT.BORDER | SWT.FLAT);
91 nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName, ""));
92 nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName));
93 GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(nameText.getWidget());
95 Label autoscrollLabel = new Label(body, support, 0);
96 autoscrollLabel.setText("Auto-scroll settings:");
97 autoscrollLabel.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
98 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(autoscrollLabel.getControl());
100 Composite templateComposite = new Composite(body, SWT.NONE);
101 templateComposite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
102 GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(templateComposite);
103 GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(3).extendedMargins(5,5,5,5).applyTo(templateComposite);
105 Label templateHeader = new Label(templateComposite, support, 0);
106 templateHeader.setText("Template");
107 //templateHeader.setFont(smallFont);
108 templateHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
109 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(templateHeader.getWidget());
111 Combo templateCombo = new Combo(templateComposite, support, SWT.NONE | SWT.READ_ONLY);
112 templateCombo.setItemFactory(new AvailableTemplateFactory());
113 templateCombo.setSelectionFactory(new CurrentTemplateFactory());
114 templateCombo.addModifyListener(new TemplateModifier());
115 GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(templateCombo.getWidget());
117 Button resetButton = new Button(templateComposite, support, SWT.NONE | SWT.READ_ONLY);
118 resetButton.setText("Apply");
119 resetButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {
121 public void apply(WriteGraph graph, Resource monitor) throws DatabaseException {
122 graph.markUndoPoint();
123 ChartResource CHART = ChartResource.getInstance(graph);
124 if (graph.hasStatement(monitor, CHART.Chart_TimeWindowStart))
125 graph.deny(monitor, CHART.Chart_TimeWindowStart);
126 if (graph.hasStatement(monitor, CHART.Chart_TimeWindowLength))
127 graph.deny(monitor, CHART.Chart_TimeWindowLength);
128 if (graph.hasStatement(monitor, CHART.Chart_TimeWindowIncrement))
129 graph.deny(monitor, CHART.Chart_TimeWindowIncrement);
132 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).applyTo(resetButton.getWidget());
134 Composite buttonComposite = new Composite(body, SWT.NONE);
135 buttonComposite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
136 GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(buttonComposite);
137 GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(4).extendedMargins(5,5,5,5).applyTo(buttonComposite);
139 Label startHeader = new Label(buttonComposite, support, 0);
140 startHeader.setText("Start time");
141 //startHeader.setFont(smallFont);
142 startHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
143 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(startHeader.getWidget());
145 TrackedText timeWindowStart = new TrackedText(buttonComposite, support, SWT.BORDER | SWT.FLAT);
146 timeWindowStart.getWidget().setToolTipText("Chart Window Fixed Start Time in Seconds or Yy Dd HH:mm:ss.ddd");
147 timeWindowStart.setTextFactory(new TimePropertyFactory(ChartResource.URIs.Chart_TimeWindowStart));
148 timeWindowStart.addModifyListener(new TimePropertyModifier(context, ChartResource.URIs.Chart_TimeWindowStart, START_VALIDATOR));
149 timeWindowStart.setInputValidator( START_VALIDATOR );
150 GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(timeWindowStart.getWidget());
152 // Label l1 = new Label(buttonComposite, support, 0);
153 // l1.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
154 // l1.setText("seconds");
156 Label sizeHeader = new Label(buttonComposite, support, 0);
157 sizeHeader.setText("Length");
158 //sizeHeader.setFont(smallFont);
159 sizeHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
160 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(sizeHeader.getWidget());
162 TrackedText timeWindowLength = new TrackedText(buttonComposite, support, SWT.BORDER | SWT.FLAT);
163 timeWindowLength.getWidget().setToolTipText("Chart Window Fixed Time Axis Length in Seconds or Yy Dd HH:mm:ss.ddd");
164 timeWindowLength.setTextFactory(new TimePropertyFactory(ChartResource.URIs.Chart_TimeWindowLength));
165 timeWindowLength.addModifyListener(new TimePropertyModifier(context, ChartResource.URIs.Chart_TimeWindowLength, LENGTH_VALIDATOR));
166 timeWindowLength.setInputValidator( LENGTH_VALIDATOR );
167 GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(timeWindowLength.getWidget());
169 // Label l2 = new Label(buttonComposite, support, 0);
170 // l2.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
171 // l2.setText("seconds");
173 Label incrementHeader = new Label(buttonComposite, support, 0);
174 incrementHeader.setText("Scroll increment");
175 //incrementHeader.setFont(smallFont);
176 incrementHeader.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
177 GridDataFactory.fillDefaults().grab(false, false).span(1, 1).align(SWT.LEFT, SWT.CENTER).applyTo(incrementHeader.getWidget());
179 Scale timeWindowIncrement = new Scale(buttonComposite, support, SWT.READ_ONLY);
180 timeWindowIncrement.getWidget().setMinimum(1);
181 timeWindowIncrement.getWidget().setMaximum(100);
182 timeWindowIncrement.getWidget().setIncrement(10);
183 timeWindowIncrement.getWidget().setPageIncrement(10);
184 timeWindowIncrement.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
185 timeWindowIncrement.setSelectionFactory(new DoubleToIntegerPropertyFactory(ChartResource.URIs.Chart_TimeWindowIncrement));
186 timeWindowIncrement.addSelectionListener(new DelayedIntegerToDoublePropertyModifier(timeWindowIncrement, context, ChartResource.URIs.Chart_TimeWindowIncrement));
187 GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(timeWindowIncrement.getWidget());
189 TrackedText timeWindowIncrementText = new TrackedText(buttonComposite, support, SWT.BORDER | SWT.FLAT);
190 timeWindowIncrementText.setTextFactory(new DoublePropertyFactory(ChartResource.URIs.Chart_TimeWindowIncrement));
191 timeWindowIncrementText.addModifyListener(new DoublePropertyModifier(context, ChartResource.URIs.Chart_TimeWindowIncrement));
192 timeWindowIncrementText.setInputValidator(new IInputValidator() {
194 public String isValid(String newText) {
195 if (newText.trim().isEmpty())
198 Double d = Double.parseDouble(newText);
199 if (d < 1 || d > 100)
200 return "Increment must be between 1..100";
202 } catch (NumberFormatException e) {
203 return e.getMessage();
207 GridDataFactory.fillDefaults().grab(false, false).align(SWT.LEAD, SWT.CENTER).span(1, 1).applyTo(timeWindowIncrementText.getWidget());
209 Label l3 = new Label(buttonComposite, support, 0);
210 l3.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
213 Composite checkboxComposite = new Composite(buttonComposite, SWT.NONE);
214 checkboxComposite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
215 GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(checkboxComposite);
216 GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(2).applyTo(checkboxComposite);
218 final Button showMilestones = new Button(checkboxComposite, support, SWT.CHECK);
219 showMilestones.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
220 showMilestones.setText("Show &Milestones");
221 GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(showMilestones.getWidget());
222 showMilestones.setSelectionFactory(new BooleanPropertyFactory(ChartResource.URIs.Chart_ShowMilestones));
223 showMilestones.addSelectionListener(new SelectionAdapter() {
225 public void widgetSelected(SelectionEvent e) {
227 final Resource r = ISelectionUtils.filterSingleSelection(support.getInput(), Resource.class);
230 final Boolean show = showMilestones.getWidget().getSelection();
231 Simantics.getSession().syncRequest(new WriteRequest() {
233 public void perform(WriteGraph graph) throws DatabaseException {
234 graph.markUndoPoint();
235 graph.claimLiteral(r, ChartResource.getInstance(graph).Chart_ShowMilestones, show, Bindings.BOOLEAN);
238 } catch (DatabaseException e1) {
239 Activator.getDefault().getLog().log(
240 new Status(IStatus.ERROR, Activator.PLUGIN_ID,
241 "Failed to set Show Milestones", e1));
246 final Button trackExperimentTime = new Button(checkboxComposite, support, SWT.CHECK);
247 trackExperimentTime.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
248 trackExperimentTime.setText("Hairline &Tracks Experiment Time");
249 trackExperimentTime.setTooltipText("Value Tip Hairline Tracks Experiment Time During Simulation");
250 GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(trackExperimentTime.getWidget());
251 trackExperimentTime.setSelectionFactory(new BooleanPropertyFactory(ChartResource.URIs.Chart_trackExperimentTime));
252 trackExperimentTime.addSelectionListener(new SelectionAdapter() {
254 public void widgetSelected(SelectionEvent e) {
256 final Resource r = ISelectionUtils.filterSingleSelection(support.getInput(), Resource.class);
259 final Boolean track = trackExperimentTime.getWidget().getSelection();
260 Simantics.getSession().syncRequest(new WriteRequest() {
262 public void perform(WriteGraph graph) throws DatabaseException {
263 graph.markUndoPoint();
264 graph.claimLiteral(r, ChartResource.getInstance(graph).Chart_trackExperimentTime, track, Bindings.BOOLEAN);
267 } catch (DatabaseException e1) {
268 Activator.getDefault().getLog().log(
269 new Status(IStatus.ERROR, Activator.PLUGIN_ID,
270 "Failed to set Track Experiment Time", e1));