tmf.ui: Add a SWTbot condition for XY charts ready
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / xycharts / TmfXYChartViewer.java
index 29ca3f9809084fde4b5975eb8e9c384ec9c76860..9511a29d4141df8e475a54e59340c411540757fb 100644 (file)
@@ -24,6 +24,8 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ui.viewers.TmfTimeViewer;
 import org.swtchart.Chart;
 import org.swtchart.IAxis;
@@ -31,6 +33,8 @@ import org.swtchart.ISeries;
 import org.swtchart.ISeriesSet;
 import org.swtchart.Range;
 
+import com.google.common.annotations.VisibleForTesting;
+
 /**
  * Base class for a XY-Chart based on SWT chart. It provides a methods to define
  * zoom, selection and tool tip providers. It also provides call backs to be
@@ -305,6 +309,32 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
      */
     protected abstract void updateContent();
 
+    /**
+     * Returns whether or not this chart viewer is dirty. The viewer is
+     * considered dirty if it has yet to completely update its model.
+     *
+     * This method is meant to be used by tests in order to know when it is safe
+     * to proceed.
+     *
+     * @return true if the time graph view has yet to completely update its
+     *         model, false otherwise
+     * @since 2.2
+     */
+    @VisibleForTesting
+    public boolean isDirty() {
+        if (getTrace() == null) {
+            return false;
+        }
+
+        TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
+        long startTime = ctx.getWindowRange().getStartTime().toNanos();
+        long endTime = ctx.getWindowRange().getEndTime().toNanos();
+
+        // If the chart viewer hasn't updated all the way to the end of
+        // the window range then it's dirty. A refresh should happen later.
+        return (getWindowStartTime() != startTime || getWindowEndTime() != endTime);
+    }
+
     // ------------------------------------------------------------------------
     // Signal Handler
     // ------------------------------------------------------------------------
This page took 0.025657 seconds and 5 git commands to generate.