1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 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 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.trend.chart.properties.xyline;
\r
14 import org.eclipse.jface.layout.GridDataFactory;
\r
15 import org.eclipse.jface.layout.GridLayoutFactory;
\r
16 import org.eclipse.jface.viewers.StructuredSelection;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.custom.ScrolledComposite;
\r
19 import org.eclipse.swt.graphics.Point;
\r
20 import org.eclipse.swt.widgets.Combo;
\r
21 import org.eclipse.swt.widgets.Composite;
\r
22 import org.eclipse.swt.widgets.Group;
\r
23 import org.eclipse.swt.widgets.Label;
\r
24 import org.eclipse.ui.IWorkbenchSite;
\r
25 import org.simantics.browsing.ui.swt.widgets.Button;
\r
26 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
\r
27 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;
\r
28 import org.simantics.browsing.ui.swt.widgets.TrackedText;
\r
29 import org.simantics.browsing.ui.swt.widgets.impl.Widget;
\r
30 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
31 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;
\r
32 import org.simantics.db.ReadGraph;
\r
33 import org.simantics.db.Resource;
\r
34 import org.simantics.db.common.request.PossibleObjectWithType;
\r
35 import org.simantics.db.common.request.ReadRequest;
\r
36 import org.simantics.db.exception.DatabaseException;
\r
37 import org.simantics.db.management.ISessionContext;
\r
38 import org.simantics.layer0.Layer0;
\r
39 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;
\r
40 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
\r
41 import org.simantics.sysdyn.JFreeChartResource;
\r
42 import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;
\r
43 import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite;
\r
44 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;
\r
45 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;
\r
46 import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;
\r
47 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;
\r
48 import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory;
\r
49 import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;
\r
50 import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;
\r
51 import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;
\r
52 import org.simantics.ui.utils.AdaptionUtils;
\r
55 * PropertyTab displaying general properties and x-axis properties of a chart
\r
57 * @author Teemu Lempinen
\r
60 public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor implements Widget {
\r
62 private ScrolledComposite sc;
\r
63 private Composite composite;
\r
64 private TrackedText name, title, xlabel, xvariable, xmin, xmax;
\r
66 private Button hgrid, htitle, hlegend;
\r
67 private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl();
\r
70 public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {
\r
71 support.register(this);
\r
73 // Scrolled composite containing all of the properties in this tab
\r
74 sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);
\r
75 GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
\r
76 GridLayoutFactory.fillDefaults().applyTo(sc);
\r
77 sc.setExpandHorizontal(true);
\r
78 sc.setExpandVertical(true);
\r
80 composite = new Composite(sc, SWT.NONE);
\r
81 GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);
\r
83 // General properties
\r
84 Group general = new Group(composite, SWT.NONE);
\r
85 GridDataFactory.fillDefaults().grab(true, false).applyTo(general);
\r
86 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general);
\r
87 general.setText("General");
\r
90 Label nameLabel = new Label(general, SWT.NONE);
\r
91 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(nameLabel);
\r
92 nameLabel.setText("Name:");
\r
93 nameLabel.setAlignment(SWT.RIGHT);
\r
95 Composite c = new Composite(general, SWT.NONE);
\r
96 GridDataFactory.fillDefaults().applyTo(c);
\r
97 GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c);
\r
99 name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER);
\r
100 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
\r
101 name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));
\r
102 name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
103 name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
106 Label label = new Label(c, SWT.NONE);
\r
107 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
108 label.setText("Type:");
\r
110 type = new Combo(c, SWT.BORDER | SWT.READ_ONLY);
\r
111 type.setItems(new String[] {"Line", "Fancy", "Area", "3D"});
\r
114 // Title (Which is different than name)
\r
115 label = new Label(general, SWT.NONE);
\r
116 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
117 label.setText("Title:");
\r
119 title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);
\r
120 GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());
\r
121 title.setTextFactory(new TitleFactory());
\r
122 title.addModifyListener(new TitleModifier());
\r
123 title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
125 // Group for hide options
\r
126 Group hideGroup = new Group(composite, SWT.NONE);
\r
127 GridDataFactory.fillDefaults().applyTo(hideGroup);
\r
128 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);
\r
129 hideGroup.setText("Hide");
\r
131 hgrid = new Button(hideGroup, support, SWT.CHECK);
\r
132 hgrid.setText("Grid");
\r
133 hgrid.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid, true));
\r
134 hgrid.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid));
\r
135 htitle = new Button(hideGroup, support, SWT.CHECK);
\r
136 htitle.setText("Title");
\r
137 htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));
\r
138 htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));
\r
139 hlegend = new Button(hideGroup, support, SWT.CHECK);
\r
140 hlegend.setText("Legend");
\r
141 hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));
\r
142 hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));
\r
145 // X-Axis properties
\r
146 Group xgroup = new Group(composite, SWT.NONE);
\r
147 GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(xgroup);
\r
148 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(xgroup);
\r
149 xgroup.setText("X-axis");
\r
151 // Variable for x-axis (default: empty == time)
\r
152 Label xVariableLabel = new Label(xgroup, SWT.NONE);
\r
153 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(xVariableLabel);
\r
154 xVariableLabel.setText("Variable:");
\r
156 xvariable = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER);
\r
157 xvariable.setTextFactory(new RVIFactory());
\r
158 xvariable.addModifyListener(new RVIModifier(xvariable.getWidget(), domainAxisSupport));
\r
159 xvariable.setColorProvider(new JFreeChartPropertyColorProvider(xvariable.getResourceManager()));
\r
160 GridDataFactory.fillDefaults().grab(true, false).applyTo(xvariable.getWidget());
\r
162 Composite axisHide = new AxisHidePropertyComposite(xgroup, context, domainAxisSupport, SWT.NONE);
\r
163 GridDataFactory.fillDefaults().span(1, 3).applyTo(axisHide);
\r
165 // Label for x-axis
\r
166 label = new Label(xgroup, SWT.NONE);
\r
167 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
168 label.setText("Label:");
\r
170 xlabel = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER);
\r
171 xlabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));
\r
172 xlabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
173 xlabel.setColorProvider(new JFreeChartPropertyColorProvider(xlabel.getResourceManager()));
\r
174 GridDataFactory.fillDefaults().grab(true, false).applyTo(xlabel.getWidget());
\r
176 // Min and max values for x-axis
\r
177 label = new Label(xgroup, SWT.NONE);
\r
178 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
179 label.setText("Min:");
\r
181 Composite minmax = new Composite(xgroup, SWT.NONE);
\r
182 GridDataFactory.fillDefaults().applyTo(minmax);
\r
183 GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax);
\r
184 xmin = new TrackedText(minmax, domainAxisSupport, SWT.BORDER);
\r
185 xmin.setColorProvider(new JFreeChartPropertyColorProvider(xmin.getResourceManager()));
\r
186 xmin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));
\r
187 xmin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));
\r
188 xmin.setInputValidator(new DoubleValidator(true));
\r
190 label = new Label(minmax, SWT.NONE);
\r
191 label.setText("Max:");
\r
192 xmax = new TrackedText(minmax, domainAxisSupport, SWT.BORDER);
\r
193 xmax.setColorProvider(new JFreeChartPropertyColorProvider(xmax.getResourceManager()));
\r
194 xmax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));
\r
195 xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));
\r
196 xmax.setInputValidator(new DoubleValidator(true));
\r
198 // Set the same width to both label rows
\r
199 composite.layout();
\r
200 GridDataFactory.fillDefaults().hint(xVariableLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(nameLabel);
\r
202 sc.setContent(composite);
\r
203 Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
204 sc.setMinSize(size);
\r
208 public void setInput(final ISessionContext context, Object input) {
\r
209 final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class);
\r
213 context.getSession().asyncRequest(new ReadRequest() {
\r
216 public void run(ReadGraph graph) throws DatabaseException {
\r
217 Layer0 l0 = Layer0.getInstance(graph);
\r
218 JFreeChartResource jfree = JFreeChartResource.getInstance(graph);
\r
219 Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot));
\r
220 if(plot == null) return;
\r
221 Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis);
\r
222 if(domainAxis == null) return;
\r
223 domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis));
\r