Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / common / AbsTimeUpdateView.java
index 86a6d23ad9056a234ca942f7884149d3f465cdf6..9fab6d2a3692d050289d997bc096b1f3c2a2a0de 100644 (file)
@@ -8,33 +8,36 @@
  * 
  * Contributors:
  *   Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *   Bernd Hufmann - Bug fixes
  *******************************************************************************/
 package org.eclipse.linuxtools.lttng.ui.views.common;
 
 import java.util.Arrays;
 
-import org.eclipse.linuxtools.lttng.LttngConstants;
-import org.eclipse.linuxtools.lttng.control.LttngCoreProviderFactory;
-import org.eclipse.linuxtools.lttng.control.LttngSyntheticEventProvider;
-import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent;
-import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
-import org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest;
-import org.eclipse.linuxtools.lttng.request.IRequestStatusListener;
-import org.eclipse.linuxtools.lttng.request.LttngSyntEventRequest;
-import org.eclipse.linuxtools.lttng.request.RequestCompletedSignal;
-import org.eclipse.linuxtools.lttng.request.RequestStartedSignal;
-import org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor;
+import org.eclipse.linuxtools.lttng.core.LttngConstants;
+import org.eclipse.linuxtools.lttng.core.control.LttngCoreProviderFactory;
+import org.eclipse.linuxtools.lttng.core.control.LttngSyntheticEventProvider;
+import org.eclipse.linuxtools.lttng.core.event.LttngSyntheticEvent;
+import org.eclipse.linuxtools.lttng.core.event.LttngTimestamp;
+import org.eclipse.linuxtools.lttng.core.request.ILttngSyntEventRequest;
+import org.eclipse.linuxtools.lttng.core.request.IRequestStatusListener;
+import org.eclipse.linuxtools.lttng.core.request.LttngSyntEventRequest;
+import org.eclipse.linuxtools.lttng.core.request.RequestCompletedSignal;
+import org.eclipse.linuxtools.lttng.core.request.RequestStartedSignal;
+import org.eclipse.linuxtools.lttng.core.state.evProcessor.ITransEventProcessor;
 import org.eclipse.linuxtools.lttng.ui.TraceDebug;
 import org.eclipse.linuxtools.lttng.ui.model.trange.ItemContainer;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
-import org.eclipse.linuxtools.tmf.request.ITmfDataRequest.ExecutionType;
-import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.signal.TmfRangeSynchSignal;
-import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
-import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
+import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer;
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent;
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent;
@@ -71,7 +74,7 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
         * Number of events before a GUI refresh
         */
        protected static final Long INPUT_CHANGED_REFRESH = 75000L;
-       private static final long DEFAULT_OFFSET = 0L;
+       private static final long DEFAULT_OFFSET = 0;
 
        protected boolean synch = true; // time synchronization, used to be an option
        protected ITimeAnalysisViewer tsfviewer = null;
@@ -102,6 +105,15 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
            return INPUT_CHANGED_REFRESH;
        }
 
