import java.util.Collections;\r
import java.util.List;\r
\r
-import org.simantics.Simantics;\r
import org.simantics.charts.editor.ChartData;\r
import org.simantics.charts.editor.ChartKeys;\r
import org.simantics.databoard.binding.error.BindingException;\r
import org.simantics.databoard.util.Bean;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.PossibleIndexRoot;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.history.HistoryException;\r
import org.simantics.history.HistorySamplerItem;\r
import org.simantics.history.ItemManager;\r
import org.simantics.modeling.subscription.SubscriptionItem;\r
import org.simantics.modeling.subscription.SubscriptionItemQuery;\r
import org.simantics.project.IProject;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.simulation.experiment.IExperiment;\r
\r
/**\r
* Main facade for externally dealing with the trending system.\r
}\r
}\r
\r
- public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem) throws DatabaseException {\r
- \r
- try {\r
-\r
- Resource model = graph.syncRequest(new PossibleModel(subscriptionItem));\r
- if ( model == null ) {\r
- throw new DatabaseException("There is no model for " + subscriptionItem);\r
- }\r
-\r
- Key chartDataKey = ChartKeys.chartSourceKey(model);\r
+ public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Variable run, Resource subscriptionItem) throws DatabaseException {\r
+ IExperiment exp = (IExperiment) run.getPropertyValue(graph, "iExperiment");\r
+ ITrendSupport support = exp.getService(ITrendSupport.class);\r
+ ChartData data = support.getChartData();\r
+ return createHistorySamplerItem(graph, subscriptionItem, data);\r
+ }\r
\r
- final ChartData data = Simantics.getProject().getHint(chartDataKey);\r
- if ( data == null ) {\r
- throw new DatabaseException("There is no chart data for " + model);\r
- }\r
+ public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem, ChartData data) throws DatabaseException {\r
\r
- ItemManager im = new ItemManager( data.history.getItems() );\r
+ try {\r
+ Resource model = graph.syncRequest(new PossibleIndexRoot(subscriptionItem));\r
+ if (model == null) {\r
+ throw new DatabaseException("There is no model for " + subscriptionItem);\r
+ }\r
\r
- SubscriptionItem i = graph.syncRequest(new SubscriptionItemQuery(subscriptionItem));\r
+ ItemManager im = new ItemManager(data.history.getItems());\r
\r
- List<Bean> items = im.search("variableId", i.variableId);\r
- Collections.sort(items, SamplingFormat.INTERVAL_COMPARATOR);\r
- if (items.isEmpty()) new DatabaseException("There is history item for " + i.variableId);\r
- Bean config = items.get(0);\r
- String historyId = (String) config.getFieldUnchecked("id");\r
+ SubscriptionItem i = graph.syncRequest(new SubscriptionItemQuery(subscriptionItem));\r
\r
- return new HistorySamplerItem(data.collector, data.history, historyId, System.identityHashCode(data));\r
+ List<Bean> items = im.search("variableId", i.variableId);\r
+ Collections.sort(items, SamplingFormat.INTERVAL_COMPARATOR);\r
+ if (items.isEmpty())\r
+ new DatabaseException("There is history item for " + i.variableId);\r
+ Bean config = items.get(0);\r
+ String historyId = (String) config.getFieldUnchecked("id");\r
\r
- } catch (HistoryException e) {\r
- throw new DatabaseException(e);\r
- } catch (BindingException e) {\r
- throw new DatabaseException(e);\r
- }\r
- \r
- }\r
+ return new HistorySamplerItem(data.collector, data.history, historyId, System.identityHashCode(data));\r
+ } catch (HistoryException e) {\r
+ throw new DatabaseException(e);\r
+ } catch (BindingException e) {\r
+ throw new DatabaseException(e);\r
+ }\r
+ }\r
\r
}\r