From c27e9fec4a96053f4628b244845e9396523cb78f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Thu, 20 Oct 2016 10:03:37 -0400 Subject: [PATCH] tmf.ui: Add a SWTbot condition for XY charts ready MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit bug 500770 Change-Id: If70437ab08871962415a2b954307b58f24460331 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/83595 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam --- .../swtbot/tests/shared/ConditionHelpers.java | 39 +++++++++++++++++++ .../ui/viewers/xycharts/TmfXYChartViewer.java | 30 ++++++++++++++ .../linecharts/TmfCommonXLineChartViewer.java | 19 +++++++++ 3 files changed, 88 insertions(+) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java index 5559e6db04..c1ecf95e42 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java @@ -45,6 +45,7 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; +import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer; import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView; import org.eclipse.ui.IEditorReference; import org.hamcrest.Matcher; @@ -572,6 +573,44 @@ public final class ConditionHelpers { return new TimeGraphIsReadyCondition(view, selectionRange, visibleTime); } + private static class XYViewerIsReadyCondition extends DefaultCondition { + + private TmfXYChartViewer fViewer; + private String fFailureMessage; + + private XYViewerIsReadyCondition(TmfXYChartViewer view) { + fViewer = view; + } + + @Override + public boolean test() throws Exception { + + if (fViewer.isDirty()) { + fFailureMessage = "Time graph is dirty"; + return false; + } + return true; + } + + @Override + public String getFailureMessage() { + return fFailureMessage; + } + } + + /** + * + * Wait until the XY chart viewer is ready. The XY chart viewer is + * considered ready when it is not updating. + * + * @param viewer + * the XY chart viewer + * @return ICondition for verification + */ + public static ICondition xyViewerIsReadyCondition(TmfXYChartViewer viewer) { + return new XYViewerIsReadyCondition(viewer); + } + private static class NumberOfEventsCondition extends DefaultCondition { private ITmfTrace fTrace; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfXYChartViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfXYChartViewer.java index 29ca3f9809..9511a29d41 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfXYChartViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfXYChartViewer.java @@ -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 // ------------------------------------------------------------------------ diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java index 10db54ba71..3030b00e4d 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java @@ -15,6 +15,7 @@ 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.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; import org.eclipse.core.runtime.IProgressMonitor; @@ -72,6 +73,8 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { private UpdateThread fUpdateThread; + private volatile AtomicInteger fDirty = new AtomicInteger(); + /** * Constructor * @@ -134,6 +137,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { */ protected void reinitialize() { fSeriesValues.clear(); + fDirty.incrementAndGet(); Thread thread = new Thread() { // Don't use TmfUiRefreshHandler (bug 467751) @Override @@ -148,6 +152,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { /* Delete the old series */ clearContent(); createSeries(); + fDirty.decrementAndGet(); } } }); @@ -185,6 +190,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { public void run() { LOGGER.info(() -> getLogMessage("UpdateDataStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$ updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor); + fDirty.decrementAndGet(); LOGGER.info(() -> getLogMessage("UpdateDataEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$ } }); @@ -227,6 +233,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { @Override protected void updateContent() { + fDirty.incrementAndGet(); getDisplay().asyncExec(new Runnable() { @Override public void run() { @@ -438,4 +445,16 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer { super.clearContent(); } + @Override + public boolean isDirty() { + boolean dirty = super.isDirty(); + + if (dirty) { + return dirty; + } + + // Check the specific dirtiness of this view + return fDirty.get() != 0; + } + } -- 2.34.1