diff options
| author | Pierre-Charles David | 2017-03-03 14:17:14 +0000 |
|---|---|---|
| committer | Joao Barata | 2017-03-28 12:22:44 +0000 |
| commit | 6cd1635ee435dc4081a4da599dc906a9dbb481a6 (patch) | |
| tree | 3daafea4ee7a84c2702659ed68652d2adb670d35 | |
| parent | 6812d85e0f0e472c01003e521e204eb3ce896936 (diff) | |
| download | org.eclipse.amalgam-6cd1635ee435dc4081a4da599dc906a9dbb481a6.tar.gz org.eclipse.amalgam-6cd1635ee435dc4081a4da599dc906a9dbb481a6.tar.xz org.eclipse.amalgam-6cd1635ee435dc4081a4da599dc906a9dbb481a6.zip | |
[509735] Use more explicit messages on index configuration errors
Bug: 509735
Change-Id: I84f2f9682d3c7bd80bf2cc9d0ddf010fb86fc3d2
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
2 files changed, 663 insertions, 651 deletions
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/CommonActivityExplorerPage.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/CommonActivityExplorerPage.java index 2afc988e..4f178ae7 100644 --- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/CommonActivityExplorerPage.java +++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/editor/pages/CommonActivityExplorerPage.java @@ -1,242 +1,248 @@ -/*******************************************************************************
- * Copyright (c) 2006, 2016 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Thales - initial API and implementation
- *******************************************************************************/
-package org.eclipse.amalgam.explorer.activity.ui.api.editor.pages;
-
-import org.eclipse.amalgam.explorer.activity.ui.ActivityExplorerActivator;
-import org.eclipse.amalgam.explorer.activity.ui.IImageKeys;
-import org.eclipse.amalgam.explorer.activity.ui.api.editor.ActivityExplorerEditor;
-import org.eclipse.amalgam.explorer.activity.ui.api.editor.predicates.IPredicate;
-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;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.editor.SharedHeaderFormEditor;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-
-/**
- * Base class to implement ActivityExplorer pages in an {@link ActivityExplorerEditor}.
- */
-public class CommonActivityExplorerPage extends FormPage implements IExecutableExtension, IOrdered, IVisibility, IPropertyListener {
-
- private boolean overview;
- private Image overviewImageOff;
- private String overviewText;
- private Image overviewImageOn;
- private String overviewImageOnPath;
- private String overviewImageOffPath;
- protected IPredicate predicate;
-
- public static final int PROP_ACTIVE = 0x185;
-
- private int index;
-
- private static String ids;
-
- public static void setID(String id) {
- ids = id;
- }
-
- public CommonActivityExplorerPage() {
- this(null, ids, ""); //$NON-NLS-1$
- }
-
- public CommonActivityExplorerPage(FormEditor editor, String id, String title) {
- super(editor, id, title);
-
- }
-
- /**
- * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
- */
- @Override
- protected void createFormContent(IManagedForm managedForm) {
- FormToolkit toolkit = managedForm.getToolkit();
- toolkit.decorateFormHeading(managedForm.getForm().getForm());
- // For performance optimization.
- // managedForm.getForm().setDelayedReflow(true);
-
- getEditor().addPropertyListener(this);
-
- }
-
- /**
- * @see org.eclipse.ui.forms.editor.FormPage#getEditor()
- */
- @Override
- public SharedHeaderFormEditor getEditor() {
- return (SharedHeaderFormEditor) super.getEditor();
- }
-
- @Override
- public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) {
-
- super.setInitializationData(cfig, propertyName, data);
-
- String title = ActivityExplorerExtensionManager.getTitle(cfig);
- String tabName = ActivityExplorerExtensionManager.getTabName(cfig);
-
- if (tabName == null) {
- tabName = title;
- }
- setPartName(tabName);
-
- overview = ActivityExplorerExtensionManager.getOverviewElement(cfig) != null;
- if (overview) {
-
- overviewImageOffPath = ActivityExplorerExtensionManager.getOverviewImageOff(cfig);
- overviewImageOnPath = ActivityExplorerExtensionManager.getOverviewImageOn(cfig);
-
- String plugin_id = ActivityExplorerExtensionManager.getPluginId(cfig);
-
- if ((overviewImageOffPath.equals(IImageKeys.IMAGE_DEFAULT_OVERVIEW_OFF))) {
- plugin_id = ActivityExplorerActivator.ID;
- }
-
- setOverviewImageOff(ActivityExplorerActivator.getDefault().getImage(plugin_id, overviewImageOffPath));
-
- if ((overviewImageOnPath.equals(IImageKeys.IMAGE_DEFAULT_OVERVIEW_ON))) {
- plugin_id = ActivityExplorerActivator.ID;
- }
-
- setOverviewImageOn(ActivityExplorerActivator.getDefault().getImage(plugin_id, overviewImageOnPath));
-
- setOverViewText(ActivityExplorerExtensionManager.getOverviewDescription(cfig));
- }
-
- predicate = ActivityExplorerExtensionManager.getPredicate(cfig);
-
- String indice = ActivityExplorerExtensionManager.getIndex(cfig);
- setIndex(Integer.parseInt(indice));
- }
-
- private void setOverviewImageOn(Image image) {
- overviewImageOn = image;
-
- }
-
- public String getOverViewImageOnPath() {
- return overviewImageOnPath;
-
- }
-
- public String getOverViewImageOffPath() {
- return overviewImageOffPath;
-
- }
-
- public Image getOverViewImageOn() {
- return overviewImageOn;
-
- }
-
- private void setOverViewText(String text) {
- overviewText = text;
-
- }
-
- public String getOverViewText() {
- return overviewText;
-
- }
-
- private void setOverviewImageOff(Image image) {
- overviewImageOff = image;
- }
-
- public Image getOverviewImageOff() {
- return overviewImageOff;
- }
-
- public boolean contributeToOverview() {
- return overview;
- }
-
- public void contributeToOverview(boolean contribute) {
- overview = contribute;
- }
-
- /**
- * Return true this page is visible.
- */
- @Override
- public boolean isVisible() {
- boolean result = ActivityExplorerActivator.getDefault().getPreferenceStore().getBoolean(getId());
-
- if (predicate != null) {
- result &= predicate.isOk();
- }
- return result;
- }
-
- public int getPosition() {
- return index;
- }
-
- public void setPosition(int index) {
- this.index = index;
-
- }
-
- @Override
- public int getIndex() {
- return index;
- }
-
- @Override
- public void setIndex(int index) {
- this.index = index;
-
- }
-
- public int compareTo(IOrdered arg0) {
- int result = 1;
- if (null != arg0) {
- result = new Integer(getPosition()).compareTo(new Integer(arg0.getPosition()));
- }
- return result;
-
- }
-
- @Override
- public void setActive(boolean active) {
- super.setActive(active);
- if (active) {
- markAsActive();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int)
- */
- @Override
- public void propertyChanged(Object source, int propId) {
- if (IEditorPart.PROP_DIRTY == propId) {
- markAsDirty();
- }
- }
-
- public void markAsDirty() {
- firePropertyChange(IEditorPart.PROP_DIRTY);
- }
-
- public void markAsActive() {
- firePropertyChange(PROP_ACTIVE);
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2006, 2017 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thales - initial API and implementation + *******************************************************************************/ +package org.eclipse.amalgam.explorer.activity.ui.api.editor.pages; + +import java.text.MessageFormat; + +import org.eclipse.amalgam.explorer.activity.ui.ActivityExplorerActivator; +import org.eclipse.amalgam.explorer.activity.ui.IImageKeys; +import org.eclipse.amalgam.explorer.activity.ui.api.editor.ActivityExplorerEditor; +import org.eclipse.amalgam.explorer.activity.ui.api.editor.predicates.IPredicate; +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; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.editor.SharedHeaderFormEditor; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * Base class to implement ActivityExplorer pages in an {@link ActivityExplorerEditor}. + */ +public class CommonActivityExplorerPage extends FormPage implements IExecutableExtension, IOrdered, IVisibility, IPropertyListener { + + private boolean overview; + private Image overviewImageOff; + private String overviewText; + private Image overviewImageOn; + private String overviewImageOnPath; + private String overviewImageOffPath; + protected IPredicate predicate; + + public static final int PROP_ACTIVE = 0x185; + + private int index; + + private static String ids; + + public static void setID(String id) { + ids = id; + } + + public CommonActivityExplorerPage() { + this(null, ids, ""); //$NON-NLS-1$ + } + + public CommonActivityExplorerPage(FormEditor editor, String id, String title) { + super(editor, id, title); + + } + + /** + * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm) + */ + @Override + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + toolkit.decorateFormHeading(managedForm.getForm().getForm()); + // For performance optimization. + // managedForm.getForm().setDelayedReflow(true); + + getEditor().addPropertyListener(this); + + } + + /** + * @see org.eclipse.ui.forms.editor.FormPage#getEditor() + */ + @Override + public SharedHeaderFormEditor getEditor() { + return (SharedHeaderFormEditor) super.getEditor(); + } + + @Override + public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) { + + super.setInitializationData(cfig, propertyName, data); + + String title = ActivityExplorerExtensionManager.getTitle(cfig); + String tabName = ActivityExplorerExtensionManager.getTabName(cfig); + + if (tabName == null) { + tabName = title; + } + setPartName(tabName); + + overview = ActivityExplorerExtensionManager.getOverviewElement(cfig) != null; + if (overview) { + + overviewImageOffPath = ActivityExplorerExtensionManager.getOverviewImageOff(cfig); + overviewImageOnPath = ActivityExplorerExtensionManager.getOverviewImageOn(cfig); + + String plugin_id = ActivityExplorerExtensionManager.getPluginId(cfig); + + if ((overviewImageOffPath.equals(IImageKeys.IMAGE_DEFAULT_OVERVIEW_OFF))) { + plugin_id = ActivityExplorerActivator.ID; + } + + setOverviewImageOff(ActivityExplorerActivator.getDefault().getImage(plugin_id, overviewImageOffPath)); + + if ((overviewImageOnPath.equals(IImageKeys.IMAGE_DEFAULT_OVERVIEW_ON))) { + plugin_id = ActivityExplorerActivator.ID; + } + + setOverviewImageOn(ActivityExplorerActivator.getDefault().getImage(plugin_id, overviewImageOnPath)); + + setOverViewText(ActivityExplorerExtensionManager.getOverviewDescription(cfig)); + } + + predicate = ActivityExplorerExtensionManager.getPredicate(cfig); + + String indice = ActivityExplorerExtensionManager.getIndex(cfig); + try { + setIndex(Integer.parseInt(indice)); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(MessageFormat.format("Attribute ''{0}'' of page {1} must be an int, but was ''{2}''", ActivityExplorerExtensionManager.ATT_INDEX, ActivityExplorerExtensionManager.getId(cfig), indice)); + } + } + + private void setOverviewImageOn(Image image) { + overviewImageOn = image; + + } + + public String getOverViewImageOnPath() { + return overviewImageOnPath; + + } + + public String getOverViewImageOffPath() { + return overviewImageOffPath; + + } + + public Image getOverViewImageOn() { + return overviewImageOn; + + } + + private void setOverViewText(String text) { + overviewText = text; + + } + + public String getOverViewText() { + return overviewText; + + } + + private void setOverviewImageOff(Image image) { + overviewImageOff = image; + } + + public Image getOverviewImageOff() { + return overviewImageOff; + } + + public boolean contributeToOverview() { + return overview; + } + + public void contributeToOverview(boolean contribute) { + overview = contribute; + } + + /** + * Return true this page is visible. + */ + @Override + public boolean isVisible() { + boolean result = ActivityExplorerActivator.getDefault().getPreferenceStore().getBoolean(getId()); + + if (predicate != null) { + result &= predicate.isOk(); + } + return result; + } + + public int getPosition() { + return index; + } + + public void setPosition(int index) { + this.index = index; + + } + + @Override + public int getIndex() { + return index; + } + + @Override + public void setIndex(int index) { + this.index = index; + + } + + public int compareTo(IOrdered arg0) { + int result = 1; + if (null != arg0) { + result = new Integer(getPosition()).compareTo(new Integer(arg0.getPosition())); + } + return result; + + } + + @Override + public void setActive(boolean active) { + super.setActive(active); + if (active) { + markAsActive(); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int) + */ + @Override + public void propertyChanged(Object source, int propId) { + if (IEditorPart.PROP_DIRTY == propId) { + markAsDirty(); + } + } + + public void markAsDirty() { + firePropertyChange(IEditorPart.PROP_DIRTY); + } + + public void markAsActive() { + firePropertyChange(PROP_ACTIVE); + } + +} 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 7d803b38..1ffc75b9 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,409 +1,415 @@ -/*******************************************************************************
- * Copyright (c) 2006, 2015 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Thales - initial API and implementation
- *******************************************************************************/
-package org.eclipse.amalgam.explorer.activity.ui.api.editor.sections;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.regex.Pattern;
-
-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.helper.FormHelper;
-import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.HTMLHelper;
-import org.eclipse.amalgam.explorer.activity.ui.api.manager.ActivityExplorerManager;
-import org.eclipse.amalgam.explorer.activity.ui.internal.Couple;
-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;
-import org.eclipse.amalgam.explorer.activity.ui.internal.util.ActivityExplorerLoggerService;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.IFormPage;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.Section;
-
-/**
- * This Class defined a Section for the DashBaord.
- *
- *
- */
-public class ActivityExplorerSection implements IVisibility, IOrdered, IPropertyChangeListener {
-
- private static final String P_PATTERN = "<p>.*</p>"; //$NON-NLS-1$
-
- /**
- * Constructor.
- *
- * @param contributor
- */
- public ActivityExplorerSection(IConfigurationElement contributor) {
- this.id = ActivityExplorerExtensionManager.getId(contributor);
- this.name = ActivityExplorerExtensionManager.getName(contributor);
- this.isExpanded = ActivityExplorerExtensionManager.getIsExpanded(contributor);
- String desc = ActivityExplorerExtensionManager.getDescription(contributor);
- if (null != desc){
- Pattern pPattern = Pattern.compile(P_PATTERN);
- boolean isInParagraph = pPattern.matcher(desc).find();
- this.description = isInParagraph ? HTMLHelper.formWrapper2(desc) : HTMLHelper.formWrapper(desc);
- }
- this.index = Integer.parseInt(ActivityExplorerExtensionManager.getIndex(contributor));
- this.isFiltering = ActivityExplorerExtensionManager.getIsFiltering(contributor);
- createActivities(contributor);
-
- }
-
- /**
- * 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) {
- super();
- this.id = id;
- this.name = name;
- this.index = index;
- this.isExpanded = isExpanded;
- this.isFiltering = isFiltering;
- this.activities.addAll(activities);
- }
-
- private TreeSet<ExplorerActivity> activities;
-
- /**
- * Create theirs Activities.
- *
- * @param contributor
- */
-
- private void createActivities(IConfigurationElement contributor) {
-
- activities = new TreeSet<ExplorerActivity>();
-
- List<IConfigurationElement> activities = ActivityExplorerExtensionManager.getActivities(contributor);
- for (IConfigurationElement element : activities) {
- try {
- this.activities.add(new ExplorerActivity(element));
- } catch (NumberFormatException e){
-
- StringBuilder message = new StringBuilder();
- message.append("ActivityExplorerSection.createActivities(...) _ "); //$NON-NLS-1$
- message.append("The Activity contribution "); //$NON-NLS-1$
- message.append(ActivityExplorerExtensionManager.getId(contributor));
- message.append(" has wrong index format ("); //$NON-NLS-1$
- message.append(ActivityExplorerExtensionManager.getIndex(contributor));
- message.append("). Only integers are valid"); //$NON-NLS-1$
-
- ActivityExplorerLoggerService.getInstance().log(IStatus.ERROR, message.toString(), e);
-
- }
- }
- }
-
- /**
- * Get all activities defined for the Section.
- *
- * @return Set<ExplorerActivity>
- */
-
- public Set<ExplorerActivity> getActivities() {
- return 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.activities = activities;
- }
-
- /**
- * Get its ID.
- *
- * @return String
- */
-
- public String getId() {
- return id;
- }
-
- /**
- * Get its Name.
- *
- * @return String
- */
-
- public String getName() {
- return name;
- }
-
- private String id;
- private String name;
- private int index;
- private boolean isExpanded;
- private boolean isFiltering;
- private String description;
- private IAction[] toolbarActions;
- private Section widget;
-
- /**
- * Return true if the section is defined as expanded.
- *
- * @return
- */
- public boolean isExpanded() {
- return isExpanded;
- }
-
- /**
- * Return true if the section should support the filtering.
- *
- * @return
- */
- public boolean isFiltering() {
- return isFiltering;
- }
-
- /**
- * Get its description.
- *
- * @return
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * 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 index;
- }
-
- /**
- * Set the position.
- */
-
- public void setPosition(int index) {
- this.index = index;
-
- }
-
- private FormToolkit toolkit;
- private Composite activityContainer;
- private IFormPage page;
-
- /**
- * 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, 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);
-
- // add/init activities
- initOwnActivities(activityContainer, toolkit);
- return widget;
- }
-
- /**
- * Get its Widget.
- *
- * @return Section
- */
-
- public Section getWidget() {
- return widget;
- }
-
- /**
- * 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;
-
- }
-
- /**
- * Init own ExplorerActivity.
- *
- * @param activityContainer
- * @param toolkit
- */
-
- private void initOwnActivities(Composite activityContainer, FormToolkit toolkit) {
- for (ExplorerActivity activity : getVisibleActivities()) {
- activity.init(activityContainer, toolkit);
- }
- }
-
- /**
- * Get the ToolBarActions
- *
- * @return IAction[]
- */
- protected IAction[] getToolBarActions() {
- return toolbarActions;
- }
-
- /**
- * @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);
- }
- }
- }
-
- protected boolean doPropertyChange(PropertyChangeEvent event, boolean value, String property) {
- boolean result = false;
-
- if (isActivity(property)) {
- updateSectionForm();
- result = true;
- }
-
- return result;
- }
-
- /**
- * Test if the id is a Activity.
- *
- * @param id
- * @return boolean
- */
- private boolean isActivity(String id) {
- return ActivityExplorerExtensionManager.isActivity(page.getId(), this.getId(), id);
- }
-
- /**
- * 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);
- }
-
- /**
- * 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;
- }
-
- public void updateSectionForm() {
- if (!activityContainer.isDisposed()) {
- for (Control c : activityContainer.getChildren()) {
- c.dispose();
- }
- initOwnActivities(activityContainer, toolkit);
- }
- // widget.getParent().layout(true, true);
- }
-}
+/******************************************************************************* + * Copyright (c) 2006, 2017 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thales - initial API and implementation + *******************************************************************************/ +package org.eclipse.amalgam.explorer.activity.ui.api.editor.sections; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.regex.Pattern; + +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.helper.FormHelper; +import org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.HTMLHelper; +import org.eclipse.amalgam.explorer.activity.ui.api.manager.ActivityExplorerManager; +import org.eclipse.amalgam.explorer.activity.ui.internal.Couple; +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; +import org.eclipse.amalgam.explorer.activity.ui.internal.util.ActivityExplorerLoggerService; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.IFormPage; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; + +/** + * This Class defined a Section for the DashBaord. + * + * + */ +public class ActivityExplorerSection implements IVisibility, IOrdered, IPropertyChangeListener { + + private static final String P_PATTERN = "<p>.*</p>"; //$NON-NLS-1$ + + /** + * Constructor. + * + * @param contributor + */ + public ActivityExplorerSection(IConfigurationElement contributor) { + this.id = ActivityExplorerExtensionManager.getId(contributor); + this.name = ActivityExplorerExtensionManager.getName(contributor); + this.isExpanded = ActivityExplorerExtensionManager.getIsExpanded(contributor); + String desc = ActivityExplorerExtensionManager.getDescription(contributor); + if (null != desc){ + Pattern pPattern = Pattern.compile(P_PATTERN); + boolean isInParagraph = pPattern.matcher(desc).find(); + this.description = isInParagraph ? HTMLHelper.formWrapper2(desc) : HTMLHelper.formWrapper(desc); + } + String indice = ActivityExplorerExtensionManager.getIndex(contributor); + try { + this.index = Integer.parseInt(indice); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(MessageFormat.format("Attribute ''{0}'' of section {1} must be an int, but was ''{2}''", ActivityExplorerExtensionManager.ATT_INDEX, ActivityExplorerExtensionManager.getId(contributor), indice)); + } + this.isFiltering = ActivityExplorerExtensionManager.getIsFiltering(contributor); + createActivities(contributor); + + } + + /** + * 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) { + super(); + this.id = id; + this.name = name; + this.index = index; + this.isExpanded = isExpanded; + this.isFiltering = isFiltering; + this.activities.addAll(activities); + } + + private TreeSet<ExplorerActivity> activities; + + /** + * Create theirs Activities. + * + * @param contributor + */ + + private void createActivities(IConfigurationElement contributor) { + + activities = new TreeSet<ExplorerActivity>(); + + List<IConfigurationElement> activities = ActivityExplorerExtensionManager.getActivities(contributor); + for (IConfigurationElement element : activities) { + try { + this.activities.add(new ExplorerActivity(element)); + } catch (NumberFormatException e){ + + StringBuilder message = new StringBuilder(); + message.append("ActivityExplorerSection.createActivities(...) _ "); //$NON-NLS-1$ + message.append("The Activity contribution "); //$NON-NLS-1$ + message.append(ActivityExplorerExtensionManager.getId(contributor)); + message.append(" has wrong index format ("); //$NON-NLS-1$ + message.append(ActivityExplorerExtensionManager.getIndex(contributor)); + message.append("). Only integers are valid"); //$NON-NLS-1$ + + ActivityExplorerLoggerService.getInstance().log(IStatus.ERROR, message.toString(), e); + + } + } + } + + /** + * Get all activities defined for the Section. + * + * @return Set<ExplorerActivity> + */ + + public Set<ExplorerActivity> getActivities() { + return 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.activities = activities; + } + + /** + * Get its ID. + * + * @return String + */ + + public String getId() { + return id; + } + + /** + * Get its Name. + * + * @return String + */ + + public String getName() { + return name; + } + + private String id; + private String name; + private int index; + private boolean isExpanded; + private boolean isFiltering; + private String description; + private IAction[] toolbarActions; + private Section widget; + + /** + * Return true if the section is defined as expanded. + * + * @return + */ + public boolean isExpanded() { + return isExpanded; + } + + /** + * Return true if the section should support the filtering. + * + * @return + */ + public boolean isFiltering() { + return isFiltering; + } + + /** + * Get its description. + * + * @return + */ + public String getDescription() { + return description; + } + + /** + * 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 index; + } + + /** + * Set the position. + */ + + public void setPosition(int index) { + this.index = index; + + } + + private FormToolkit toolkit; + private Composite activityContainer; + private IFormPage page; + + /** + * 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, 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); + + // add/init activities + initOwnActivities(activityContainer, toolkit); + return widget; + } + + /** + * Get its Widget. + * + * @return Section + */ + + public Section getWidget() { + return widget; + } + + /** + * 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; + + } + + /** + * Init own ExplorerActivity. + * + * @param activityContainer + * @param toolkit + */ + + private void initOwnActivities(Composite activityContainer, FormToolkit toolkit) { + for (ExplorerActivity activity : getVisibleActivities()) { + activity.init(activityContainer, toolkit); + } + } + + /** + * Get the ToolBarActions + * + * @return IAction[] + */ + protected IAction[] getToolBarActions() { + return toolbarActions; + } + + /** + * @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); + } + } + } + + protected boolean doPropertyChange(PropertyChangeEvent event, boolean value, String property) { + boolean result = false; + + if (isActivity(property)) { + updateSectionForm(); + result = true; + } + + return result; + } + + /** + * Test if the id is a Activity. + * + * @param id + * @return boolean + */ + private boolean isActivity(String id) { + return ActivityExplorerExtensionManager.isActivity(page.getId(), this.getId(), id); + } + + /** + * 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); + } + + /** + * 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; + } + + public void updateSectionForm() { + if (!activityContainer.isDisposed()) { + for (Control c : activityContainer.getChildren()) { + c.dispose(); + } + initOwnActivities(activityContainer, toolkit); + } + // widget.getParent().layout(true, true); + } +} |
