From: lempinen Date: Fri, 9 Dec 2011 13:18:18 +0000 (+0000) Subject: Cleaner chart properties X-Git-Tag: simantics-1.6~74 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b325c558c24f6f8e3ee3bfdfabeed1589bd55c74;p=simantics%2Fsysdyn.git Cleaner chart properties git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23473 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index b576aade..d4922270 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -1067,7 +1067,15 @@ property="org.simantics.sysdyn.ui.nodeClass"> + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 1fb72a78..7b8ac685 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -34,6 +34,7 @@ import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; import org.simantics.sysdyn.ui.trend.chart.properties.ChartTab; +import org.simantics.sysdyn.ui.trend.chart.properties.bar.BarAxisTab; import org.simantics.sysdyn.ui.trend.chart.properties.bar.BarGeneralPropertiesTab; import org.simantics.sysdyn.ui.trend.chart.properties.bar.BarSeriesTab; import org.simantics.sysdyn.ui.trend.chart.properties.pie.PieGeneralPropertiesTab; @@ -343,6 +344,11 @@ public class ResourceSelectionProcessor implements SelectionProcessor { + + @Override + public Integer perform(ReadGraph graph, Resource domainAxis) throws DatabaseException { + if(angleInt == null) { + Double angle = 0.0; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(domainAxis != null) { + Double value = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees); + if(value != null) + angle = value; + } + return angle.intValue(); + } else { + return angleInt; + } + } + + } + + @Override + public void setInput(final ISessionContext context, Object input) { + final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); + if(chart == null) + return; + + context.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); + if(plot == null) return; + Resource rangeAxis = graph.getPossibleObject(plot, jfree.Plot_rangeAxis); + if(rangeAxis == null) return; + rangeAxisSupport.fireInput(context, new StructuredSelection(rangeAxis)); + + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + if(domainAxis == null) return; + domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis)); + } + }); + } + + + /** + * 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 aebd5e97..387f34e6 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 @@ -22,7 +22,6 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.swt.widgets.Button; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; @@ -31,16 +30,11 @@ import org.simantics.browsing.ui.swt.widgets.TrackedCombo; import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; -import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; @@ -52,8 +46,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; 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; -import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; -import org.simantics.ui.utils.AdaptionUtils; + /** * General properties of a bar chart @@ -67,7 +60,7 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { private Button hgrid, htitle, hlegend; private TrackedText name, title; private TrackedCombo type; - private TrackedSpinner angle; + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { @@ -143,22 +136,7 @@ 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)); - Composite angleComposite = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(angleComposite); - GridLayoutFactory.fillDefaults().numColumns(2).applyTo(angleComposite); - // Line width - label = new Label(angleComposite, SWT.NONE); - label.setText("Label angle:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - angle = new TrackedSpinner(angleComposite, support, SWT.BORDER); - angle.setSelectionFactory(new AngleSelectionFactory()); - angle.addModifyListener(new AngleModifyListener()); - angle.setMinimum(0); - angle.setMaximum(90); - angle.getWidget().setIncrement(5); - GridDataFactory.fillDefaults().applyTo(angle.getWidget()); - + // Resize scrolled composite sc.setContent(composite); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); sc.setMinSize(size); @@ -174,13 +152,13 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { public String perform(ReadGraph graph, Resource chart) throws DatabaseException { JFreeChartResource jfree = JFreeChartResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); - + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot)); if(plot != null) { Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.CategoryDataset)); - + if(dataset != null) { - Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, l0.ConsistsOf, jfree.Dataset_renderer)); + Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, jfree.Dataset_renderer, jfree.Renderer)); if(renderer != null && graph.isInstanceOf(renderer, jfree.StackedBarRenderer)) return "Stacked"; @@ -237,89 +215,4 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { } } - - - /** - * ModifyListener for the angle {@link TrackedSpinner} - * - * @author Teemu Lempinen - * - */ - private class AngleModifyListener implements TextModifyListener, Widget { - - private ISessionContext context; - private Object lastInput = null; - - @Override - public void modifyText(TrackedModifyEvent e) { - if(context == null) - return; - - // Get the text value from spinner and associated resource (input) - Spinner spinner = (Spinner)e.getWidget(); - final String textValue = spinner.getText(); - final Object input = lastInput; - - try { - context.getSession().syncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); - Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot)); - Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); - - try { - // usually reliable, since the spinner does all the checks - Double value = Double.parseDouble(textValue); - graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, value, Bindings.DOUBLE); - } catch (NumberFormatException e) { - graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, 0.0, Bindings.DOUBLE); - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - } - - @Override - public void setInput(ISessionContext context, Object parameter) { - this.context = context; - lastInput = parameter; - } - - } - - /** - * Class for setting the value for angle {@link TrackedSpinner} - * @author Teemu Lempinen - * - */ - private class AngleSelectionFactory extends ReadFactoryImpl { - - @Override - public Integer perform(ReadGraph graph, Resource chart) throws DatabaseException { - Double angle = 0.0; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot)); - if(plot != null) { - Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); - if(domainAxis != null) { - Double value = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees); - if(value != null) - angle = value; - } - } - return angle.intValue(); - - } - - } - } 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 3900631f..fdff61b0 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 @@ -16,7 +16,6 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -47,7 +46,6 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { private Composite composite; private Button htitle, hlegend; private TrackedText name, title; - private Combo type; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { @@ -72,25 +70,12 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { GridDataFactory.fillDefaults().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(general, 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.setText("Type:"); - - type = new Combo(c, SWT.BORDER | SWT.READ_ONLY); - type.setItems(new String[] {"Normal", "Stacked"}); - type.select(0); - // Title (Which is different than name) label = new Label(general, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); 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 ea64a17d..421c63c2 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 @@ -87,9 +87,10 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl general.setText("General"); // Name - Label label = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Name:"); + Label nameLabel = new Label(general, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(nameLabel); + nameLabel.setText("Name:"); + nameLabel.setAlignment(SWT.RIGHT); Composite c = new Composite(general, SWT.NONE); GridDataFactory.fillDefaults().applyTo(c); @@ -102,7 +103,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); // Type - label = new Label(c, SWT.NONE); + Label label = new Label(c, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Type:"); @@ -148,9 +149,9 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl xgroup.setText("X-axis"); // Variable for x-axis (default: empty == time) - label = new Label(xgroup, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Variable:"); + Label xVariableLabel = new Label(xgroup, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(xVariableLabel); + xVariableLabel.setText("Variable:"); xvariable = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER); xvariable.setTextFactory(new RVIFactory()); @@ -194,7 +195,10 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); xmax.setInputValidator(new DoubleValidator()); - + // Set the same width to both label rows + composite.layout(); + GridDataFactory.fillDefaults().hint(xVariableLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(nameLabel); + sc.setContent(composite); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); sc.setMinSize(size);