Skip to content

Commit

Permalink
[559142] [Activity Explorer] Add the access to the current section in
Browse files Browse the repository at this point in the history
section predicates

Bug: 559142
Change-Id: Ic8532cfd5dfe50daf03bc3243395981a71a85eb2
Signed-off-by: Tu Ton <[email protected]>
  • Loading branch information
minhtutonthat authored and pdulth committed Oct 19, 2020
1 parent 849bca3 commit 7f53ee2
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;

public Image getImage() {
return image;
}
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 String getDescription() {
return description;
}
public String getDescription() {
return description;
}

/**
* 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;
}
/**
* Return true this activity is visible.
*/
public boolean isVisible() {

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() {
Expand All @@ -140,4 +143,8 @@ public String getLocalId() {
public String getPluginId() {
return pluginId;
}

public ActivityExplorerSection getSection() {
return section;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -379,7 +379,7 @@ public Set<ActivityExplorerSection> getSections() {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -270,7 +270,7 @@ public Set<String> getHandledViewpoint() {
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() {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -56,7 +57,7 @@ public class ActivityExplorerSection implements IVisibility, IOrdered, IProperty
*
* @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);
Expand All @@ -74,6 +75,7 @@ public ActivityExplorerSection(IConfigurationElement contributor) {
this.isFiltering = ActivityExplorerExtensionManager.getIsFiltering(contributor);
createActivities(contributor);
this.pluginId = contributor.getContributor().getName();
this.activityPage = activityPage;
}

/**
Expand All @@ -88,14 +90,15 @@ public ActivityExplorerSection(IConfigurationElement contributor) {
*/

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;
this.index = index;
this.isExpanded = isExpanded;
this.isFiltering = isFiltering;
this.activities.addAll(activities);
this.activityPage = activityPage;
}

private TreeSet<ExplorerActivity> activities;
Expand All @@ -113,7 +116,7 @@ private void createActivities(IConfigurationElement contributor) {
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();
Expand Down Expand Up @@ -197,6 +200,7 @@ public String getName() {
private IAction[] toolbarActions;
private Section widget;
private String pluginId;
private ActivityExplorerPage activityPage;

/**
* Return true if the section is defined as expanded.
Expand Down Expand Up @@ -425,4 +429,8 @@ public String getLocalId() {
public String getPluginId() {
return pluginId;
}

public ActivityExplorerPage getActivityExplorerPage() {
return activityPage;
}
}

0 comments on commit 7f53ee2

Please sign in to comment.