[509735] Get the session from the root EObject instead of a global singleton

This makes it possible for AbstractHyperlinkAdapter to be executed
from other contexts than the ActicityExplorer editor (e.g. the Sirius
aird editor).

Bug: 509735
Change-Id: I99d5b0402b4ea78603bcec78033e3bd4320930e9
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractHyperlinkAdapter.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractHyperlinkAdapter.java
index a501a0b..bc31c34 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractHyperlinkAdapter.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractHyperlinkAdapter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c)  2006, 2015 THALES GLOBAL SERVICES.
+ * Copyright (c)  2006, 2017 THALES GLOBAL SERVICES and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,7 +10,6 @@
  *******************************************************************************/
 package org.eclipse.amalgam.explorer.activity.ui.api.hyperlinkadapter;
 
-import org.eclipse.amalgam.explorer.activity.ui.api.manager.ActivityExplorerManager;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.sirius.business.api.session.Session;
 import org.eclipse.ui.forms.events.HyperlinkAdapter;
@@ -18,57 +17,44 @@
 
 /**
  * Base class to implement an {@link HyperlinkAdapter} in Modeling context.
- * 
+ *
  */
 public abstract class AbstractHyperlinkAdapter extends HyperlinkAdapter {
-	/**
-	 * Root Element of the Semantic model.
-	 */
-	protected EObject _root;
+    /**
+     * Root Element of the Semantic model.
+     */
+    protected final EObject root;
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param root
-	 */
-	public AbstractHyperlinkAdapter(EObject root) {
-		_root = root;
-	}
+    /**
+     * Constructor.
+     *
+     * @param root
+     */
+    public AbstractHyperlinkAdapter(EObject root) {
+        this.root = root;
+    }
 
-	/**
-   * Constructor.
-   * 
-   * @param root
-   */
-	@Deprecated
-  public AbstractHyperlinkAdapter(EObject root, Session session) {
-    this(root);
-  }
-	
-	/**
-	 * Get the model element that the run is performed against.<br>
-	 * 
-	 * @param root
-	 * @return
-	 */
-	protected EObject getModelElement(EObject root) {
-		return _root;
-	}
+    /**
+     * Get the model element that the run is performed against.<br>
+     *
+     * @param root
+     * @return
+     */
+    protected EObject getModelElement(EObject root) {
+        return this.root;
+    }
 
-	/**
-	 * @see org.eclipse.ui.forms.events.HyperlinkAdapter#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
-	 */
-	@Override
-	public void linkActivated(HyperlinkEvent event) {
-		linkPressed(event, _root, ActivityExplorerManager.INSTANCE.getSession());
-	}
+    @Override
+    public void linkActivated(HyperlinkEvent event) {
+        Session.of(root).ifPresent(s -> linkPressed(event, root, s));
+    }
 
-	/**
-	 * Called when link is activated i.e pressed by the end-user.
-	 * 
-	 * @param event
-	 * @param root
-	 * @param session
-	 */
-	protected abstract void linkPressed(HyperlinkEvent event, EObject root, Session session);
+    /**
+     * Called when link is activated i.e pressed by the end-user.
+     *
+     * @param event
+     * @param root
+     * @param session
+     */
+    protected abstract void linkPressed(HyperlinkEvent event, EObject root, Session session);
 }