--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.properties.bar;\r
+\r
+import org.eclipse.jface.dialogs.IInputValidator;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.ScrolledComposite;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Group;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Spinner;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;\r
+import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+/**\r
+ * Tab for bar chart axis properties\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class BarAxisTab extends LabelPropertyTabContributor implements Widget {\r
+\r
+ private TrackedSpinner angle;\r
+ private Integer angleInt = null;\r
+ private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl();\r
+ private WidgetSupportImpl rangeAxisSupport = new WidgetSupportImpl();\r
+ private TrackedText rangelabel, rangemin, rangemax;\r
+ private ScrolledComposite sc;\r
+ private Composite composite;\r
+\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+ support.register(this);\r
+\r
+ // Scrolled composite containing all of the properties in this tab\r
+ sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(sc);\r
+ sc.setExpandHorizontal(true);\r
+ sc.setExpandVertical(true);\r
+\r
+ composite = new Composite(sc, SWT.NONE);\r
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);\r
+\r
+ // Domain Axis properties\r
+ Group domainGroup = new Group(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(domainGroup);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(domainGroup);\r
+ domainGroup.setText("Domain axis");\r
+\r
+ // Label for x-axis\r
+ Label label = new Label(domainGroup, SWT.NONE);\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+ label.setText("Label:");\r
+\r
+ rangelabel = new TrackedText(domainGroup, domainAxisSupport, SWT.BORDER);\r
+ rangelabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));\r
+ rangelabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
+ rangelabel.setColorProvider(new JFreeChartPropertyColorProvider(rangelabel.getResourceManager()));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(rangelabel.getWidget());\r
+\r
+ Composite axisHide = new AxisHidePropertyComposite(domainGroup, context, domainAxisSupport, SWT.NONE);\r
+ GridDataFactory.fillDefaults().span(1, 3).applyTo(axisHide);\r
+\r
+ Label angleLabel = new Label(domainGroup, SWT.NONE);\r
+ angleLabel.setText("Label angle:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(angleLabel);\r
+\r
+ Composite angleComposite = new Composite(domainGroup, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(angleComposite);\r
+ GridLayoutFactory.fillDefaults().applyTo(angleComposite);\r
+ angle = new TrackedSpinner(angleComposite, domainAxisSupport, SWT.BORDER);\r
+ angle.setSelectionFactory(new AngleSelectionFactory());\r
+ angle.addModifyListener(new AngleModifyListener());\r
+ angle.setMinimum(0);\r
+ angle.setMaximum(90);\r
+ angle.getWidget().setIncrement(5);\r
+ GridDataFactory.fillDefaults().applyTo(angle.getWidget());\r
+\r
+ // Domain Color\r
+ label = new Label(domainGroup, SWT.NONE);\r
+ label.setText("Color:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+\r
+ Composite colorPicker = new ColorPicker(domainGroup, context, domainAxisSupport, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);\r
+\r
+ domainGroup.layout();\r
+\r
+ // Range Axis properties\r
+ Group rangeGroup = new Group(composite, SWT.NONE);\r
+ GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(rangeGroup);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(rangeGroup);\r
+ rangeGroup.setText("Range axis");\r
+\r
+ // Label for range axis\r
+ label = new Label(rangeGroup, SWT.NONE);\r
+ label.setText("Label:");\r
+ label.setAlignment(SWT.RIGHT);\r
+ GridDataFactory.fillDefaults().hint(angleLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(label);\r
+\r
+ rangelabel = new TrackedText(rangeGroup, rangeAxisSupport, SWT.BORDER);\r
+ rangelabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));\r
+ rangelabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
+ rangelabel.setColorProvider(new JFreeChartPropertyColorProvider(rangelabel.getResourceManager()));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(rangelabel.getWidget());\r
+\r
+ axisHide = new AxisHidePropertyComposite(rangeGroup, context, rangeAxisSupport, SWT.NONE);\r
+ GridDataFactory.fillDefaults().span(1, 4).applyTo(axisHide);\r
+\r
+ // Min and max values for range axis\r
+ label = new Label(rangeGroup, SWT.NONE);\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+ label.setText("Min:");\r
+\r
+ Composite minmax = new Composite(rangeGroup, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(minmax);\r
+ GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax);\r
+ rangemin = new TrackedText(minmax, rangeAxisSupport, SWT.BORDER);\r
+ rangemin.setColorProvider(new JFreeChartPropertyColorProvider(rangemin.getResourceManager()));\r
+ rangemin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));\r
+ rangemin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));\r
+ rangemin.setInputValidator(new DoubleValidator());\r
+\r
+ label = new Label(minmax, SWT.NONE);\r
+ label.setText("Max:");\r
+ rangemax = new TrackedText(minmax, rangeAxisSupport, SWT.BORDER);\r
+ rangemax.setColorProvider(new JFreeChartPropertyColorProvider(rangemax.getResourceManager()));\r
+ rangemax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));\r
+ rangemax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));\r
+ rangemax.setInputValidator(new DoubleValidator());\r
+\r
+ // Range Color\r
+ label = new Label(rangeGroup, SWT.NONE);\r
+ label.setText("Color:");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+\r
+ colorPicker = new ColorPicker(rangeGroup, context, rangeAxisSupport, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);\r
+\r
+ // Resize scrolled composite\r
+ sc.setContent(composite);\r
+ Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+ sc.setMinSize(size);\r
+ }\r
+\r
+ /**\r
+ * ModifyListener for the angle {@link TrackedSpinner}\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class AngleModifyListener implements TextModifyListener, Widget {\r
+\r
+ private ISessionContext context;\r
+ private Object lastInput = null;\r
+\r
+ @Override\r
+ public void modifyText(TrackedModifyEvent e) {\r
+ if(context == null)\r
+ return;\r
+\r
+ // Get the text value from spinner and associated resource (input)\r
+ Spinner spinner = (Spinner)e.getWidget();\r
+ final String textValue = spinner.getText();\r
+ final Object input = lastInput;\r
+\r
+ try {\r
+ context.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Resource domainAxis = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+ try {\r
+ // usually reliable, since the spinner does all the checks\r
+ Double value = Double.parseDouble(textValue); \r
+ Double oldValue = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees, Bindings.DOUBLE);\r
+ if(oldValue == null || !oldValue.equals(value)) {\r
+ graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, value, Bindings.DOUBLE);\r
+ angleInt = value.intValue();\r
+ }\r
+ } catch (NumberFormatException e) {\r
+ graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, 0.0, Bindings.DOUBLE);\r
+ angleInt = 0;\r
+ }\r
+ }\r
+\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void setInput(ISessionContext context, Object parameter) {\r
+ this.context = context;\r
+ lastInput = parameter;\r
+ }\r
+\r
+ }\r
+\r
+ /**\r
+ * Class for setting the value for angle {@link TrackedSpinner}\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class AngleSelectionFactory extends ReadFactoryImpl<Resource, Integer> {\r
+\r
+ @Override\r
+ public Integer perform(ReadGraph graph, Resource domainAxis) throws DatabaseException {\r
+ if(angleInt == null) {\r
+ Double angle = 0.0;\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ if(domainAxis != null) {\r
+ Double value = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees);\r
+ if(value != null)\r
+ angle = value;\r
+ }\r
+ return angle.intValue();\r
+ } else {\r
+ return angleInt;\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void setInput(final ISessionContext context, Object input) {\r
+ final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+ if(chart == null)\r
+ return; \r
+\r
+ context.getSession().asyncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+ Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot));\r
+ if(plot == null) return;\r
+ Resource rangeAxis = graph.getPossibleObject(plot, jfree.Plot_rangeAxis);\r
+ if(rangeAxis == null) return;\r
+ rangeAxisSupport.fireInput(context, new StructuredSelection(rangeAxis));\r
+\r
+ Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis);\r
+ if(domainAxis == null) return;\r
+ domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis));\r
+ }\r
+ });\r
+ }\r
+\r
+\r
+ /**\r
+ * Validator for validating that an input is double\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ private class DoubleValidator implements IInputValidator {\r
+ @Override\r
+ public String isValid(String newText) {\r
+ if (newText.trim().isEmpty())\r
+ return null;\r
+ try {\r
+ Double.parseDouble(newText);\r
+ return null;\r
+ } catch (NumberFormatException e) {\r
+ return e.getMessage();\r
+ }\r
+ }\r
+ }\r
+}\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Group;\r
import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Spinner;\r
import org.eclipse.ui.IWorkbenchSite;\r
import org.simantics.browsing.ui.swt.widgets.Button;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
-import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
-import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
-import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.PossibleObjectWithType;\r
-import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;\r
import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;\r
-import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
+\r
\r
/**\r
* General properties of a bar chart\r
private Button hgrid, htitle, hlegend;\r
private TrackedText name, title;\r
private TrackedCombo type;\r
- private TrackedSpinner angle;\r
+\r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { \r
hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));\r
hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));\r
\r
- Composite angleComposite = new Composite(composite, SWT.NONE);\r
- GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(angleComposite);\r
- GridLayoutFactory.fillDefaults().numColumns(2).applyTo(angleComposite);\r
- // Line width\r
- label = new Label(angleComposite, SWT.NONE);\r
- label.setText("Label angle:");\r
- GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
-\r
- angle = new TrackedSpinner(angleComposite, support, SWT.BORDER);\r
- angle.setSelectionFactory(new AngleSelectionFactory());\r
- angle.addModifyListener(new AngleModifyListener());\r
- angle.setMinimum(0);\r
- angle.setMaximum(90);\r
- angle.getWidget().setIncrement(5);\r
- GridDataFactory.fillDefaults().applyTo(angle.getWidget());\r
-\r
+ // Resize scrolled composite\r
sc.setContent(composite);\r
Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
sc.setMinSize(size);\r
public String perform(ReadGraph graph, Resource chart) throws DatabaseException {\r
JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
- \r
+\r
Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot));\r
if(plot != null) {\r
Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.CategoryDataset));\r
- \r
+\r
if(dataset != null) {\r
- Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, l0.ConsistsOf, jfree.Dataset_renderer));\r
+ Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, jfree.Dataset_renderer, jfree.Renderer));\r
\r
if(renderer != null && graph.isInstanceOf(renderer, jfree.StackedBarRenderer))\r
return "Stacked";\r
}\r
}\r
\r
-\r
-\r
- /**\r
- * ModifyListener for the angle {@link TrackedSpinner}\r
- * \r
- * @author Teemu Lempinen\r
- *\r
- */\r
- private class AngleModifyListener implements TextModifyListener, Widget {\r
-\r
- private ISessionContext context;\r
- private Object lastInput = null;\r
-\r
- @Override\r
- public void modifyText(TrackedModifyEvent e) {\r
- if(context == null)\r
- return;\r
-\r
- // Get the text value from spinner and associated resource (input)\r
- Spinner spinner = (Spinner)e.getWidget();\r
- final String textValue = spinner.getText();\r
- final Object input = lastInput;\r
-\r
- try {\r
- context.getSession().syncRequest(new WriteRequest() {\r
-\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
-\r
- Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class);\r
- Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot));\r
- Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis);\r
-\r
- try {\r
- // usually reliable, since the spinner does all the checks\r
- Double value = Double.parseDouble(textValue); \r
- graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, value, Bindings.DOUBLE);\r
- } catch (NumberFormatException e) {\r
- graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, 0.0, Bindings.DOUBLE);\r
- }\r
- }\r
-\r
- });\r
- } catch (DatabaseException e1) {\r
- e1.printStackTrace();\r
- }\r
- }\r
-\r
- @Override\r
- public void setInput(ISessionContext context, Object parameter) {\r
- this.context = context;\r
- lastInput = parameter;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Class for setting the value for angle {@link TrackedSpinner}\r
- * @author Teemu Lempinen\r
- *\r
- */\r
- private class AngleSelectionFactory extends ReadFactoryImpl<Resource, Integer> {\r
-\r
- @Override\r
- public Integer perform(ReadGraph graph, Resource chart) throws DatabaseException {\r
- Double angle = 0.0;\r
- JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot));\r
- if(plot != null) {\r
- Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis);\r
- if(domainAxis != null) {\r
- Double value = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees);\r
- if(value != null)\r
- angle = value;\r
- }\r
- }\r
- return angle.intValue();\r
-\r
- }\r
-\r
- }\r
-\r
}\r