[559142] [Activity Explorer] Add the access to the current section in
section predicates

Bug: 559142
Change-Id: Ic8532cfd5dfe50daf03bc3243395981a71a85eb2
Signed-off-by: Tu Ton <minhtutonthat@gmail.com>
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/activities/ExplorerActivity.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/activities/ExplorerActivity.java
index ecf9c22..fac5069 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/activities/ExplorerActivity.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/activities/ExplorerActivity.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c)  2006, 2019 THALES GLOBAL SERVICES.
+ * Copyright (c)  2006, 2020 THALES GLOBAL SERVICES.
  * 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
@@ -13,6 +13,7 @@
 import org.eclipse.amalgam.explorer.activity.ui.ActivityExplorerActivator;
 import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.FormHelper;
 import org.eclipse.amalgam.explorer.activity.ui.api.editor.predicates.IPredicate;
+import org.eclipse.amalgam.explorer.activity.ui.api.editor.sections.ActivityExplorerSection;
 import org.eclipse.amalgam.explorer.activity.ui.internal.extension.point.manager.ActivityExplorerExtensionManager;
 import org.eclipse.amalgam.explorer.activity.ui.internal.intf.IOrdered;
 import org.eclipse.amalgam.explorer.activity.ui.internal.intf.IVisibility;
