Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Li2015-05-06 12:03:34 +0000
committerGerrit Code Review @ Eclipse.org2015-11-18 10:01:35 +0000
commit5c6b9f2134605509211bcf3ef271799e1554d5f2 (patch)
treecc7b4e8625597e82c1a1d02f3a77b2b7dc06ddd0 /plugins/infra/services/org.eclipse.papyrus.infra.services.navigation
parent7dbaf8867e0b3e43d606caa8f2d342dbf479d3d6 (diff)
downloadorg.eclipse.papyrus-5c6b9f2134605509211bcf3ef271799e1554d5f2.tar.gz
org.eclipse.papyrus-5c6b9f2134605509211bcf3ef271799e1554d5f2.tar.xz
org.eclipse.papyrus-5c6b9f2134605509211bcf3ef271799e1554d5f2.zip
Bug 463589 - [Navigation] Alt Menu
- Add navigation menu on alt+hover over a navigable element (in diagram or model explorer) - Move hyperlinks to this navigation menu - First version of navigation extension framework to contribute navigation menu buttons to the menu. These contributors are handled by the navigation service. - Current contributors are: parents, children, types, views, targets, sources - Add NamedElement navigable element - Add method to chose navigation target provider in navigation service - Add method to get semantic element from navigable element - Change some navigable element labels - Rm DiagramNavigationProvider because views where the element appears are already shown. - Add PopupBarEditPolicyProvider to edit policy extensions Patch set 20: Architecture changes: - oep.views.navigation is deleted and its content moved to oep.infra.gmfdiag.navigation. Several changes were made beforehand: - Remove dependency on oep.uml.tools - Remove useless import of org.eclipse.uml.uml2 - Remove dependencies on uml and nattable - Move oep.views.navigation.contributor oep.uml.navigation.menuContributor - Remove useless imports of navigation menu button package elsewhere - Delete oep.views.navigation[.feature] and remove from main pom Feature changes: - In oep.infra.gmfdiag.navigation, added OwnedDiagramButton menu contributor, which will show diagrams owned by the hovered element Other changes: - Contribute DiagramOfViewLabelProvider extension in context of "oep.infra.services.navigation.menu.labelprovider" - Add ViewerSearchService to DefaultNavigationMenu. This replaces getViewsToSelect and getClosedViewsToSelect methods. - Rename oep.uml.navigation.contributor to navigableElement - Remove old navigation contributors from oep.infra.gmfdiag.navigation (not contributed through extensions anyway) Change-Id: I895ea3923b1e5612b3bba4d3296a91176b7c2b94 Signed-off-by: Shuai Li <shuai.li@cea.fr>
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.navigation')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/plugin.xml77
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenu.exsd125
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenuContributor.exsd125
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/preferences/NavigationServicePreferencesPage.java427
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/ExtendedNavigableElement.java23
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigableElement.java148
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenu.java30
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuButton.java59
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuContributor.java24
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationService.java113
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/impl/NavigationServiceImpl.java826
11 files changed, 1219 insertions, 758 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/plugin.xml
index 175d5758d53..bd4f371808d 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/plugin.xml
@@ -1,34 +1,43 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension-point id="navigationContributor" name="navigationContributor" schema="schema/navigationContributor.exsd"/>
- <extension
- point="org.eclipse.papyrus.infra.core.service">
- <service
- classname="org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl"
- id="org.eclipse.papyrus.infra.services.navigation.service.NavigationService"
- priority="1"
- startKind="lazy">
- </service>
- </extension>
- <extension
- point="org.eclipse.ui.preferencePages">
- <page
- category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
- class="org.eclipse.papyrus.infra.services.navigation.preferences.NavigationServicePreferencesPage"
- id="org.eclipse.papyrus.infra.services.navigation.preferences"
- name="Navigation Service">
- </page>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.services.navigation.navigationContributor">
- <target
- description="Display elements in the current active editor"
- id="org.eclipse.papyrus.infra.services.navigation.target.activeEditor"
- label="Show in the active editor"
- navigationTargetProvider="org.eclipse.papyrus.infra.services.navigation.provider.impl.ActiveEditorNavigationTargetProvider"
- order="10">
- </target>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="navigationContributor" name="navigationContributor" schema="schema/navigationContributor.exsd"/>
+ <extension-point id="navigationMenuContributor" name="navigationMenuContributor" schema="schema/navigationMenuContributor.exsd"/>
+ <extension-point id="navigationMenu" name="navigationMenu" schema="schema/navigationMenu.exsd"/>
+ <extension
+ point="org.eclipse.papyrus.infra.core.service">
+ <service
+ classname="org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl"
+ id="org.eclipse.papyrus.infra.services.navigation.service.NavigationService"
+ priority="1"
+ startKind="lazy">
+ </service>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
+ class="org.eclipse.papyrus.infra.services.navigation.preferences.NavigationServicePreferencesPage"
+ id="org.eclipse.papyrus.infra.services.navigation.preferences"
+ name="Navigation Service">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.navigation.navigationContributor">
+ <target
+ description="Display elements in the current active editor"
+ id="org.eclipse.papyrus.infra.services.navigation.target.activeEditor"
+ label="Show in the active editor"
+ navigationTargetProvider="org.eclipse.papyrus.infra.services.navigation.provider.impl.ActiveEditorNavigationTargetProvider"
+ order="10">
+ </target>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider">
+ <context
+ description="Context of the navigation alt menu"
+ id="org.eclipse.papyrus.infra.services.navigation.menu.labelprovider">
+ </context>
+ </extension>
+
+</plugin>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenu.exsd b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenu.exsd
new file mode 100644
index 00000000000..bb286b734c9
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenu.exsd
@@ -0,0 +1,125 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.infra.services.navigation" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.infra.services.navigation" id="navigationMenu" name="navigationMenu"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <choice>
+ <element ref="menu"/>
+ </choice>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="menu">
+ <complexType>
+ <attribute name="menu" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="label" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="description" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenuContributor.exsd b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenuContributor.exsd
new file mode 100644
index 00000000000..d4d5d15155f
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/schema/navigationMenuContributor.exsd
@@ -0,0 +1,125 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.infra.services.navigation" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.infra.services.navigation" id="navigationMenuContributor" name="navigationMenuContributor"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <choice>
+ <element ref="contributor"/>
+ </choice>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="contributor">
+ <complexType>
+ <attribute name="contributor" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="label" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="description" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/preferences/NavigationServicePreferencesPage.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/preferences/NavigationServicePreferencesPage.java
index d26a03442b5..0f52c8b44c2 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/preferences/NavigationServicePreferencesPage.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/preferences/NavigationServicePreferencesPage.java
@@ -1,211 +1,216 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Nizar GUEDIDI (CEA LIST) - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.navigation.preferences;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.jface.window.ToolTip;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.services.navigation.Activator;
-import org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl;
-import org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl.NavigationContributorDescriptor;
-import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.TableEditor;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.osgi.service.prefs.BackingStoreException;
-
-public class NavigationServicePreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
-
- public static final int ACTIVATION_COLUMN = 0;
-
- private Map<NavigationContributorDescriptor, Button> checkboxes;
-
- private NavigationServiceImpl navigation = new NavigationServiceImpl();
-
- /**
- *
- * Constructor.
- *
- */
- public NavigationServicePreferencesPage() {
- super("Navigation Services", org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"));
- }
-
- public void init(IWorkbench workbench) {
- setPreferenceStore(Activator.getDefault().getPreferenceStore());
- setDescription("Papyrus navigation services configuration.\nSelect the strategies you wish to activate.");
- }
-
- @Override
- protected Control createContents(Composite parent) {
-
- Composite self = new Composite(parent, SWT.NONE);
- self.setLayout(new GridLayout(1, true));
- self.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- final TableViewer tableViewer = new TableViewer(self, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- tableViewer.getTable().setLayoutData(gridData);
-
- ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
-
- tableViewer.setContentProvider(CollectionContentProvider.instance);
-
- try {
- navigation.startService();
- } catch (ServiceException ex) {
- return self;
- }
-
- tableViewer.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public void update(ViewerCell cell) {
- if (cell.getColumnIndex() == 1) {
- super.update(cell);
- } else {
- return;
- }
- }
-
- @Override
- public String getToolTipText(Object element) {
- if (element instanceof NavigationContributorDescriptor) {
- return ((NavigationContributorDescriptor) element).getDescription();
- }
- return super.getToolTipText(element);
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof NavigationContributorDescriptor) {
- return null;
- }
-
- return super.getImage(element);
- }
-
- @Override
- public String getText(Object element) {
- if (element instanceof NavigationContributorDescriptor) {
- return ((NavigationContributorDescriptor) element).getLabel();
- }
- return super.getText(element);
- }
- });
-
- TableLayout layout = new TableLayout();
-
- new TableColumn(tableViewer.getTable(), SWT.LEFT);
- layout.addColumnData(new ColumnWeightData(10, 25, false));
-
- new TableColumn(tableViewer.getTable(), SWT.LEFT);
- layout.addColumnData(new ColumnWeightData(100, 250, true));
-
- tableViewer.getTable().setLayout(layout);
- tableViewer.getTable().setHeaderVisible(false);
-
- tableViewer.setInput(navigation.getNavigationContributors());
-
- // Adds a checkbox for each service navigation, to toggle it
- checkboxes = new HashMap<NavigationContributorDescriptor, Button>();
-
- for (TableItem item : tableViewer.getTable().getItems()) {
- if (item.getData() instanceof NavigationContributorDescriptor) {
- TableEditor editor = new TableEditor(tableViewer.getTable());
-
- final Button button = new Button(tableViewer.getTable(), SWT.CHECK);
- final TableItem currentItem = item;
-
- final NavigationContributorDescriptor strategy = (NavigationContributorDescriptor) currentItem.getData();
-
- checkboxes.put(strategy, button);
-
- button.setSelection(strategy.isActive());
-
- editor.setEditor(button, item, ACTIVATION_COLUMN);
- editor.horizontalAlignment = SWT.CENTER;
- editor.grabHorizontal = true;
-
- }
- }
-
- return self;
- }
-
- @Override
- protected void performDefaults() {
- restoreDefaults();
- super.performDefaults();
- }
-
- @Override
- protected void performApply() {
- IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
-
- for (Map.Entry<NavigationContributorDescriptor, Button> entry : checkboxes.entrySet()) {
- boolean checked = entry.getValue().getSelection();
- String isActiveKey = NavigationContributorDescriptor.getIsActiveKey(entry.getKey());
- preferences.setValue(isActiveKey, checked);
- }
-
- try {
- IEclipsePreferences preferenceStore = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
- preferenceStore.flush();
- } catch (BackingStoreException ex) {
- Activator.log.error(ex);
- }
- }
-
- @Override
- public boolean performOk() {
- performApply();
- return super.performOk();
- }
-
- /**
- * Restores the default preferences
- */
-
- public void restoreDefaults() {
- IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
-
- for (Map.Entry<NavigationContributorDescriptor, Button> entry : checkboxes.entrySet()) {
- String isActiveKey = NavigationContributorDescriptor.getIsActiveKey(entry.getKey());
- boolean selected = preferences.getDefaultBoolean(isActiveKey);
-
- entry.getValue().setSelection(selected);
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Nizar GUEDIDI (CEA LIST) - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.navigation.preferences;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.window.ToolTip;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.navigation.Activator;
+import org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl;
+import org.eclipse.papyrus.infra.services.navigation.service.impl.NavigationServiceImpl.ContributorDescriptor;
+import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.osgi.service.prefs.BackingStoreException;
+
+public class NavigationServicePreferencesPage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ public static final int ACTIVATION_COLUMN = 0;
+
+ private Map<ContributorDescriptor, Button> checkboxes;
+
+ private NavigationServiceImpl navigation = new NavigationServiceImpl();
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public NavigationServicePreferencesPage() {
+ super("Navigation Services", org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor("/icons/papyrus.png"));
+ }
+
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription("Papyrus navigation services configuration.\nSelect the strategies you wish to activate.");
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+
+ Composite self = new Composite(parent, SWT.NONE);
+ self.setLayout(new GridLayout(1, true));
+ self.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ final TableViewer tableViewer = new TableViewer(self, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ tableViewer.getTable().setLayoutData(gridData);
+
+ ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
+
+ tableViewer.setContentProvider(CollectionContentProvider.instance);
+
+ try {
+ navigation.startService();
+ } catch (ServiceException ex) {
+ return self;
+ }
+
+ tableViewer.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public void update(ViewerCell cell) {
+ if (cell.getColumnIndex() == 1) {
+ super.update(cell);
+ } else {
+ return;
+ }
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof ContributorDescriptor) {
+ return ((ContributorDescriptor) element).getDescription();
+ }
+ return super.getToolTipText(element);
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof ContributorDescriptor) {
+ return null;
+ }
+
+ return super.getImage(element);
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof ContributorDescriptor) {
+ return ((ContributorDescriptor) element).getLabel();
+ }
+ return super.getText(element);
+ }
+ });
+
+ TableLayout layout = new TableLayout();
+
+ new TableColumn(tableViewer.getTable(), SWT.LEFT);
+ layout.addColumnData(new ColumnWeightData(10, 25, false));
+
+ new TableColumn(tableViewer.getTable(), SWT.LEFT);
+ layout.addColumnData(new ColumnWeightData(100, 250, true));
+
+ tableViewer.getTable().setLayout(layout);
+ tableViewer.getTable().setHeaderVisible(false);
+
+ List<ContributorDescriptor> contributors = new LinkedList<ContributorDescriptor>();
+ contributors.addAll(navigation.getNavigationContributors());
+ contributors.addAll(navigation.getNavigationMenuContributors());
+ tableViewer.setInput(contributors);
+
+ // Adds a checkbox for each service navigation, to toggle it
+ checkboxes = new HashMap<ContributorDescriptor, Button>();
+
+ for (TableItem item : tableViewer.getTable().getItems()) {
+ if (item.getData() instanceof ContributorDescriptor) {
+ TableEditor editor = new TableEditor(tableViewer.getTable());
+
+ final Button button = new Button(tableViewer.getTable(), SWT.CHECK);
+ final TableItem currentItem = item;
+
+ final ContributorDescriptor strategy = (ContributorDescriptor) currentItem.getData();
+
+ checkboxes.put(strategy, button);
+
+ button.setSelection(strategy.isActive());
+
+ editor.setEditor(button, item, ACTIVATION_COLUMN);
+ editor.horizontalAlignment = SWT.CENTER;
+ editor.grabHorizontal = true;
+
+ }
+ }
+
+ return self;
+ }
+
+ @Override
+ protected void performDefaults() {
+ restoreDefaults();
+ super.performDefaults();
+ }
+
+ @Override
+ protected void performApply() {
+ IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
+
+ for (Map.Entry<ContributorDescriptor, Button> entry : checkboxes.entrySet()) {
+ boolean checked = entry.getValue().getSelection();
+ String isActiveKey = ContributorDescriptor.getIsActiveKey(entry.getKey());
+ preferences.setValue(isActiveKey, checked);
+ }
+
+ try {
+ IEclipsePreferences preferenceStore = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+ preferenceStore.flush();
+ } catch (BackingStoreException ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ @Override
+ public boolean performOk() {
+ performApply();
+ return super.performOk();
+ }
+
+ /**
+ * Restores the default preferences
+ */
+
+ public void restoreDefaults() {
+ IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
+
+ for (Map.Entry<ContributorDescriptor, Button> entry : checkboxes.entrySet()) {
+ String isActiveKey = ContributorDescriptor.getIsActiveKey(entry.getKey());
+ boolean selected = preferences.getDefaultBoolean(isActiveKey);
+
+ entry.getValue().setSelection(selected);
+ }
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/ExtendedNavigableElement.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/ExtendedNavigableElement.java
new file mode 100644
index 00000000000..e0a9085f3a0
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/ExtendedNavigableElement.java
@@ -0,0 +1,23 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.navigation.service;
+
+public interface ExtendedNavigableElement extends NavigableElement {
+ /**
+ * Get the semantic element associated with this navigable element
+ *
+ * @return
+ */
+ public Object getSemanticElement();
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigableElement.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigableElement.java
index 9f4a8e0e0b4..ac10b60d17d 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigableElement.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigableElement.java
@@ -1,74 +1,74 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.navigation.service;
-
-import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
-import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Represents a single instance of NavigableElement
- *
- * @author Camille Letavernier
- *
- */
-public interface NavigableElement {
-
- /**
- * The label of this navigable element
- *
- * @return
- */
- public String getLabel();
-
- /**
- * The description of this navigable element
- *
- * @return
- */
- public String getDescription();
-
- /**
- * Executes the navigation action
- *
- * @param navigationContext
- * The NavigationTarget that can be used to select the navigation target
- * @return true if the navigation context could select and reveal this element
- */
- public boolean navigate(NavigationTarget navigationContext);
-
- /**
- * Executes the navigation action
- *
- * @param navigationContext
- * The IRevealSemanticElement that can be used to select the navigation target
- *
- * @deprecated Use {@link #navigate(NavigationTarget)} instead
- */
- @Deprecated
- public void navigate(IRevealSemanticElement revealSemanticElement);
-
- /**
- * The Image of this navigable element
- *
- * @return
- */
- public Image getImage();
-
- /**
- * Indicates whether this element is enabled. The element will be displayed
- * but won't be navigable
- *
- * @return
- */
- public boolean isEnabled();
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.navigation.service;
+
+import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Represents a single instance of NavigableElement
+ *
+ * @author Camille Letavernier
+ *
+ */
+public interface NavigableElement {
+
+ /**
+ * The label of this navigable element
+ *
+ * @return
+ */
+ public String getLabel();
+
+ /**
+ * The description of this navigable element
+ *
+ * @return
+ */
+ public String getDescription();
+
+ /**
+ * Executes the navigation action
+ *
+ * @param navigationContext
+ * The NavigationTarget that can be used to select the navigation target
+ * @return true if the navigation context could select and reveal this element
+ */
+ public boolean navigate(NavigationTarget navigationContext);
+
+ /**
+ * Executes the navigation action
+ *
+ * @param navigationContext
+ * The IRevealSemanticElement that can be used to select the navigation target
+ *
+ * @deprecated Use {@link #navigate(NavigationTarget)} instead
+ */
+ @Deprecated
+ public void navigate(IRevealSemanticElement revealSemanticElement);
+
+ /**
+ * The Image of this navigable element
+ *
+ * @return
+ */
+ public Image getImage();
+
+ /**
+ * Indicates whether this element is enabled. The element will be displayed
+ * but won't be navigable
+ *
+ * @return
+ */
+ public boolean isEnabled();
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenu.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenu.java
new file mode 100644
index 00000000000..20beff52e09
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenu.java
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.navigation.service;
+
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.swt.widgets.Shell;
+
+public interface NavigationMenu {
+ public void handleRequest(Object request, Object target);
+ public boolean willEnter(Object request, Object target);
+ public void exitItem();
+ public Object navigate(Object request, Object host);
+ public List<Object> getAppendObjects();
+ public List<Object> getPrependObjects();
+ public void setServicesRegistry(ServicesRegistry registry);
+ public void setParentShell(Shell parentShell);
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuButton.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuButton.java
new file mode 100644
index 00000000000..ddaf1638471
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuButton.java
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.navigation.service;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * This class represents a wrapper that contains info on a button in the navigation menu.
+ * It is only a model that contains enough information so the navigation menu can implement
+ * the actual button (frontend).
+ *
+ */
+
+public abstract class NavigationMenuButton {
+ protected String label;
+ protected Image icon;
+ protected String tooltip;
+
+ public NavigationMenuButton(String label, Image icon, String tooltip) {
+ this.label = label;
+ this.icon = icon;
+ this.tooltip = tooltip;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public Image getIcon() {
+ return icon;
+ }
+
+ public String getTooltip() {
+ return tooltip;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public void setIcon(Image icon) {
+ this.icon = icon;
+ }
+
+ public void setTooltip(String tooltip) {
+ this.tooltip = tooltip;
+ }
+} // end NavMenuButton \ No newline at end of file
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuContributor.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuContributor.java
new file mode 100644
index 00000000000..d11e8767db9
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationMenuContributor.java
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Shuai Li (CEA LIST) <shuai.li@cea.fr> - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.navigation.service;
+
+import java.util.List;
+
+/**
+ * Classes that implement this interface returns a list of related objects to the given object in the parameter
+ *
+ */
+public interface NavigationMenuContributor {
+ public List<NavigationMenuButton> getButtons(Object fromElement);
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationService.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationService.java
index b072d9d5f71..24facdaadb8 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationService.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/NavigationService.java
@@ -1,54 +1,59 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.navigation.service;
-
-import org.eclipse.papyrus.infra.core.services.IService;
-import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
-import org.eclipse.swt.widgets.Control;
-
-/**
- * A Service to navigate from an element.
- * The navigation is based on external contributions.
- *
- * Examples:
- * - Navigate from a TypedElement to its Type declaration in the ModelExplorer
- * - ...
- *
- * @author Camille Letavernier
- *
- * @see NavigationContributor
- */
-public interface NavigationService extends IService, NavigationContributor {
-
- /**
- * Creates a Selection Menu to display all the NavigableElement which can be reached from an element
- *
- * @param fromElement
- * @param parent
- * @return
- */
- public SelectionMenu createNavigationList(Object fromElement, Control parent);
-
- /**
- * Navigate to the target of the given NavigableElement (e.g. To the type of a TypedElement)
- *
- * @param navigableElement
- */
- public void navigate(NavigableElement navigableElement);
-
- /**
- * Navigate directly to the given element (e.g. a UML Element)
- *
- * @param element
- */
- public void navigate(Object element);
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.navigation.service;
+
+import org.eclipse.papyrus.infra.core.services.IService;
+
+/**
+ * A Service to navigate from an element.
+ * The navigation is based on external contributions.
+ *
+ * Examples:
+ * - Navigate from a TypedElement to its Type declaration in the ModelExplorer
+ * - ...
+ *
+ * @author Camille Letavernier
+ *
+ * @see NavigationContributor
+ */
+public interface NavigationService extends IService, NavigationContributor, NavigationMenuContributor {
+
+ /**
+ * Creates a Selection Menu to display all the NavigableElement which can be reached from an element
+ *
+ * @param fromElement
+ * @param parent
+ * @return
+ */
+ public NavigationMenu createNavigationList();
+
+ /**
+ * Navigate to the target of the given NavigableElement (e.g. To the type of a TypedElement)
+ *
+ * @param navigableElement
+ */
+ public void navigate(NavigableElement navigableElement);
+
+ /**
+ * Navigate directly to the given element (e.g. a UML Element)
+ *
+ * @param element
+ */
+ public void navigate(Object element);
+
+ /**
+ * Navigate to the given element with the chosen target provider
+ *
+ * @param element
+ */
+ public void navigate(Object element, String providerClassKey);
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/impl/NavigationServiceImpl.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/impl/NavigationServiceImpl.java
index 8c8ad2ca484..d1ed2566660 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/impl/NavigationServiceImpl.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.navigation/src/org/eclipse/papyrus/infra/services/navigation/service/impl/NavigationServiceImpl.java
@@ -1,385 +1,441 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.navigation.service.impl;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.TreeSet;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.services.navigation.Activator;
-import org.eclipse.papyrus.infra.services.navigation.provider.NavigationTargetProvider;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigationService;
-import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
-import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
-import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Control;
-
-/**
- * Base implementation of the NavigationService. It is based on the
- * navigationContributor extension point.
- *
- * @author Camille Letavernier
- */
-public class NavigationServiceImpl implements NavigationService {
-
- public static final String EXTENSION_ID = Activator.PLUGIN_ID + ".navigationContributor";
-
- /**
- * The isActive property suffix (For preferences)
- */
- public static final String IS_ACTIVE_KEY = "isActive"; //$NON-NLS-1$
-
- protected ServicesRegistry registry;
-
- /**
- * {@inheritDoc}
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
- // Nothing
- this.registry = servicesRegistry;
- }
-
- /**
- * {@inheritDoc}
- */
- public void startService() throws ServiceException {
- createNavigationContributors();
- createNavigationTargetProviders();
- }
-
- protected void createNavigationContributors() {
- navigationContributors = new LinkedList<NavigationContributorDescriptor>();
-
- IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
-
- for (IConfigurationElement e : config) {
- if (!"contributor".equals(e.getName())) {
- continue;
- }
- try {
- Object instance = e.createExecutableExtension("contributor");
- if (instance instanceof NavigationContributor) {
- NavigationContributorDescriptor wrapper = new NavigationContributorDescriptor((NavigationContributor) instance);
- wrapper.setId(e.getAttribute("id"));
- wrapper.setLabel(e.getAttribute("label"));
- wrapper.setDescription(e.getAttribute("description"));
- wrapper.init();
- navigationContributors.add(wrapper);
- }
- } catch (Exception ex) {
- Activator.log.warn("Invalid navigation contribution from: " + e.getContributor());
- }
- }
- }
-
- protected void createNavigationTargetProviders() {
- navigationTargetProviders = new TreeSet<NavigationTargetProvider>();
-
- IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
-
- for (IConfigurationElement e : config) {
- if (!"target".equals(e.getName())) {
- continue;
- }
- try {
- Object instance = e.createExecutableExtension("navigationTargetProvider");
- if (instance instanceof NavigationTargetProvider) {
- NavigationTargetProviderDescriptor descriptor = new NavigationTargetProviderDescriptor((NavigationTargetProvider) instance);
- descriptor.setId(e.getAttribute("id"));
- descriptor.setLabel(e.getAttribute("label"));
- descriptor.setDescription(e.getAttribute("description"));
- descriptor.setOrder(Integer.parseInt(e.getAttribute("order")));
- navigationTargetProviders.add(descriptor);
- }
- } catch (Exception ex) {
- Activator.log.warn("Invalid navigation target contribution from: " + e.getContributor());
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void disposeService() throws ServiceException {
- this.registry = null;
- }
-
- /**
- * {@inheritDoc}
- */
- public List<NavigableElement> getNavigableElements(Object fromElement) {
- List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
-
- for (NavigationContributorDescriptor contributor : navigationContributors) {
- if (contributor.isActive()) {
- navigableElements.addAll(contributor.getNavigableElements(fromElement));
- }
- }
-
- return navigableElements;
- }
-
- public static class NavigationTargetProviderDescriptor implements NavigationTargetProvider, Comparable<NavigationTargetProviderDescriptor> {
-
- private NavigationTargetProvider provider;
-
- private int order;
-
- private String label;
-
- private String description;
-
- private String id;
-
- public NavigationTargetProviderDescriptor(NavigationTargetProvider provider) {
- this.provider = provider;
- }
-
- public NavigationTarget getNavigationTarget(ServicesRegistry registry) {
- return provider.getNavigationTarget(registry);
- }
-
- public int getOrder() {
- return order;
- }
-
- public String getLabel() {
- return label;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setOrder(int order) {
- this.order = order;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public int compareTo(NavigationTargetProviderDescriptor o) {
- if (o == null) {
- return -1;
- }
-
- if (o.order == order) {
- return 0;
- }
-
- return o.order < order ? 1 : -1;
- }
-
- }
-
- public static class NavigationContributorDescriptor implements NavigationContributor {
-
- private final NavigationContributor contributor;
-
- private String label;
-
- private String description;
-
- private String id;
-
- private final IPreferenceStore preferences;
-
- public NavigationContributorDescriptor(NavigationContributor contributor) {
- this.contributor = contributor;
-
- preferences = Activator.getDefault().getPreferenceStore();
- }
-
- public void init() {
- String isActiveKey = getIsActiveKey(this);
- preferences.setDefault(isActiveKey, true);
- }
-
- public List<NavigableElement> getNavigableElements(Object fromElement) {
- if (isActive()) {
- return contributor.getNavigableElements(fromElement);
- } else {
- return Collections.emptyList();
- }
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public boolean isActive() { /* NavigationContributorWrapper strategy */
- String preferenceKey = getIsActiveKey(this);
- return preferences.getBoolean(preferenceKey);
- }
-
- public static String getIsActiveKey(NavigationContributorDescriptor strategy) {
- return strategy.getId() + "." + IS_ACTIVE_KEY;
- }
-
- }
-
- private List<NavigationContributorDescriptor> navigationContributors;
-
- private Collection<NavigationTargetProvider> navigationTargetProviders;
-
- public List<NavigationContributorDescriptor> getNavigationContributors() {
- return navigationContributors;
- }
-
- public Collection<NavigationTargetProvider> getNavigationTargetProviders() {
- return navigationTargetProviders;
- }
-
- /**
- * {@inheritDoc}
- */
- public SelectionMenu createNavigationList(Object fromElement, final Control parent) {
- List<NavigableElement> navigableElements = getNavigableElements(fromElement);
- if (navigableElements.isEmpty()) {
- return null;
- }
-
- SelectionMenu selectionMenu = new SelectionMenu(parent.getShell());
- selectionMenu.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (element instanceof NavigableElement) {
- return ((NavigableElement) element).getLabel();
- }
- return super.getText(element);
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof NavigableElement) {
- return ((NavigableElement) element).getImage();
- }
- return super.getImage(element);
- }
-
- @Override
- public String getToolTipText(Object element) {
- if (element instanceof NavigableElement) {
- return ((NavigableElement) element).getDescription();
- }
- return super.getToolTipText(element);
- }
-
- @Override
- public Color getForeground(Object element) {
- if (element instanceof NavigableElement) {
- NavigableElement navigableElement = (NavigableElement) element;
- if (!navigableElement.isEnabled()) {
- return parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
- }
- }
- return super.getForeground(element);
- }
- });
-
- selectionMenu.setContentProvider(CollectionContentProvider.instance);
- selectionMenu.setInput(navigableElements);
-
- selectionMenu.open();
-
- return selectionMenu;
- }
-
- /**
- * {@inheritDoc}
- */
- public void navigate(NavigableElement navigableElement) {
- if (registry == null) {
- throw new IllegalStateException("The navigation service is not initialized");
- }
-
- for (NavigationTargetProvider provider : getNavigationTargetProviders()) {
- NavigationTarget target = provider.getNavigationTarget(registry);
-
- if (target == null) {
- continue;
- }
-
- if (navigableElement.navigate(target)) {
- return;
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void navigate(Object element) {
- if (registry == null) {
- throw new IllegalStateException("The navigation service is not initialized");
- }
-
- for (NavigationTargetProvider provider : getNavigationTargetProviders()) {
- NavigationTarget target = provider.getNavigationTarget(registry);
-
- if (target == null) {
- continue;
- }
-
- if (target.revealElement(element)) {
- return;
- }
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.navigation.service.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.TreeSet;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.services.navigation.Activator;
+import org.eclipse.papyrus.infra.services.navigation.provider.NavigationTargetProvider;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationService;
+import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
+
+/**
+ * Base implementation of the NavigationService. It is based on the
+ * navigationContributor extension point.
+ *
+ * @author Camille Letavernier
+ */
+public class NavigationServiceImpl implements NavigationService {
+
+ public static final String NAVIGATION_CONTRIBUTOR_EXTENSION_ID = Activator.PLUGIN_ID + ".navigationContributor";
+
+ public static final String NAVIGATION_MENU_CONTRIBUTOR_EXTENSION_ID = Activator.PLUGIN_ID + ".navigationMenuContributor";
+
+ public static final String NAVIGATION_MENU_EXTENSION_ID = Activator.PLUGIN_ID + ".navigationMenu";
+
+ /**
+ * The isActive property suffix (For preferences)
+ */
+ public static final String IS_ACTIVE_KEY = "isActive"; //$NON-NLS-1$
+
+ protected ServicesRegistry registry;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ // Nothing
+ this.registry = servicesRegistry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void startService() throws ServiceException {
+ createNavigationContributors();
+ createNavigationTargetProviders();
+ createNavigationMenuContributors();
+ }
+
+ protected void createNavigationContributors() {
+ navigationContributors = new LinkedList<NavigationContributorDescriptor>();
+
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(NAVIGATION_CONTRIBUTOR_EXTENSION_ID);
+
+ for (IConfigurationElement e : config) {
+ if (!"contributor".equals(e.getName())) {
+ continue;
+ }
+ try {
+ Object instance = e.createExecutableExtension("contributor");
+ if (instance instanceof NavigationContributor) {
+ NavigationContributorDescriptor wrapper = new NavigationContributorDescriptor((NavigationContributor) instance);
+ wrapper.setId(e.getAttribute("id"));
+ wrapper.setLabel(e.getAttribute("label"));
+ wrapper.setDescription(e.getAttribute("description"));
+ wrapper.init();
+ navigationContributors.add(wrapper);
+ }
+ } catch (Exception ex) {
+ Activator.log.warn("Invalid navigation contribution from: " + e.getContributor());
+ }
+ }
+ }
+
+ protected void createNavigationMenuContributors() {
+ navigationMenuContributors = new LinkedList<NavigationMenuContributorDescriptor>();
+
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(NAVIGATION_MENU_CONTRIBUTOR_EXTENSION_ID);
+
+ for (IConfigurationElement e : config) {
+ if (!"contributor".equals(e.getName())) {
+ continue;
+ }
+ try {
+ Object instance = e.createExecutableExtension("contributor");
+ if (instance instanceof NavigationMenuContributor) {
+ NavigationMenuContributorDescriptor wrapper = new NavigationMenuContributorDescriptor((NavigationMenuContributor) instance);
+ wrapper.setId(e.getAttribute("id"));
+ wrapper.setLabel(e.getAttribute("label"));
+ wrapper.setDescription(e.getAttribute("description"));
+ wrapper.init();
+ navigationMenuContributors.add(wrapper);
+ }
+ } catch (Exception ex) {
+ Activator.log.warn("Invalid navigation contribution from: " + e.getContributor());
+ }
+ }
+ }
+
+ protected void createNavigationTargetProviders() {
+ navigationTargetProviders = new TreeSet<NavigationTargetProvider>();
+
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(NAVIGATION_CONTRIBUTOR_EXTENSION_ID);
+
+ for (IConfigurationElement e : config) {
+ if (!"target".equals(e.getName())) {
+ continue;
+ }
+ try {
+ Object instance = e.createExecutableExtension("navigationTargetProvider");
+ if (instance instanceof NavigationTargetProvider) {
+ NavigationTargetProviderDescriptor descriptor = new NavigationTargetProviderDescriptor((NavigationTargetProvider) instance);
+ descriptor.setId(e.getAttribute("id"));
+ descriptor.setLabel(e.getAttribute("label"));
+ descriptor.setDescription(e.getAttribute("description"));
+ descriptor.setOrder(Integer.parseInt(e.getAttribute("order")));
+ navigationTargetProviders.add(descriptor);
+ }
+ } catch (Exception ex) {
+ Activator.log.warn("Invalid navigation target contribution from: " + e.getContributor());
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void disposeService() throws ServiceException {
+ this.registry = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<NavigableElement> getNavigableElements(Object fromElement) {
+ List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
+
+ for (NavigationContributorDescriptor contributor : navigationContributors) {
+ if (contributor.isActive()) {
+ navigableElements.addAll(contributor.getNavigableElements(fromElement));
+ }
+ }
+
+ return navigableElements;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ for (NavigationMenuContributorDescriptor contributor : navigationMenuContributors) {
+ if (contributor.isActive()) {
+ buttons.addAll(contributor.getButtons(fromElement));
+ }
+ }
+
+ return buttons;
+ }
+
+ public static class NavigationTargetProviderDescriptor implements NavigationTargetProvider, Comparable<NavigationTargetProviderDescriptor> {
+
+ private NavigationTargetProvider provider;
+
+ private int order;
+
+ private String label;
+
+ private String description;
+
+ private String id;
+
+ public NavigationTargetProviderDescriptor(NavigationTargetProvider provider) {
+ this.provider = provider;
+ }
+
+ public NavigationTarget getNavigationTarget(ServicesRegistry registry) {
+ return provider.getNavigationTarget(registry);
+ }
+
+ public int getOrder() {
+ return order;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public int compareTo(NavigationTargetProviderDescriptor o) {
+ if (o == null) {
+ return -1;
+ }
+
+ if (o.order == order) {
+ return 0;
+ }
+
+ return o.order < order ? 1 : -1;
+ }
+
+ }
+
+ public static class ContributorDescriptor {
+ private String label;
+
+ private String description;
+
+ private String id;
+
+ private final IPreferenceStore preferences;
+
+ public ContributorDescriptor() {
+ preferences = Activator.getDefault().getPreferenceStore();
+ }
+
+ public void init() {
+ String isActiveKey = getIsActiveKey(this);
+ preferences.setDefault(isActiveKey, true);
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isActive() { /* NavigationContributorWrapper strategy */
+ String preferenceKey = getIsActiveKey(this);
+ return preferences.getBoolean(preferenceKey);
+ }
+
+ public static String getIsActiveKey(ContributorDescriptor strategy) {
+ return strategy.getId() + "." + IS_ACTIVE_KEY;
+ }
+ }
+
+ public static class NavigationContributorDescriptor extends ContributorDescriptor implements NavigationContributor {
+ private final NavigationContributor contributor;
+
+ public NavigationContributorDescriptor(NavigationContributor contributor) {
+ this.contributor = contributor;
+ }
+
+ public List<NavigableElement> getNavigableElements(Object fromElement) {
+ if (isActive()) {
+ return contributor.getNavigableElements(fromElement);
+ } else {
+ return Collections.emptyList();
+ }
+ }
+ }
+
+ public static class NavigationMenuContributorDescriptor extends ContributorDescriptor implements NavigationMenuContributor {
+ private final NavigationMenuContributor contributor;
+
+ public NavigationMenuContributorDescriptor(NavigationMenuContributor contributor) {
+ this.contributor = contributor;
+ }
+
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ if (isActive()) {
+ return contributor.getButtons(fromElement);
+ } else {
+ return Collections.emptyList();
+ }
+ }
+ }
+
+ private List<NavigationContributorDescriptor> navigationContributors;
+
+ private Collection<NavigationTargetProvider> navigationTargetProviders;
+
+ private List<NavigationMenuContributorDescriptor> navigationMenuContributors;
+
+ public List<NavigationContributorDescriptor> getNavigationContributors() {
+ return navigationContributors;
+ }
+
+ public Collection<NavigationTargetProvider> getNavigationTargetProviders() {
+ return navigationTargetProviders;
+ }
+
+ public List<NavigationMenuContributorDescriptor> getNavigationMenuContributors() {
+ return navigationMenuContributors;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NavigationMenu createNavigationList() {
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(NAVIGATION_MENU_EXTENSION_ID);
+
+ for (IConfigurationElement e : config) {
+ if (!"menu".equals(e.getName())) {
+ continue;
+ }
+ try {
+ Object instance = e.createExecutableExtension("menu");
+ if (instance instanceof NavigationMenu) {
+ return (NavigationMenu) instance;
+ }
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ Activator.log.warn("Invalid navigation menu from: " + e.getContributor());
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void navigate(NavigableElement navigableElement) {
+ if (registry == null) {
+ throw new IllegalStateException("The navigation service is not initialized");
+ }
+
+ for (NavigationTargetProvider provider : getNavigationTargetProviders()) {
+ NavigationTarget target = provider.getNavigationTarget(registry);
+
+ if (target == null) {
+ continue;
+ }
+
+ if (navigableElement.navigate(target)) {
+ return;
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void navigate(Object element) {
+ if (registry == null) {
+ throw new IllegalStateException("The navigation service is not initialized");
+ }
+
+ for (NavigationTargetProvider provider : getNavigationTargetProviders()) {
+ NavigationTarget target = provider.getNavigationTarget(registry);
+
+ if (target == null) {
+ continue;
+ }
+
+ if (target.revealElement(element)) {
+ return;
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void navigate(Object element, String providerId) {
+ if (registry == null) {
+ throw new IllegalStateException("The navigation service is not initialized");
+ }
+
+ for (NavigationTargetProvider provider : getNavigationTargetProviders()) {
+ if (((NavigationTargetProviderDescriptor) provider).getId().equals(providerId)) {
+ NavigationTarget target = provider.getNavigationTarget(registry);
+
+ if (target == null) {
+ continue;
+ }
+
+ if (target.revealElement(element)) {
+ return;
+ }
+ }
+ }
+ }
+}

Back to the top