tmf: Bug 490400: Leaking widgets due to incorrect cleanup in dispose()
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / xycharts / TmfXYChartViewer.java
index f658ee7ed1b31c352e94a2e87c6a19ed13e82549..b9baefac3e27c1767d32eda7059e80722fba18cf 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2013, 2015 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2013, 2016 Ericsson, École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -118,6 +118,10 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
         fMouseWheelZoomProvider = new TmfMouseWheelZoomProvider(this);
         fToolTipProvider = new TmfSimpleTooltipProvider(this);
         fMouseDragProvider = new TmfMouseDragProvider(this);
+
+        fSwtChart.addDisposeListener((e) -> {
+            internalDispose();
+        });
     }
 
     // ------------------------------------------------------------------------
@@ -239,10 +243,14 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     // ------------------------------------------------------------------------
     // TmfComponent
     // ------------------------------------------------------------------------
+
     @Override
     public void dispose() {
-        super.dispose();
         fSwtChart.dispose();
+    }
+
+    private void internalDispose() {
+        super.dispose();
 
         if (fMouseSelectionProvider != null) {
             fMouseSelectionProvider.dispose();
@@ -393,20 +401,9 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
 
         int pixelCoordinate = 0;
         IAxis[] xAxes = getSwtChart().getAxisSet().getXAxes();
-        ISeries[] series = fSwtChart.getSeriesSet().getSeries();
-        if ((xAxes.length > 0) && (series.length > 0) &&
-                (series[0].getXSeries() != null) && (series[0].getXSeries().length > 0)) {
+        if (xAxes.length > 0) {
             IAxis axis = xAxes[0];
-            // All series have the same X series
-            double[] xSeries = series[0].getXSeries();
-            double minX = Double.MAX_VALUE;
-            for (double x : xSeries) {
-                if (minX > x) {
-                    minX = x;
-                }
-            }
-
-            pixelCoordinate = axis.getPixelCoordinate(minX);
+            pixelCoordinate = axis.getPixelCoordinate(axis.getRange().lower);
         }
         return getSwtChart().toControl(getSwtChart().getPlotArea().toDisplay(pixelCoordinate, 0)).x;
     }
@@ -424,21 +421,10 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
      */
     public int getPointAreaWidth() {
         IAxis[] xAxes = getSwtChart().getAxisSet().getXAxes();
-        ISeries[] series = fSwtChart.getSeriesSet().getSeries();
-        if ((xAxes.length > 0) && (series.length > 0) &&
-                (series[0].getXSeries() != null) && (series[0].getXSeries().length > 0)) {
+        if (xAxes.length > 0) {
             IAxis axis = xAxes[0];
-            // All series have the same X series
-            double[] xSeries = series[0].getXSeries();
-            double maxX = Double.MIN_VALUE;
-            for (double x : xSeries) {
-                if (maxX < x) {
-                    maxX = x;
-                }
-            }
-
             int x1 = getPointAreaOffset();
-            int x2 = axis.getPixelCoordinate(maxX);
+            int x2 = axis.getPixelCoordinate(axis.getRange().upper);
             x2 = getSwtChart().toControl(getSwtChart().getPlotArea().toDisplay(x2, 0)).x;
             int width = x2 - x1;
             return width;
This page took 0.027216 seconds and 5 git commands to generate.