@@ -28,108 +29,110 @@
 
 public class ExplorerActivity implements IVisibility, IOrdered, IPluginContribution {
 
-	public ExplorerActivity(IConfigurationElement element_p) {
-		name = ActivityExplorerExtensionManager.getName(element_p);
-		description = ActivityExplorerExtensionManager.getDescription(element_p);
-		index = Integer.parseInt(ActivityExplorerExtensionManager.getIndex(element_p));
+  public ExplorerActivity(IConfigurationElement element_p, ActivityExplorerSection section) {
+    name = ActivityExplorerExtensionManager.getName(element_p);
+    description = ActivityExplorerExtensionManager.getDescription(element_p);
+    index = Integer.parseInt(ActivityExplorerExtensionManager.getIndex(element_p));
 
-		listener = ActivityExplorerExtensionManager.getActivityAdapter(element_p);
+    listener = ActivityExplorerExtensionManager.getActivityAdapter(element_p);
 
-		image = ActivityExplorerExtensionManager.getImage(element_p);
-		id = ActivityExplorerExtensionManager.getId(element_p);
-		predicate = ActivityExplorerExtensionManager.getPredicate(element_p);
-		pluginId = element_p.getContributor().getName();
-	}
+    image = ActivityExplorerExtensionManager.getImage(element_p);
+    id = ActivityExplorerExtensionManager.getId(element_p);
+    predicate = ActivityExplorerExtensionManager.getPredicate(element_p);
+    pluginId = element_p.getContributor().getName();
+    this.section = section;
+  }
 
-	public ExplorerActivity(String id, String name, IHyperlinkListener listener, IPredicate predicate, int index) {
+  public ExplorerActivity(String id, String name, IHyperlinkListener listener, IPredicate predicate, int index, ActivityExplorerSection section) {
 		super();
 		this.id = id;
 		this.name = name;
 		this.listener = listener;
 		this.predicate = predicate;
+		this.section = section;
 		setPosition(index);
-
 	}
 
-	public String getId() {
-		return id;
-	}
+  public String getId() {
+    return id;
+  }
 
-	public String getName() {
-		return name;
-	}
+  public String getName() {
+    return name;
+  }
 
-	public IHyperlinkListener getListener() {
-		return listener;
-	}
+  public IHyperlinkListener getListener() {
+    return listener;
+  }
 
-	private String pluginId;
-	private String id;
-	private String name;
-	private IHyperlinkListener listener;
-	private int index;
-	private Image image;
-	private String description;
-	private IPredicate predicate;
+  private String pluginId;
+  private String id;
+  private String name;
+  private IHyperlinkListener listener;
+  private int index;
+  private Image image;
+  private String description;
+  private IPredicate predicate;
+  private ActivityExplorerSection section;
 
-	public Image getImage() {
-		return image;
-	}
+  public Image getImage() {
+    return image;
+  }
 
-	public String getDescription() {
-		return description;
-	}
+  public String getDescription() {
+    return description;
+  }
 
-	/**
-	 * Return true this activity is visible.
-	 */
-	public boolean isVisible() {
+  /**
+   * Return true this activity is visible.
+   */
+  public boolean isVisible() {
 
-		boolean result = ActivityExplorerActivator.getDefault().getPreferenceStore().getBoolean(getId());
-		if (predicate != null) {
-			result &= predicate.isOk();
-		}
-		result &= !WorkbenchActivityHelper.filterItem(this);
-		return result;
-	}
+    boolean result = ActivityExplorerActivator.getDefault().getPreferenceStore().getBoolean(getId());
+    if (predicate != null) {
+      result &= predicate.isActivityOk(this);
+    }
+    result &= !WorkbenchActivityHelper.filterItem(this);
+    return result;
+  }
 
-	public IPredicate getPredicate() {
-		return predicate;
-	}
+  public IPredicate getPredicate() {
+    return predicate;
+  }
 
-	public int getPosition() {
-		return index;
-	}
+  public int getPosition() {
+    return index;
+  }
 
-	public void setPosition(int index_p) {
-		this.index = index_p;
+  public void setPosition(int index_p) {
+    this.index = index_p;
 
-	}
+  }
 
-	public Control init(Composite activityContainer_p, FormToolkit toolkit_p) {
-		widget = FormHelper.createLinkWithDescription(toolkit_p, activityContainer_p, image, name, null, description,
-				listener);
-		return widget;
+  public Control init(Composite activityContainer_p, FormToolkit toolkit_p) {
+    widget = FormHelper.createLinkWithDescription(toolkit_p, activityContainer_p, image, name, null, description,
+        listener);
+    return widget;
 
-	}
+  }
 
-	ImageHyperlink widget;
+  ImageHyperlink widget;
 
-	public ImageHyperlink getWidget() {
-		return widget;
-	}
+  public ImageHyperlink getWidget() {
+    return widget;
+  }
 
-	public void dispose() {
-		// dispose the section widget
-		if (widget != null && !widget.isDisposed())
-			widget.dispose();
+  public void dispose() {
+    // dispose the section widget
+    if (widget != null && !widget.isDisposed())
+      widget.dispose();
 
-	}
+  }
 
-	public int compareTo(IOrdered arg0) {
-		return new Integer(getPosition()).compareTo(new Integer(arg0.getPosition()));
+  public int compareTo(IOrdered arg0) {
+    return new Integer(getPosition()).compareTo(new Integer(arg0.getPosition()));
 
-	}
+  }
 
   @Override
   public String getLocalId() {
@@ -140,4 +143,8 @@
   public String getPluginId() {
     return pluginId;
   }
+  
+  public ActivityExplorerSection getSection() {
+    return section;
+  }
 }
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/ActivityExplorerPage.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/ActivityExplorerPage.java
index 2641721..3b18f69 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/ActivityExplorerPage.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/ActivityExplorerPage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c)  2006, 2017 THALES GLOBAL SERVICES.
+ * Copyright (c)  2006, 2020 THALES GLOBAL SERVICES.
  * 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
@@ -379,7 +379,7 @@
   protected void handleContributedSectionsFor(IConfigurationElement contributor) {
 
 		  // create a Activity Explorer section
-		  ActivityExplorerSection section = new ActivityExplorerSection(contributor) {
+		  ActivityExplorerSection section = new ActivityExplorerSection(contributor, this) {
 			  @Override
 			  protected IAction[] getToolBarActions() {
 				  IAction[] toolbarActions = new IAction[] { new DescriptionAction(ActivityExplorerPage.this.getSite().getShell(), description)
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/BasicSessionActivityExplorerPage.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/BasicSessionActivityExplorerPage.java
index 5c4c7fe..1187596 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/BasicSessionActivityExplorerPage.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/BasicSessionActivityExplorerPage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c)  2006, 2015 THALES GLOBAL SERVICES.
+ * Copyright (c)  2006, 2020 THALES GLOBAL SERVICES.
  * 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
@@ -270,7 +270,7 @@
   protected void handleContributedSectionsFor(IConfigurationElement contributor_p) {
 
 	  // create the session
-	  ActivityExplorerSection newSection = new ActivityExplorerSection(contributor_p) {
+	  ActivityExplorerSection newSection = new ActivityExplorerSection(contributor_p, this) {
 		  @Override
 		  protected IAction[] getToolBarActions() {
 
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/predicates/IPredicate.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/predicates/IPredicate.java
index 6285050..817b85e 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/predicates/IPredicate.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/predicates/IPredicate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c)  2006, 2015 THALES GLOBAL SERVICES.
+ * Copyright (c)  2006, 2020 THALES GLOBAL SERVICES.
  * 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,8 +10,20 @@
  *******************************************************************************/
 package org.eclipse.amalgam.explorer.activity.ui.api.editor.predicates;
 
+import org.eclipse.amalgam.explorer.activity.ui.api.editor.activities.ExplorerActivity;
+import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.CommonActivityExplorerPage;
+
 public interface IPredicate {
 
-	public boolean isOk();
+  public default boolean isOk() {
+    return true;
+  }
+  
+	public default boolean isActivityOk(ExplorerActivity activity) {
+	  return true;
+	}
 
+	public default boolean isPageOk(CommonActivityExplorerPage page) {
+    return true;
+  }
 }
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/sections/ActivityExplorerSection.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/sections/ActivityExplorerSection.java
index 34111d6..c29734e 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/sections/ActivityExplorerSection.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/sections/ActivityExplorerSection.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c)  2006, 2019 THALES GLOBAL SERVICES.
+ * Copyright (c)  2006, 2020 THALES GLOBAL SERVICES.
  * 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
@@ -20,6 +20,7 @@
 
 import org.eclipse.amalgam.explorer.activity.ui.ActivityExplorerActivator;
 import org.eclipse.amalgam.explorer.activity.ui.api.editor.activities.ExplorerActivity;
+import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.ActivityExplorerPage;
 import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.FormHelper;
 import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.HTMLHelper;
 import org.eclipse.amalgam.explorer.activity.ui.api.manager.ActivityExplorerManager;
@@ -56,7 +57,7 @@
 	 * 
 	 * @param contributor
 	 */
-	public ActivityExplorerSection(IConfigurationElement contributor) {
+	public ActivityExplorerSection(IConfigurationElement contributor, ActivityExplorerPage activityPage) {
 		this.id = ActivityExplorerExtensionManager.getId(contributor);
 		this.name = ActivityExplorerExtensionManager.getName(contributor);
 		this.isExpanded = ActivityExplorerExtensionManager.getIsExpanded(contributor);
@@ -74,6 +75,7 @@
 		this.isFiltering = ActivityExplorerExtensionManager.getIsFiltering(contributor);
 		createActivities(contributor);
 		this.pluginId = contributor.getContributor().getName();
+		this.activityPage = activityPage;
 	}
 
 	/**
@@ -88,7 +90,7 @@
 	 */
 
 	public ActivityExplorerSection(String id, String name, int index, boolean isExpanded, boolean isFiltering,
-			String description, List<ExplorerActivity> activities) {
+			String description, List<ExplorerActivity> activities, ActivityExplorerPage activityPage) {
 		super();
 		this.id = id;
 		this.name = name;
@@ -96,6 +98,7 @@
 		this.isExpanded = isExpanded;
 		this.isFiltering = isFiltering;
 		this.activities.addAll(activities);
+		this.activityPage = activityPage;
 	}
 
 	private TreeSet<ExplorerActivity> activities;
@@ -113,7 +116,7 @@
 		List<IConfigurationElement> activities = ActivityExplorerExtensionManager.getActivities(contributor);
 		for (IConfigurationElement element : activities) {
 			try {
-				this.activities.add(new ExplorerActivity(element));
+				this.activities.add(new ExplorerActivity(element, this));
 			} catch (NumberFormatException e){
 
 				StringBuilder message = new StringBuilder();
@@ -197,6 +200,7 @@
 	private IAction[] toolbarActions;
 	private Section widget;
 	private String pluginId;
+	private ActivityExplorerPage activityPage;
 
 	/**
 	 * Return true if the section is defined as expanded.
@@ -425,4 +429,8 @@
   public String getPluginId() {
     return pluginId;
   }
+  
+  public ActivityExplorerPage getActivityExplorerPage() {
+    return activityPage;
+  }
 }