Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2017-08-08 16:16:11 +0000
committerPierre-Charles David2017-08-17 13:28:59 +0000
commit87ea675af5108bf0ed8db6edfa2fe946847288ef (patch)
tree926dae5a7826d3eeeace797e18da114006af308a
parentc5d0c7dac0b9233666d74511861d1c73f0a4bde2 (diff)
downloadorg.eclipse.amalgam-87ea675af5108bf0ed8db6edfa2fe946847288ef.tar.gz
org.eclipse.amalgam-87ea675af5108bf0ed8db6edfa2fe946847288ef.tar.xz
org.eclipse.amalgam-87ea675af5108bf0ed8db6edfa2fe946847288ef.zip
[509735] Cleanup ActivityExplorerSection class
Bug: 509735 Change-Id: Ie44191b9579c005550fefa6a3b6f87296d3a2079 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/sections/ActivityExplorerSection.java478
1 files changed, 191 insertions, 287 deletions
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 413a6854..55ee1a73 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
@@ -14,10 +14,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
-import java.util.TreeSet;
import org.eclipse.amalgam.explorer.activity.ui.ActivityExplorerActivator;
import org.eclipse.amalgam.explorer.activity.ui.api.configuration.SectionConfiguration;
+import org.eclipse.amalgam.explorer.activity.ui.api.editor.ActivityExplorerEditor;
import org.eclipse.amalgam.explorer.activity.ui.api.editor.activities.ExplorerActivity;
import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.FormHelper;
import org.eclipse.amalgam.explorer.activity.ui.api.manager.ActivityExplorerManager;
@@ -26,6 +26,7 @@ import org.eclipse.amalgam.explorer.activity.ui.internal.extension.point.manager
import org.eclipse.amalgam.explorer.activity.ui.internal.intf.IOrdered;
import org.eclipse.amalgam.explorer.activity.ui.internal.intf.IVisibility;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
@@ -36,319 +37,222 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
/**
- * This Class defined a Section for the DashBaord.
- *
- *
+ * Represents a titled section inside a page, which can contain a number of
+ * activities.
*/
public class ActivityExplorerSection implements IVisibility, IOrdered, IPropertyChangeListener {
- private SectionConfiguration config;
- private IAction[] toolbarActions;
- private Section widget;
- private FormToolkit toolkit;
- private Composite activityContainer;
+ /**
+ * The configuration for this section.
+ */
+ private final SectionConfiguration config;
+
+ /**
+ * The preference store where to look for visibility configuration (can be
+ * changed the the end-user).
+ */
+ private final IPreferenceStore preferenceStore = ActivityExplorerActivator.getDefault().getPreferenceStore();
+
+ /**
+ * The parent page in which the section is displayed.
+ */
private IFormPage page;
-
+ /**
+ * The toolkit to use for widget creation & styling.
+ */
+ private FormToolkit toolkit;
+
+ /**
+ * The actual widget representing the section in the UI.
+ */
+ private Section widget;
+
+ /**
+ * The composite for the content of the section.
+ */
+ private Composite activityContainer;
/**
* Constructor.
- *
- * @param cfg the configuration.
+ *
+ * @param cfg
+ * the configuration.
*/
public ActivityExplorerSection(SectionConfiguration cfg) {
this.config = cfg;
}
-
- /**
- * Constructor.
- *
- * @param id
- * @param name
- * @param index
- * @param isExpanded
- * @param description
- * @param activities
- */
- public ActivityExplorerSection(String id, String name, int index, boolean isExpanded, boolean isFiltering,
- String description, List<ExplorerActivity> activities) {
- this.config = new SectionConfiguration();
- this.config.setId(id);
- this.config.setName(name);
- this.config.setIndex(index);
- this.config.setExpanded(isExpanded);
- this.config.setFiltering(isFiltering);
- this.config.activities.addAll(activities);
- }
-
- /**
- * Get all activities defined for the Section.
- *
- * @return Set<ExplorerActivity>
- */
-
- public Set<ExplorerActivity> getActivities() {
- return this.config.activities;
- }
-
- /**
- * Get an particular activity from its ID.
- *
- * @param id
- * @return {@link ExplorerActivity}
- */
-
- public ExplorerActivity getActivityById(final String id) {
- ExplorerActivity result = null;
- for (ExplorerActivity activity : getActivities()) {
- if (activity.getId().equals(id)) {
- result = activity;
- }
- }
- return result;
- }
-
- /**
- * Set a Collections of {@link ExplorerActivity} in the
- * {@link ActivityExplorerSection}.
- *
- * @param activities
- */
-
- public void setActivities(TreeSet<ExplorerActivity> activities) {
- this.config.activities = activities;
- }
-
- /**
- * Get its ID.
- *
- * @return String
- */
-
- public String getId() {
- return this.config.getId();
- }
-
- /**
- * Get its Name.
- *
- * @return String
- */
-
- public String getName() {
- return this.config.getName();
- }
-
-
- /**
- * Return true if the section is defined as expanded.
- *
- * @return
- */
- public boolean isExpanded() {
- return this.config.isExpanded();
- }
-
- /**
- * Return true if the section should support the filtering.
- *
- * @return
- */
- public boolean isFiltering() {
- return this.config.isFiltering();
- }
-
- /**
- * Get its description.
- *
- * @return
- */
- public String getDescription() {
- return this.config.getDescription();
- }
-
- /**
- * Return true this section is visible.
- */
-
- public boolean isVisible() {
- return ActivityExplorerActivator.getDefault().getPreferenceStore().getBoolean(getId())
- && !getVisibleActivities().isEmpty();
- }
-
- /**
- * Get the position defined in the extension point.
- */
-
- public int getPosition() {
- return this.config.getIndex();
- }
-
- /**
- * Set the position.
- */
-
- public void setPosition(int index) {
- this.config.setIndex(index);
-
- }
-
- /**
- * Initialize the DashBaord Section
- *
- * @param sectionContainer
- * @param page
- * @param managedForm
- * @return Control
- */
- public Control init(Composite sectionContainer, IFormPage page, IManagedForm managedForm) {
- this.page = page;
- toolkit = managedForm.getToolkit();
- Couple<Section, Composite> section = FormHelper.createTwistieSectionWithToolbar(sectionContainer,
- managedForm, getName(), null, this.config.isExpanded(), Arrays.asList(getToolBarActions()));
- widget = (Section) section.getKey();
-
- activityContainer = section.getValue();
-
- // Register as property listener, to live refresh check / unckeck
- // sections.
- ActivityExplorerActivator.getDefault().getPreferenceStore().addPropertyChangeListener(this);
- return widget;
- }
-
- /**
- * Initialise the DashBaordSection.
- *
- * @param sectionContainer
- * @param page
- * @param managedForm
- * @return Control
- */
- public Control initialize(Composite sectionContainer, IFormPage page, IManagedForm managedForm) {
-
- // init the section
- init(sectionContainer, page, managedForm);
+ public String getId() {
+ return this.config.getId();
+ }
- // add/init activities
- initOwnActivities(activityContainer, toolkit);
- return widget;
- }
+ public String getName() {
+ return this.config.getName();
+ }
- /**
- * Get its Widget.
- *
- * @return Section
- */
+ /**
+ * Get all activities defined for the Section.
+ *
+ * @return Set<ExplorerActivity>
+ */
+ public Set<ExplorerActivity> getActivities() {
+ return this.config.activities;
+ }
- public Section getWidget() {
- return widget;
- }
+ /**
+ * Return true if the section should support the filtering.
+ *
+ * @return
+ */
+ public boolean isFiltering() {
+ return this.config.isFiltering();
+ }
- /**
- * Get all visible activities.
- *
- * @return List<ExplorerActivity>
- */
- public List<ExplorerActivity> getVisibleActivities() {
- List<ExplorerActivity> visibleActivities = new ArrayList<ExplorerActivity>();
- for (ExplorerActivity activity : getActivities()) {
- if (activity.isVisible())
- visibleActivities.add(activity);
+ /**
+ * Get its description.
+ *
+ * @return
+ */
+ public String getDescription() {
+ return this.config.getDescription();
+ }
- }
- return visibleActivities;
+ /**
+ * Return true this section is visible. Empty sections (with no visible
+ * activities) are automatically hidden.
+ */
+ @Override
+ public boolean isVisible() {
+ return preferenceStore.getBoolean(getId()) && !getVisibleActivities().isEmpty();
+ }
- }
+ /**
+ * Get the position defined in the extension point.
+ */
+ @Override
+ public int getPosition() {
+ return this.config.getIndex();
+ }
- /**
- * Init own ExplorerActivity.
- *
- * @param activityContainer
- * @param toolkit
- */
+ /**
+ * Set the position.
+ */
+ @Override
+ public void setPosition(int index) {
+ this.config.setIndex(index);
+ }
- private void initOwnActivities(Composite activityContainer, FormToolkit toolkit) {
- for (ExplorerActivity activity : getVisibleActivities()) {
- activity.init(activityContainer, toolkit);
- }
- }
+ /**
+ * Allows to Compare Two ActivityExplorerSection.
+ */
+ @Override
+ public int compareTo(IOrdered other) {
+ int value = Integer.valueOf(getPosition()).compareTo(Integer.valueOf(other.getPosition()));
+ return value == 0 ? 1 : value;
+ }
- /**
- * Get the ToolBarActions
- *
- * @return IAction[]
- */
- protected IAction[] getToolBarActions() {
- return toolbarActions;
- }
+ /**
+ * Initialize the section.
+ *
+ * @param sectionContainer
+ * @param page
+ * @param managedForm
+ * @return Control
+ */
+ public Control initialize(Composite sectionContainer, IFormPage page, IManagedForm managedForm) {
+ // Create the widgets.
+ this.page = page;
+ this.toolkit = managedForm.getToolkit();
+ Couple<Section, Composite> section = FormHelper.createTwistieSectionWithToolbar(sectionContainer, managedForm, getName(), null, this.config.isExpanded(), Arrays.asList(getToolBarActions()));
+ this.widget = section.getKey();
+ this.activityContainer = section.getValue();
+
+ // Register as property listener, to live refresh check / unckeck sections.
+ this.preferenceStore.addPropertyChangeListener(this);
+
+ // Add/init activities
+ initOwnActivities(this.activityContainer, this.toolkit);
+ return this.widget;
+ }
- /**
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- @Override
- public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
- String property = event.getProperty();
- boolean value = (Boolean.valueOf(event.getNewValue().toString()));
- if (doPropertyChange(event, value, property)) {
- if (ActivityExplorerManager.INSTANCE.getEditor() != null && ActivityExplorerManager.INSTANCE.getEditor().getActivePageInstance()!= null) {
- ActivityExplorerManager.INSTANCE.getEditor().getActivePageInstance().getManagedForm().reflow(true);
- }
- }
- }
+ /**
+ * Dispose the Activity Explorer Section.
+ */
+ public void dispose() {
+ // dispose the section widget
+ if (widget != null && !widget.isDisposed()) {
+ widget.dispose();
+ }
+ // dispose the editor
+ ActivityExplorerManager.INSTANCE.getEditor().dispose();
+ // dispose the preference property listener
+ preferenceStore.removePropertyChangeListener(this);
+ }
- protected boolean doPropertyChange(PropertyChangeEvent event, boolean value, String property) {
- boolean result = false;
+ /**
+ * Get all visible activities.
+ *
+ * @return List<ExplorerActivity>
+ */
+ public List<ExplorerActivity> getVisibleActivities() {
+ List<ExplorerActivity> visibleActivities = new ArrayList<ExplorerActivity>();
+ for (ExplorerActivity activity : getActivities()) {
+ if (activity.isVisible()) {
+ visibleActivities.add(activity);
+ }
+ }
+ return visibleActivities;
+ }
- if (isActivity(property)) {
- updateSectionForm();
- result = true;
- }
+ /**
+ * Init own ExplorerActivity.
+ *
+ * @param activityContainer
+ * @param toolkit
+ */
- return result;
- }
+ private void initOwnActivities(Composite activityContainer, FormToolkit toolkit) {
+ for (ExplorerActivity activity : getVisibleActivities()) {
+ activity.init(activityContainer, toolkit);
+ }
+ }
- /**
- * Test if the id is a Activity.
- *
- * @param id
- * @return boolean
- */
- private boolean isActivity(String id) {
- return ActivityExplorerExtensionManager.isActivity(page.getId(), this.getId(), id);
- }
+ /**
+ * Get the ToolBarActions
+ *
+ * @return IAction[]
+ */
+ protected IAction[] getToolBarActions() {
+ return new IAction[0];
+ }
- /**
- * Dispose the Activity Explorer Section.
- */
- public void dispose() {
- // dispose the section widget
- if (widget != null && !widget.isDisposed())
- widget.dispose();
- /*
- * for(ExplorerActivity activity: getActivities()){ activity.dispose();
- * }
- */
- // dispose the editor
- ActivityExplorerManager.INSTANCE.getEditor().dispose();
- // dispose the preference property listener
- ActivityExplorerActivator.getDefault().getPreferenceStore().removePropertyChangeListener(this);
- }
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ boolean value = Boolean.valueOf(event.getNewValue().toString());
+ if (doPropertyChange(event, value, property)) {
+ ActivityExplorerEditor editor = ActivityExplorerManager.INSTANCE.getEditor();
+ if (editor != null && editor.getActivePageInstance() != null) {
+ editor.getActivePageInstance().getManagedForm().reflow(true);
+ }
+ }
+ }
- /**
- * Allows to Compare Two ActivityExplorerSection.
- */
- public int compareTo(IOrdered arg0) {
- int value = new Integer(getPosition()).compareTo(new Integer(arg0.getPosition()));
- return value == 0 ? 1 : value;
- }
+ protected boolean doPropertyChange(PropertyChangeEvent event, boolean value, String property) {
+ boolean result = false;
+ if (ActivityExplorerExtensionManager.isActivity(page.getId(), this.getId(), property)) {
+ updateSectionForm();
+ result = true;
+ }
+ return result;
+ }
- public void updateSectionForm() {
- if (!activityContainer.isDisposed()) {
- for (Control c : activityContainer.getChildren()) {
- c.dispose();
- }
- initOwnActivities(activityContainer, toolkit);
- }
- // widget.getParent().layout(true, true);
- }
+ private void updateSectionForm() {
+ if (!activityContainer.isDisposed()) {
+ for (Control c : activityContainer.getChildren()) {
+ c.dispose();
+ }
+ initOwnActivities(activityContainer, toolkit);
+ }
+ }
}

Back to the top