442629: remove watchdog thread

Change-Id: Iff011a976a68907bad4b9014aaf6e7bb785a63a2
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=442629
Signed-off-by: Guy Perron <guy.perron@ericsson.com>
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
index 0b876cc..9947f58 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
@@ -56,7 +56,7 @@
 
 /**
  * Manages annotation models for compare viewers.
- * 
+ *
  * @author Thomas Ehrnhoefer
  * @author Steffen Pingel
  * @author Guy Perron
@@ -67,10 +67,6 @@
 		LEFT_SIDE, RIGHT_SIDE
 	}
 
-	private static final int INTERRUPT_INTERVAL = 16;
-
-	private static final int PAUSE_DELAY = 250;
-
 	private static String KEY_ANNOTAION_SUPPORT = ReviewItemSetCompareEditorInput.class.getName();
 
 	private CommentPopupDialog commentPopupDialog = null;
@@ -84,10 +80,6 @@
 		return support;
 	}
 
-	private Thread watchDog = null;
-
-	private boolean sentinel = false;
-
 	public class MonitorObject {
 	};
 
@@ -186,7 +178,7 @@
 
 	/**
 	 * Jumps to the next annotation according to the given direction.
-	 * 
+	 *
 	 * @param direction
 	 *            the search direction
 	 * @return the selected annotation or <code>null</code> if none
@@ -334,17 +326,8 @@
 		LineRange range = new LineRange(p.x + 1, p.y);
 
 		if (commentPopupDialog != null) {
-			if (watchDog != null) {
-				try {
-					synchronized (myMonitorObject) {
-						sentinel = true;
-						commentPopupDialog.dispose();
-						myMonitorObject.wait();
-					}
-				} catch (InterruptedException e) {
-					StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Error destroying dialog", e)); //$NON-NLS-1$
-				}
-			}
+			commentPopupDialog.dispose();
+			commentPopupDialog = null;
 		}
 
 		commentPopupDialog = new CommentPopupDialog(ReviewsUiPlugin.getDefault()
@@ -362,39 +345,8 @@
 		location.y = location.y + (sourceViewer.getViewportHeight() / 2);
 		commentPopupDialog.setLocation(location);
 		commentPopupDialog.open();
+		commentPopupDialog.setFocus();
 
-		watchDog = new Thread(new Runnable() {
-			public void run() {
-				try {
-					for (int x = 0; x < INTERRUPT_INTERVAL; x++) {
-						if (sentinel) {
-							Thread.currentThread().interrupt();
-							break;
-						}
-						Thread.sleep(PAUSE_DELAY);
-					}
-				} catch (Exception e) {
-					StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID,
-							"Error interrupting thread", e)); //$NON-NLS-1$
-				}
-				if (!sentinel) {
-					Display.getDefault().asyncExec(new Runnable() {
-						public void run() {
-							if (commentPopupDialog != null) {
-								commentPopupDialog.dispose();
-								commentPopupDialog = null;
-							}
-						}
-					});
-				}
-				synchronized (myMonitorObject) {
-					myMonitorObject.notify();
-				}
-			}
-		});
-		sentinel = false;
-
-		watchDog.start();
 		widget.setRedraw(true);
 	}
 
@@ -454,7 +406,7 @@
 		return false;
 	}
 
-	// adapted from {@link AbstractTextEditor#selectAndReveal(int, int)}
+// adapted from {@link AbstractTextEditor#selectAndReveal(int, int)}
 	protected void adjustHighlightRange(SourceViewer sourceViewer, int offset, int length) {
 		if (sourceViewer instanceof ITextViewerExtension5) {
 			ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
@@ -464,7 +416,7 @@
 		}
 	}
 
-	// adapted from {@link AbstractTextEditor#selectAndReveal(int, int)}
+// adapted from {@link AbstractTextEditor#selectAndReveal(int, int)}
 	private boolean isVisible(SourceViewer viewer, int offset, int length) {
 		if (viewer instanceof ITextViewerExtension5) {
 			ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
@@ -509,7 +461,7 @@
 	/**
 	 * Returns the annotation closest to the given range respecting the given direction. If an annotation is found, the
 	 * annotations current position is copied into the provided annotation position.
-	 * 
+	 *
 	 * @param viewer
 	 *            the viewer
 	 * @param direction
@@ -558,7 +510,7 @@
 					&& p.offset + p.getLength() == offset + length) {// || p.includes(offset)) {
 				if (containingAnnotation == null
 						|| (direction == Direction.FORWARDS && p.length >= containingAnnotationPosition.length || direction == Direction.BACKWARDS
-								&& p.length >= containingAnnotationPosition.length)) {
+						&& p.length >= containingAnnotationPosition.length)) {
 					containingAnnotation = a;
 					containingAnnotationPosition = p;
 					currentAnnotation = p.length == length;