From 49999e806935cba3509f98a5e3e509d663e15072 Mon Sep 17 00:00:00 2001 From: luukkainen Date: Wed, 16 Jan 2013 16:12:55 +0000 Subject: [PATCH] chart selection processor moved to jfreechart plug-in refs #3988 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26627 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ChartSelectionTabContributor.java | 89 ++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 1 - .../ResourceSelectionProcessor.java | 131 +++++++++--------- 3 files changed, 157 insertions(+), 64 deletions(-) create mode 100644 org.simantics.jfreechart/src/org/simantics/jfreechart/ChartSelectionTabContributor.java diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/ChartSelectionTabContributor.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/ChartSelectionTabContributor.java new file mode 100644 index 00000000..01a076b9 --- /dev/null +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/ChartSelectionTabContributor.java @@ -0,0 +1,89 @@ +package org.simantics.jfreechart; + +import java.util.Collection; +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.jfreechart.chart.properties.ChartTab; +import org.simantics.jfreechart.chart.properties.bar.BarAxisTab; +import org.simantics.jfreechart.chart.properties.bar.BarGeneralPropertiesTab; +import org.simantics.jfreechart.chart.properties.bar.BarSeriesTab; +import org.simantics.jfreechart.chart.properties.pie.PieGeneralPropertiesTab; +import org.simantics.jfreechart.chart.properties.pie.PieSeriesTab; +import org.simantics.jfreechart.chart.properties.xyline.XYLineAxisAndVariablesTab; +import org.simantics.jfreechart.chart.properties.xyline.XYLineGeneralPropertiesTab; +import org.simantics.layer0.Layer0; +import org.simantics.selectionview.ComparableTabContributor; +import org.simantics.sysdyn.JFreeChartResource; + +public class ChartSelectionTabContributor { + + + public static boolean contibuteTabs(ReadGraph backend, Resource r, List tabs) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(backend); + if(backend.isInstanceOf(r, jfree.ChartElement)) { + if(backend.hasStatement(r, jfree.ChartElement_component)) + r = backend.getSingleObject(r, jfree.ChartElement_component); + } + + if (backend.isInstanceOf(r, jfree.Chart)) { + + Collection plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot)); + if(!plots.isEmpty()) { + Resource plot = plots.iterator().next(); + + if(backend.isInstanceOf(plot, jfree.XYPlot)) { + tabs.add(new ComparableTabContributor( + new XYLineGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new XYLineAxisAndVariablesTab(), + 9, + r, + "Axis and Variables")); + } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) { + tabs.add(new ComparableTabContributor( + new BarGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new BarSeriesTab(), + 9, + r, + "Variables")); + tabs.add(new ComparableTabContributor( + new BarAxisTab(), + 8, + r, + "Axis")); + } else if(backend.isInstanceOf(plot, jfree.PiePlot)) { + tabs.add(new ComparableTabContributor( + new PieGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new PieSeriesTab(), + 9, + r, + "Variables")); + } + + tabs.add(new ComparableTabContributor( + new ChartTab(), + 1, + r, + "Chart")); + + return true; + } + } + return false; + } +} diff --git a/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs b/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs index e9cf5f10..f287d53c 100644 --- a/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,3 @@ -#Tue Nov 10 13:35:16 EET 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 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 a4de67b0..5581db47 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 @@ -30,6 +30,7 @@ import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.request.PossibleActiveVariableFromVariable; import org.simantics.db.layer0.variable.Variable; import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.jfreechart.ChartSelectionTabContributor; import org.simantics.jfreechart.chart.properties.ChartTab; import org.simantics.jfreechart.chart.properties.bar.BarAxisTab; import org.simantics.jfreechart.chart.properties.bar.BarGeneralPropertiesTab; @@ -64,12 +65,12 @@ public class ResourceSelectionProcessor implements SelectionProcessor process(Object selection, ReadGraph backend) { - Collection tabs = new ArrayList(); + List tabs = new ArrayList(); SysdynResource sr = SysdynResource.getInstance(backend); DiagramResource dr = DiagramResource.getInstance(backend); ModelingResources mr = ModelingResources.getInstance(backend); SimulationResource simu = SimulationResource.getInstance(backend); - JFreeChartResource jfree = JFreeChartResource.getInstance(backend); +// JFreeChartResource jfree = JFreeChartResource.getInstance(backend); // Test nodes if(sharedFunctionsTestNode == null) @@ -398,68 +399,72 @@ public class ResourceSelectionProcessor implements SelectionProcessor plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot)); - if(!plots.isEmpty()) { - Resource plot = plots.iterator().next(); - - if(backend.isInstanceOf(plot, jfree.XYPlot)) { - tabs.add(new ComparableTabContributor( - new XYLineGeneralPropertiesTab(), - 10, - r, - "General")); - tabs.add(new ComparableTabContributor( - new XYLineAxisAndVariablesTab(), - 9, - r, - "Axis and Variables")); - } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) { - tabs.add(new ComparableTabContributor( - new BarGeneralPropertiesTab(), - 10, - r, - "General")); - tabs.add(new ComparableTabContributor( - new BarSeriesTab(), - 9, - r, - "Variables")); - tabs.add(new ComparableTabContributor( - new BarAxisTab(), - 8, - r, - "Axis")); - } else if(backend.isInstanceOf(plot, jfree.PiePlot)) { - tabs.add(new ComparableTabContributor( - new PieGeneralPropertiesTab(), - 10, - r, - "General")); - tabs.add(new ComparableTabContributor( - new PieSeriesTab(), - 9, - r, - "Variables")); - } - - tabs.add(new ComparableTabContributor( - new ChartTab(), - 1, - r, - "Chart")); - return tabs; - - } + if (ChartSelectionTabContributor.contibuteTabs(backend, r, tabs)) { + return tabs; } + + +// // Chart Element +// if(backend.isInstanceOf(r, jfree.ChartElement)) { +// if(backend.hasStatement(r, jfree.ChartElement_component)) +// r = backend.getSingleObject(r, jfree.ChartElement_component); +// } +// // Chart +// if (backend.isInstanceOf(r, jfree.Chart)) { +// +// Collection plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot)); +// if(!plots.isEmpty()) { +// Resource plot = plots.iterator().next(); +// +// if(backend.isInstanceOf(plot, jfree.XYPlot)) { +// tabs.add(new ComparableTabContributor( +// new XYLineGeneralPropertiesTab(), +// 10, +// r, +// "General")); +// tabs.add(new ComparableTabContributor( +// new XYLineAxisAndVariablesTab(), +// 9, +// r, +// "Axis and Variables")); +// } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) { +// tabs.add(new ComparableTabContributor( +// new BarGeneralPropertiesTab(), +// 10, +// r, +// "General")); +// tabs.add(new ComparableTabContributor( +// new BarSeriesTab(), +// 9, +// r, +// "Variables")); +// tabs.add(new ComparableTabContributor( +// new BarAxisTab(), +// 8, +// r, +// "Axis")); +// } else if(backend.isInstanceOf(plot, jfree.PiePlot)) { +// tabs.add(new ComparableTabContributor( +// new PieGeneralPropertiesTab(), +// 10, +// r, +// "General")); +// tabs.add(new ComparableTabContributor( +// new PieSeriesTab(), +// 9, +// r, +// "Variables")); +// } +// +// tabs.add(new ComparableTabContributor( +// new ChartTab(), +// 1, +// r, +// "Chart")); +// return tabs; +// +// } +// } // Default experiment if (backend.isInstanceOf(r, sr.AdditionalSymbols_MultilineText)) -- 2.47.1