427542: single click / double click in outline view

Single click now selects the node in the widget, a double click sets the
caret to the start of the node and gives focus to the widget.

Change-Id: I9bb4960ad4780cf363e4043ef6f29662c3fae290
Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DocumentOutlinePage.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DocumentOutlinePage.java
index f1d6389..3f8ee8b 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DocumentOutlinePage.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/outline/DocumentOutlinePage.java
@@ -19,6 +19,8 @@
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -245,6 +247,7 @@
 		document.addDocumentListener(documentListener);
 
 		treeViewer.addSelectionChangedListener(selectionListener);
+		treeViewer.addDoubleClickListener(doubleClickListener);
 	}
 
 	/**
@@ -317,13 +320,34 @@
 						// way to make sure we end up with the
 						// caret at the top of the viewport
 						vexWidget.moveTo(node.getEndPosition());
-						vexWidget.moveTo(node.getStartPosition().moveBy(1));
+						vexWidget.moveTo(node.getStartPosition().moveBy(1), true);
 					}
 				}
 			}
 		}
 	};
 
+	/**
+	 * Receives double click events from our TreeViewer. We simply give focus to the VexWidget here. The first click
+	 * already moved the caret to the selected element.
+	 */
+	private final IDoubleClickListener doubleClickListener = new IDoubleClickListener() {
+
+		@Override
+		public void doubleClick(final DoubleClickEvent event) {
+			if (treeViewer.getTree().isFocusControl()) {
+				final TreeItem[] selected = treeViewer.getTree().getSelection();
+				if (selected.length > 0) {
+					final INode node = (INode) selected[0].getData();
+					final VexWidget vexWidget = vexEditor.getVexWidget();
+					vexWidget.moveTo(node.getStartPosition().moveBy(1));
+					vexWidget.setFocus();
+				}
+			}
+		}
+
+	};
+
 	private final IVexEditorListener vexEditorListener = new EditorEventAdapter() {
 
 		@Override