]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/editor/TimeSeriesEditor.java
Tested and fixed utility for truncating history data.
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / TimeSeriesEditor.java
index d83a37ad4f665241aed27d1b3618b1a549216714..cadb5bd4b372e5841479497d672cd1fde938511e 100644 (file)
@@ -586,6 +586,7 @@ public class TimeSeriesEditor extends ResourceEditorPart {
         // Track data source and preinitialize chartData
         project.addHintListener(chartDataListener);
         chartData.readFrom( (ChartData) project.getHint( chartDataKey ) );
+        chartData.reference();
 
         if (chartData.run != null) {
             milestoneListener = new MilestoneSpecListener();
@@ -748,6 +749,7 @@ public class TimeSeriesEditor extends ResourceEditorPart {
                 chartData.datasource.removeListener( stepListener );
             if (chartData.experiment!=null)
                 chartData.experiment.removeListener( experimentStateListener );
+            chartData.dereference();
             chartData.readFrom( null );
         }
 
@@ -840,7 +842,9 @@ public class TimeSeriesEditor extends ResourceEditorPart {
         }
 
         if (doLayout) trendNode.layout();
+        this.chartData.dereference();
         this.chartData.readFrom( data );
+        this.chartData.reference();
         tp.setDirty();
         
         if (!ObjectUtils.objectEquals(oldExperimentResource, newExperimentResource)) {
@@ -857,14 +861,14 @@ public class TimeSeriesEditor extends ResourceEditorPart {
         }
         @Override
         public void execute(ReadGraph graph, final Resource run) throws DatabaseException {
-               if(run != null) {
-                       SimulationResource SIMU = SimulationResource.getInstance(graph);
-                       Variable var = Variables.getVariable(graph, run);
-                       IExperiment exp = var.getPossiblePropertyValue(graph, SIMU.Run_iExperiment);
-                       ITrendSupport ts = exp.getService(ITrendSupport.class);
-                       if (ts != null)
-                           ts.setChartData(graph);
-               }
+            if(run != null) {
+                SimulationResource SIMU = SimulationResource.getInstance(graph);
+                Variable var = Variables.getPossibleVariable(graph, run);
+                IExperiment exp = var != null ? var.getPossiblePropertyValue(graph, SIMU.Run_iExperiment) : null;
+                ITrendSupport ts = exp != null ? exp.getService(ITrendSupport.class) : null;
+                if (ts != null)
+                    ts.setChartData(graph);
+            }
         }
         @Override
         public boolean isDisposed() {
@@ -989,18 +993,18 @@ public class TimeSeriesEditor extends ResourceEditorPart {
         tp.setDirty();
     }
 
-    @SuppressWarnings("rawtypes")
+    @SuppressWarnings("unchecked")
     @Override
-    public Object getAdapter(Class adapter) {
+    public <T> T getAdapter(Class<T> adapter) {
         if (adapter == INode.class) {
             ICanvasContext ctx = cvsCtx;
             if (ctx != null)
-                return ctx.getSceneGraph();
+                return (T) ctx.getSceneGraph();
         }
         if (adapter == IPropertyPage.class)
-            return new StandardPropertyPage(getSite(), getPropertyPageContexts());
+            return (T) new StandardPropertyPage(getSite(), getPropertyPageContexts());
         if (adapter == ICanvasContext.class)
-            return cvsCtx;
+            return (T) cvsCtx;
         return super.getAdapter(adapter);
     }