tmf: Bug 468867: Time graph listener notifier interference from ext sync
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 29 May 2015 20:37:20 +0000 (16:37 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 10 Jun 2015 17:00:10 +0000 (13:00 -0400)
Change-Id: Ibf072ff1bcd322dedcd3479cb2d08d051c332d50
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/49009
Reviewed-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java

index 7e1ec6cc1c1d7016496522df4d8bd05475387032..7ec110db06ed6cd695b9aa63dbf3b2dea70c1995 100644 (file)
@@ -136,7 +136,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     private Action fFollowArrowBwdAction;
 
     private ListenerNotifier fListenerNotifier;
-    private final Object fListenerNotifierLock = new Object();
 
     private Composite fTimeAlignedComposite;
 
@@ -157,28 +156,27 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
                     return;
                 }
             }
-            synchronized (fListenerNotifierLock) {
-                fListenerNotifier = null;
-            }
-            if (!isInterrupted()) {
-                Display.getDefault().asyncExec(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (fDataViewer.isDisposed()) {
-                            return;
-                        }
-                        if (fSelectionChanged) {
-                            fireSelectionChanged(fSelectedEntry);
-                        }
-                        if (fTimeRangeUpdated) {
-                            fireTimeRangeUpdated(fTime0, fTime1);
-                        }
-                        if (fTimeSelected) {
-                            fireTimeSelected(fSelectionBegin, fSelectionEnd);
-                        }
+            Display.getDefault().asyncExec(new Runnable() {
+                @Override
+                public void run() {
+                    if (fListenerNotifier != ListenerNotifier.this) {
+                        return;
                     }
-                });
-            }
+                    fListenerNotifier = null;
+                    if (ListenerNotifier.this.isInterrupted() || fDataViewer.isDisposed()) {
+                        return;
+                    }
+                    if (fSelectionChanged) {
+                        fireSelectionChanged(fSelectedEntry);
+                    }
+                    if (fTimeRangeUpdated) {
+                        fireTimeRangeUpdated(fTime0, fTime1);
+                    }
+                    if (fTimeSelected) {
+                        fireTimeSelected(fSelectionBegin, fSelectionEnd);
+                    }
+                }
+            });
         }
 
         public void selectionChanged() {
@@ -195,6 +193,18 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             fTimeSelected = true;
             fLastUpdateTime = System.currentTimeMillis();
         }
+
+        public boolean hasSelectionChanged() {
+            return fSelectionChanged;
+        }
+
+        public boolean hasTimeRangeUpdated() {
+            return fTimeRangeUpdated;
+        }
+
+        public boolean hasTimeSelected() {
+            return fTimeSelected;
+        }
     }
 
     /**
@@ -254,7 +264,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     public void setInput(Object inputElement) {
         fInputElement = inputElement;
         ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(inputElement);
-
+        fListenerNotifier = null;
         if (fTimeGraphCtrl != null) {
             setTimeRange(input);
             setTopIndex(0);
@@ -740,6 +750,10 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
 
     @Override
     public void setStartFinishTime(long time0, long time1) {
+        /* if there is a pending time range, ignore this one */
+        if (fListenerNotifier != null && fListenerNotifier.hasTimeRangeUpdated()) {
+            return;
+        }
         fTime0 = time0;
         if (fTime0 < fTime0Bound) {
             fTime0 = fTime0Bound;
@@ -776,6 +790,10 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
 
     @Override
     public void setSelectedTime(long time, boolean ensureVisible) {
+        /* if there is a pending time selection, ignore this one */
+        if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) {
+            return;
+        }
         setSelectedTimeInt(time, ensureVisible, false);
     }
 
@@ -799,6 +817,10 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
 
     @Override
     public void setSelectionRange(long beginTime, long endTime) {
+        /* if there is a pending time selection, ignore this one */
+        if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) {
+            return;
+        }
         fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
         fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
         fTimeGraphCtrl.redraw();
@@ -957,13 +979,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     }
 
     private void notifySelectionListeners() {
-        synchronized (fListenerNotifierLock) {
-            if (fListenerNotifier == null) {
-                fListenerNotifier = new ListenerNotifier();
-                fListenerNotifier.start();
-            }
-            fListenerNotifier.selectionChanged();
+        if (fListenerNotifier == null) {
+            fListenerNotifier = new ListenerNotifier();
+            fListenerNotifier.start();
         }
+        fListenerNotifier.selectionChanged();
     }
 
     private void fireSelectionChanged(ITimeGraphEntry selection) {
@@ -995,13 +1015,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     }
 
     private void notifyTimeListeners() {
-        synchronized (fListenerNotifierLock) {
-            if (fListenerNotifier == null) {
-                fListenerNotifier = new ListenerNotifier();
-                fListenerNotifier.start();
-            }
-            fListenerNotifier.timeSelected();
+        if (fListenerNotifier == null) {
+            fListenerNotifier = new ListenerNotifier();
+            fListenerNotifier.start();
         }
+        fListenerNotifier.timeSelected();
     }
 
     private void fireTimeSelected(long startTime, long endTime) {
@@ -1033,13 +1051,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
     }
 
     private void notifyRangeListeners() {
-        synchronized (fListenerNotifierLock) {
-            if (fListenerNotifier == null) {
-                fListenerNotifier = new ListenerNotifier();
-                fListenerNotifier.start();
-            }
-            fListenerNotifier.timeRangeUpdated();
+        if (fListenerNotifier == null) {
+            fListenerNotifier = new ListenerNotifier();
+            fListenerNotifier.start();
         }
+        fListenerNotifier.timeRangeUpdated();
     }
 
     private void fireTimeRangeUpdated(long startTime, long endTime) {
@@ -1103,6 +1119,10 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The trace that was selected
      */
     public void setSelection(ITimeGraphEntry trace) {
+        /* if there is a pending selection, ignore this one */
+        if (fListenerNotifier != null && fListenerNotifier.hasSelectionChanged()) {
+            return;
+        }
         fSelectedEntry = trace;
         fTimeGraphCtrl.selectItem(trace, false);
         adjustVerticalScrollBar();
This page took 0.030255 seconds and 5 git commands to generate.