]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
f4ff81a405a2417fd7eabe4e0420b142eee0f137
[simantics/sysdyn.git] /
1 package org.simantics.jfreechart;\r
2 \r
3 import java.util.Collection;\r
4 import java.util.List;\r
5 \r
6 import org.simantics.db.ReadGraph;\r
7 import org.simantics.db.Resource;\r
8 import org.simantics.db.common.request.ObjectsWithType;\r
9 import org.simantics.db.exception.DatabaseException;\r
10 import org.simantics.jfreechart.chart.properties.ChartTab;\r
11 import org.simantics.jfreechart.chart.properties.bar.BarAxisTab;\r
12 import org.simantics.jfreechart.chart.properties.bar.BarGeneralPropertiesTab;\r
13 import org.simantics.jfreechart.chart.properties.bar.BarSeriesTab;\r
14 import org.simantics.jfreechart.chart.properties.bar.BarSeriesTab2;\r
15 import org.simantics.jfreechart.chart.properties.pie.PieGeneralPropertiesTab;\r
16 import org.simantics.jfreechart.chart.properties.pie.PieSeriesTab;\r
17 import org.simantics.jfreechart.chart.properties.pie.PieSeriesTab2;\r
18 import org.simantics.jfreechart.chart.properties.xyline.XYLineAxisAndVariablesTab;\r
19 import org.simantics.jfreechart.chart.properties.xyline.XYLineGeneralPropertiesTab;\r
20 import org.simantics.layer0.Layer0;\r
21 import org.simantics.selectionview.ComparableTabContributor;\r
22 import org.simantics.sysdyn.JFreeChartResource;\r
23 \r
24 public class ChartSelectionTabContributor {\r
25 \r
26         \r
27         public static boolean contibuteTabs(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs) throws DatabaseException {\r
28                 JFreeChartResource jfree = JFreeChartResource.getInstance(backend);\r
29                 if(backend.isInstanceOf(r, jfree.ChartElement)) {\r
30             if(backend.hasStatement(r, jfree.ChartElement_component))\r
31                 r = backend.getSingleObject(r, jfree.ChartElement_component);\r
32         }\r
33                 \r
34                 if (backend.isInstanceOf(r, jfree.Chart)) {\r
35 \r
36              Collection<Resource> plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot));\r
37              if(!plots.isEmpty()) {\r
38                  Resource plot = plots.iterator().next();\r
39 \r
40                  if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
41                      tabs.add(new ComparableTabContributor(\r
42                              new XYLineGeneralPropertiesTab(),\r
43                              10,\r
44                              r,\r
45                              "General"));\r
46                      tabs.add(new ComparableTabContributor(\r
47                              new XYLineAxisAndVariablesTab(),\r
48                              9,\r
49                              r,\r
50                              "Axis and Variables"));\r
51                  } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
52                      tabs.add(new ComparableTabContributor(\r
53                              new BarGeneralPropertiesTab(),\r
54                              10,\r
55                              r,\r
56                              "General"));\r
57                      tabs.add(new ComparableTabContributor(\r
58                              new BarSeriesTab(),\r
59                              9,\r
60                              r,\r
61                              "Variables"));\r
62                      tabs.add(new ComparableTabContributor(\r
63                              new BarAxisTab(),\r
64                              8,\r
65                              r,\r
66                              "Axis"));                        \r
67                  } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
68                      tabs.add(new ComparableTabContributor(\r
69                              new PieGeneralPropertiesTab(),\r
70                              10,\r
71                              r,\r
72                              "General"));\r
73                      tabs.add(new ComparableTabContributor(\r
74                              new PieSeriesTab(),\r
75                              9,\r
76                              r,\r
77                              "Variables"));\r
78                  }\r
79 \r
80                  tabs.add(new ComparableTabContributor(\r
81                          new ChartTab(),\r
82                          1,\r
83                          r,\r
84                          "Chart"));\r
85                 \r
86                  return true;\r
87              } \r
88          }\r
89                 return false;\r
90         }\r
91         \r
92         public static boolean contibuteTabs2(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs) throws DatabaseException {\r
93                 JFreeChartResource jfree = JFreeChartResource.getInstance(backend);\r
94                 if(backend.isInstanceOf(r, jfree.ChartElement)) {\r
95             if(backend.hasStatement(r, jfree.ChartElement_component))\r
96                 r = backend.getSingleObject(r, jfree.ChartElement_component);\r
97         }\r
98                 \r
99                 if (backend.isInstanceOf(r, jfree.Chart)) {\r
100 \r
101              Collection<Resource> plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot));\r
102              if(!plots.isEmpty()) {\r
103                  Resource plot = plots.iterator().next();\r
104 \r
105                  if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
106                      tabs.add(new ComparableTabContributor(\r
107                              new XYLineGeneralPropertiesTab(),\r
108                              10,\r
109                              r,\r
110                              "General"));\r
111                      tabs.add(new ComparableTabContributor(\r
112                              new XYLineAxisAndVariablesTab(),\r
113                              9,\r
114                              r,\r
115                              "Axis and Variables"));\r
116                  } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
117                      tabs.add(new ComparableTabContributor(\r
118                              new BarGeneralPropertiesTab(),\r
119                              10,\r
120                              r,\r
121                              "General"));\r
122                      tabs.add(new ComparableTabContributor(\r
123                              new BarSeriesTab2(),\r
124                              9,\r
125                              r,\r
126                              "Variables"));\r
127                      tabs.add(new ComparableTabContributor(\r
128                              new BarAxisTab(),\r
129                              8,\r
130                              r,\r
131                              "Axis"));                        \r
132                  } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
133                      tabs.add(new ComparableTabContributor(\r
134                              new PieGeneralPropertiesTab(),\r
135                              10,\r
136                              r,\r
137                              "General"));\r
138                      tabs.add(new ComparableTabContributor(\r
139                              new PieSeriesTab2(),\r
140                              9,\r
141                              r,\r
142                              "Variables"));\r
143                  }\r
144 \r
145                  tabs.add(new ComparableTabContributor(\r
146                          new ChartTab(),\r
147                          1,\r
148                          r,\r
149                          "Chart"));\r
150                 \r
151                  return true;\r
152              } \r
153          }\r
154                 return false;\r
155         }\r
156 }\r