+   /**
+     * Cancel the ongoing request if another experiment is being selected
+     * @param experimentDisposedSignal
+     */
+    @TmfSignalHandler
+    public void experimentDisposed(TmfExperimentDisposedSignal<? extends TmfEvent> experimentDisposedSignal) {
+        fProvider.conditionallyCancelRequests();
+    }
+       
        /*
         * (non-Javadoc)
         * 
@@ -185,17 +197,39 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
                if (synch) {
                        Object source = signal.getSource();
                        if (signal != null && source != null && source != this) {
-                               // Internal value is expected in nano seconds.
-                               long selectedTime = signal.getCurrentTime().getValue();
-                               if (tsfviewer != null) {
-                                       tsfviewer.setSelectedTime(selectedTime, true, source);
-
-                                       ParamsUpdater paramUpdater = getParamsUpdater();
-                                   Long savedSelTime = paramUpdater.getSelectedTime();
-                                   if ((savedSelTime == null) || (savedSelTime != selectedTime)) {
-                                   // Update the parameter updater to save the selected time
-                                   paramUpdater.setSelectedTime(selectedTime);   
-                               }
+
+                               if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) {
+
+                                       // Check for GUI thread
+                                       if (Display.getCurrent() != null) {
+                                               // GUI thread - execute update right away.
+                                               
+                                               // Internal value is expected in nano seconds.
+                                               long selectedTime = signal.getCurrentTime().getValue();
+                                               if (tsfviewer != null) {
+                                                       tsfviewer.setSelectedTime(selectedTime, true, source);
+
+                                                       ParamsUpdater paramUpdater = getParamsUpdater();
+                                                   Long savedSelTime = paramUpdater.getSelectedTime();
+                                                   if ((savedSelTime == null) || (savedSelTime != selectedTime)) {
+                                                   // Update the parameter updater to save the selected time
+                                                   paramUpdater.setSelectedTime(selectedTime);   
+                                               }
+                                               }
+                                       } else {
+                                               // Perform the updates on the UI thread
+                                               
+                                               // We need to clone the timestamp in the signal so that it won't be overwritten duo to multipe thread access 
+                                               final TmfTimeSynchSignal savedSignal = new TmfTimeSynchSignal(signal.getSource(), signal.getCurrentTime().clone());
+                                               tsfviewer.getControl().getDisplay().asyncExec(new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               if ((tsfviewer != null) && (!tsfviewer.getControl().isDisposed())) {
+                                                                       synchToTime(savedSignal);
+                                                               }
+                                                       }
+                                               });
+                                       }
                                }
                        }
                }
@@ -221,7 +255,7 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
                                }
 
                                // Clearing of process data is configurable
-                               dataRequest(trange, experiment.getTimeRange(), clearingData, ExecutionType.FOREGROUND);
+                               eventRequest(trange, experiment.getTimeRange(), clearingData, ExecutionType.FOREGROUND);
                        }
                }
        }
@@ -336,13 +370,30 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
        /**
         * @param zoomedTRange
         * @param experimentTRange
+        * @param clearingData
         * @param execType 
         */
-       public void dataRequest(TmfTimeRange zoomedTRange,
-                       TmfTimeRange experimentTRange, boolean clearingData, ExecutionType execType) {
+       public void eventRequest(TmfTimeRange zoomedTRange, TmfTimeRange experimentTRange, boolean clearingData, ExecutionType execType) {
 
                // timeRange is the Experiment time range
-                boolean sent = processDataRequest(zoomedTRange, experimentTRange, clearingData, execType);
+               boolean sent = processDataRequest(zoomedTRange, experimentTRange, DEFAULT_OFFSET, TmfDataRequest.ALL_DATA, clearingData, execType);
+
+               if (sent) {
+                       waitCursor(true);
+               }
+       }
+
+       /**
+        * @param offset
+        * @param nbRequested
+        * @param startTime
+        * @param clearingData
+        * @param execType 
+        */
+       public void eventRequest(long offset, TmfTimeRange range, boolean clearingData, ExecutionType execType) {
+
+               // timeRange is the Experiment time range
+               boolean sent = processDataRequest(range, null, offset, TmfDataRequest.ALL_DATA, clearingData, execType);
 
                if (sent) {
                        waitCursor(true);
@@ -376,18 +427,17 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
         * @return
         */
        private boolean processDataRequest(TmfTimeRange requestTrange,
-                       TmfTimeRange experimentTRange, boolean clearingData, ExecutionType execType) {
+                       TmfTimeRange experimentTRange, long offset, int nbRequested, boolean clearingData, ExecutionType execType) {
                // Validate input
-               if (requestTrange == null || experimentTRange == null) {
+               if (requestTrange == null) {
                        TraceDebug.debug("Invalid input"); //$NON-NLS-1$
                        return false;
                }
 
                // Cancel the currently executing request before starting a new one
                fProvider.conditionallyCancelRequests();
-
                fCurrentRequest = new LttngSyntEventRequest(
-                               requestTrange, DEFAULT_OFFSET, TmfDataRequest.ALL_DATA,
+                               requestTrange, offset, nbRequested,
                                LttngConstants.DEFAULT_BLOCK_SIZE, this, experimentTRange, getEventProcessor(), 
                                TmfExperiment.getCurrentExperiment().getName(), execType) {
        
@@ -613,6 +663,7 @@ public abstract class AbsTimeUpdateView extends TmfView implements IRequestStatu
         * @param complete
         *            true: yes, false: partial update
         */
+       @SuppressWarnings("deprecation")
        protected void modelInputChanged(ILttngSyntEventRequest request, boolean complete) {
                long experimentStartTime = -1;
                long experimentEndTime = -1;
This page took 0.027023 seconds and 5 git commands to generate.