import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.linuxtools.internal.lttng2.ust.core.memoryusage.UstMemoryStrings;
import org.eclipse.linuxtools.internal.tmf.core.Activator;
import org.eclipse.linuxtools.lttng2.ust.ui.analysis.memory.UstMemoryAnalysisModule;
}
@Override
- protected void updateData(long start, long end, int nb) {
+ protected void updateData(long start, long end, int nb, IProgressMonitor monitor) {
try {
if (getTrace() == null || fModule == null) {
return;
*/
double yvalue = 0.0;
for (int i = 0; i < xvalues.length; i++) {
+ if (monitor.isCanceled()) {
+ return;
+ }
double x = xvalues[i];
long time = (long) x + offset;
// make sure that time is in the trace range after double to
import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.ui.viewers.xycharts.TmfChartTimeStampFormat;
import org.eclipse.linuxtools.tmf.ui.viewers.xycharts.TmfXYChartViewer;
private double[] fXValues;
private double fResolution;
+ private UpdateThread fUpdateThread;
+
/**
* Constructor
*
}
+ private class UpdateThread extends Thread {
+ private final IProgressMonitor fMonitor;
+ private final int fNumRequests;
+
+ public UpdateThread(int numRequests) {
+ super("Line chart update"); //$NON-NLS-1$
+ fNumRequests = numRequests;
+ fMonitor = new NullProgressMonitor();
+ }
+
+ @Override
+ public void run() {
+ updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
+ updateThreadFinished(this);
+ }
+
+ public void cancel() {
+ fMonitor.setCanceled(true);
+ }
+ }
+
+ private synchronized void newUpdateThread() {
+ cancelUpdate();
+ final int numRequests = (int) (getSwtChart().getPlotArea().getBounds().width * fResolution);
+ fUpdateThread = new UpdateThread(numRequests);
+ fUpdateThread.start();
+ }
+
+ private synchronized void updateThreadFinished(UpdateThread thread) {
+ if (thread == fUpdateThread) {
+ fUpdateThread = null;
+ }
+ }
+
+ /**
+ * Cancels the currently running update thread. It is automatically called
+ * when the content is updated, but child viewers may want to call it
+ * manually to do some operations before calling
+ * {@link TmfCommonXLineChartViewer#updateContent}
+ */
+ protected synchronized void cancelUpdate() {
+ if (fUpdateThread != null) {
+ fUpdateThread.cancel();
+ }
+ }
+
@Override
protected void updateContent() {
getDisplay().asyncExec(new Runnable() {
-
@Override
public void run() {
- final int numRequests = (int) (getSwtChart().getPlotArea().getBounds().width * fResolution);
- Thread thread = new Thread("Line chart update") { //$NON-NLS-1$
- @Override
- public void run() {
- updateData(getWindowStartTime(), getWindowEndTime(), numRequests);
- }
- };
- thread.start();
+ newUpdateThread();
}
});
}
* The end time of the range
* @param nb
* The number of 'points' in the chart.
+ * @param monitor
+ * The progress monitor object
*/
- protected abstract void updateData(long start, long end, int nb);
+ protected abstract void updateData(long start, long end, int nb, IProgressMonitor monitor);
/**
* Set the data for a given series of the graph. The series does not need to