Add SelectionProvider behavior to the Interpreter view

In order to manage TreeItem selection in the results section of the
Interpreter View in other plugins, the Interpreter View now implements
ISelectionProvider to be able to access the selected results easier.

Change-Id: I8616ee7620ee25baef368e5bda21ae3b9a7625c4
Signed-off-by: Glenn Plouhinec <glenn.plouhinec@obeo.fr>
diff --git a/plugins/org.eclipse.acceleo.ui.interpreter/src/org/eclipse/acceleo/ui/interpreter/view/InterpreterView.java b/plugins/org.eclipse.acceleo.ui.interpreter/src/org/eclipse/acceleo/ui/interpreter/view/InterpreterView.java
index f6d254d..2aa410d 100644
--- a/plugins/org.eclipse.acceleo.ui.interpreter/src/org/eclipse/acceleo/ui/interpreter/view/InterpreterView.java
+++ b/plugins/org.eclipse.acceleo.ui.interpreter/src/org/eclipse/acceleo/ui/interpreter/view/InterpreterView.java
@@ -104,6 +104,7 @@
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeSelection;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -166,7 +167,7 @@
  * 
  * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
  */
-public class InterpreterView extends ViewPart {
+public class InterpreterView extends ViewPart implements ISelectionProvider {
 	/** Prefix of the messages corresponding to compilation problems. */
 	protected static final String COMPILATION_MESSAGE_PREFIX = "compilation.message"; //$NON-NLS-1$
 
@@ -713,7 +714,7 @@
 		IContextService contextService = (IContextService)site.getService(IContextService.class);
 		contextActivationToken = contextService.activateContext(INTERPRETER_VIEW_CONTEXT_ID);
 
-		eobjectSelectionListener = new NotifierSelectionListener();
+		eobjectSelectionListener = new NotifierSelectionListener(this);
 		activationListener = new ActivationListener(this);
 		site.getPage().addPartListener(activationListener);
 		site.getPage().addSelectionListener(eobjectSelectionListener);
@@ -1214,6 +1215,8 @@
 
 		toolkit.paintBordersFor(resultSectionBody);
 		resultSection.setClient(resultSectionBody);
+
+		getSite().setSelectionProvider(this.resultViewer);
 	}
 
 	/**
@@ -2414,11 +2417,20 @@
 	 * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
 	 */
 	private class NotifierSelectionListener implements ISelectionListener {
+	    
+	    /**
+	     * This interpreter view.
+	     */
+		private final InterpreterView view;
+
 		/**
-		 * Increases visibility of the default constructor.
+		 * Constructs this listener.
+		 * 
+		 * @param view
+		 *            The view on which the selection should not be triggered.
 		 */
-		NotifierSelectionListener() {
-			// Increases visibility
+		NotifierSelectionListener(InterpreterView view) {
+			this.view = view;
 		}
 
 		/**
@@ -2429,7 +2441,7 @@
 		 */
 		@SuppressWarnings("unchecked")
 		public void selectionChanged(IWorkbenchPart part, ISelection selection) {
-			if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
+			if (!selection.isEmpty() && selection instanceof IStructuredSelection && part != this.view) {
 				boolean cleared = false;
 				final Iterator<Object> selectionIterator = ((IStructuredSelection)selection).iterator();
 				while (selectionIterator.hasNext()) {
@@ -2914,4 +2926,32 @@
 			}
 		}
 	}
+
+	public void addSelectionChangedListener(ISelectionChangedListener listener) {
+		if (resultViewer != null) {
+			this.resultViewer.addSelectionChangedListener(listener);
+		}
+
+	}
+
+	public ISelection getSelection() {
+		if (resultViewer != null) {
+			return this.resultViewer.getSelection();
+		} else {
+			return null;
+		}
+	}
+
+	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+		if (resultViewer != null) {
+			this.resultViewer.removeSelectionChangedListener(listener);
+		}
+
+	}
+
+	public void setSelection(ISelection selection) {
+		if (resultViewer != null) {
+			this.resultViewer.setSelection(selection);
+		}
+	}
 }