From: lempinen Date: Wed, 14 Dec 2011 06:37:07 +0000 (+0000) Subject: Time property for pie and bar charts X-Git-Tag: simantics-1.6~70 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=04b89bdbf22698a602d4cf44433ff0d9155b38c1;p=simantics%2Fsysdyn.git Time property for pie and bar charts git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23538 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF b/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF index 6ab2f810..c792a6a0 100644 --- a/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF +++ b/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF @@ -5,6 +5,9 @@ Bundle-SymbolicName: org.simantics.jfreechart.ontology Bundle-Version: 0.1.0.qualifier Require-Bundle: org.simantics.layer0, org.simantics.layer0x.ontology;bundle-version="1.0.0", - org.simantics.g2d.ontology;bundle-version="1.0.0" + org.simantics.g2d.ontology;bundle-version="1.0.0", + org.simantics.diagram.ontology;bundle-version="2.1.0", + org.simantics.structural.ontology;bundle-version="1.1.0", + org.simantics.modeling.ontology;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: org.simantics.sysdyn diff --git a/org.simantics.jfreechart.ontology/graph.tg b/org.simantics.jfreechart.ontology/graph.tg index d250dc96..32d291bd 100644 Binary files a/org.simantics.jfreechart.ontology/graph.tg and b/org.simantics.jfreechart.ontology/graph.tg differ diff --git a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph index 2526730c..5aa93b6b 100644 --- a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph +++ b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph @@ -1,6 +1,9 @@ L0 = L0X = G2D = +DIA = +MOD = +STR = //##################################################################### // Ontology for defining JFreeChart charts @@ -20,6 +23,7 @@ JFREE.Chart -- JFREE.Chart.visibleBorder --> L0.Boolean -- JFREE.Chart.borderWidth --> L0.Double -- JFREE.Chart.visibleLegend --> L0.Boolean -- JFREE.Chart.time --> L0.Double -- JFREE.ChartElement.component --> JFREE.Chart datasets; protected HashMap rangeMappings; protected HashMap domainMappings; + protected Plot plot; public AbstractPlot(ReadGraph graph, Resource resource) { this.resource = resource; @@ -116,4 +120,23 @@ public abstract class AbstractPlot implements IPlot { public Resource getResource() { return resource; } + + protected abstract Plot newPlot(); + protected abstract void setPlotProperties(); + + @Override + public Plot getPlot() { + if(plot == null) + plot = newPlot(); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + setPlotProperties(); + } + }); + + return plot; + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java index 75be9b98..1fa12dbd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java @@ -145,6 +145,21 @@ public class CategoryDataset extends AbstractDataset { } } + // Find if a specific time is set for this chart + Double chartTime = null; + if(!datasets.isEmpty()) { + Layer0 l0 = Layer0.getInstance(graph); + Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); + if(datasetResource != null) { + Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); + if(plot != null) { + Resource chart = graph.getPossibleObject(plot, l0.PartOf); + if(chart != null) + chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); + } + } + } + for(SysdynDataSet dataset : datasets) { double[] va = dataset.values; @@ -152,9 +167,16 @@ public class CategoryDataset extends AbstractDataset { if(va == null || va.length == 0) continue; - // Time + /* + * Time + * + * 1. find time for the individual series. + * 2. find time for the whole chart + * 3. find simulation time + */ Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); - + if(time == null) + time = chartTime; if(time == null) time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE); @@ -211,7 +233,6 @@ public class CategoryDataset extends AbstractDataset { @Override public void run() { - // Remove all unused series dataset.clear(); BarRenderer renderer = ((BarRenderer)getRenderer()); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java index 297eb678..69d5d791 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java @@ -28,7 +28,6 @@ import org.simantics.sysdyn.JFreeChartResource; */ public class CategoryPlot extends AbstractPlot { - private org.jfree.chart.plot.CategoryPlot plot; private Boolean visibleGrid; @@ -47,46 +46,50 @@ public class CategoryPlot extends AbstractPlot { } @Override - public Plot getPlot() { - if(plot == null) { - plot = new org.jfree.chart.plot.CategoryPlot(null, null, null, null); - } + protected Plot newPlot() { + return new org.jfree.chart.plot.CategoryPlot(null, null, null, null); + } + + @Override + protected void setPlotProperties() { + if(!(plot instanceof org.jfree.chart.plot.CategoryPlot)) + return; + + org.jfree.chart.plot.CategoryPlot cplot = (org.jfree.chart.plot.CategoryPlot) plot; /* Support using multiple axis, but prefer using only one domain and * one range axis */ for(int i = 0; i < ranges.size(); i++) { - plot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); + cplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); } for(int i = 0; i < domains.size(); i++) { - plot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis()); + cplot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis()); } IAxis axis; for(int i = 0; i < datasets.size(); i++) { IDataset dataset = datasets.get(i); org.jfree.data.category.CategoryDataset ds = (org.jfree.data.category.CategoryDataset)dataset.getDataset(); - plot.setDataset(i, ds); + cplot.setDataset(i, ds); // System.out.println("setting dataset " + i + ": " + ds); - plot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer()); + cplot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer()); axis = rangeMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); + cplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); axis = domainMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); + cplot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); } if(visibleGrid != null) { - plot.setRangeGridlinesVisible(visibleGrid); - plot.setDomainGridlinesVisible(false); + cplot.setRangeGridlinesVisible(visibleGrid); + cplot.setDomainGridlinesVisible(false); } // Cleaner look: no outline borders - plot.setInsets(new RectangleInsets(2,2,2,2), false); - plot.setOutlineVisible(false); - - return plot; + cplot.setInsets(new RectangleInsets(2,2,2,2), false); + cplot.setOutlineVisible(false); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java index 200f0a21..5db0e809 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java @@ -17,8 +17,6 @@ import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.widgets.Composite; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; @@ -88,16 +86,7 @@ public class ChartComposite extends Composite { */ private void CreateContent(final Resource chartResource) { composite = this; - - composite.addDisposeListener(new DisposeListener() { - - @Override - public void widgetDisposed(DisposeEvent e) { - if(chart != null) - chart.dispose(); - } - }); - + GridLayoutFactory.fillDefaults().applyTo(composite); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); frame = SWT_AWT.new_Frame(composite); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java index 826c0320..e9c36388 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java @@ -13,7 +13,6 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.Color; import java.awt.Font; -import java.lang.reflect.InvocationTargetException; import java.util.Collection; import javax.swing.SwingUtilities; @@ -79,34 +78,34 @@ public class JFreeChart implements IJFreeChart { if(plot == null) return null; - try { - SwingUtilities.invokeAndWait(new RunnableWithObject(plot) { - @Override - public void run() { - jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); - - jfreechart.setBackgroundPaint(Color.WHITE); + jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); + + SwingUtilities.invokeLater(new RunnableWithObject(plot) { + @Override + public void run() { + if(jfreechart == null) + return; + + jfreechart.setBackgroundPaint(Color.WHITE); + if(jfreechart.getLegend() != null) { jfreechart.getLegend().setBorder(0, 0, 0, 0); int size = jfreechart.getLegend().getItemFont().getSize(); jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size)); - - org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); - if(t.isVisible()) { - t.setFont(new Font("georgia", Font.BOLD, 13)); - t.setPadding(new RectangleInsets(4, 0, 0, 0)); - jfreechart.setTitle(t); - } - - if(legendVisible != null && !legendVisible) { - jfreechart.removeLegend(); - } } - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } + + org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); + if(t.isVisible()) { + t.setFont(new Font("georgia", Font.BOLD, 13)); + t.setPadding(new RectangleInsets(4, 0, 0, 0)); + jfreechart.setTitle(t); + } + + if(legendVisible != null && !legendVisible) { + jfreechart.removeLegend(); + } + } + }); + return jfreechart; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java index da1b61a1..af50b718 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java @@ -170,15 +170,37 @@ public class PieDataset extends AbstractDataset { } } + // Find if a specific time is set for this chart + Double chartTime = null; + if(!datasets.isEmpty()) { + Layer0 l0 = Layer0.getInstance(graph); + Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); + if(datasetResource != null) { + Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); + if(plot != null) { + Resource chart = graph.getPossibleObject(plot, l0.PartOf); + if(chart != null) + chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); + } + } + } + for(SysdynDataSet dataset : datasets) { double[] va = dataset.values; if(va == null || va.length == 0) continue; - // Time + /* + * Time + * + * 1. find time for the individual series. + * 2. find time for the whole chart + * 3. find simulation time + */ Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); - + if(time == null) + time = chartTime; if(time == null) time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java index 231b6446..556c8742 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java @@ -37,7 +37,6 @@ import org.simantics.sysdyn.JFreeChartResource; */ public class PiePlot extends AbstractPlot { - private org.jfree.chart.plot.PiePlot plot; private org.jfree.data.general.PieDataset pieDataset; private DatasetChangeListener listener; @@ -53,28 +52,62 @@ public class PiePlot extends AbstractPlot { } } - @Override - public Plot getPlot() { - if(plot == null) { - plot = new MyPiePlot(); - plot.setToolTipGenerator(new StandardPieToolTipGenerator()); + /** + * Pie plot class with a stricter equals condition + * @author Teemu Lempinen + * + */ + private class MyPiePlot extends org.jfree.chart.plot.PiePlot { + + private static final long serialVersionUID = -5917620061541212934L; + + @Override + public boolean equals(Object obj) { + boolean result = super.equals(obj); + if(result == true) { + org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj; + if (this.getDataset() != that.getDataset()) { + return false; // Normally plot does not check this. We need this to properly update the charts + } + } + + return result; } + } + + @Override + protected Plot newPlot() { + MyPiePlot plot = new MyPiePlot(); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); + return plot; + } + + @Override + protected void setPlotProperties() { + if(!(plot instanceof MyPiePlot)) + return; + + final MyPiePlot piePlot = (MyPiePlot)plot; + if(!datasets.isEmpty()) { // We assume that a pie plot has only one dataset final IDataset ds = datasets.get(0); Dataset dataset = ((PieDataset)ds).getDataset(); + + if(dataset == null) + return; if(pieDataset != null && listener != null) { pieDataset.removeChangeListener(listener); } pieDataset = (org.jfree.data.general.PieDataset)dataset; - plot.setDataset(pieDataset); + piePlot.setDataset(pieDataset); if(Boolean.FALSE.equals(labelsVisible)) - plot.setLabelGenerator(null); - else if(plot.getLabelGenerator() == null) - plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); + piePlot.setLabelGenerator(null); + else if(piePlot.getLabelGenerator() == null) + piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator()); listener = new DatasetChangeListener() { @@ -83,14 +116,14 @@ public class PiePlot extends AbstractPlot { HashMap colorMap = ((PieDataset)ds).getColorMap(); HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); - for(Object o : plot.getDataset().getKeys()) { + for(Object o : piePlot.getDataset().getKeys()) { if(o instanceof Comparable) { Comparable key = (Comparable)o; if(explodedMap.containsKey(key) && explodedMap.get(key)) { - plot.setExplodePercent(key, 0.3); + piePlot.setExplodePercent(key, 0.3); } else { - plot.setExplodePercent(key, 0); + piePlot.setExplodePercent(key, 0); } } } @@ -98,12 +131,12 @@ public class PiePlot extends AbstractPlot { for(String name : explodedMap.keySet()) { Boolean exploded = explodedMap.get(name); if(Boolean.TRUE.equals(exploded)) - plot.setExplodePercent(name, 0.3); + piePlot.setExplodePercent(name, 0.3); } - plot.clearSectionPaints(false); - plot.setDrawingSupplier(new DefaultDrawingSupplier()); + piePlot.clearSectionPaints(false); + piePlot.setDrawingSupplier(new DefaultDrawingSupplier()); for(String name : colorMap.keySet()) - plot.setSectionPaint(name, colorMap.get(name)); + piePlot.setSectionPaint(name, colorMap.get(name)); } }; @@ -111,36 +144,10 @@ public class PiePlot extends AbstractPlot { } // Cleaner look: no outline borders - plot.setInsets(new RectangleInsets(0,0,0,0), false); - plot.setOutlineVisible(false); - plot.setLabelBackgroundPaint(Color.WHITE); - plot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); - - return plot; - } - - /** - * Pie plot class with a stricter equals condition - * @author Teemu Lempinen - * - */ - private class MyPiePlot extends org.jfree.chart.plot.PiePlot { - - private static final long serialVersionUID = -5917620061541212934L; - - @Override - public boolean equals(Object obj) { - boolean result = super.equals(obj); - if(result == true) { - org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj; - if (this.getDataset() != that.getDataset()) { - return false; // Normally plot does not check this. We need this to properly update the charts - } - } - - return result; - } - + piePlot.setInsets(new RectangleInsets(0,0,0,0), false); + piePlot.setOutlineVisible(false); + piePlot.setLabelBackgroundPaint(Color.WHITE); + piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java index af0cc336..b30c323f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java @@ -29,10 +29,8 @@ import org.simantics.sysdyn.JFreeChartResource; */ public class XYPlot extends AbstractPlot { - private org.jfree.chart.plot.XYPlot plot; private Boolean visibleGrid; - public XYPlot(ReadGraph graph, Resource plotResource) { super(graph, plotResource); @@ -47,45 +45,49 @@ public class XYPlot extends AbstractPlot { } @Override - public Plot getPlot() { - if(plot == null) - plot = new org.jfree.chart.plot.XYPlot(null, null, null, null); + protected Plot newPlot() { + return new org.jfree.chart.plot.XYPlot(null, null, null, null); + } + + @Override + protected void setPlotProperties() { + if(!(plot instanceof org.jfree.chart.plot.XYPlot)) + return; - plot.clearDomainAxes(); - plot.clearRangeAxes(); + org.jfree.chart.plot.XYPlot xyplot = (org.jfree.chart.plot.XYPlot)plot; + xyplot.clearDomainAxes(); + xyplot.clearRangeAxes(); for(int i = 0; i < ranges.size(); i++) { - plot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); + xyplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis()); } for(int i = 0; i < domains.size(); i++) { - plot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis()); + xyplot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis()); } IAxis axis; for(int i = 0; i < datasets.size(); i++) { IDataset dataset = datasets.get(i); - plot.setDataset(i, (XYDataset)dataset.getDataset()); - plot.setRenderer(i, (XYItemRenderer)dataset.getRenderer()); + xyplot.setDataset(i, (XYDataset)dataset.getDataset()); + xyplot.setRenderer(i, (XYItemRenderer)dataset.getRenderer()); axis = rangeMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); + xyplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis)); axis = domainMappings.get(dataset); if(axis != null && ranges.contains(axis)) - plot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); + xyplot.mapDatasetToDomainAxis(i, domains.indexOf(axis)); } if(visibleGrid == null) visibleGrid = true; - plot.setRangeGridlinesVisible(visibleGrid); - plot.setDomainGridlinesVisible(visibleGrid); + xyplot.setRangeGridlinesVisible(visibleGrid); + xyplot.setDomainGridlinesVisible(visibleGrid); // Cleaner look: no outline borders - plot.setInsets(new RectangleInsets(2,2,2,2), false); - plot.setOutlineVisible(false); - - return plot; + xyplot.setInsets(new RectangleInsets(2,2,2,2), false); + xyplot.setOutlineVisible(false); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java new file mode 100644 index 00000000..74b984bd --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.dialogs.IInputValidator; + +/** + * Validator for validating that an input is double. + * + * Can allow empty strings. + * + * @author Teemu Lempinen + * + */ +public class DoubleValidator implements IInputValidator { + + boolean allowEmpty; + + /** + * New double validator. Does not allow empty strings + */ + public DoubleValidator() { + this(false); + } + + /** + * New double validator. + * @param allowEmpty Are empty strings allowed + */ + public DoubleValidator(boolean allowEmpty) { + this.allowEmpty = allowEmpty; + } + + @Override + public String isValid(String newText) { + if (allowEmpty && newText.trim().isEmpty()) + return null; + try { + Double.parseDouble(newText); + return null; + } catch (NumberFormatException e) { + return e.getMessage(); + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java index c0e84e6f..c17e6939 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.bar; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.StructuredSelection; @@ -48,6 +47,7 @@ import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; import org.simantics.ui.utils.AdaptionUtils; @@ -160,7 +160,7 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget { rangemin.setColorProvider(new JFreeChartPropertyColorProvider(rangemin.getResourceManager())); rangemin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); rangemin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - rangemin.setInputValidator(new DoubleValidator()); + rangemin.setInputValidator(new DoubleValidator(true)); label = new Label(minmax, SWT.NONE); label.setText("Max:"); @@ -168,7 +168,7 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget { rangemax.setColorProvider(new JFreeChartPropertyColorProvider(rangemax.getResourceManager())); rangemax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); rangemax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - rangemax.setInputValidator(new DoubleValidator()); + rangemax.setInputValidator(new DoubleValidator(true)); // Range Color label = new Label(rangeGroup, SWT.NONE); @@ -289,24 +289,4 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget { } }); } - - - /** - * Validator for validating that an input is double - * @author Teemu Lempinen - * - */ - private class DoubleValidator implements IInputValidator { - @Override - public String isValid(String newText) { - if (newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } - } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java index 387f34e6..5982d6dc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java @@ -16,6 +16,7 @@ import java.util.Map; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.LayoutConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; @@ -41,8 +42,11 @@ import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; @@ -58,7 +62,7 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { private ScrolledComposite sc; private Composite composite; private Button hgrid, htitle, hlegend; - private TrackedText name, title; + private TrackedText name, title, time; private TrackedCombo type; @@ -77,46 +81,74 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { // General properties Group general = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); general.setText("General"); + // first column: labels + Composite labelColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); + GridLayoutFactory.fillDefaults().applyTo(labelColumn1); + + // first column: name and title + Composite propertyColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); + + // first column: labels + Composite labelColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); + + // first column: type and time + Composite propertyColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); + GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); + // Name - Label label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + Label label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Name:"); - Composite c = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(c); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c); - - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER); + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); // Type - label = new Label(c, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Type:"); - type = new TrackedCombo(c, support, SWT.BORDER | SWT.READ_ONLY); + type = new TrackedCombo(propertyColumn2, support, SWT.BORDER | SWT.READ_ONLY); type.addModifyListener(new TypeModifyListener()); type.setItemFactory(new TypeItemFactory()); type.setSelectionFactory(new TypeSelectionFactory()); GridDataFactory.fillDefaults().applyTo(type.getWidget()); // Title (Which is different than name) - label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Title:"); - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); title.setTextFactory(new TitleFactory()); title.addModifyListener(new TitleModifier()); title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + // Time + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Time:"); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + // Group for hide options Group hideGroup = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().applyTo(hideGroup); @@ -136,6 +168,8 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + + // Resize scrolled composite sc.setContent(composite); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java index 7ccbbc4a..c7597ac0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java @@ -22,6 +22,10 @@ import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; @@ -34,7 +38,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; */ public class BarSeriesPropertyComposite extends Composite { - private TrackedText variable, label; + private TrackedText variable, label, time; public BarSeriesPropertyComposite(Composite parent, final ISessionContext context, WidgetSupport support, int style) { super(parent, style); @@ -71,5 +75,21 @@ public class BarSeriesPropertyComposite extends Composite { this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); + + // Time + label = new Label(this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + label.setText("Time:"); + + Composite composite = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(composite); + GridLayoutFactory.fillDefaults().applyTo(composite); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + GridDataFactory.fillDefaults().applyTo(time.getWidget()); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java index bbaa7b4b..10b034aa 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.trend.chart.properties.pie; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.LayoutConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; @@ -29,8 +30,11 @@ import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; @@ -45,7 +49,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { private ScrolledComposite sc; private Composite composite; private Button htitle, hlegend, hlabels; - private TrackedText name, title; + private TrackedText name, title, time; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { @@ -62,31 +66,72 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { // General properties Group general = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); general.setText("General"); + // first column: labels + Composite labelColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); + GridLayoutFactory.fillDefaults().applyTo(labelColumn1); + + // first column: name and title + Composite propertyColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); + + // first column: labels + Composite labelColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); + + // first column: type and time + Composite propertyColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); + GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); + // Name - Label label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + Label label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Name:"); - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + // Dummy data for now. Waiting for different pie chart types + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(label); + label.setText(""); + + label = new Label(propertyColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(label); + label.setText(""); + // Title (Which is different than name) - label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Title:"); - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); title.setTextFactory(new TitleFactory()); title.addModifyListener(new TitleModifier()); title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + // Time + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Time:"); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + // Group for hide options Group hideGroup = new Group(composite, SWT.NONE); GridDataFactory.fillDefaults().applyTo(hideGroup); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java index 1e8786c4..dad20d4a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java @@ -24,9 +24,12 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; @@ -39,7 +42,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; */ public class PieSeriesPropertyComposite extends Composite { - private TrackedText variable, label; + private TrackedText variable, label, time; public PieSeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { super(parent, style); @@ -85,6 +88,22 @@ public class PieSeriesPropertyComposite extends Composite { Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + // Time + label = new Label(this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + label.setText("Time:"); + + Composite composite = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(composite); + GridLayoutFactory.fillDefaults().applyTo(composite); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + GridDataFactory.fillDefaults().applyTo(time.getWidget()); + // Exploded label = new Label(this, SWT.NONE); label.setText(""); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java index d029ddf4..22228fde 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.xyline; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; @@ -29,6 +28,7 @@ import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; /** @@ -70,7 +70,7 @@ public class AxisPropertyComposite extends Composite { min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager())); min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - min.setInputValidator(new DoubleValidator()); + min.setInputValidator(new DoubleValidator(true)); label = new Label(minmax, SWT.NONE); label.setText("Max:"); @@ -78,7 +78,7 @@ public class AxisPropertyComposite extends Composite { max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager())); max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - max.setInputValidator(new DoubleValidator()); + max.setInputValidator(new DoubleValidator(true)); // Color @@ -97,24 +97,4 @@ public class AxisPropertyComposite extends Composite { GridDataFactory.fillDefaults().applyTo(axisHide); } - /** - * Validator for validating that an input is double - * @author Teemu Lempinen - * - */ - private class DoubleValidator implements IInputValidator { - @Override - public String isValid(String newText) { - if (newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } - } - - } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java index 421c63c2..857a7caf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.xyline; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.StructuredSelection; @@ -44,6 +43,7 @@ import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; @@ -185,7 +185,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl xmin.setColorProvider(new JFreeChartPropertyColorProvider(xmin.getResourceManager())); xmin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); xmin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - xmin.setInputValidator(new DoubleValidator()); + xmin.setInputValidator(new DoubleValidator(true)); label = new Label(minmax, SWT.NONE); label.setText("Max:"); @@ -193,7 +193,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl xmax.setColorProvider(new JFreeChartPropertyColorProvider(xmax.getResourceManager())); xmax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - xmax.setInputValidator(new DoubleValidator()); + xmax.setInputValidator(new DoubleValidator(true)); // Set the same width to both label rows composite.layout(); @@ -225,25 +225,4 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl }); } - - /** - * Validator for validating that an input is double - * @author Teemu Lempinen - * - */ - private class DoubleValidator implements IInputValidator { - @Override - public String isValid(String newText) { - if (newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } - } - - -} +} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java index 39f85dcb..26602293 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -112,11 +112,26 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen if(variable != null) vars.add(variable); } + + // If there is no vars and only one selection, it can be a chart + if(vars.isEmpty() && ress.size() == 1) { + Resource r = ress.iterator().next(); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(r, jfree.ChartElement)) { + if(graph.hasStatement(r, jfree.ChartElement_component)) { + r = graph.getSingleObject(r, jfree.ChartElement_component); + selectionChanged(graph, r); + return; + } + } + } + } else { // Selection is a jfreechart if(ress.size() == 1) { Resource r = ress.iterator().next(); - if(graph.isInstanceOf(r, JFreeChartResource.getInstance(graph).Chart)) { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(r, jfree.Chart)) { selectionChanged(graph, r); return; }