tmf.ui: make common line charts display the window range, not their model range
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / xycharts / linecharts / TmfCommonXLineChartViewer.java
index 72a89a297d2beeb6543b6e32bdfe940cb68bb909..10db54ba7168a57a9393ef71852f2867650080c9 100644 (file)
@@ -15,13 +15,16 @@ package org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.logging.Logger;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
@@ -52,6 +55,9 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
     /* The desired number of points per pixel */
     private static final double RESOLUTION = 1.0;
+    private static final Logger LOGGER = TraceCompassLog.getLogger(TmfCommonXLineChartViewer.class);
+    private static final String LOG_STRING_WITH_PARAM = "[TmfCommonXLineChart:%s] viewerId=%s, %s"; //$NON-NLS-1$
+    private static final String LOG_STRING = "[TmfCommonXLineChart:%s] viewerId=%s"; //$NON-NLS-1$
 
     private static final int[] LINE_COLORS = { SWT.COLOR_BLUE, SWT.COLOR_RED, SWT.COLOR_GREEN,
             SWT.COLOR_MAGENTA, SWT.COLOR_CYAN,
@@ -103,6 +109,25 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
         reinitialize();
     }
 
+    /**
+     * Formats a log message for this class
+     *
+     * @param event
+     *            The event to log, that will be appended to the class name to
+     *            make the full event name
+     * @param parameters
+     *            The string of extra parameters to add to the log message, in
+     *            the format name=value[, name=value]*, or <code>null</code> for
+     *            no params
+     * @return The complete log message for this class
+     */
+    private String getLogMessage(String event, @Nullable String parameters) {
+        if (parameters == null) {
+            return String.format(LOG_STRING, event, getClass().getName());
+        }
+        return String.format(LOG_STRING_WITH_PARAM, event, getClass().getName(), parameters);
+    }
+
     /**
      * Forces a reinitialization of the data sources, even if it has already
      * been initialized for this trace before
@@ -113,6 +138,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
             // Don't use TmfUiRefreshHandler (bug 467751)
             @Override
             public void run() {
+                LOGGER.info(() -> getLogMessage("InitializeThreadStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
                 initializeDataSource();
                 if (!getSwtChart().isDisposed()) {
                     getDisplay().asyncExec(new Runnable() {
@@ -126,6 +152,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
                         }
                     });
                 }
+                LOGGER.info(() -> getLogMessage("InitializeThreadEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
             }
         };
         thread.start();
@@ -152,16 +179,21 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
         @Override
         public void run() {
+            LOGGER.info(() -> getLogMessage("UpdateThreadStart", "numRequests=" + fNumRequests + ", tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
             Display.getDefault().syncExec(new Runnable() {
                 @Override
                 public void run() {
+                    LOGGER.info(() -> getLogMessage("UpdateDataStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
                     updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
+                    LOGGER.info(() -> getLogMessage("UpdateDataEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
                 }
             });
             updateThreadFinished(this);
+            LOGGER.info(() -> getLogMessage("UpdateThreadEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
         }
 
         public void cancel() {
+            LOGGER.info(() -> getLogMessage("UpdateThreadCanceled", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
             fMonitor.setCanceled(true);
         }
     }
@@ -291,8 +323,8 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
      *            The array of values for the series
      */
     protected void setSeries(String seriesName, double[] seriesValues) {
-        if (fXValues.length > seriesValues.length) {
-            throw new IllegalStateException();
+        if (fXValues.length != seriesValues.length) {
+            throw new IllegalStateException("All series in list must be of length : " + fXValues.length); //$NON-NLS-1$
         }
         fSeriesValues.put(seriesName, seriesValues);
     }
@@ -368,9 +400,8 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
                     IAxisTick xTick = getSwtChart().getAxisSet().getXAxis(0).getTick();
                     xTick.setFormat(tmfChartTimeStampFormat);
 
-                    final double start = xValues[0];
-                    int lastX = xValues.length - 1;
-                    double end = (start == xValues[lastX]) ? start + 1 : xValues[lastX];
+                    final double start = 0.0;
+                    double end = getWindowEndTime() - getWindowStartTime();
                     getSwtChart().getAxisSet().getXAxis(0).setRange(new Range(start, end));
                     if (maxy > miny) {
                         getSwtChart().getAxisSet().getYAxis(0).setRange(new Range(miny, maxy));
This page took 0.026444 seconds and 5 git commands to generate.