X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2FCharts.java;h=1e503159e0cb8af4585ce6a17882dbd0440cb0c1;hp=dd7ae02a08bf809c4b5aaa607a7681e89af5520b;hb=bf75fd9740858140eac90c18f0bca0aea3893248;hpb=21f879fcd72d7749836fb64375094ef29573fe8c diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java b/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java index dd7ae02a0..1e503159e 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/Charts.java @@ -3,7 +3,6 @@ package org.simantics.charts; import java.util.Collections; import java.util.List; -import org.simantics.Simantics; import org.simantics.charts.editor.ChartData; import org.simantics.charts.editor.ChartKeys; import org.simantics.databoard.binding.error.BindingException; @@ -12,6 +11,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; import org.simantics.history.HistoryException; import org.simantics.history.HistorySamplerItem; import org.simantics.history.ItemManager; @@ -19,7 +19,7 @@ import org.simantics.history.util.subscription.SamplingFormat; import org.simantics.modeling.subscription.SubscriptionItem; import org.simantics.modeling.subscription.SubscriptionItemQuery; import org.simantics.project.IProject; -import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.simulation.experiment.IExperiment; /** * Main facade for externally dealing with the trending system. @@ -38,40 +38,38 @@ public final class Charts { } } - public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem) throws DatabaseException { - - try { - - Resource model = graph.syncRequest(new PossibleIndexRoot(subscriptionItem)); - if ( model == null ) { - throw new DatabaseException("There is no model for " + subscriptionItem); - } - - Key chartDataKey = ChartKeys.chartSourceKey(model); + public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Variable run, Resource subscriptionItem) throws DatabaseException { + IExperiment exp = (IExperiment) run.getPropertyValue(graph, "iExperiment"); + ITrendSupport support = exp.getService(ITrendSupport.class); + ChartData data = support.getChartData(); + return createHistorySamplerItem(graph, subscriptionItem, data); + } - final ChartData data = Simantics.getProject().getHint(chartDataKey); - if ( data == null ) { - throw new DatabaseException("There is no chart data for " + model); - } + public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem, ChartData data) throws DatabaseException { - ItemManager im = new ItemManager( data.history.getItems() ); + try { + Resource model = graph.syncRequest(new PossibleIndexRoot(subscriptionItem)); + if (model == null) { + throw new DatabaseException("There is no model for " + subscriptionItem); + } - SubscriptionItem i = graph.syncRequest(new SubscriptionItemQuery(subscriptionItem)); + ItemManager im = new ItemManager(data.history.getItems()); - List items = im.search("variableId", i.variableId); - Collections.sort(items, SamplingFormat.INTERVAL_COMPARATOR); - if (items.isEmpty()) new DatabaseException("There is history item for " + i.variableId); - Bean config = items.get(0); - String historyId = (String) config.getFieldUnchecked("id"); + SubscriptionItem i = graph.syncRequest(new SubscriptionItemQuery(subscriptionItem)); - return new HistorySamplerItem(data.collector, data.history, historyId, System.identityHashCode(data)); + List items = im.search("variableId", i.variableId); + Collections.sort(items, SamplingFormat.INTERVAL_COMPARATOR); + if (items.isEmpty()) + new DatabaseException("There is history item for " + i.variableId); + Bean config = items.get(0); + String historyId = (String) config.getFieldUnchecked("id"); - } catch (HistoryException e) { - throw new DatabaseException(e); - } catch (BindingException e) { - throw new DatabaseException(e); - } - - } + return new HistorySamplerItem(data.collector, data.history, historyId, System.identityHashCode(data)); + } catch (HistoryException e) { + throw new DatabaseException(e); + } catch (BindingException e) { + throw new DatabaseException(e); + } + } }