]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
fea54159531a02e2048bfa555e673f886a1bf659
[simantics/sysdyn.git] /
1 package org.simantics.jfreechart.chart.properties;\r
2 \r
3 import java.util.Collection;\r
4 import java.util.HashMap;\r
5 import java.util.Map;\r
6 \r
7 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
8 import org.simantics.db.ReadGraph;\r
9 import org.simantics.db.Resource;\r
10 import org.simantics.db.exception.DatabaseException;\r
11 import org.simantics.sysdyn.JFreeChartResource;\r
12 \r
13 public class ChartVariableFactory extends ReadFactoryImpl<Resource, ChartVariable>{\r
14         \r
15         private Map<String,ChartVariable> map;\r
16         \r
17         public ChartVariableFactory(Collection<ChartVariable> data) {\r
18                 map = new HashMap<String, ChartVariable>();\r
19                 for (ChartVariable v : data) {\r
20                         map.put(v.getRvi(), v);\r
21                 }\r
22         }\r
23         \r
24         @Override\r
25         public ChartVariable perform(ReadGraph graph, Resource input)\r
26                         throws DatabaseException {\r
27                  String rvi = graph.getPossibleRelatedValue(input, JFreeChartResource.getInstance(graph).variableRVI);\r
28                  if (rvi == null)\r
29                          return null;\r
30                  return map.get(rvi);\r
31                 \r
32         }\r
33 \r
34 }\r