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
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>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml6
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/PopupBarEditPolicyProvider.java73
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml63
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperLinkPopupBarEditPolicy.java3
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperlinkNavigationMenuEditPolicy.java252
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/NavigationEditPolicy.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigableElement.java80
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/providers/HyperlinkEditPolicyProvider.java147
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/META-INF/MANIFEST.MF11
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/plugin.xml140
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/decorator/NavigationDecoratorProvider.java196
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/editpolicy/NavigationEditPolicy.java254
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/DefaultNavigationMenu.java566
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/HyperlinkButton.java48
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/MoreButton.java23
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/NavigationSubMenuButton.java44
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/NavigationMenuKeyListener.java45
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuMouseTrackListener.java147
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuSelectionChangedListener.java104
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SubSelectionMenuSelectionChangedListener.java74
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SelectionMenuLabelProvider.java131
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SubSelectionMenuLabelProvider.java49
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menuContributor/OwnedDiagramsButton.java (renamed from plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigationProvider.java)170
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.viewersearcher/src/org/eclipse/papyrus/infra/gmfdiag/viewersearcher/DiagramViewerSearcher.java5
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/AbstractEditHyperlinkShell.java378
-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
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/plugin.xml37
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/src/org/eclipse/papyrus/infra/services/viewlabelprovider/provider/DiagramOfViewLabelProvider.java78
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/SelectionMenu.java422
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/META-INF/MANIFEST.MF39
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/plugin.xml84
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ChildrenButton.java70
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ParentsButton.java66
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/SourcesButton.java71
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TargetsButton.java71
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TypesButton.java74
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/CBANavigableElement.java (renamed from plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/CBANavigableElement.java)214
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/CBANavigationContributor.java (renamed from plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/CBANavigationContributor.java)82
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedElementNavigationContributor.java42
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedNavigableElement.java115
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/OperationTypeNavigableElement.java (renamed from plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/OperationTypeNavigableElement.java)74
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/TypedElementNavigationContributor.java (renamed from plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/TypedElementNavigationContributor.java)88
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/TypedNavigableElement.java (renamed from plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/TypedNavigableElement.java)210
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF130
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java308
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IPageBookViewPageListener.java4
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java8
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java2558
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java4
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actionprovider/UndoRedoActionProvider.java8
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actions/GenericTransformer.java886
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java882
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java326
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java4
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java2
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java244
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java2
67 files changed, 7368 insertions, 4823 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
index 569d0eba835..ec3bfd1fd8a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -311,6 +311,12 @@
name="Lowest">
</Priority>
</editpolicyProvider>
+ <editpolicyProvider
+ class="org.eclipse.papyrus.infra.gmfdiag.common.providers.PopupBarEditPolicyProvider">
+ <Priority
+ name="Lowest">
+ </Priority>
+ </editpolicyProvider>
</extension>
<extension
point="org.eclipse.papyrus.infra.gmfdiag.commands.historyListeners">
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/PopupBarEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/PopupBarEditPolicyProvider.java
new file mode 100644
index 00000000000..9b4bbca4027
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/PopupBarEditPolicyProvider.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (c) 2012, 2014 CEA LIST, Christian W. Damus, 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
+ * Shuai Li
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusPopupBarEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+
+/**
+ * An EditPolicyProvider for Papyrus
+ *
+ * @author Shuai Li
+ *
+ */
+public class PopupBarEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
+
+ /**
+ * {@inheritDoc}
+ *
+ * This provider can handle GraphicalEditParts
+ */
+ public boolean provides(IOperation operation) {
+ if (operation instanceof CreateEditPoliciesOperation) {
+ CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
+ EditPart editPart = epOperation.getEditPart();
+ try {
+ ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(editPart);
+ if (registry == null) {
+ // We're not in the Papyrus context
+ return false;
+ }
+ } catch (ServiceException ex) {
+ // We're not in the Papyrus context
+ // Ignore the exception and do not provide the EditPolicy
+ return false;
+ }
+ return editPart instanceof IGraphicalEditPart;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Installs the Papyrus edit policy
+ */
+ public void createEditPolicies(EditPart editPart) {
+ if (editPart instanceof IPrimaryEditPart) {
+ editPart.installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new PapyrusPopupBarEditPolicy());
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml
index c2e965c397e..91cc4e06ce7 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml
@@ -1,36 +1,27 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension
- point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
- <editpolicyProvider
- class="org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers.HyperlinkEditPolicyProvider">
- <Priority
- name="Lowest">
- </Priority>
- </editpolicyProvider>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy">
- <strategy
- strategy="org.eclipse.papyrus.infra.gmfdiag.hyperlink.dnd.HyperlinkDropStrategy">
- </strategy>
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.hyperlink.specificHyperLinks">
- <specificHyperLink
- contentProvider="org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers.SpecificViewContentProvider">
- </specificHyperLink>
-
- </extension>
- <extension
- point="org.eclipse.papyrus.infra.services.navigation.navigationContributor">
- <contributor
- contributor="org.eclipse.papyrus.infra.gmfdiag.hyperlink.navigation.DiagramNavigationProvider"
- description="Navigates to the current element&apos;s diagram(s)"
- id="org.eclipse.papyrus.infra.gmfdiag.hyperlink.diagram"
- label="Automatic Diagram Navigation">
- </contributor>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
+ <editpolicyProvider
+ class="org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers.HyperlinkEditPolicyProvider">
+ <Priority
+ name="Lowest">
+ </Priority>
+ </editpolicyProvider>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy">
+ <strategy
+ strategy="org.eclipse.papyrus.infra.gmfdiag.hyperlink.dnd.HyperlinkDropStrategy">
+ </strategy>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.hyperlink.specificHyperLinks">
+ <specificHyperLink
+ contentProvider="org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers.SpecificViewContentProvider">
+ </specificHyperLink>
+
+ </extension>
+
+</plugin>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperLinkPopupBarEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperLinkPopupBarEditPolicy.java
index 543cefd253f..83753f6b0fd 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperLinkPopupBarEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperLinkPopupBarEditPolicy.java
@@ -33,8 +33,7 @@ import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusPopupBarEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.hyperlink.ui.AdvancedHLManager;
-import org.eclipse.papyrus.infra.hyperlink.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.hyperlink.Activator;
import org.eclipse.papyrus.infra.hyperlink.helper.AbstractHyperLinkHelper;
import org.eclipse.papyrus.infra.hyperlink.helper.HyperLinkHelperFactory;
import org.eclipse.papyrus.infra.hyperlink.object.HyperLinkObject;
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperlinkNavigationMenuEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperlinkNavigationMenuEditPolicy.java
new file mode 100644
index 00000000000..03cf2f11cde
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/HyperlinkNavigationMenuEditPolicy.java
@@ -0,0 +1,252 @@
+/*****************************************************************************
+ * Copyright (c) 2009, 2014 CEA LIST, Christian W. Damus, 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
+ * Shuai Li - Modifications for navigation menu integration
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.tools.AbstractPopupBarTool;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistry;
+import org.eclipse.papyrus.infra.core.editorsfactory.PageIconsRegistry;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.hyperlink.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.editpolicy.NavigationEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.HyperlinkButton;
+import org.eclipse.papyrus.infra.hyperlink.helper.AbstractHyperLinkHelper;
+import org.eclipse.papyrus.infra.hyperlink.helper.HyperLinkHelperFactory;
+import org.eclipse.papyrus.infra.hyperlink.object.HyperLinkDocument;
+import org.eclipse.papyrus.infra.hyperlink.object.HyperLinkObject;
+import org.eclipse.papyrus.infra.hyperlink.object.HyperLinkWeb;
+import org.eclipse.papyrus.infra.hyperlink.ui.HyperLinkManagerShell;
+import org.eclipse.papyrus.infra.hyperlink.util.HyperLinkException;
+import org.eclipse.papyrus.infra.hyperlink.util.HyperLinkHelpersRegistrationUtil;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * The Class HyperlinkNavigationMenuEditPolicy can be applied on edit part to display
+ * shortcuts on sub-diagrams or to associate hyper-link of files, in addition to the
+ * tools provided by the Navigation menu.
+ */
+public class HyperlinkNavigationMenuEditPolicy extends NavigationEditPolicy {
+
+ /** The editor registry. */
+ private IPageIconsRegistry editorRegistry;
+
+ /** The hyper link manager shell. */
+ private HyperLinkManagerShell hyperLinkManagerShell;
+
+ protected LinkedList<HyperLinkObject> hyperLinkObjectList;
+
+ protected HyperLinkHelperFactory hyperlinkHelperFactory;
+
+ public HyperlinkNavigationMenuEditPolicy() {
+ super();
+
+ ArrayList<AbstractHyperLinkHelper> hyperLinkHelpers = new ArrayList<AbstractHyperLinkHelper>();
+ // TODO
+ // hyperLinkHelpers.add(new DiagramHyperLinkHelper());
+ // hyperLinkHelpers.add(new DocumentHyperLinkHelper());
+ // hyperLinkHelpers.add(new WebHyperLinkHelper());
+ hyperLinkHelpers.addAll(HyperLinkHelpersRegistrationUtil.INSTANCE.getAllRegisteredHyperLinkHelper());
+ hyperlinkHelperFactory = new HyperLinkHelperFactory(hyperLinkHelpers);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void appendNavigationMenuItem() {
+ clearAppendObjects();
+
+ // add all subdiagrams
+ try {
+ hyperLinkObjectList = new LinkedList<HyperLinkObject>();
+ ArrayList<HyperLinkObject> unfilteredHyperlinkObjects = (ArrayList<HyperLinkObject>) hyperlinkHelperFactory.getAllreferenced(((IGraphicalEditPart) getHost()).getNotationView());
+
+ for (AbstractHyperLinkHelper hyperlinkHelper : hyperlinkHelperFactory.getHyperLinkHelpers()) {
+ hyperLinkObjectList.addAll(hyperlinkHelper.getFilteredObject(unfilteredHyperlinkObjects));
+ }
+
+ if (hyperLinkObjectList.isEmpty()) {
+ hyperLinkObjectList.addAll(unfilteredHyperlinkObjects);
+ } else if (hyperLinkObjectList.size() != unfilteredHyperlinkObjects.size()) {
+ hyperLinkObjectList.clear();
+ hyperLinkObjectList.addAll(unfilteredHyperlinkObjects);
+ }
+
+ addHyperlinks();
+ } catch (HyperLinkException e) {
+ Activator.log.error(e);
+ }
+
+ // Add the New Hyperlink tool
+ addNavigationMenuHyperlinkDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.uml.diagram.common", "/icons/obj16/Plus.gif").createImage(), new AddHyperlinkAction(), "Open hyperlinks menu", "Modify hyperlinks");
+ }
+
+ private void addHyperlinks() {
+ ILabelProvider labelProvider = null;
+ boolean localLabelProvider = false;
+ try {
+ EObject contextElement = EMFHelper.getEObject(getHost());
+ labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, contextElement).getLabelProvider();
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+
+ if (labelProvider == null) {
+ labelProvider = new LabelProvider();
+ localLabelProvider = true;
+ }
+
+ for (HyperLinkObject hyperlink : hyperLinkObjectList) {
+ String tooltip;
+ String text;
+ if (labelProvider instanceof CellLabelProvider) {
+ tooltip = ((CellLabelProvider) labelProvider).getToolTipText(hyperlink);
+ text = tooltip;
+ } else {
+ if (hyperlink instanceof HyperLinkDocument || hyperlink instanceof HyperLinkWeb) {
+ text = hyperlink.getTooltipText();
+ tooltip = labelProvider.getText(hyperlink);
+ } else {
+ text = labelProvider.getText(hyperlink);
+ tooltip = hyperlink.getTooltipText();
+ }
+
+ if (tooltip == null) {
+ tooltip = text;
+ }
+
+ if (text == null) {
+ text = tooltip;
+ }
+ }
+
+ addNavigationMenuHyperlinkDescriptor(labelProvider.getImage(hyperlink), new NavigateHyperlinkAction(hyperlink), tooltip, text);
+ }
+
+ if (localLabelProvider) {
+ labelProvider.dispose();
+ }
+ }
+
+ protected void addNavigationMenuHyperlinkDescriptor(Image theImage, IAction theAction, String theTip, String theText) {
+ if (!(theAction instanceof AbstractPopupBarTool) || ((AbstractPopupBarTool) theAction).isCommandEnabled()) {
+ // We only add pop-up bar tools whose commands are actually executable in this context
+ HyperlinkButton desc = new HyperlinkButton(theText, theTip, theImage, theAction);
+ this.navigationMenu.getAppendObjects().add(desc);
+ }
+ }
+
+ //
+ // Nested types
+ //
+
+ //protected abstract class AbstractHyperlinkTool extends AbstractTool implements DragTracker {
+ protected abstract class AbstractHyperlinkAction extends Action {
+
+ }
+
+ public class AddHyperlinkAction extends AbstractHyperlinkAction {
+ @Override
+ public void run() {
+ hyperLinkManagerShell = new HyperLinkManagerShell(getEditorRegistry(), ((IGraphicalEditPart) getHost()).getEditingDomain(), (EModelElement) ((IGraphicalEditPart) getHost()).getNotationView().getElement(),
+ ((IGraphicalEditPart) getHost()).getNotationView(), hyperlinkHelperFactory);
+ hyperLinkManagerShell.setInput(hyperLinkObjectList);
+
+ // Hide the navigation menu now because the shell is modal
+ //destroyViewerContext();
+
+ hyperLinkManagerShell.open();
+ }
+ }
+
+ protected class NavigateHyperlinkAction extends AbstractHyperlinkAction {
+ private final HyperLinkObject hyperlink;
+
+ public NavigateHyperlinkAction(HyperLinkObject hyperlink) {
+ super();
+
+ this.hyperlink = hyperlink;
+ }
+
+ @Override
+ public void run() {
+ if (hyperlink.needsOpenCommand()) {
+ try {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForEditPart.getInstance().getTransactionalEditingDomain(getHost());
+ editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain, hyperlink.getTooltipText()) {
+
+ @Override
+ protected void doExecute() {
+ hyperlink.openLink();
+ }
+ });
+ } catch (ServiceException ex) {
+
+ }
+ } else {
+ hyperlink.openLink();
+ }
+ }
+ }
+
+ /**
+ * Return the EditorRegistry for nested editor descriptors. Subclass should
+ * implements this method in order to return the registry associated to the
+ * extension point namespace.
+ *
+ * @return the EditorRegistry for nested editor descriptors
+ *
+ * @generated NOT
+ */
+ protected IPageIconsRegistry createEditorRegistry() {
+ try {
+ return ServiceUtilsForEditPart.getInstance().getService(IPageIconsRegistry.class, getHost());
+ } catch (ServiceException e) {
+ // Return an empty registry always providing null;
+ return new PageIconsRegistry();
+ }
+ }
+
+ /**
+ * Gets the editor registry.
+ *
+ * @return the singleton eINSTANCE of editor registry
+ *
+ * @generated NOT Get the EditorRegistry used to create editor instances.
+ * This default implementation return the singleton eINSTANCE.
+ * This method can be subclassed to return another registry.
+ */
+ protected IPageIconsRegistry getEditorRegistry() {
+ if (editorRegistry == null) {
+ editorRegistry = createEditorRegistry();
+ }
+ return editorRegistry;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/NavigationEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/NavigationEditPolicy.java
index ce46788598b..27fe0bc19a4 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/NavigationEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/editpolicies/NavigationEditPolicy.java
@@ -437,7 +437,7 @@ public class NavigationEditPolicy extends OpenEditPolicy {
/**
* Get the open command previously defined by ShortCutEditPolicy
- *
+ *
* @param request
* @return
*/
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigableElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigableElement.java
deleted file mode 100644
index 017312dd0e8..00000000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigableElement.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*****************************************************************************
- * 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.gmfdiag.hyperlink.navigation;
-
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.infra.gmfdiag.hyperlink.Activator;
-import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
-import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
-import org.eclipse.swt.graphics.Image;
-
-
-public class DiagramNavigableElement implements NavigableElement {
-
- protected Diagram targetDiagram;
-
- public DiagramNavigableElement(Diagram target) {
- this.targetDiagram = target;
- }
-
- public String getLabel() {
- return "Navigate to diagram " + targetDiagram.getName();
- }
-
- public String getDescription() {
- return String.format("Navigates to the %s %s", targetDiagram.getType(), targetDiagram.getName());
- }
-
- public boolean navigate(NavigationTarget navigationContext) {
- try {
- final IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(targetDiagram);
- if (pageManager.isOpen(targetDiagram)) {
- pageManager.selectPage(targetDiagram);
- } else {
- pageManager.openPage(targetDiagram);
- }
-
- return true;
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
-
- return false;
- }
-
- @Deprecated
- public void navigate(IRevealSemanticElement revealSemanticElement) {
- }
-
- public Image getImage() {
- if (targetDiagram != null) {
- try {
- ILabelProvider labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, targetDiagram).getLabelProvider();
- return labelProvider.getImage(targetDiagram);
- } catch (ServiceException ex) {
- return null;
- }
- }
- return null;
- }
-
- public boolean isEnabled() {
- return targetDiagram != null;
- }
-
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/providers/HyperlinkEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/providers/HyperlinkEditPolicyProvider.java
index eb71d7edd18..10fab80d91b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/providers/HyperlinkEditPolicyProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/providers/HyperlinkEditPolicyProvider.java
@@ -1,77 +1,70 @@
-/*****************************************************************************
- * Copyright (c) 2012, 2014 CEA LIST, Christian W. Damus, 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 451230
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.HyperLinkPopupBarEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.NavigationEditPolicy;
-
-/**
- * An EditPolicyProvider for Navigation and Hyperlinks
- *
- * @author Camille Letavernier
- *
- */
-public class HyperlinkEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
-
- /**
- * {@inheritDoc}
- *
- * This provider can handle GraphicalEditParts
- */
- public boolean provides(IOperation operation) {
- if (operation instanceof CreateEditPoliciesOperation) {
- CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
- EditPart editPart = epOperation.getEditPart();
- try {
- ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(editPart);
- if (registry == null) {
- // We're not in the Papyrus context
- return false;
- }
- } catch (ServiceException ex) {
- // We're not in the Papyrus context
- // Ignore the exception and do not provide the EditPolicy
- return false;
- }
- return editPart instanceof IGraphicalEditPart;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * Installs the Hyperlink and Navigation edit policies
- */
- public void createEditPolicies(EditPart editPart) {
- if (editPart instanceof IPrimaryEditPart) {
- editPart.removeEditPolicy(EditPolicyRoles.POPUPBAR_ROLE);
- editPart.installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new HyperLinkPopupBarEditPolicy());
- }
- editPart.installEditPolicy(NavigationEditPolicy.NAVIGATION_POLICY, new NavigationEditPolicy());
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2014 CEA LIST, Christian W. Damus, 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
+ * Shuai Li
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.HyperlinkNavigationMenuEditPolicy;
+
+/**
+ * An EditPolicyProvider for Navigation and Hyperlinks
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class HyperlinkEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
+
+ /**
+ * {@inheritDoc}
+ *
+ * This provider can handle GraphicalEditParts
+ */
+ public boolean provides(IOperation operation) {
+ if (operation instanceof CreateEditPoliciesOperation) {
+ CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
+ EditPart editPart = epOperation.getEditPart();
+ try {
+ ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(editPart);
+ if (registry == null) {
+ // We're not in the Papyrus context
+ return false;
+ }
+ } catch (ServiceException ex) {
+ // We're not in the Papyrus context
+ // Ignore the exception and do not provide the EditPolicy
+ return false;
+ }
+ return editPart instanceof IGraphicalEditPart;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Installs the Hyperlink and Navigation edit policies
+ */
+ public void createEditPolicies(EditPart editPart) {
+ editPart.installEditPolicy(org.eclipse.papyrus.infra.gmfdiag.navigation.editpolicy.NavigationEditPolicy.EDIT_POLICY_ID, new HyperlinkNavigationMenuEditPolicy());
+ editPart.installEditPolicy(org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.NavigationEditPolicy.NAVIGATION_POLICY, new org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.NavigationEditPolicy());
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/META-INF/MANIFEST.MF
index 1b534447835..9f0cf30520d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/META-INF/MANIFEST.MF
@@ -13,10 +13,17 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0",
org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.services.navigation;bundle-version="1.2.0"
+ org.eclipse.papyrus.infra.services.navigation;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.openelement;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.viewersearch;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.2.0"
Export-Package: org.eclipse.papyrus.infra.gmfdiag.navigation,
org.eclipse.papyrus.infra.gmfdiag.navigation.decorator,
- org.eclipse.papyrus.infra.gmfdiag.navigation.preference
+ org.eclipse.papyrus.infra.gmfdiag.navigation.editpolicy,
+ org.eclipse.papyrus.infra.gmfdiag.navigation.preference,
+ org.eclipse.papyrus.infra.gmfdiag.navigation,
+ org.eclipse.papyrus.infra.gmfdiag.navigation.menu,
+ org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.2.0.qualifier
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/plugin.xml
index 3cf7598e118..4b28c900086 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/plugin.xml
@@ -1,65 +1,75 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension-point id="navigationRules" name="navigationRules" schema="schema/navigationRules.exsd"/>
- <extension-point id="navigationDecoratorRules" name="navigationDecoratorRules" schema="schema/navigationDecoratorRules.exsd"/>
- <extension-point id="navigationColorProviders" name="navigationColorProviders" schema="schema/navigationColorProviders.exsd"/>
- <extension
- point="org.eclipse.ui.preferencePages">
- <page
- category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
- class="org.eclipse.papyrus.infra.gmfdiag.navigation.preference.NavigationPreferencePage"
- id="org.eclipse.papyrus.navigation"
- name="Navigation">
- </page>
- </extension>
- <extension
- point="org.eclipse.core.runtime.preferences">
- <initializer
- class="org.eclipse.papyrus.infra.gmfdiag.navigation.preference.NavigationPreferenceInitializer">
- </initializer>
- </extension>
- <extension
- point="org.eclipse.gmf.runtime.diagram.ui.decoratorProviders">
- <decoratorProvider
- class="org.eclipse.papyrus.infra.gmfdiag.navigation.decorator.NavigationDecoratorProvider">
- <Priority
- name="Medium">
- </Priority>
- </decoratorProvider>
- </extension>
- <extension
- point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
- <editpolicyProvider
- class="org.eclipse.papyrus.infra.gmfdiag.navigation.provider.NavigationEditPolicyProvider">
- <Priority
- name="Medium">
- </Priority>
- </editpolicyProvider>
- </extension>
-
- <!--commented for the build Juno M4, because perspective doesn't work-->
-
- <!--<extension
- point="org.eclipse.papyrus.editor.perspectiveconfiguration">
- <configuration
- perspectiveID="org.eclipse.papyrus.infra.core.perspective">
- <toolbar
- toolbarID="org.eclipse.papyrus.navigation.toolbars.navigationToolbar">
- </toolbar>
- <command
- commandID="org.eclipse.papyrus.navigation.commands.backNavigationCommand">
- </command>
- <command
- commandID="org.eclipse.papyrus.navigation.commands.nextNavigationCommand">
- </command>
- <command
- commandID="org.eclipse.papyrus.navigation.commands.topNavigationCommand">
- </command>
- <command
- commandID="org.eclipse.papyrus.navigation.commands.upNavigationCommand">
- </command>
- </configuration>
- </extension>
- -->
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="navigationRules" name="navigationRules" schema="schema/navigationRules.exsd"/>
+ <extension-point id="navigationDecoratorRules" name="navigationDecoratorRules" schema="schema/navigationDecoratorRules.exsd"/>
+ <extension-point id="navigationColorProviders" name="navigationColorProviders" schema="schema/navigationColorProviders.exsd"/>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
+ class="org.eclipse.papyrus.infra.gmfdiag.navigation.preference.NavigationPreferencePage"
+ id="org.eclipse.papyrus.navigation"
+ name="Navigation">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.papyrus.infra.gmfdiag.navigation.preference.NavigationPreferenceInitializer">
+ </initializer>
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.decoratorProviders">
+ <decoratorProvider
+ class="org.eclipse.papyrus.infra.gmfdiag.navigation.decorator.NavigationDecoratorProvider">
+ <Priority
+ name="Medium">
+ </Priority>
+ </decoratorProvider>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.navigation.navigationMenuContributor">
+ <contributor
+ contributor="org.eclipse.papyrus.infra.gmfdiag.navigation.menuContributor.OwnedDiagramsButton"
+ description="Diagrams owned by the selected element"
+ id="org.eclipse.papyrus.infra.gmfdiag.navigation..ownedDiagramsButton"
+ label="Owned diagrams">
+ </contributor>
+ </extension>
+
+ <extension
+ point="org.eclipse.papyrus.infra.services.navigation.navigationMenu">
+ <menu
+ description="The default navigation menu that appears on Alt+Hover"
+ id="org.eclipse.papyrus.infra.gmfdiag.navigation.defaultNavigationMenu"
+ label="Default navigation menu"
+ menu="org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu">
+ </menu>
+ </extension>
+
+ <!--commented for the build Juno M4, because perspective doesn't work-->
+
+ <!--<extension
+ point="org.eclipse.papyrus.editor.perspectiveconfiguration">
+ <configuration
+ perspectiveID="org.eclipse.papyrus.infra.core.perspective">
+ <toolbar
+ toolbarID="org.eclipse.papyrus.navigation.toolbars.navigationToolbar">
+ </toolbar>
+ <command
+ commandID="org.eclipse.papyrus.navigation.commands.backNavigationCommand">
+ </command>
+ <command
+ commandID="org.eclipse.papyrus.navigation.commands.nextNavigationCommand">
+ </command>
+ <command
+ commandID="org.eclipse.papyrus.navigation.commands.topNavigationCommand">
+ </command>
+ <command
+ commandID="org.eclipse.papyrus.navigation.commands.upNavigationCommand">
+ </command>
+ </configuration>
+ </extension>
+ -->
+</plugin>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/decorator/NavigationDecoratorProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/decorator/NavigationDecoratorProvider.java
index a935aa4c6a9..920c20f3935 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/decorator/NavigationDecoratorProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/decorator/NavigationDecoratorProvider.java
@@ -1,98 +1,98 @@
-/*****************************************************************************
- * Copyright (c) 2011 Atos Origin.
- *
- *
- * 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:
- * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.navigation.decorator;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
-import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
-import org.eclipse.papyrus.infra.gmfdiag.navigation.preference.INavigationPreferenceConstant;
-import org.eclipse.papyrus.infra.gmfdiag.preferences.Activator;
-
-public class NavigationDecoratorProvider extends AbstractProvider implements IDecoratorProvider {
-
- private static Set<Class<?>> forbiddenClasses = new HashSet<Class<?>>();
-
- private static Set<Class<?>> decoratedClasses = new HashSet<Class<?>>();
-
- private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.gmfdiag.navigation.navigationDecoratorRules";
-
- private static final String FORBIDDENCLASS_ID = "forbiddenClass";
-
- private static final String DECORATEDCLASS_ID = "decoratedClass";
-
- private static final String CLASS_ID = "class";
-
- static {
- // Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
- for (IConfigurationElement configElement : configElements) {
- String className = configElement.getAttribute(CLASS_ID);
- Class<?> class_ = null;
- try {
- class_ = Platform.getBundle(configElement.getContributor().getName()).loadClass(className);
- } catch (Exception e) {
- }
-
- if (class_ != null) {
- if (FORBIDDENCLASS_ID.equals(configElement.getName())) {
- forbiddenClasses.add(class_);
- } else if (DECORATEDCLASS_ID.equals(configElement.getName())) {
- decoratedClasses.add(class_);
- }
- }
- }
- }
-
- public boolean provides(IOperation operation) {
- String decoratorVisibility = Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY);
- if (operation instanceof CreateDecoratorsOperation && !INavigationPreferenceConstant.DISABLED.equals(decoratorVisibility)) {
- IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation).getDecoratorTarget();
- EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class);
- if (editPart instanceof IPrimaryEditPart) {
- EObject element = ((IGraphicalEditPart) editPart).resolveSemanticElement();
- boolean decorate = false;
- for (Class<?> class_ : decoratedClasses) {
- if (class_.isInstance(element)) {
- decorate = true;
- break;
- }
- }
- for (Class<?> class_ : forbiddenClasses) {
- if (class_.isInstance(element)) {
- decorate = false;
- break;
- }
- }
- return decorate;
- }
- }
- return false;
- }
-
- public void createDecorators(IDecoratorTarget decoratorTarget) {
- new NavigationDecorator(decoratorTarget);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin.
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.navigation.decorator;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.preference.INavigationPreferenceConstant;
+import org.eclipse.papyrus.infra.gmfdiag.preferences.Activator;
+
+public class NavigationDecoratorProvider extends AbstractProvider implements IDecoratorProvider {
+
+ private static Set<Class<?>> forbiddenClasses = new HashSet<Class<?>>();
+
+ private static Set<Class<?>> decoratedClasses = new HashSet<Class<?>>();
+
+ private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.gmfdiag.navigation.navigationDecoratorRules";
+
+ private static final String FORBIDDENCLASS_ID = "forbiddenClass";
+
+ private static final String DECORATEDCLASS_ID = "decoratedClass";
+
+ private static final String CLASS_ID = "class";
+
+ static {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+ for (IConfigurationElement configElement : configElements) {
+ String className = configElement.getAttribute(CLASS_ID);
+ Class<?> class_ = null;
+ try {
+ class_ = Platform.getBundle(configElement.getContributor().getName()).loadClass(className);
+ } catch (Exception e) {
+ }
+
+ if (class_ != null) {
+ if (FORBIDDENCLASS_ID.equals(configElement.getName())) {
+ forbiddenClasses.add(class_);
+ } else if (DECORATEDCLASS_ID.equals(configElement.getName())) {
+ decoratedClasses.add(class_);
+ }
+ }
+ }
+ }
+
+ public boolean provides(IOperation operation) {
+ String decoratorVisibility = Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY);
+ if (operation instanceof CreateDecoratorsOperation && !INavigationPreferenceConstant.DISABLED.equals(decoratorVisibility)) {
+ IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation).getDecoratorTarget();
+ EditPart editPart = decoratorTarget.getAdapter(EditPart.class);
+ if (editPart instanceof IPrimaryEditPart) {
+ EObject element = ((IGraphicalEditPart) editPart).resolveSemanticElement();
+ boolean decorate = false;
+ for (Class<?> class_ : decoratedClasses) {
+ if (class_.isInstance(element)) {
+ decorate = true;
+ break;
+ }
+ }
+ for (Class<?> class_ : forbiddenClasses) {
+ if (class_.isInstance(element)) {
+ decorate = false;
+ break;
+ }
+ }
+ return decorate;
+ }
+ }
+ return false;
+ }
+
+ public void createDecorators(IDecoratorTarget decoratorTarget) {
+ new NavigationDecorator(decoratorTarget);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/editpolicy/NavigationEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/editpolicy/NavigationEditPolicy.java
index 06121f1c88d..97fd218b966 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/editpolicy/NavigationEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/editpolicy/NavigationEditPolicy.java
@@ -8,13 +8,10 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Shuai Li (CEA LIST) shuai.li@cea.fr - Selection menu modifications
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.navigation.editpolicy;
-import java.util.List;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.EditPolicy;
@@ -23,19 +20,13 @@ import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gef.requests.SelectionRequest;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
import org.eclipse.papyrus.infra.gmfdiag.navigation.Activator;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu;
import org.eclipse.papyrus.infra.services.navigation.service.NavigationService;
-import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
+import org.eclipse.swt.widgets.Shell;
/**
* An edit policy to use the {@link NavigationService} on GMF Diagrams
@@ -47,14 +38,13 @@ public class NavigationEditPolicy extends GraphicalEditPolicy {
public static final String EDIT_POLICY_ID = "org.eclipse.papyrus.infra.gmfdiag.navigation.NavigationEditPolicy";
- private ViewerContext viewerContext;
+ protected NavigationMenu navigationMenu;
@Override
public void activate() {
super.activate();
initViewerContext();
-
- if (viewerContext == null) {
+ if (navigationMenu == null) {
return;
}
}
@@ -62,11 +52,22 @@ public class NavigationEditPolicy extends GraphicalEditPolicy {
private void initViewerContext() {
if (getHost() == getRoot()) {
EditPartViewer viewer = getHost().getViewer();
- viewerContext = new ViewerContext(viewer);
+ try {
+ ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(getHost());
+ Shell parentShell = viewer.getControl().getShell();
+
+ navigationMenu = registry.getService(NavigationService.class).createNavigationList();
+ if (navigationMenu != null) {
+ navigationMenu.setServicesRegistry(registry);
+ navigationMenu.setParentShell(parentShell);
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
} else {
EditPolicy rootNavigationEditPolicy = getRoot().getEditPolicy(EDIT_POLICY_ID);
if (rootNavigationEditPolicy instanceof NavigationEditPolicy) {
- this.viewerContext = ((NavigationEditPolicy) rootNavigationEditPolicy).viewerContext;
+ this.navigationMenu = ((NavigationEditPolicy) rootNavigationEditPolicy).navigationMenu;
}
}
}
@@ -75,7 +76,7 @@ public class NavigationEditPolicy extends GraphicalEditPolicy {
public void showTargetFeedback(Request request) {
super.showTargetFeedback(request);
- if (viewerContext == null) {
+ if (navigationMenu == null) {
return;
}
@@ -86,14 +87,25 @@ public class NavigationEditPolicy extends GraphicalEditPolicy {
if (request instanceof SelectionRequest) {
SelectionRequest selectionRequest = (SelectionRequest) request;
- viewerContext.handleRequest(selectionRequest);
+ EditPart targetEditPart = getHost().getViewer().findObjectAt(selectionRequest.getLocation());
+
+ if (navigationMenu.willEnter(selectionRequest, targetEditPart)) {
+ prependNavigationMenuItem();
+ appendNavigationMenuItem();
+ }
+
+ navigationMenu.handleRequest(selectionRequest, targetEditPart);
}
}
@Override
public Command getCommand(Request request) {
- if (request instanceof SelectionRequest && viewerContext != null) {
- return viewerContext.navigate((SelectionRequest) request);
+ if (request instanceof SelectionRequest && navigationMenu != null) {
+ SelectionRequest selectionRequest = (SelectionRequest) request;
+ Object command = navigationMenu.navigate(selectionRequest, getHost());
+ if (command instanceof Command) {
+ return (Command) command;
+ }
}
return super.getCommand(request);
}
@@ -103,197 +115,23 @@ public class NavigationEditPolicy extends GraphicalEditPolicy {
return rootEditPart.getContents();
}
- // A Single ViewerContext for each diagram (Root EditPartViewer)
- private class ViewerContext {
-
- private EditPartViewer editPartViewer;
-
- private EObject currentModel;
-
- private SelectionMenu selectionMenu;
-
- private boolean wasUnderlined;
-
- private WrappingLabel lastWrappingLabel;
-
- public void handleRequest(SelectionRequest request) {
- if (isExitState(request)) {
- exitItem();
- }
-
- if (isEnterState(request)) {
- enterItem(currentModel, request);
- }
- }
-
- public Command navigate(final SelectionRequest request) {
- if (!isAlt(request)) {
- return null;
- }
-
- final NavigableElement element = getElementToNavigate(request);
- if (element == null) {
- return null;
- }
-
- return new Command() {
-
- @Override
- public void execute() {
- try {
- getNavigationService(request).navigate(element);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- exitItem();
- }
- };
- }
-
- private NavigableElement getElementToNavigate(SelectionRequest request) {
- try {
- List<NavigableElement> navigableElements = getNavigationService(request).getNavigableElements(getEditPart(request));
- if (navigableElements.isEmpty()) {
- return null;
- }
-
- for (NavigableElement element : navigableElements) {
- if (element.isEnabled()) {
- return element;
- }
- }
- } catch (ServiceException ex) {
- // Ignore: the service is not available, do nothing
- }
- return null;
- }
-
- private NavigationService getNavigationService(SelectionRequest request) throws ServiceException {
- return getServicesRegistry().getService(NavigationService.class);
- }
-
- public ViewerContext(EditPartViewer editPartViewer) {
- this.editPartViewer = editPartViewer;
- }
-
- private boolean isExitState(SelectionRequest request) {
- if (currentModel == null) {
- return false;
- }
-
- EObject newModel = getModel(request);
- if (newModel == null) {
- return true;
- }
-
- if (newModel != currentModel) {
- return true;
- }
-
- if (!isAlt(request)) {
- return true;
- }
-
- return false;
- }
-
- private boolean isEnterState(SelectionRequest request) {
- EObject model = getModel(request);
- if (model == currentModel) {
- return false;
- }
-
- if (model == null) {
- return false;
- }
-
- if (!isAlt(request)) {
- return false;
- }
-
- currentModel = model;
-
- return true;
- }
-
- private boolean isAlt(SelectionRequest request) {
- return request.isAltKeyPressed();
- }
-
- private EObject getModel(SelectionRequest request) {
- return EMFHelper.getEObject(getEditPart(request));
-
- }
-
- private EditPart getEditPart(SelectionRequest request) {
- return editPartViewer.findObjectAt(request.getLocation());
- }
-
- private void disposeCurrentMenu() {
- if (selectionMenu != null) {
- selectionMenu.dispose();
- selectionMenu = null;
- }
- }
-
- private void exitItem() {
- if (lastWrappingLabel != null) {
- lastWrappingLabel.setTextUnderline(wasUnderlined);
- }
- wasUnderlined = false;
- lastWrappingLabel = null;
- currentModel = null;
- disposeCurrentMenu();
- }
-
- private void enterItem(EObject model, SelectionRequest request) {
- try {
- EditPart targetEditPart = getEditPart(request);
-
- final NavigationService navigation = getServicesRegistry().getService(NavigationService.class);
- disposeCurrentMenu();
- selectionMenu = navigation.createNavigationList(targetEditPart, editPartViewer.getControl());
- if (selectionMenu == null) {
- return;
- }
-
- wasUnderlined = false;
- if (targetEditPart instanceof IGraphicalEditPart) {
- IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) targetEditPart;
- IFigure figure = graphicalEditPart.getFigure();
- if (figure instanceof WrappingLabel) {
- lastWrappingLabel = ((WrappingLabel) figure);
- wasUnderlined = lastWrappingLabel.isTextUnderlined();
- lastWrappingLabel.setTextUnderline(!wasUnderlined);
- }
- }
-
- selectionMenu.addSelectionChangedListener(new ISelectionChangedListener() {
+ protected void prependNavigationMenuItem () {
+ // Nothing here, written in sub-classes
+ }
- public void selectionChanged(SelectionChangedEvent event) {
- if (event.getSelection().isEmpty()) {
- return;
- }
- Object selectedElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
- if (selectedElement instanceof NavigableElement) {
- NavigableElement navigableElement = (NavigableElement) selectedElement;
- navigate(navigableElement, navigation);
- }
- }
- });
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- }
+ protected void appendNavigationMenuItem () {
+ // Nothing here, written in sub-classes
+ }
- private void navigate(NavigableElement navigableElement, NavigationService navigationService) {
- navigationService.navigate(navigableElement);
- exitItem();
+ protected void clearAppendObjects() {
+ if (navigationMenu != null && navigationMenu.getAppendObjects() != null) {
+ navigationMenu.getAppendObjects().clear();
}
+ }
- private ServicesRegistry getServicesRegistry() throws ServiceException {
- return ServiceUtilsForEditPart.getInstance().getServiceRegistry(getHost());
+ protected void clearPrependObjects() {
+ if (navigationMenu != null && navigationMenu.getPrependObjects() != null) {
+ this.navigationMenu.getPrependObjects().clear();
}
-
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/DefaultNavigationMenu.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/DefaultNavigationMenu.java
new file mode 100644
index 00000000000..8deb3c8c0e5
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/DefaultNavigationMenu.java
@@ -0,0 +1,566 @@
+/*****************************************************************************
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.navigation.menu;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.SelectionRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.papyrus.infra.core.services.BadStateException;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.MoreButton;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.listener.NavigationMenuKeyListener;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.listener.SelectionMenuMouseTrackListener;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.listener.SelectionMenuSelectionChangedListener;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.provider.SelectionMenuLabelProvider;
+import org.eclipse.papyrus.infra.services.navigation.service.ExtendedNavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+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.NavigationService;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.infra.services.viewersearch.impl.ViewerSearchService;
+import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
+import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TreeItem;
+
+// A Single ViewerContext for each diagram (Root EditPartViewer)
+public class DefaultNavigationMenu implements NavigationMenu {
+ private ServicesRegistry servicesRegistry;
+
+ private Shell parentShell;
+
+ private NavigationService navigationService;
+
+ private ViewerSearchService viewerSearchService;
+
+ private EObject currentModel;
+
+ private List<Object> prependObjects;
+
+ private List<Object> appendObjects;
+
+ private SelectionMenu selectionMenu;
+
+ private List<SelectionMenu> subMenus;
+
+ private boolean wasUnderlined;
+
+ private WrappingLabel lastWrappingLabel;
+
+ public class NavigationMenuInitializationException extends Exception {
+ private static final long serialVersionUID = 1094797103244873186L;
+
+ private Object source;
+
+ public NavigationMenuInitializationException(Object source) {
+ this.source = source;
+ }
+
+ @Override
+ public String getMessage() {
+ String error = "";
+
+ if (source instanceof ServicesRegistry) {
+ error = "services registry is not set";
+ } else if (source instanceof Shell) {
+ error = "parent shell is not set";
+ } else if (source instanceof NavigationService) {
+ error = "navigation service could not be initialized";
+ }
+
+ return "Navigation menu initialization error: " + error;
+ }
+ }
+
+ public DefaultNavigationMenu() {
+ this.appendObjects = new LinkedList<Object>();
+ this.prependObjects = new LinkedList<Object>();
+ }
+
+ public void handleRequest(SelectionRequest request, EditPart targetEditPart) {
+ if (targetEditPart != null) {
+ EObject model = EMFHelper.getEObject(targetEditPart);
+
+ if (isExitState(request, model)) {
+ exitItem();
+ }
+
+ if (isEnterState(request, model)) {
+ enterItem(targetEditPart);
+ }
+ }
+ }
+
+ public void handleRequest(MouseEvent e, TreeItem treeItem) {
+ if (treeItem != null) {
+ EObject model = EMFHelper.getEObject(treeItem.getData());
+
+ if (isExitState(e, model)) {
+ exitItem();
+ }
+
+ if (isEnterState(e, model)) {
+ enterItem(model);
+ }
+ }
+ }
+
+ protected boolean isExitState(SelectionRequest request, EObject model) {
+ if (!request.isAltKeyPressed()) {
+ return true;
+ }
+
+ return isExitState(model);
+ }
+
+ private boolean isExitState(MouseEvent e, EObject model) {
+ if ((e.stateMask & SWT.ALT) == 0) {
+ return true;
+ }
+
+ return isExitState(model);
+ }
+
+ protected boolean isExitState(EObject model) {
+ if (currentModel == null) {
+ return false;
+ }
+
+ if (model == null) {
+ return true;
+ }
+
+ if (model != currentModel) {
+ return true;
+ }
+
+ return false;
+ }
+
+ protected boolean isEnterState(SelectionRequest request, EObject model) {
+ if (!request.isAltKeyPressed()) {
+ return false;
+ }
+
+ return isEnterState(model);
+ }
+
+ protected boolean isEnterState(MouseEvent e, EObject model) {
+ if ((e.stateMask & SWT.ALT) == 0) {
+ return false;
+ }
+
+ return isEnterState(model);
+ }
+
+ protected boolean isEnterState(EObject model) {
+ if (model == currentModel) {
+ return false;
+ }
+
+ if (model == null) {
+ return false;
+ }
+
+ currentModel = model;
+
+ return true;
+ }
+
+ public boolean willEnter(SelectionRequest request, EditPart targetEditPart) {
+ if (!request.isAltKeyPressed()) {
+ return false;
+ }
+
+ EObject model = null;
+ if (targetEditPart != null) {
+ model = EMFHelper.getEObject(targetEditPart);
+
+ }
+
+ return willEnter(model);
+ }
+
+ public boolean willEnter(EObject model) {
+ if (model == currentModel) {
+ return false;
+ }
+
+ if (model == null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private void disposeCurrentMenu() {
+ if (selectionMenu != null) {
+ selectionMenu.dispose();
+ selectionMenu = null;
+ }
+ }
+
+ public void exitItem() {
+ if (lastWrappingLabel != null) {
+ lastWrappingLabel.setTextUnderline(wasUnderlined);
+ }
+
+ wasUnderlined = false;
+ lastWrappingLabel = null;
+ currentModel = null;
+
+ disposeCurrentMenu();
+ }
+
+ private void enterItem(Object source) {
+ disposeCurrentMenu();
+
+ Shell shell;
+ try {
+ shell = getParentShell();
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ return;
+ }
+
+ // The list that contains items of the Navigation Menu
+ final List<Object> navigationMenuElements = new LinkedList<Object>();
+
+ // Add objects to prepend
+ if (prependObjects != null && prependObjects.size() > 0) {
+ navigationMenuElements.addAll(prependObjects);
+ }
+
+ // Add navigable objects
+ try {
+ navigationMenuElements.addAll(getNavigationService().getNavigableElements(source));
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ return;
+ }
+
+ // Add objects to append
+ if (appendObjects != null && appendObjects.size() > 0) {
+ navigationMenuElements.addAll(appendObjects);
+ }
+
+ // Nothing to display...
+ if (navigationMenuElements.isEmpty()) {
+ return;
+ }
+
+ // Add "More..." button
+ navigationMenuElements.add(new MoreButton());
+
+ // The semantic element
+ EObject umlElement = EMFHelper.getEObject(source);
+
+ // Create the selection menu and subMenus list
+ selectionMenu = new SelectionMenu(shell);
+ subMenus = new LinkedList<SelectionMenu>();
+
+ selectionMenu.setLabelProvider(new SelectionMenuLabelProvider());
+
+ selectionMenu.setContentProvider(CollectionContentProvider.instance);
+ selectionMenu.setInput(navigationMenuElements);
+ selectionMenu.open();
+
+ wasUnderlined = false;
+ if (source instanceof IGraphicalEditPart) {
+ IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) source;
+ IFigure figure = graphicalEditPart.getFigure();
+ if (figure instanceof WrappingLabel) {
+ lastWrappingLabel = ((WrappingLabel) figure);
+ wasUnderlined = lastWrappingLabel.isTextUnderlined();
+ lastWrappingLabel.setTextUnderline(!wasUnderlined);
+ }
+ }
+
+ selectionMenu.addSelectionChangedListener(new SelectionMenuSelectionChangedListener(DefaultNavigationMenu.this, selectionMenu, navigationMenuElements, umlElement, subMenus));
+ selectionMenu.addKeyListener(new NavigationMenuKeyListener(this));
+ selectionMenu.addMouseTrackListener(new SelectionMenuMouseTrackListener(DefaultNavigationMenu.this, selectionMenu, subMenus, umlElement));
+ }
+
+ public void addContextualMenus(List<Object> navigationMenuElements, Object umlElement) {
+ List<NavigationMenuButton> buttons;
+ try {
+ buttons = getNavigationService().getButtons(umlElement);
+ navigationMenuElements.addAll(buttons);
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ public List<Object> getViewsToSelect(NavigableElement navElement, boolean onlyOpened) {
+ if (navElement == null) {
+ return null;
+ }
+
+ EObject element = null;
+ if (navElement instanceof ExtendedNavigableElement
+ && ((ExtendedNavigableElement) navElement).getSemanticElement() instanceof EObject) {
+ element = (EObject) ((ExtendedNavigableElement) navElement).getSemanticElement();
+ }
+
+ if (element != null) {
+ ViewerSearchService viewerSearchService = null;
+
+ try {
+ viewerSearchService = getViewerSearchService();
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ }
+
+ if (viewerSearchService != null) {
+ return viewerSearchService.getViewersInCurrentModel(element, null, false, true);
+ }
+ }
+
+ return new LinkedList<Object>();
+ }
+
+ public void showInModelExplorer(NavigableElement navigableElement) {
+ Object semanticElement = null;
+ if (navigableElement instanceof ExtendedNavigableElement) {
+ semanticElement = ((ExtendedNavigableElement) navigableElement).getSemanticElement();
+ }
+
+ if (semanticElement != null) {
+ try {
+ getNavigationService().navigate(semanticElement, "org.eclipse.papyrus.views.modelexplorer.navigation.target");
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ exitItem();
+ }
+
+ public void revealObject(Object object) {
+ ServicesRegistry registry = null;
+ try {
+ registry = getServicesRegistry();
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ exitItem();
+ return;
+ }
+
+ try {
+ OpenElementService service = registry.getService(OpenElementService.class);
+ if (object instanceof EObject) {
+ service.openElement((EObject) object);
+ }
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ exitItem();
+ }
+
+ private ServicesRegistry getServicesRegistry() throws NavigationMenuInitializationException {
+ if (servicesRegistry == null) {
+ throw new NavigationMenuInitializationException(servicesRegistry);
+ }
+ return servicesRegistry;
+ }
+
+ private NavigationService getNavigationService() throws NavigationMenuInitializationException {
+ if (navigationService == null) {
+ throw new NavigationMenuInitializationException(navigationService);
+ }
+ return navigationService;
+ }
+
+ public ViewerSearchService getViewerSearchService() throws NavigationMenuInitializationException {
+ if (viewerSearchService == null) {
+ throw new NavigationMenuInitializationException(viewerSearchService);
+ }
+ return viewerSearchService;
+ }
+
+ private Shell getParentShell() throws NavigationMenuInitializationException {
+ if (parentShell == null) {
+ throw new NavigationMenuInitializationException(parentShell);
+ }
+ return parentShell;
+ }
+
+
+ public List<Object> getAppendObjects() {
+ return appendObjects;
+ }
+
+ public void setAppendObjects(List<Object> appendObjects) {
+ this.appendObjects = appendObjects;
+ }
+
+ public List<Object> getPrependObjects() {
+ return prependObjects;
+ }
+
+ public void setPrependObjects(List<Object> prependObjects) {
+ this.prependObjects = prependObjects;
+ }
+
+ /* These are not used but they are necessary for the getCommand method of the NavigationEditPolicy */
+
+ public Command navigate(final SelectionRequest request, final EditPart host) {
+ if (!request.isAltKeyPressed()) {
+ return null;
+ }
+
+ EditPart targetEditPart = host.getViewer().findObjectAt(request.getLocation());
+
+ final NavigableElement element = getElementToNavigate(targetEditPart);
+ if (element == null) {
+ return null;
+ }
+
+ return new Command() {
+
+ @Override
+ public void execute() {
+ try {
+ getNavigationService().navigate(element);
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ }
+ exitItem();
+ }
+ };
+ }
+
+ private NavigableElement getElementToNavigate(EditPart target) {
+ List<NavigableElement> navigableElements;
+ try {
+ navigableElements = getNavigationService().getNavigableElements(target);
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ return null;
+ }
+
+ if (navigableElements.isEmpty()) {
+ return null;
+ }
+
+ for (NavigableElement element : navigableElements) {
+ if (element.isEnabled()) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu#handleRequest(java.lang.Object, java.lang.Object)
+ *
+ * @param request
+ * @param target
+ */
+ public void handleRequest(Object request, Object target) {
+ if (request instanceof SelectionRequest && target instanceof EditPart) {
+ handleRequest((SelectionRequest) request, (EditPart) target);
+ }
+
+ if (request instanceof MouseEvent && target instanceof TreeItem) {
+ handleRequest((MouseEvent) request, (TreeItem) target);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu#willEnter(java.lang.Object, java.lang.Object)
+ *
+ * @param request
+ * @param target
+ * @return
+ */
+ public boolean willEnter(Object request, Object target) {
+ if (request instanceof SelectionRequest && target instanceof EditPart) {
+ return willEnter((SelectionRequest) request, (EditPart) target);
+ }
+
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu#navigate(java.lang.Object, java.lang.Object)
+ *
+ * @param request
+ * @param host
+ * @return
+ */
+ public Object navigate(Object request, Object host) {
+ if (request instanceof SelectionRequest && host instanceof EditPart) {
+ return navigate((SelectionRequest) request, (EditPart) host);
+ }
+
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu#setServicesRegistry(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param registry
+ */
+ public void setServicesRegistry(ServicesRegistry registry) {
+ this.servicesRegistry = registry;
+ try {
+ this.navigationService = getServicesRegistry().getService(NavigationService.class);
+ this.viewerSearchService = getServicesRegistry().getService(ViewerSearchService.class);
+ } catch (ServiceException e) {
+ if (e instanceof ServiceNotFoundException) {
+ viewerSearchService = new ViewerSearchService();
+ try {
+ viewerSearchService.startService();
+ getServicesRegistry().add(ViewerSearchService.class, 1, viewerSearchService);
+ } catch (Exception e1) {
+ Activator.log.error(e1);
+ }
+ } else if (e instanceof BadStateException) {
+ try {
+ getServicesRegistry().startRegistry();
+ viewerSearchService = getServicesRegistry().getService(ViewerSearchService.class);
+ } catch (Exception e1) {
+ Activator.log.error(e1);
+ }
+ }
+ } catch (NavigationMenuInitializationException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu#setParentShell(org.eclipse.swt.widgets.Shell)
+ *
+ * @param parentShell
+ */
+ public void setParentShell(Shell parentShell) {
+ this.parentShell = parentShell;
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/HyperlinkButton.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/HyperlinkButton.java
new file mode 100644
index 00000000000..724c762ee59
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/HyperlinkButton.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menu.button;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.graphics.Image;
+
+public class HyperlinkButton {
+ private String _text = new String();
+ private String _tooltip = new String();
+ private Image _icon = null;
+ private IAction _action = null;
+
+ public HyperlinkButton(String text, String tooltip, Image image, IAction action) {
+ _text = text;
+ _tooltip = tooltip;
+ _icon = image;
+ _action = action;
+ }
+
+ public final Image getIcon() {
+ return _icon;
+ }
+
+ public final IAction getAction() {
+ return _action;
+ }
+
+ public final String getToolTip() {
+ return _tooltip;
+ }
+
+ public final String getText() {
+ return _text;
+ }
+
+} // end NavigationMenuDescriptor \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/MoreButton.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/MoreButton.java
new file mode 100644
index 00000000000..2f82c7448c9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/MoreButton.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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button;
+
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuButton;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+public class MoreButton extends NavigationMenuButton {
+ public MoreButton() {
+ super("More...", AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.uml.diagram.common", "/icons/separator.gif").createImage(), "More...");
+ }
+} // end MoreButton \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/NavigationSubMenuButton.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/NavigationSubMenuButton.java
new file mode 100644
index 00000000000..5f357cd0f7a
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/button/NavigationSubMenuButton.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menu.button;
+
+import java.util.List;
+
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuButton;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * This class is a navigation menu button that contains also a list of
+ * elements. These elements should be shown in some sub-menu once an event
+ * is fired on the button. The implementation depends on the actual
+ * navigation menu.
+ *
+ */
+
+public class NavigationSubMenuButton extends NavigationMenuButton {
+ private List subMenuElements; // View or NavigableElement
+
+ public NavigationSubMenuButton(String label, Image icon, String tooltip, List subMenuElements) {
+ super(label, icon, tooltip);
+ this.subMenuElements = subMenuElements;
+ }
+
+ public List getSubMenuElements() {
+ return subMenuElements;
+ }
+
+ public void setSubMenuElements(List subMenuElements) {
+ this.subMenuElements = subMenuElements;
+ }
+} // end DynamicSubMenuButton \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/NavigationMenuKeyListener.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/NavigationMenuKeyListener.java
new file mode 100644
index 00000000000..a9fe7e08f6e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/NavigationMenuKeyListener.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.navigation.menu.listener;
+
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+
+public class NavigationMenuKeyListener implements KeyListener {
+ /**
+ *
+ */
+ protected DefaultNavigationMenu navigationMenu;
+
+ /**
+ * Constructor.
+ *
+ * @param navigationMenu
+ */
+ public NavigationMenuKeyListener(DefaultNavigationMenu navigationMenu) {
+ this.navigationMenu = navigationMenu;
+ }
+
+ public void keyPressed(KeyEvent e) {
+ // Nothing
+ }
+
+ public void keyReleased(KeyEvent e) {
+ if (e.keyCode == SWT.ALT) {
+ navigationMenu.exitItem();
+ }
+ }
+} // end NavigationMenuKeyListener \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuMouseTrackListener.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuMouseTrackListener.java
new file mode 100644
index 00000000000..7451095feee
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuMouseTrackListener.java
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.navigation.menu.listener;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.MoreButton;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.provider.SelectionMenuLabelProvider;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.provider.SubSelectionMenuLabelProvider;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
+import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ * @author Shuai Li
+ *
+ */
+public class SelectionMenuMouseTrackListener implements MouseTrackListener {
+
+ private Object previousData;
+
+ private DefaultNavigationMenu navigationMenu;
+ private SelectionMenu selectionMenu;
+ private List<SelectionMenu> subMenus;
+ private Object umlElement;
+
+ public SelectionMenuMouseTrackListener(DefaultNavigationMenu navigationMenu, SelectionMenu selectionMenu, List<SelectionMenu> subMenus, Object umlElement) {
+ this.navigationMenu = navigationMenu;
+ this.selectionMenu = selectionMenu;
+ this.subMenus = subMenus;
+ this.umlElement = umlElement;
+
+ previousData = null;
+ }
+
+ public void mouseEnter(MouseEvent e) {
+ openSubMenu(e);
+ }
+
+ public void mouseExit(MouseEvent e) {
+ // Nothing
+ }
+
+ public void mouseHover(MouseEvent e) {
+ openSubMenu(e);
+ }
+
+ private Object getData(MouseEvent e) {
+ if (e.getSource() instanceof Table) {
+ TableItem item = ((Table) e.getSource()).getItem(new Point(e.x, e.y));
+ if (item != null) {
+ return item.getData();
+ }
+ }
+
+ return null;
+ }
+
+ private void openSubMenu(MouseEvent event) {
+ Object hoveredItem = getData(event);
+ Point cursorPosition = new Point(event.x, event.y);
+
+ if (hoveredItem != null && hoveredItem != previousData && event.getSource() instanceof Table) {
+ previousData = hoveredItem;
+
+ // Close submenus of same level or higher
+ if (subMenus != null) {
+ Composite levelShell = ((Table) event.getSource()).getShell();
+
+ List<SelectionMenu> subMenusToDelete = new ArrayList<SelectionMenu>();
+ for (SelectionMenu subMenu : subMenus) {
+ if (subMenu.getParentShell().equals(levelShell)) {
+ subMenusToDelete.add(subMenu);
+ subMenu.dispose();
+ }
+ }
+
+ subMenus.removeAll(subMenusToDelete);
+ }
+
+ if (hoveredItem instanceof NavigableElement) {
+ List<Object> viewsToSelect = navigationMenu.getViewsToSelect((NavigableElement) hoveredItem, true);
+
+ //if ((viewsToSelect != null && !viewsToSelect.isEmpty()) || hasMoreViews) {
+ // Case of DiagramNavigableElement for example
+ if (viewsToSelect != null && !viewsToSelect.isEmpty()) {
+ final List<Object> subSelectionMenuItems = new LinkedList<Object>();
+ subSelectionMenuItems.add(hoveredItem);
+ subSelectionMenuItems.addAll(viewsToSelect);
+
+ /*if (hasMoreViews) {
+ navigableElementSelectionMenuElements.add(new MoreButton());
+ }*/
+
+ //subSelectionMenuItems.add(new MoreButton());
+
+ final SelectionMenu subSelectionMenu = new SelectionMenu(selectionMenu.getShell(), event.getSource(), cursorPosition);
+
+ subSelectionMenu.setLabelProvider(new SubSelectionMenuLabelProvider());
+ subSelectionMenu.setContentProvider(CollectionContentProvider.instance);
+ subSelectionMenu.setInput(subSelectionMenuItems);
+ subSelectionMenu.open();
+
+ subSelectionMenu.addSelectionChangedListener(new SubSelectionMenuSelectionChangedListener(navigationMenu, subSelectionMenu, subSelectionMenuItems));
+ subSelectionMenu.addKeyListener(new NavigationMenuKeyListener(navigationMenu));
+
+ subMenus.add(subSelectionMenu);
+ }
+ } else if (hoveredItem instanceof NavigationSubMenuButton) {
+ SelectionMenu dynamicSelectionMenu = new SelectionMenu(selectionMenu.getShell(), event.getSource(), cursorPosition);
+
+ dynamicSelectionMenu.setLabelProvider(new SelectionMenuLabelProvider());
+
+ dynamicSelectionMenu.setContentProvider(CollectionContentProvider.instance);
+ dynamicSelectionMenu.setInput(((NavigationSubMenuButton) hoveredItem).getSubMenuElements());
+ dynamicSelectionMenu.open();
+
+ dynamicSelectionMenu.addSelectionChangedListener(new SelectionMenuSelectionChangedListener(navigationMenu, dynamicSelectionMenu, ((NavigationSubMenuButton) hoveredItem).getSubMenuElements(), umlElement, subMenus));
+ dynamicSelectionMenu.addKeyListener(new NavigationMenuKeyListener(navigationMenu));
+ dynamicSelectionMenu.addMouseTrackListener(new SelectionMenuMouseTrackListener(navigationMenu, dynamicSelectionMenu, subMenus, umlElement));
+
+ subMenus.add(dynamicSelectionMenu);
+ }
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuSelectionChangedListener.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuSelectionChangedListener.java
new file mode 100644
index 00000000000..1319d09ebad
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuSelectionChangedListener.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menu.listener;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.HyperlinkButton;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.MoreButton;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Shuai Li
+ *
+ */
+public class SelectionMenuSelectionChangedListener implements ISelectionChangedListener {
+ protected DefaultNavigationMenu navigationMenu;
+ protected List<Object> selectionMenuItems;
+ protected SelectionMenu selectionMenu;
+ protected List<SelectionMenu> subMenus;
+ protected Object umlElement;
+ protected boolean moreButton = false;
+
+ public SelectionMenuSelectionChangedListener(DefaultNavigationMenu navigationMenu, SelectionMenu selectionMenu, List<Object> selectionMenuItems, Object umlElement, List<SelectionMenu> subMenus) {
+ this.navigationMenu = navigationMenu;
+ this.selectionMenu = selectionMenu;
+ this.selectionMenuItems = selectionMenuItems;
+
+ this.umlElement = umlElement;
+ this.subMenus = subMenus;
+ }
+
+ public SelectionMenuSelectionChangedListener(DefaultNavigationMenu navigationMenu, SelectionMenu selectionMenu, List<Object> selectionMenuItems) {
+ this.navigationMenu = navigationMenu;
+ this.selectionMenu = selectionMenu;
+ this.selectionMenuItems = selectionMenuItems;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ *
+ * @param event
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection().isEmpty()) {
+ return;
+ }
+
+ Object selectedElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
+
+ // Close submenus of same level or higher
+ if (!(selectedElement instanceof NavigationSubMenuButton)) {
+ if (subMenus != null) {
+ if (event.getSource() instanceof TableViewer) {
+ Composite levelShell = ((TableViewer) event.getSource()).getTable().getShell();
+
+ List<SelectionMenu> subMenusToDelete = new ArrayList<SelectionMenu>();
+ for (SelectionMenu subMenu : subMenus) {
+ if (subMenu.getParentShell().equals(levelShell)) {
+ subMenusToDelete.add(subMenu);
+ subMenu.dispose();
+ }
+ }
+
+ subMenus.removeAll(subMenusToDelete);
+ }
+ }
+ }
+
+ if (selectedElement instanceof NavigableElement) {
+ navigationMenu.showInModelExplorer((NavigableElement) selectedElement);
+ } else if (selectedElement instanceof HyperlinkButton) {
+ ((HyperlinkButton) selectedElement).getAction().run();
+ navigationMenu.exitItem();
+ } else if (selectedElement instanceof MoreButton) {
+ ((LinkedList<Object>) selectionMenuItems).removeLast();
+ navigationMenu.addContextualMenus(selectionMenuItems, umlElement);
+ selectionMenu.refresh();
+ } else {
+ navigationMenu.revealObject(selectedElement);
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SubSelectionMenuSelectionChangedListener.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SubSelectionMenuSelectionChangedListener.java
new file mode 100644
index 00000000000..7def41b9b87
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SubSelectionMenuSelectionChangedListener.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menu.listener;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.MoreButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
+
+/**
+ * @author Shuai Li
+ *
+ */
+public class SubSelectionMenuSelectionChangedListener extends SelectionMenuSelectionChangedListener {
+ public SubSelectionMenuSelectionChangedListener(DefaultNavigationMenu navigationMenu, SelectionMenu selectionMenu, List<Object> selectionMenuItems) {
+ super(navigationMenu, selectionMenu, selectionMenuItems);
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ *
+ * @param event
+ */
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (event.getSelection().isEmpty()) {
+ return;
+ }
+
+ Object selectedElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
+
+ if (selectedElement instanceof NavigableElement) {
+ NavigableElement navigableElement = (NavigableElement) selectedElement;
+ navigationMenu.showInModelExplorer(navigableElement);
+ return;
+ }
+ // "More..." button handling (in case we activate it again one day)
+ /*else if (selectedElement instanceof MoreButton) {
+ // Get views with the navigable element, with "onlyOpened" false
+ NavigableElement navigableElement = (NavigableElement) selectionMenuItems.get(0);
+ List<Object> viewsToSelect = navigationMenu.getClosedViewsToSelect(navigableElement);
+
+ // Remove "More" button, and add new views that don't already exist in the menu
+ ((LinkedList<Object>) selectionMenuItems).removeLast();
+ if (viewsToSelect != null) {
+ selectionMenuItems.addAll(viewsToSelect);
+ }
+
+ // Refresh the UI
+ selectionMenu.refresh();
+ //hasMoreViews = false;
+ return;
+ }*/
+
+ super.selectionChanged(event);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SelectionMenuLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SelectionMenuLabelProvider.java
new file mode 100644
index 00000000000..e0216f4c62e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SelectionMenuLabelProvider.java
@@ -0,0 +1,131 @@
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menu.provider;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.HyperlinkButton;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Shuai Li
+ *
+ */
+public class SelectionMenuLabelProvider extends ColumnLabelProvider {
+ protected boolean isLocalLabelProvider;
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof NavigationMenuButton) {
+ return ((NavigationMenuButton) element).getLabel();
+ } else if (element instanceof HyperlinkButton) {
+ return ((HyperlinkButton) element).getText();
+ } else if (element instanceof NavigableElement) {
+ return ((NavigableElement) element).getLabel();
+ } else if (element instanceof EObject) {
+ return getName((EObject) element);
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof NavigableElement) {
+ return ((NavigableElement) element).getImage();
+ } else if (element instanceof NavigationMenuButton) {
+ return ((NavigationMenuButton) element).getIcon();
+ } else if (element instanceof HyperlinkButton) {
+ return ((HyperlinkButton) element).getIcon();
+ } else if (element instanceof EObject) {
+ ILabelProvider labelProvider = getLabelProvider((EObject) element);
+
+ Image icon = null;
+ icon = labelProvider.getImage(element);
+
+ if (isLocalLabelProvider) {
+ labelProvider.dispose();
+ }
+
+ return icon;
+ }
+ return super.getImage(element);
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof HyperlinkButton) {
+ return ((HyperlinkButton) element).getToolTip();
+ } else if (element instanceof NavigationMenuButton) {
+ return ((NavigationMenuButton) element).getTooltip();
+ } else if (element instanceof NavigableElement) {
+ return ((NavigableElement) element).getDescription();
+ } else if (element instanceof EObject) {
+ return getName((EObject) element);
+ }
+ return super.getToolTipText(element);
+ }
+
+ protected ILabelProvider getLabelProvider(EObject element) {
+ ILabelProvider labelProvider = null;
+
+ try {
+ labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, element).getLabelProvider("org.eclipse.papyrus.infra.services.navigation.menu.labelprovider");
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+
+ if (labelProvider == null) {
+ labelProvider = new LabelProvider();
+ isLocalLabelProvider = true;
+ } else {
+ isLocalLabelProvider = false;
+ }
+
+ return labelProvider;
+ }
+
+ protected String getName(EObject element) {
+ ILabelProvider labelProvider = getLabelProvider((EObject) element);
+
+ String name = labelProvider.getText(element);
+
+ if (isLocalLabelProvider) {
+ labelProvider.dispose();
+ }
+
+ if (name != null) {
+ return name;
+ } else {
+ return element.toString();
+ }
+ }
+// @Override
+// public Color getForeground(Object element) {
+// if (element instanceof NavigableElement) {
+// NavigableElement navigableElement = (NavigableElement) element;
+// if (!navigableElement.isEnabled()) {
+// return navigationMenu.getEditPartViewer().getControl().getDisplay().getSystemColor(SWT.COLOR_GRAY);
+// }
+// }
+// return super.getForeground(element);
+// }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SubSelectionMenuLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SubSelectionMenuLabelProvider.java
new file mode 100644
index 00000000000..57344f6be2d
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/provider/SubSelectionMenuLabelProvider.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menu.provider;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+
+/**
+ * @author Shuai Li (CEA LIST) <shuai.li@cea.fr>
+ *
+ */
+public class SubSelectionMenuLabelProvider extends SelectionMenuLabelProvider {
+ public SubSelectionMenuLabelProvider() {
+ super();
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof NavigableElement) {
+ return "in Model Explorer";
+ } else if (element instanceof EObject) {
+ String name = getName((EObject) element);
+ return "in " + name;
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ if (element instanceof NavigableElement) {
+ return "Show in Model Explorer";
+ } else if (element instanceof EObject) {
+ String name = getName((EObject) element);
+ return "Show in " + name;
+ }
+ return super.getToolTipText(element);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigationProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menuContributor/OwnedDiagramsButton.java
index 6c0e00e2ad9..0a5b35a8c2a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/navigation/DiagramNavigationProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menuContributor/OwnedDiagramsButton.java
@@ -1,82 +1,88 @@
-/*****************************************************************************
- * Copyright (c) 2013, 2014 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 430726
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.hyperlink.navigation;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
-
-
-public class DiagramNavigationProvider implements NavigationContributor {
-
- public List<NavigableElement> getNavigableElements(Object fromElement) {
- if (fromElement != null) {
- // Find pages under the element (isPageContainer)
- // Alt1: Find diagrams under the element (+ all Tables in a separate provider)
-
- List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
-
-
- for (Diagram diagram : getOwnedDiagrams(fromElement)) {
- navigableElements.add(new DiagramNavigableElement(diagram));
- }
- return navigableElements;
- }
- return Collections.emptyList();
- }
-
- protected List<Diagram> getOwnedDiagrams(Object fromElement) {
- EObject eObject = EMFHelper.getEObject(fromElement); // Should not be null (Otherwise, return=)
- View currentView = NotationHelper.findView(fromElement); // May be null (e.g. Selection from the ModelExplorer)
- if (eObject instanceof View || eObject == null) {
- return Collections.emptyList();
- }
-
- try {
- List<Diagram> ownedDiagrams = new LinkedList<Diagram>();
-
- IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(eObject);
- for (Object pageObject : pageManager.allPages()) {
- if (pageObject instanceof Diagram) {
- Diagram diagram = (Diagram) pageObject;
-
- // Avoid navigation to the current diagram
- if (currentView != null && currentView.getDiagram() == diagram) {
- continue;
- }
-
- if (diagram.getElement() == eObject) {
- ownedDiagrams.add(diagram);
- }
- }
- }
-
- return ownedDiagrams;
- } catch (ServiceException ex) {
- return Collections.emptyList();
- }
- }
-
-}
+/*****************************************************************************
+ * 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.gmfdiag.navigation.menuContributor;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor;
+
+/**
+ * @author Shuai Li (CEA LIST) <shuai.li@cea.fr>
+ *
+ */
+public class OwnedDiagramsButton implements NavigationMenuContributor {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor#getButtons(java.lang.Object)
+ *
+ * @param fromElement
+ * @return
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ if (fromElement != null) {
+ List<Diagram> diagrams = getOwnedDiagrams(fromElement);
+ if (!diagrams.isEmpty()) {
+ buttons.add(new NavigationSubMenuButton("Owned diagrams...", null, "Show owned diagrams", diagrams));
+ }
+ }
+
+ return buttons;
+ }
+
+ protected List<Diagram> getOwnedDiagrams(Object fromElement) {
+ EObject eObject = EMFHelper.getEObject(fromElement); // Should not be null (Otherwise, return=)
+ View currentView = NotationHelper.findView(fromElement); // May be null (e.g. Selection from the ModelExplorer)
+ if (eObject instanceof View || eObject == null) {
+ return Collections.emptyList();
+ }
+
+ try {
+ List<Diagram> ownedDiagrams = new LinkedList<Diagram>();
+
+ IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(eObject);
+ for (Object pageObject : pageManager.allPages()) {
+ if (pageObject instanceof Diagram) {
+ Diagram diagram = (Diagram) pageObject;
+
+ // Avoid navigation to the current diagram
+ /*if (currentView != null && currentView.getDiagram() == diagram) {
+ continue;
+ }*/
+
+ if (diagram.getElement() == eObject) {
+ ownedDiagrams.add(diagram);
+ }
+ }
+ }
+
+ return ownedDiagrams;
+ } catch (ServiceException ex) {
+ return Collections.emptyList();
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.viewersearcher/src/org/eclipse/papyrus/infra/gmfdiag/viewersearcher/DiagramViewerSearcher.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.viewersearcher/src/org/eclipse/papyrus/infra/gmfdiag/viewersearcher/DiagramViewerSearcher.java
index 7cbd528b83b..bd3e54d3b97 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.viewersearcher/src/org/eclipse/papyrus/infra/gmfdiag/viewersearcher/DiagramViewerSearcher.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.viewersearcher/src/org/eclipse/papyrus/infra/gmfdiag/viewersearcher/DiagramViewerSearcher.java
@@ -129,10 +129,11 @@ public class DiagramViewerSearcher extends AbstractViewerSearcher {
try {
for (Object page : pageManager.allPages()) {
+ if (openPagesOnly && !pageManager.isOpen(page)) {
+ continue;
+ }
if (page instanceof Diagram) {
- // TODO openPagesOnly: contributed by future navigation patch
-
// Container checks
if (container != null) {
EObject owner = DiagramUtils.getOwner((Diagram) page);
diff --git a/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/AbstractEditHyperlinkShell.java b/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/AbstractEditHyperlinkShell.java
index dd3985c3392..bcfcc316c4a 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/AbstractEditHyperlinkShell.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/AbstractEditHyperlinkShell.java
@@ -1,189 +1,189 @@
-/*****************************************************************************
- * Copyright (c) 2009 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.hyperlink.ui;
-
-import org.eclipse.papyrus.infra.hyperlink.messages.Messages;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * The Class EditHyperlinkShell. This Class has been generated from
- * VisualEditor. Do not modify it manually by adding behavior! you will lose the
- * capacity to open with VE. So this class is abstract and it contains set of
- * getter in order to connect behavior in subclasses
- */
-public abstract class AbstractEditHyperlinkShell {
-
- /** The Constant OBJECT_LABEL. */
- protected static final String OBJECT_LABEL = Messages.AbstractEditHyperlinkShell_object;
-
- /** The edit hyperlink shell. */
- private Shell editHyperlinkShell = null; // @jve:decl-index=0:visual-constraint="12,45"
-
- /** The Ok button. */
- private Button OkButton = null;
-
- /** The cancel button. */
- private Button cancelButton = null;
-
- /** The tooltip input text. */
- private Text tooltipInputText = null;
-
- /** The tooltip input label. */
- private CLabel tooltipInputLabel = null;
-
- /** The Object labeltext. */
- private Text ObjectLabeltext = null;
-
- /** The Objectc label. */
- private CLabel ObjectcLabel = null;
-
- private Button useDefaultCheckBox = null;
-
- /**
- * This method initializes editHyperlinkShell.
- */
- protected void createEditHyperlinkShell() {
- GridData gridData3 = new GridData();
- gridData3.grabExcessHorizontalSpace = true;
- gridData3.verticalAlignment = GridData.CENTER;
- gridData3.horizontalAlignment = GridData.FILL;
- GridData gridData2 = new GridData();
- gridData2.grabExcessHorizontalSpace = true;
- gridData2.verticalAlignment = GridData.CENTER;
- gridData2.horizontalAlignment = GridData.FILL;
- GridData gridData1 = new GridData();
- gridData1.horizontalSpan = 6;
- gridData1.verticalAlignment = GridData.FILL;
- gridData1.grabExcessHorizontalSpace = true;
- gridData1.grabExcessVerticalSpace = false;
- gridData1.horizontalAlignment = GridData.FILL;
- GridData gridData = new GridData();
- gridData.horizontalSpan = 5;
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.CENTER;
- gridData.grabExcessHorizontalSpace = true;
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 7;
- gridLayout.makeColumnsEqualWidth = true;
-
- // this line has to be commented in order to open with VISUAL EDITOR
- editHyperlinkShell = new Shell(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.DIALOG_TRIM | SWT.RESIZE);
-
- // editHyperlinkShell = new Shell(display, SWT.DIALOG_TRIM |
- // SWT.APPLICATION_MODAL);
-
- // editHyperlinkShell = new Shell();
- editHyperlinkShell.setText(Messages.AbstractEditHyperlinkShell_EditHyperLink);
- editHyperlinkShell.setToolTipText(Messages.AbstractEditHyperlinkShell_EditionOfAHyperLink);
- editHyperlinkShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
- editHyperlinkShell.setLayout(gridLayout);
- // editHyperlinkShell.setSize(new Point(601, 119));
- ObjectcLabel = new CLabel(editHyperlinkShell, SWT.NONE);
- ObjectcLabel.setText(OBJECT_LABEL);
- ObjectcLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
- ObjectLabeltext = new Text(editHyperlinkShell, SWT.BORDER);
- ObjectLabeltext.setLayoutData(gridData1);
- tooltipInputLabel = new CLabel(editHyperlinkShell, SWT.NONE);
- tooltipInputLabel.setText(Messages.AbstractEditHyperlinkShell_ToolTipText);
- tooltipInputLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
- tooltipInputLabel.setToolTipText(Messages.AbstractEditHyperlinkShell_ToolTipText_);
- tooltipInputText = new Text(editHyperlinkShell, SWT.BORDER);
- tooltipInputText.setLayoutData(gridData);
- useDefaultCheckBox = new Button(getEditHyperlinkShell(), SWT.CHECK);
- useDefaultCheckBox.setText(Messages.AbstractEditHyperlinkShell_UseDefault);
- useDefaultCheckBox.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
- new Label(editHyperlinkShell, SWT.NONE);
- new Label(editHyperlinkShell, SWT.NONE);
- new Label(editHyperlinkShell, SWT.NONE);
- new Label(editHyperlinkShell, SWT.NONE);
- new Label(getEditHyperlinkShell(), SWT.NONE);
- OkButton = new Button(getEditHyperlinkShell(), SWT.NONE);
- OkButton.setText(Messages.AbstractEditHyperlinkShell_OK);
- OkButton.setLayoutData(gridData2);
- cancelButton = new Button(getEditHyperlinkShell(), SWT.NONE);
- cancelButton.setText(Messages.AbstractEditHyperlinkShell_Cancel);
- cancelButton.setLayoutData(gridData3);
-
- editHyperlinkShell.pack();
- }
-
- /**
- * Gets the edit hyperlink shell.
- *
- * @return the editHyperlinkShell
- */
- public Shell getEditHyperlinkShell() {
- return editHyperlinkShell;
- }
-
- /**
- * Gets the ok button.
- *
- * @return the okButton
- */
- protected Button getOkButton() {
- return OkButton;
- }
-
- /**
- * Gets the cancel button.
- *
- * @return the cancelButton
- */
- protected Button getCancelButton() {
- return cancelButton;
- }
-
- /**
- * Gets the tooltip input text.
- *
- * @return the tooltipInputText
- */
- protected Text getTooltipInputText() {
- return tooltipInputText;
- }
-
- /**
- * Gets the object labeltext.
- *
- * @return the objectLabeltext
- */
- protected Text getObjectLabeltext() {
- return ObjectLabeltext;
- }
-
- /**
- * @return the objectcLabel
- */
- public CLabel getObjectcLabel() {
- return ObjectcLabel;
- }
-
- /**
- * @return the useDefaultCheckBox
- */
- protected Button getUseDefaultCheckBox() {
- return useDefaultCheckBox;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2009 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.hyperlink.ui;
+
+import org.eclipse.papyrus.infra.hyperlink.messages.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The Class EditHyperlinkShell. This Class has been generated from
+ * VisualEditor. Do not modify it manually by adding behavior! you will lose the
+ * capacity to open with VE. So this class is abstract and it contains set of
+ * getter in order to connect behavior in subclasses
+ */
+public abstract class AbstractEditHyperlinkShell {
+
+ /** The Constant OBJECT_LABEL. */
+ protected static final String OBJECT_LABEL = Messages.AbstractEditHyperlinkShell_object;
+
+ /** The edit hyperlink shell. */
+ private Shell editHyperlinkShell = null; // @jve:decl-index=0:visual-constraint="12,45"
+
+ /** The Ok button. */
+ private Button OkButton = null;
+
+ /** The cancel button. */
+ private Button cancelButton = null;
+
+ /** The tooltip input text. */
+ private Text tooltipInputText = null;
+
+ /** The tooltip input label. */
+ private CLabel tooltipInputLabel = null;
+
+ /** The Object labeltext. */
+ private Text ObjectLabeltext = null;
+
+ /** The Objectc label. */
+ private CLabel ObjectcLabel = null;
+
+ private Button useDefaultCheckBox = null;
+
+ /**
+ * This method initializes editHyperlinkShell.
+ */
+ protected void createEditHyperlinkShell() {
+ GridData gridData3 = new GridData();
+ gridData3.grabExcessHorizontalSpace = true;
+ gridData3.verticalAlignment = GridData.CENTER;
+ gridData3.horizontalAlignment = GridData.FILL;
+ GridData gridData2 = new GridData();
+ gridData2.grabExcessHorizontalSpace = true;
+ gridData2.verticalAlignment = GridData.CENTER;
+ gridData2.horizontalAlignment = GridData.FILL;
+ GridData gridData1 = new GridData();
+ gridData1.horizontalSpan = 6;
+ gridData1.verticalAlignment = GridData.FILL;
+ gridData1.grabExcessHorizontalSpace = true;
+ gridData1.grabExcessVerticalSpace = false;
+ gridData1.horizontalAlignment = GridData.FILL;
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = 5;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.CENTER;
+ gridData.grabExcessHorizontalSpace = true;
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 7;
+ gridLayout.makeColumnsEqualWidth = true;
+
+ // this line has to be commented in order to open with VISUAL EDITOR
+ editHyperlinkShell = new Shell(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
+
+ // editHyperlinkShell = new Shell(display, SWT.DIALOG_TRIM |
+ // SWT.APPLICATION_MODAL);
+
+ // editHyperlinkShell = new Shell();
+ editHyperlinkShell.setText(Messages.AbstractEditHyperlinkShell_EditHyperLink);
+ editHyperlinkShell.setToolTipText(Messages.AbstractEditHyperlinkShell_EditionOfAHyperLink);
+ editHyperlinkShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ editHyperlinkShell.setLayout(gridLayout);
+ // editHyperlinkShell.setSize(new Point(601, 119));
+ ObjectcLabel = new CLabel(editHyperlinkShell, SWT.NONE);
+ ObjectcLabel.setText(OBJECT_LABEL);
+ ObjectcLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ ObjectLabeltext = new Text(editHyperlinkShell, SWT.BORDER);
+ ObjectLabeltext.setLayoutData(gridData1);
+ tooltipInputLabel = new CLabel(editHyperlinkShell, SWT.NONE);
+ tooltipInputLabel.setText(Messages.AbstractEditHyperlinkShell_ToolTipText);
+ tooltipInputLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ tooltipInputLabel.setToolTipText(Messages.AbstractEditHyperlinkShell_ToolTipText_);
+ tooltipInputText = new Text(editHyperlinkShell, SWT.BORDER);
+ tooltipInputText.setLayoutData(gridData);
+ useDefaultCheckBox = new Button(getEditHyperlinkShell(), SWT.CHECK);
+ useDefaultCheckBox.setText(Messages.AbstractEditHyperlinkShell_UseDefault);
+ useDefaultCheckBox.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ new Label(editHyperlinkShell, SWT.NONE);
+ new Label(editHyperlinkShell, SWT.NONE);
+ new Label(editHyperlinkShell, SWT.NONE);
+ new Label(editHyperlinkShell, SWT.NONE);
+ new Label(getEditHyperlinkShell(), SWT.NONE);
+ OkButton = new Button(getEditHyperlinkShell(), SWT.NONE);
+ OkButton.setText(Messages.AbstractEditHyperlinkShell_OK);
+ OkButton.setLayoutData(gridData2);
+ cancelButton = new Button(getEditHyperlinkShell(), SWT.NONE);
+ cancelButton.setText(Messages.AbstractEditHyperlinkShell_Cancel);
+ cancelButton.setLayoutData(gridData3);
+
+ editHyperlinkShell.pack();
+ }
+
+ /**
+ * Gets the edit hyperlink shell.
+ *
+ * @return the editHyperlinkShell
+ */
+ public Shell getEditHyperlinkShell() {
+ return editHyperlinkShell;
+ }
+
+ /**
+ * Gets the ok button.
+ *
+ * @return the okButton
+ */
+ protected Button getOkButton() {
+ return OkButton;
+ }
+
+ /**
+ * Gets the cancel button.
+ *
+ * @return the cancelButton
+ */
+ protected Button getCancelButton() {
+ return cancelButton;
+ }
+
+ /**
+ * Gets the tooltip input text.
+ *
+ * @return the tooltipInputText
+ */
+ protected Text getTooltipInputText() {
+ return tooltipInputText;
+ }
+
+ /**
+ * Gets the object labeltext.
+ *
+ * @return the objectLabeltext
+ */
+ protected Text getObjectLabeltext() {
+ return ObjectLabeltext;
+ }
+
+ /**
+ * @return the objectcLabel
+ */
+ public CLabel getObjectcLabel() {
+ return ObjectcLabel;
+ }
+
+ /**
+ * @return the useDefaultCheckBox
+ */
+ protected Button getUseDefaultCheckBox() {
+ return useDefaultCheckBox;
+ }
+
+}
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;
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/plugin.xml
index 95a2195ad0d..bd28222fe71 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/plugin.xml
@@ -1,15 +1,22 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
-
- <extension
- id="org.eclipse.papyrus.infra.services.viewLabelProvider"
- name="ViewLabelProvider"
- point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider">
- <labelProvider
- priority="10"
- provider="org.eclipse.papyrus.infra.services.viewlabelprovider.provider.ViewLabelProvider">
- </labelProvider>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <extension
+ id="org.eclipse.papyrus.infra.services.viewLabelProvider"
+ name="ViewLabelProvider"
+ point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider">
+ <labelProvider
+ priority="10"
+ provider="org.eclipse.papyrus.infra.services.viewlabelprovider.provider.ViewLabelProvider">
+ </labelProvider>
+ <labelProvider
+ priority="9"
+ provider="org.eclipse.papyrus.infra.services.viewlabelprovider.provider.DiagramOfViewLabelProvider">
+ <labelProviderContext
+ context="org.eclipse.papyrus.infra.services.navigation.menu.labelprovider">
+ </labelProviderContext>
+ </labelProvider>
+ </extension>
+
+</plugin>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/src/org/eclipse/papyrus/infra/services/viewlabelprovider/provider/DiagramOfViewLabelProvider.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/src/org/eclipse/papyrus/infra/services/viewlabelprovider/provider/DiagramOfViewLabelProvider.java
new file mode 100644
index 00000000000..1efeefdc761
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.viewlabelprovider/src/org/eclipse/papyrus/infra/services/viewlabelprovider/provider/DiagramOfViewLabelProvider.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * 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.viewlabelprovider.provider;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.viewlabelprovider.Activator;
+import org.eclipse.papyrus.infra.services.viewlabelprovider.Messages;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Shuai Li (CEA LIST) <shuai.li@cea.fr>
+ *
+ */
+public class DiagramOfViewLabelProvider extends ViewLabelProvider {
+ /**
+ * Returns the image of the diagram of the view
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ public Image getImage(Object element) {
+ if (element instanceof View) {
+ Diagram diagram = ((View) element).getDiagram();
+
+ if (diagram != null) {
+ try {
+ LabelProviderService service = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, diagram);
+ return service.getLabelProvider().getImage(diagram);
+ } catch (ServiceException e) {
+ Activator.log.warn(Messages.ViewLabelProvider_0 + diagram);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the text of the diagram of the view
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ public String getText(Object element) {
+ if (element instanceof View) {
+ Diagram diagram = ((View) element).getDiagram();
+
+ if (diagram != null) {
+ try {
+ LabelProviderService service = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, diagram);
+ return service.getLabelProvider().getText(diagram);
+ } catch (ServiceException e) {
+ Activator.log.warn(Messages.ViewLabelProvider_0 + diagram);
+ }
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/SelectionMenu.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/SelectionMenu.java
index 47a30eb4df3..22a624ecf77 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/SelectionMenu.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/SelectionMenu.java
@@ -1,131 +1,291 @@
-/*****************************************************************************
- * 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.widgets.editors;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * A basic menu which proposes a list of choices.
- *
- * Implementation is based on a JFace TableViewer
- *
- * Typical usage: JDT-like Ctrl + Click (Navigation)
- *
- * @author Camille Letavernier
- *
- */
-public class SelectionMenu {
-
- private ILabelProvider labelProvider;
-
- private IStructuredContentProvider contentProvider;
-
- private Shell parentShell;
-
- private Point location;
-
- private Object input;
-
- private Shell shell;
-
- private final ISelectionChangedListener selectionChangedListener;
-
- private final List<ISelectionChangedListener> selectionChangedListeners;
-
- public SelectionMenu(Shell parentShell) {
- this(parentShell, parentShell.getDisplay().getCursorLocation());
- }
-
- public SelectionMenu(Shell parentShell, Point location) {
- // Move the shell so that it doesn't open under the mouse
- // The hovered element can still be selected
- location.x += 1;
- location.y += 1;
-
- this.parentShell = parentShell;
- this.location = location;
- labelProvider = new LabelProvider();
- selectionChangedListeners = new LinkedList<ISelectionChangedListener>();
- selectionChangedListener = new ISelectionChangedListener() {
-
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- for (ISelectionChangedListener listener : selectionChangedListeners) {
- listener.selectionChanged(event);
- }
- }
- };
- }
-
- public void open() {
- shell = new Shell(parentShell, SWT.NONE);
- shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
- shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
-
- GridLayout gridLayout = new GridLayout(1, false);
- gridLayout.marginWidth = 5;
- gridLayout.marginHeight = 5;
- shell.setLayout(gridLayout);
-
- shell.setLayout(new GridLayout(1, false));
-
- final TableViewer tableViewer = new TableViewer(shell, SWT.NO_SCROLL);
-
- tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- tableViewer.setContentProvider(contentProvider);
- tableViewer.setLabelProvider(labelProvider);
-
- ColumnViewerToolTipSupport.enableFor(tableViewer);
- tableViewer.setInput(input);
- tableViewer.addSelectionChangedListener(selectionChangedListener);
-
- shell.setLocation(location);
- shell.pack();
- shell.open();
- }
-
- public void dispose() {
- if (shell != null) {
- shell.dispose();
- }
- }
-
- public void setContentProvider(IStructuredContentProvider provider) {
- this.contentProvider = provider;
- }
-
- public void setInput(Object input) {
- this.input = input;
- }
-
- public void setLabelProvider(ILabelProvider labelProvider) {
- this.labelProvider = labelProvider;
- }
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- this.selectionChangedListeners.add(listener);
- }
-}
+/*****************************************************************************
+ * 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
+ * Shuai Li (CEA LIST) shuai.li@cea.fr - SelectionMenu#refresh method
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.editors;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ * A basic menu which proposes a list of choices.
+ *
+ * Implementation is based on a JFace TableViewer
+ *
+ * Typical usage: JDT-like Ctrl + Click (Navigation)
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class SelectionMenu {
+
+ private ILabelProvider labelProvider;
+
+ private IStructuredContentProvider contentProvider;
+
+ private Shell parentShell;
+
+ private Point location;
+
+ private Object input;
+
+ private Shell shell;
+
+ private TableViewer tableViewer;
+
+ private ISelectionChangedListener selectionChangedListener;
+
+ private List<ISelectionChangedListener> selectionChangedListeners;
+
+ private KeyListener keyListener;
+
+ private List<KeyListener> keyListeners;
+
+ private MouseTrackListener mouseTrackListener;
+
+ private List<MouseTrackListener> mouseTrackListeners;
+
+ public SelectionMenu(Shell parentShell) {
+ this(parentShell, parentShell.getDisplay().getCursorLocation());
+ }
+
+ public SelectionMenu(Shell parentShell, Object source) {
+ if (source instanceof TableViewer && parentShell != null) {
+ TableViewer tableViewer = (TableViewer) source;
+
+ // Get the cell's y position (we can't use the getCell(Point location) method)
+ int selectionIndex = tableViewer.getTable().getSelectionIndex();
+ int cellHeight = tableViewer.getTable().getItem(selectionIndex).getBounds().height;
+ int y = tableViewer.getTable().getShell().getLocation().y;
+ y += selectionIndex * cellHeight;
+
+ // Get the cell's x position and append by the table's width
+ //int width= tableViewer.getTable().getSize().x;
+ int width = tableViewer.getTable().getShell().getBounds().width;
+ int x = tableViewer.getTable().getShell().getLocation().x + width;
+
+ Point location = new Point(x, y);
+ init(parentShell, location, -1, 0);
+ return;
+ }
+
+ init(parentShell, parentShell.getDisplay().getCursorLocation(), 1, 1);
+ }
+
+ public SelectionMenu(Shell parentShell, Object source, Point cursorPosition) {
+ if (source instanceof Table && parentShell != null && cursorPosition != null) {
+ Table table = (Table) source;
+
+ TableItem item = table.getItem(cursorPosition);
+
+ if (item != null) {
+ int selectionIndex = 0;
+ for (Object tableItem : table.getItems()) {
+ if (tableItem.equals(item)) {
+ break;
+ }
+ selectionIndex++;
+ }
+
+ int cellHeight = item.getBounds().height;
+ int y = table.getShell().getLocation().y;
+ y += selectionIndex * cellHeight;
+
+ // Get the cell's x position and append by the table's width
+ //int width= tableViewer.getTable().getSize().x;
+ int width = table.getShell().getBounds().width;
+ int x = table.getShell().getLocation().x + width;
+
+ Point location = new Point(x, y);
+ init(parentShell, location, -1, 0);
+ return;
+ }
+ }
+
+ init(parentShell, parentShell.getDisplay().getCursorLocation(), 1, 1);
+ }
+
+ public SelectionMenu(Shell parentShell, Point location) {
+ init(parentShell, location, 1, 1);
+ }
+
+ protected void init(Shell parentShell, Point location, int xOffset, int yOffset) {
+ // Move the shell so that it doesn't open under the mouse
+ // The hovered element can still be selected
+ location.x += xOffset;
+ location.y += yOffset;
+
+ this.parentShell = parentShell;
+ this.location = location;
+ labelProvider = new LabelProvider();
+
+ selectionChangedListeners = new LinkedList<ISelectionChangedListener>();
+ selectionChangedListener = new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ for (ISelectionChangedListener listener : selectionChangedListeners) {
+ listener.selectionChanged(event);
+ }
+ }
+ };
+
+ keyListeners = new LinkedList<KeyListener>();
+ keyListener = new KeyListener() {
+ @Override
+ public void keyPressed(KeyEvent event) {
+ for (KeyListener listener : keyListeners) {
+ listener.keyPressed(event);
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent event) {
+ for (KeyListener listener : keyListeners) {
+ listener.keyReleased(event);
+ }
+ }
+ };
+
+ mouseTrackListeners = new LinkedList<MouseTrackListener>();
+ mouseTrackListener = new MouseTrackListener() {
+ @Override
+ public void mouseEnter(MouseEvent event) {
+ for (MouseTrackListener mouseTrackListener : mouseTrackListeners) {
+ mouseTrackListener.mouseEnter(event);
+ }
+ }
+
+ @Override
+ public void mouseExit(MouseEvent event) {
+ for (MouseTrackListener mouseTrackListener : mouseTrackListeners) {
+ mouseTrackListener.mouseExit(event);
+ }
+ }
+
+ @Override
+ public void mouseHover(MouseEvent event) {
+ for (MouseTrackListener mouseTrackListener : mouseTrackListeners) {
+ mouseTrackListener.mouseHover(event);
+ }
+ }
+ };
+ }
+
+ public void open() {
+ // Shell background and background
+ shell = new Shell(parentShell, SWT.NONE);
+ shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
+ shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
+ /*GridLayout gridLayout = new GridLayout(1, false);
+ gridLayout.marginWidth = 5;
+ gridLayout.marginHeight = 5;
+ shell.setLayout(gridLayout);*/
+ shell.setLayout(new GridLayout(1, false));
+
+ // TableViewer for menu items
+ tableViewer = new TableViewer(shell, SWT.NO_SCROLL);
+ tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tableViewer.setContentProvider(contentProvider);
+ tableViewer.setLabelProvider(labelProvider);
+ ColumnViewerToolTipSupport.enableFor(tableViewer);
+ tableViewer.setInput(input);
+
+ // Listeners
+ tableViewer.addSelectionChangedListener(selectionChangedListener);
+ tableViewer.getTable().addKeyListener(keyListener);
+ tableViewer.getTable().addMouseTrackListener(mouseTrackListener);
+
+ // Open
+ shell.setLocation(location);
+ shell.pack();
+ shell.open();
+
+
+ }
+
+ public void refresh() {
+ tableViewer.refresh();
+ shell.pack();
+ }
+
+ public void dispose() {
+ if (tableViewer != null) {
+ tableViewer.removeSelectionChangedListener(selectionChangedListener);
+ }
+
+ if (tableViewer.getTable() != null) {
+ tableViewer.getTable().removeKeyListener(keyListener);
+ }
+
+ if (shell != null) {
+ shell.dispose();
+ }
+ }
+
+ public void setContentProvider(IStructuredContentProvider provider) {
+ this.contentProvider = provider;
+ }
+
+ public void setInput(Object input) {
+ this.input = input;
+ }
+
+ public void setLabelProvider(ILabelProvider labelProvider) {
+ this.labelProvider = labelProvider;
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ this.selectionChangedListeners.add(listener);
+ }
+
+ public void addKeyListener(KeyListener listener) {
+ this.keyListeners.add(listener);
+ }
+
+ public void addMouseTrackListener(MouseTrackListener listener) {
+ this.mouseTrackListeners.add(listener);
+ }
+
+ public Shell getShell() {
+ return shell;
+ }
+
+ public void setShell(Shell shell) {
+ this.shell = shell;
+ }
+
+ public Shell getParentShell() {
+ return parentShell;
+ }
+
+ public TableViewer getTableViewer() {
+ return tableViewer;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.navigation/META-INF/MANIFEST.MF
index 301f7558c53..79d67725a67 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/META-INF/MANIFEST.MF
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/META-INF/MANIFEST.MF
@@ -1,19 +1,20 @@
-Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.papyrus.infra.services.navigation;bundle-version="1.2.0",
- org.eclipse.uml2.uml;bundle-version="4.1.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.tools.utils;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0"
-Bundle-Vendor: Eclipse Modeling Project
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.2.0.qualifier
-Bundle-Name: UML Navigation
-Bundle-Activator: org.eclipse.papyrus.uml.navigation.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.uml.navigation;singleton:=true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.services.navigation;bundle-version="1.2.0",
+ org.eclipse.uml2.uml;bundle-version="4.1.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.2.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.2.0"
+Bundle-Vendor: Eclipse Modeling Project
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.2.0.qualifier
+Bundle-Name: UML Navigation
+Bundle-Activator: org.eclipse.papyrus.uml.navigation.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.uml.navigation;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/plugin.xml b/plugins/uml/org.eclipse.papyrus.uml.navigation/plugin.xml
index a3dc19593a7..6f4c0c3a116 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/plugin.xml
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/plugin.xml
@@ -1,20 +1,64 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension
- point="org.eclipse.papyrus.infra.services.navigation.navigationContributor">
- <contributor
- contributor="org.eclipse.papyrus.uml.navigation.contributor.TypedElementNavigationContributor"
- description="Navigates to the type of the current UML Element"
- id="org.eclipse.papyrus.uml.navigation.typedElement"
- label="UML Typed Element navigation">
- </contributor>
- <contributor
- contributor="org.eclipse.papyrus.uml.navigation.contributor.CBANavigationContributor"
- description="Navigates to the Behavior linked to the current UML CallBehaviourAction"
- id="org.eclipse.papyrus.uml.navigation.callBehaviorAction"
- label="UML Call Behavior Action navigation">
- </contributor>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.infra.services.navigation.navigationContributor">
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.navigableElement.TypedElementNavigationContributor"
+ description="Navigates to the type of the current UML Element"
+ id="org.eclipse.papyrus.uml.navigation.typedElement"
+ label="UML Typed Element navigation">
+ </contributor>
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.navigableElement.CBANavigationContributor"
+ description="Navigates to the behavior linked to the current UML CallBehaviourAction"
+ id="org.eclipse.papyrus.uml.navigation.callBehaviorAction"
+ label="UML Call Behavior Action navigation">
+ </contributor>
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.navigableElement.NamedElementNavigationContributor"
+ description="Navigates to the current UML Named Element"
+ id="org.eclipse.papyrus.uml.navigation.namedElement"
+ label="UML Named Element navigation">
+ </contributor>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.services.navigation.navigationMenuContributor">
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.menuContributor.ParentsButton"
+ description="Navigate to parents of an element"
+ id="org.eclipse.papyrus.uml.navigation.menuContributor.parentsButton"
+ label="Parents">
+ </contributor>
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.menuContributor.ChildrenButton"
+ description="Navigate to children of an element"
+ id="org.eclipse.papyrus.uml.navigation.menuContributor.childrenButton"
+ label="Children">
+ </contributor>
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.menuContributor.TypesButton"
+ description="Navigate to elements typed by selected element"
+ id="org.eclipse.papyrus.uml.navigation.menuContributor.typesButton"
+ label="Types">
+ </contributor>
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.menuContributor.TargetsButton"
+ description="Navigate to targets of relationships for which the selected element is a source"
+ id="org.eclipse.papyrus.uml.navigation.menuContributor.targetsButton"
+ label="Targets">
+ </contributor>
+ <contributor
+ contributor="org.eclipse.papyrus.uml.navigation.menuContributor.SourcesButton"
+ description="Navigate to sources of relationships for which the selected element is a target"
+ id="org.eclipse.papyrus.uml.navigation.menuContributor.sourcesButton"
+ label="Sources">
+ </contributor>
+ <!--<contributor
+ contributor="org.eclipse.papyrus.uml.navigation.menuContributor.ViewsButton"
+ description="Views button"
+ id="org.eclipse.papyrus.uml.navigation.menuContributor.viewsButton"
+ label="Views button">
+ </contributor>-->
+ </extension>
+</plugin>
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ChildrenButton.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ChildrenButton.java
new file mode 100644
index 00000000000..3bfab6b14df
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ChildrenButton.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * 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.uml.navigation.menuContributor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+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.uml.navigation.Activator;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Generalization;
+import org.eclipse.uml2.uml.Relationship;
+
+public class ChildrenButton implements NavigationMenuContributor {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor#getButtons(java.lang.Object)
+ *
+ * @param fromElement
+ * @return
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ if (fromElement instanceof Classifier) {
+ try {
+ NavigationService navigationService = ServiceUtilsForEObject.getInstance().getService(NavigationService.class, (Classifier) fromElement);
+
+ List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
+ for (Relationship relationship : ((Element) fromElement).getRelationships()) {
+ if (relationship instanceof Generalization) {
+ Generalization generalization = (Generalization) relationship;
+ if (generalization.getGeneral() == fromElement) {
+ Classifier specific = generalization.getSpecific();
+ if (specific != null) {
+ navigableElements.addAll(navigationService.getNavigableElements(specific));
+ }
+ }
+ }
+ }
+
+ if (!navigableElements.isEmpty()) {
+ buttons.add(new NavigationSubMenuButton("Children...", null, "Show children classes", navigableElements));
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ return buttons;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ParentsButton.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ParentsButton.java
new file mode 100644
index 00000000000..3c647d4b45a
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/ParentsButton.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 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.uml.navigation.menuContributor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+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.uml.navigation.Activator;
+import org.eclipse.uml2.uml.Classifier;
+
+/**
+ * The navigation menu contributor returns a navigation menu button that contains
+ * the parents of the element that is clicked on.
+ *
+ */
+public class ParentsButton implements NavigationMenuContributor {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor#getButtons(java.lang.Object)
+ *
+ * @param fromElement
+ * @return
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ if (fromElement instanceof Classifier) {
+ try {
+ NavigationService navigationService = ServiceUtilsForEObject.getInstance().getService(NavigationService.class, (Classifier) fromElement);
+ // Parents
+ if (!((Classifier) fromElement).parents().isEmpty()) {
+ List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
+ for (Classifier parent : ((Classifier) fromElement).parents()) {
+ navigableElements.addAll(navigationService.getNavigableElements(parent));
+ }
+
+ if (!navigableElements.isEmpty()) {
+ buttons.add(new NavigationSubMenuButton("Parents...", null, "Show parent classes", navigableElements));
+ }
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ return buttons;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/SourcesButton.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/SourcesButton.java
new file mode 100644
index 00000000000..2b9534c1977
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/SourcesButton.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * 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.uml.navigation.menuContributor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+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.uml.navigation.Activator;
+import org.eclipse.uml2.uml.DirectedRelationship;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * The navigation menu contributor returns a navigation menu button that contains
+ * the sources of the element that is clicked on.
+ *
+ */
+public class SourcesButton implements NavigationMenuContributor {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor#getButtons(java.lang.Object)
+ *
+ * @param fromElement
+ * @return
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ if (fromElement instanceof Element) {
+ try {
+ NavigationService navigationService = ServiceUtilsForEObject.getInstance().getService(NavigationService.class, (Element) fromElement);
+
+ List<DirectedRelationship> relationships = ((Element) fromElement).getTargetDirectedRelationships();
+
+ if (!relationships.isEmpty()) {
+ List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
+ for (DirectedRelationship relationship : relationships) {
+ for (Element source : relationship.getSources()) {
+ navigableElements.addAll(navigationService.getNavigableElements(source));
+ }
+ }
+
+ if (!navigableElements.isEmpty()) {
+ buttons.add(new NavigationSubMenuButton("Sources...", null, "Show sources", navigableElements));
+ }
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ return buttons;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TargetsButton.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TargetsButton.java
new file mode 100644
index 00000000000..0933470cc63
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TargetsButton.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * 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.uml.navigation.menuContributor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+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.uml.navigation.Activator;
+import org.eclipse.uml2.uml.DirectedRelationship;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * The navigation menu contributor returns a navigation menu button that contains
+ * the targets of the element that is clicked on.
+ *
+ */
+public class TargetsButton implements NavigationMenuContributor {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor#getButtons(java.lang.Object)
+ *
+ * @param fromElement
+ * @return
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ if (fromElement instanceof Element) {
+ try {
+ NavigationService navigationService = ServiceUtilsForEObject.getInstance().getService(NavigationService.class, (Element) fromElement);
+
+ List<DirectedRelationship> relationships = ((Element) fromElement).getSourceDirectedRelationships();
+
+ if (!relationships.isEmpty()) {
+ List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
+ for (DirectedRelationship relationship : relationships) {
+ for (Element target : relationship.getTargets()) {
+ navigableElements.addAll(navigationService.getNavigableElements(target));
+ }
+ }
+
+ if (!navigableElements.isEmpty()) {
+ buttons.add(new NavigationSubMenuButton("Targets...", null, "Show targets", navigableElements));
+ }
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ return buttons;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TypesButton.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TypesButton.java
new file mode 100644
index 00000000000..ff828cd23e1
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/menuContributor/TypesButton.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * 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.uml.navigation.menuContributor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.button.NavigationSubMenuButton;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+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.uml.navigation.Activator;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.TypedElement;
+
+public class TypesButton implements NavigationMenuContributor {
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenuContributor#getButtons(java.lang.Object)
+ *
+ * @param fromElement
+ * @return
+ */
+ public List<NavigationMenuButton> getButtons(Object fromElement) {
+ List<NavigationMenuButton> buttons = new LinkedList<NavigationMenuButton>();
+
+ if (fromElement instanceof Type) {
+ try {
+ NavigationService navigationService = ServiceUtilsForEObject.getInstance().getService(NavigationService.class, (Classifier) fromElement);
+ List<NavigableElement> navigableElements = new LinkedList<NavigableElement>();
+
+ List<Element> elements = ((Element) fromElement).getModel().allOwnedElements();
+ for (Element element : elements) {
+ if (element instanceof TypedElement) {
+ if (((TypedElement) element).getType() == fromElement) {
+ List<NavigableElement> typesNavigableElements = navigationService.getNavigableElements(element);
+ for (NavigableElement typesNavigableElement : typesNavigableElements) {
+ if (!typesNavigableElement.getClass().getSimpleName().equalsIgnoreCase("TypedNavigableElement")
+ && !typesNavigableElement.getClass().getSimpleName().equalsIgnoreCase("OperationTypeNavigableElement")) {
+ navigableElements.add(typesNavigableElement);
+ }
+ }
+ }
+ }
+ }
+
+ if (!navigableElements.isEmpty()) {
+ buttons.add(new NavigationSubMenuButton("Types...", null, "Show other elements typed by this element", navigableElements));
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ return buttons;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/CBANavigableElement.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/CBANavigableElement.java
index 8de6f1aaadf..1004d012a1d 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/CBANavigableElement.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/CBANavigableElement.java
@@ -1,98 +1,116 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST, 2014 Flanders' Make.
- *
- * 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
- * Klaas Gadeyne (Flanders' Make) klaas.gadeyne@flandersmake.be - Extended for CallBehaviorActions,
- * see bug 453721
- *****************************************************************************/
-package org.eclipse.papyrus.uml.navigation.contributor;
-
-import java.util.Collections;
-
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
-import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Behavior;
-
-/**
- * Navigates from a CallBehaviorAction to its Behavior declaration
- *
- * @author Klaas Gadeyne
- */
-public class CBANavigableElement implements NavigableElement {
-
- protected final Behavior behavior;
-
- /**
- *
- * @param type
- * The Type to navigate to. May be null.
- */
- public CBANavigableElement(Behavior behavior) {
- this.behavior = behavior;
- }
-
- public String getLabel() {
- String label = "Go to behavior" + getCBALabel();
- return label;
- }
-
- public String getDescription() {
- return "Go to the Behavior linked with to this CallBehaviorAction" + getCBALabel();
- }
-
- protected String getCBALabel() {
- if (behavior == null) {
- return " (Undefined)";
- } else {
- return " (" + behavior.getName() + ")";
- }
- }
-
- @Deprecated
- public void navigate(IRevealSemanticElement navigationContext) {
- if (!isEnabled()) {
- return;
- }
-
- navigationContext.revealSemanticElement(Collections.singletonList(behavior));
- }
-
- public Image getImage() {
- if (behavior == null) {
- return null;
- }
-
- try {
- return ServiceUtilsForEObject.getInstance().getServiceRegistry(behavior).getService(LabelProviderService.class).getLabelProvider().getImage(behavior);
- } catch (Exception ex) {
- return null;
- }
- }
-
- /**
- * Enabled when the behavior is defined
- */
- public boolean isEnabled() {
- return behavior != null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean navigate(NavigationTarget navigationContext) {
- if (!isEnabled()) {
- return false;
- }
- return navigationContext.revealElement(behavior);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST, 2014 Flanders' Make.
+ *
+ * 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
+ * Klaas Gadeyne (Flanders' Make) klaas.gadeyne@flandersmake.be - Extended for CallBehaviorActions,
+ * see bug 453721
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.navigation.navigableElement;
+
+import java.util.Collections;
+
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.navigation.service.ExtendedNavigableElement;
+import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Behavior;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * Navigates from a CallBehaviorAction to its Behavior declaration
+ *
+ * @author Klaas Gadeyne
+ */
+public class CBANavigableElement implements ExtendedNavigableElement {
+
+ protected final Behavior behavior;
+
+ /**
+ *
+ * @param type
+ * The Type to navigate to. May be null.
+ */
+ public CBANavigableElement(Behavior behavior) {
+ this.behavior = behavior;
+ }
+
+ public String getLabel() {
+ String label = "Go to behavior" + getCBALabel();
+ return label;
+ }
+
+ public String getDescription() {
+ return "Go to the Behavior linked with to this CallBehaviorAction" + getCBALabel();
+ }
+
+ protected String getCBALabel() {
+ if (behavior == null) {
+ return " (Undefined)";
+ } else {
+ return " (" + behavior.getName() + ")";
+ }
+ }
+
+ @Deprecated
+ public void navigate(IRevealSemanticElement navigationContext) {
+ if (!isEnabled()) {
+ return;
+ }
+
+ navigationContext.revealSemanticElement(Collections.singletonList(behavior));
+ }
+
+ public Image getImage() {
+ if (behavior == null) {
+ return null;
+ }
+
+ try {
+ return ServiceUtilsForEObject.getInstance().getServiceRegistry(behavior).getService(LabelProviderService.class).getLabelProvider().getImage(behavior);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ /**
+ * Enabled when the behavior is defined
+ */
+ public boolean isEnabled() {
+ return behavior != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean navigate(NavigationTarget navigationContext) {
+ if (!isEnabled()) {
+ return false;
+ }
+ return navigationContext.revealElement(behavior);
+ }
+
+ /**
+ * Returns the behavior (UML Element) of the CBANavigableElement
+ * @return behavior
+ */
+ public Element getBehavior() {
+ return behavior;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigableElement#getSemanticElement()
+ *
+ * @return
+ */
+ public Object getSemanticElement() {
+ return getBehavior();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/CBANavigationContributor.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/CBANavigationContributor.java
index d9d2c3e1303..9799b9d42e2 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/CBANavigationContributor.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/CBANavigationContributor.java
@@ -1,42 +1,42 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST, 2014 Flanders' Make.
- *
- * 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
- * Klaas Gadeyne (Flanders' Make) klaas.gadeyne@flandersmake.be - Extended for CallBehaviorActions,
- * see bug 453721
- *****************************************************************************/
-package org.eclipse.papyrus.uml.navigation.contributor;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
-import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.CallBehaviorAction;
-
-/**
- * NavigationContributor to navigate from a CallBehaviorAction to its Behavior declaration
- *
- * @author Klaas Gadeyne
- *
- */
-public class CBANavigationContributor implements NavigationContributor {
-
- public List<NavigableElement> getNavigableElements(Object fromElement) {
- List<NavigableElement> result = new LinkedList<NavigableElement>();
-
- Element element = UMLUtil.resolveUMLElement(fromElement);
- if (element instanceof CallBehaviorAction) {
- result.add(new CBANavigableElement(((CallBehaviorAction) element).getBehavior()));
- }
- return result;
- }
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST, 2014 Flanders' Make.
+ *
+ * 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
+ * Klaas Gadeyne (Flanders' Make) klaas.gadeyne@flandersmake.be - Extended for CallBehaviorActions,
+ * see bug 453721
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.navigation.navigableElement;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
+import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.CallBehaviorAction;
+
+/**
+ * NavigationContributor to navigate from a CallBehaviorAction to its Behavior declaration
+ *
+ * @author Klaas Gadeyne
+ *
+ */
+public class CBANavigationContributor implements NavigationContributor {
+
+ public List<NavigableElement> getNavigableElements(Object fromElement) {
+ List<NavigableElement> result = new LinkedList<NavigableElement>();
+
+ Element element = UMLUtil.resolveUMLElement(fromElement);
+ if (element instanceof CallBehaviorAction) {
+ result.add(new CBANavigableElement(((CallBehaviorAction) element).getBehavior()));
+ }
+ return result;
+ }
} \ No newline at end of file
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedElementNavigationContributor.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedElementNavigationContributor.java
new file mode 100644
index 00000000000..4e2ccc1a993
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedElementNavigationContributor.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * 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
+ * Shuai Li (CEA LIST) shuai.li@cea.fr - Creation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.navigation.navigableElement;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
+import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * NavigationContributor to navigate from TypedElement to their Type
+ *
+ * @author Shuai Li
+ *
+ */
+public class NamedElementNavigationContributor implements NavigationContributor {
+
+ public List<NavigableElement> getNavigableElements(Object fromElement) {
+ List<NavigableElement> result = new LinkedList<NavigableElement>();
+
+ Element element = UMLUtil.resolveUMLElement(fromElement);
+ if (element instanceof NamedElement) {
+ result.add(new NamedNavigableElement(((NamedElement) element)));
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedNavigableElement.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedNavigableElement.java
new file mode 100644
index 00000000000..8946f3df3b4
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/NamedNavigableElement.java
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * 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
+ * Shuai Li (CEA LIST) shuai.li@cea.fr - Creation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.navigation.navigableElement;
+
+import java.util.Collections;
+
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.navigation.service.ExtendedNavigableElement;
+import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * Navigates from a NamedElementdElement to its NamedElement declaration
+ *
+ * @author Shuai Li
+ */
+public class NamedNavigableElement implements ExtendedNavigableElement {
+
+ protected final NamedElement element;
+
+ /**
+ *
+ * @param element
+ * The NamedElement to navigate to. May be null.
+ */
+ public NamedNavigableElement(NamedElement element) {
+ this.element = element;
+ }
+
+ public String getLabel() {
+ String label = "Go to element" + getNamedElementLabel() + "...";
+ return label;
+ }
+
+ public String getDescription() {
+ return "Go to the element declaration of this NamedElement" + getNamedElementLabel();
+ }
+
+ protected String getNamedElementLabel() {
+ if (element == null) {
+ return " (Undefined)";
+ } else {
+ return " (" + element.getName() + ")";
+ }
+ }
+
+ @Deprecated
+ public void navigate(IRevealSemanticElement navigationContext) {
+ if (!isEnabled()) {
+ return;
+ }
+
+ navigationContext.revealSemanticElement(Collections.singletonList(element));
+ }
+
+ public Image getImage() {
+ if (element == null) {
+ return null;
+ }
+
+ try {
+ return ServiceUtilsForEObject.getInstance().getServiceRegistry(element).getService(LabelProviderService.class).getLabelProvider().getImage(element);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ /**
+ * Enabled when the element is defined
+ */
+ public boolean isEnabled() {
+ return element != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean navigate(NavigationTarget navigationContext) {
+ if (!isEnabled()) {
+ return false;
+ }
+ return navigationContext.revealElement(element);
+ }
+
+ /**
+ * Returns the element (UML Element) of the NamedElementdNavigableElement
+ * @return element
+ */
+ public Element getNamedElement() {
+ return this.element;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigableElement#getSemanticElement()
+ *
+ * @return
+ */
+ public Object getSemanticElement() {
+ return getNamedElement();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/OperationTypeNavigableElement.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/OperationTypeNavigableElement.java
index fd52df2b4d2..037a21614fe 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/OperationTypeNavigableElement.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/OperationTypeNavigableElement.java
@@ -1,37 +1,37 @@
-/*****************************************************************************
- * 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.uml.navigation.contributor;
-
-import org.eclipse.uml2.uml.Operation;
-
-/**
- * Navigates from an Operation to it's return type declaration
- *
- * @author CL228098
- *
- */
-public class OperationTypeNavigableElement extends TypedNavigableElement {
-
- public OperationTypeNavigableElement(Operation operation) {
- super(operation.getType());
- }
-
- @Override
- public String getLabel() {
- return "Go to return Type" + getTypeLabel();
- }
-
- @Override
- public String getDescription() {
- return "Go to the return type declaration of this Operation" + getTypeLabel();
- }
-}
+/*****************************************************************************
+ * 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.uml.navigation.navigableElement;
+
+import org.eclipse.uml2.uml.Operation;
+
+/**
+ * Navigates from an Operation to it's return type declaration
+ *
+ * @author CL228098
+ *
+ */
+public class OperationTypeNavigableElement extends TypedNavigableElement {
+
+ public OperationTypeNavigableElement(Operation operation) {
+ super(operation.getType());
+ }
+
+ @Override
+ public String getLabel() {
+ return "Go to return type" + getTypeLabel() + "...";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Go to the return type declaration of this Operation" + getTypeLabel();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/TypedElementNavigationContributor.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/TypedElementNavigationContributor.java
index 42bf705e7ae..0ae43d449ca 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/TypedElementNavigationContributor.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/TypedElementNavigationContributor.java
@@ -1,44 +1,44 @@
-/*****************************************************************************
- * 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.uml.navigation.contributor;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
-import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Operation;
-import org.eclipse.uml2.uml.TypedElement;
-
-/**
- * NavigationContributor to navigate from TypedElement to their Type
- *
- * @author Camille Letavernier
- *
- */
-public class TypedElementNavigationContributor implements NavigationContributor {
-
- public List<NavigableElement> getNavigableElements(Object fromElement) {
- List<NavigableElement> result = new LinkedList<NavigableElement>();
-
- Element element = UMLUtil.resolveUMLElement(fromElement);
- if (element instanceof TypedElement) {
- result.add(new TypedNavigableElement(((TypedElement) element).getType()));
- } else if (element instanceof Operation) {
- result.add(new OperationTypeNavigableElement((Operation) element));
- }
-
- return result;
- }
-}
+/*****************************************************************************
+ * 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.uml.navigation.navigableElement;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationContributor;
+import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.TypedElement;
+
+/**
+ * NavigationContributor to navigate from TypedElement to their Type
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class TypedElementNavigationContributor implements NavigationContributor {
+
+ public List<NavigableElement> getNavigableElements(Object fromElement) {
+ List<NavigableElement> result = new LinkedList<NavigableElement>();
+
+ Element element = UMLUtil.resolveUMLElement(fromElement);
+ if (element instanceof TypedElement && ((TypedElement) element).getType() != null) {
+ result.add(new TypedNavigableElement(((TypedElement) element).getType()));
+ } else if (element instanceof Operation && ((Operation) element).getType() != null) {
+ result.add(new OperationTypeNavigableElement((Operation) element));
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/TypedNavigableElement.java b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/TypedNavigableElement.java
index cf9d286fde8..3e856a98319 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/contributor/TypedNavigableElement.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.navigation/src/org/eclipse/papyrus/uml/navigation/navigableElement/TypedNavigableElement.java
@@ -1,96 +1,114 @@
-/*****************************************************************************
- * 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.uml.navigation.contributor;
-
-import java.util.Collections;
-
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
-import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Type;
-
-/**
- * Navigates from a TypedElement to its Type declaration
- *
- * @author Camille Letavernier
- */
-public class TypedNavigableElement implements NavigableElement {
-
- protected final Type type;
-
- /**
- *
- * @param type
- * The Type to navigate to. May be null.
- */
- public TypedNavigableElement(Type type) {
- this.type = type;
- }
-
- public String getLabel() {
- String label = "Go to type" + getTypeLabel();
- return label;
- }
-
- public String getDescription() {
- return "Go to the type declaration of this TypedElement" + getTypeLabel();
- }
-
- protected String getTypeLabel() {
- if (type == null) {
- return " (Undefined)";
- } else {
- return " (" + type.getName() + ")";
- }
- }
-
- @Deprecated
- public void navigate(IRevealSemanticElement navigationContext) {
- if (!isEnabled()) {
- return;
- }
-
- navigationContext.revealSemanticElement(Collections.singletonList(type));
- }
-
- public Image getImage() {
- if (type == null) {
- return null;
- }
-
- try {
- return ServiceUtilsForEObject.getInstance().getServiceRegistry(type).getService(LabelProviderService.class).getLabelProvider().getImage(type);
- } catch (Exception ex) {
- return null;
- }
- }
-
- /**
- * Enabled when the type is defined
- */
- public boolean isEnabled() {
- return type != null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean navigate(NavigationTarget navigationContext) {
- if (!isEnabled()) {
- return false;
- }
- return navigationContext.revealElement(type);
- }
-}
+/*****************************************************************************
+ * 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.uml.navigation.navigableElement;
+
+import java.util.Collections;
+
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.navigation.service.ExtendedNavigableElement;
+import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * Navigates from a TypedElement to its Type declaration
+ *
+ * @author Camille Letavernier
+ */
+public class TypedNavigableElement implements ExtendedNavigableElement {
+
+ protected final Type type;
+
+ /**
+ *
+ * @param type
+ * The Type to navigate to. May be null.
+ */
+ public TypedNavigableElement(Type type) {
+ this.type = type;
+ }
+
+ public String getLabel() {
+ String label = "Go to type" + getTypeLabel() + "...";
+ return label;
+ }
+
+ public String getDescription() {
+ return "Go to the type declaration of this TypedElement" + getTypeLabel();
+ }
+
+ protected String getTypeLabel() {
+ if (type == null) {
+ return " (Undefined)";
+ } else {
+ return " (" + type.getName() + ")";
+ }
+ }
+
+ @Deprecated
+ public void navigate(IRevealSemanticElement navigationContext) {
+ if (!isEnabled()) {
+ return;
+ }
+
+ navigationContext.revealSemanticElement(Collections.singletonList(type));
+ }
+
+ public Image getImage() {
+ if (type == null) {
+ return null;
+ }
+
+ try {
+ return ServiceUtilsForEObject.getInstance().getServiceRegistry(type).getService(LabelProviderService.class).getLabelProvider().getImage(type);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ /**
+ * Enabled when the type is defined
+ */
+ public boolean isEnabled() {
+ return type != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean navigate(NavigationTarget navigationContext) {
+ if (!isEnabled()) {
+ return false;
+ }
+ return navigationContext.revealElement(type);
+ }
+
+ /**
+ * Returns the type (UML Element) of the TypedNavigableElement
+ * @return type
+ */
+ public Element getType() {
+ return this.type;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.navigation.service.NavigableElement#getSemanticElement()
+ *
+ * @return
+ */
+ public Object getSemanticElement() {
+ return getType();
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF
index 30333282c2b..98d1f603c90 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/META-INF/MANIFEST.MF
@@ -1,65 +1,65 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.views.modelexplorer,
- org.eclipse.papyrus.views.modelexplorer.actionprovider,
- org.eclipse.papyrus.views.modelexplorer.actions,
- org.eclipse.papyrus.views.modelexplorer.commands,
- org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview,
- org.eclipse.papyrus.views.modelexplorer.dialog,
- org.eclipse.papyrus.views.modelexplorer.dnd,
- org.eclipse.papyrus.views.modelexplorer.factory,
- org.eclipse.papyrus.views.modelexplorer.handler,
- org.eclipse.papyrus.views.modelexplorer.matching,
- org.eclipse.papyrus.views.modelexplorer.preferences,
- org.eclipse.papyrus.views.modelexplorer.queries
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.ui.navigator;bundle-version="3.4.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0",
- org.eclipse.emf.converter;bundle-version="2.5.0",
- org.eclipse.papyrus.infra.core.sasheditor.di;bundle-version="1.2.0",
- org.eclipse.emf.ecore.editor;bundle-version="2.6.0",
- org.eclipse.emf.workspace.ui;bundle-version="1.3.0",
- org.eclipse.core.expressions;bundle-version="3.4.200",
- org.eclipse.papyrus.infra.services.edit;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.services.decoration;bundle-version="1.2.0",
- org.eclipse.emf.transaction;bundle-version="1.4.0",
- org.eclipse.gmf.runtime.notation;bundle-version="1.5.0",
- org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1",
- org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
- org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.4.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
- com.google.guava;bundle-version="11.0.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.2.0",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.6.0",
- org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.services.semantic;bundle-version="1.2.0",
- org.eclipse.emf.ecore,
- org.eclipse.papyrus.infra.services.navigation;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.tools;bundle-version="1.2.0",
- org.eclipse.papyrus.extensionpoints.editors;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.custom.metamodel;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.util.ui;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.query.java.core;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.util.emf.ui;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.efacet.core;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.efacet;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.efacet.metamodel;bundle-version="1.2.0",
- org.eclipse.papyrus.emf.facet.util.emf.core;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.2.0"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.2.0.qualifier
-Bundle-Localization: plugin
-Bundle-Name: %pluginName
-Bundle-Activator: org.eclipse.papyrus.views.modelexplorer.Activator
-Bundle-ManifestVersion: 2
-Bundle-Description: %pluginDescription
-Bundle-SymbolicName: org.eclipse.papyrus.views.modelexplorer;singleton:=true
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.views.modelexplorer,
+ org.eclipse.papyrus.views.modelexplorer.actionprovider,
+ org.eclipse.papyrus.views.modelexplorer.actions,
+ org.eclipse.papyrus.views.modelexplorer.commands,
+ org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview,
+ org.eclipse.papyrus.views.modelexplorer.dialog,
+ org.eclipse.papyrus.views.modelexplorer.dnd,
+ org.eclipse.papyrus.views.modelexplorer.factory,
+ org.eclipse.papyrus.views.modelexplorer.handler,
+ org.eclipse.papyrus.views.modelexplorer.matching,
+ org.eclipse.papyrus.views.modelexplorer.preferences,
+ org.eclipse.papyrus.views.modelexplorer.queries
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.ui.navigator;bundle-version="3.4.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0",
+ org.eclipse.emf.converter;bundle-version="2.5.0",
+ org.eclipse.papyrus.infra.core.sasheditor.di;bundle-version="1.2.0",
+ org.eclipse.emf.ecore.editor;bundle-version="2.6.0",
+ org.eclipse.emf.workspace.ui;bundle-version="1.3.0",
+ org.eclipse.core.expressions;bundle-version="3.4.200",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.decoration;bundle-version="1.2.0",
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.gmf.runtime.notation;bundle-version="1.5.0",
+ org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1",
+ org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
+ org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.4.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.2.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.6.0",
+ org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.services.semantic;bundle-version="1.2.0",
+ org.eclipse.emf.ecore,
+ org.eclipse.papyrus.infra.services.navigation;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="1.2.0",
+ org.eclipse.papyrus.extensionpoints.editors;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.custom.metamodel;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.util.ui;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.query.java.core;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.util.emf.ui;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.efacet.core;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.efacet;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.efacet.metamodel;bundle-version="1.2.0",
+ org.eclipse.papyrus.emf.facet.util.emf.core;bundle-version="1.2.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.2.0"
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.2.0.qualifier
+Bundle-Localization: plugin
+Bundle-Name: %pluginName
+Bundle-Activator: org.eclipse.papyrus.views.modelexplorer.Activator
+Bundle-ManifestVersion: 2
+Bundle-Description: %pluginDescription
+Bundle-SymbolicName: org.eclipse.papyrus.views.modelexplorer;singleton:=true
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java
index 106d5c979ec..398f0364ec2 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java
@@ -1,155 +1,155 @@
-/*****************************************************************************
- * Copyright (c) 2010 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.jface.viewers.ColumnViewerEditor;
-import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
-import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
-import org.eclipse.jface.viewers.FocusCellHighlighter;
-import org.eclipse.jface.viewers.IElementComparer;
-import org.eclipse.jface.viewers.TreeViewerEditor;
-import org.eclipse.jface.viewers.TreeViewerFocusCellManager;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EReferenceTreeElement;
-import org.eclipse.papyrus.views.modelexplorer.matching.HashCodeCalculus;
-import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
-import org.eclipse.papyrus.views.modelexplorer.matching.IReferencable;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
-import org.eclipse.ui.navigator.CommonDragAdapter;
-import org.eclipse.ui.navigator.CommonDropAdapter;
-import org.eclipse.ui.navigator.CommonViewer;
-
-/**
- * this class was created in order to access to the drop adapter
- *
- */
-@SuppressWarnings("restriction")
-public class CustomCommonViewer extends CommonViewer {
- protected CommonDropAdapter dropAdapter;
-
- public CustomCommonViewer(String aViewerId, Composite aParent, int aStyle) {
- super(aViewerId, aParent, aStyle);
- // TODO Auto-generated constructor stub
- setComparer(new IElementComparer() {
-
- public int hashCode(Object element) {
- if (element instanceof EObjectTreeElement) {
- EObject eObject = ((EObjectTreeElement) element).getEObject();
- return HashCodeCalculus.getHashCode(eObject);
- }
-
- if (element instanceof EReferenceTreeElement) {
- EObject eParent = ((EReferenceTreeElement) element).getParent().getEObject();
- EReference eref = ((EReferenceTreeElement) element).getEReference();
- return HashCodeCalculus.getHashCode(eParent, eref);
- }
- if (element instanceof IReferencable) {
- IReferencable ref = (IReferencable) element;
- return ref.getElementBehind().hashCode();
- }
- if (element instanceof IMatchingItem) {
- IMatchingItem matchItem = (IMatchingItem) element;
- return matchItem.matchingItemHashcode();
- }
- return element.hashCode();
- }
-
- public boolean equals(Object a, Object b) {
- if (a instanceof IMatchingItem) {
- return ((IMatchingItem) a).matchingItemEquals(b);
- }
-
- if (b != null) {
- return b.equals(a);
- }
- return false;
- }
- });
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void initDragAndDrop() {
- dropAdapter = null;
- int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
-
- CommonDragAdapter dragAdapter = createDragAdapter();
- addDragSupport(operations, dragAdapter.getSupportedDragTransfers(), dragAdapter);
- dropAdapter = createDropAdapter();
- addDropSupport(operations, dropAdapter.getSupportedDropTransfers(), dropAdapter);
-
- NavigatorDnDService dnd = (NavigatorDnDService) getNavigatorContentService().getDnDService();
- dnd.setDropAdaptor(dropAdapter);
- }
-
- /**
- * get the listener in order to parameterize during the runtime the drop
- *
- * @return the dropadapter
- */
- public CommonDropAdapter getDropAdapter() {
- return dropAdapter;
- }
-
- /**
- * Overridden to disable cell editor activation by single click, it can be activated by double click instead.
- */
- @Override
- protected ColumnViewerEditor createViewerEditor() {
- // instantiate abstract focus cell high-lighter as dummy object for focus manager. The sub class
- // FocusCellOwnerDrawHighlighter would break multi-selections in Papyrus, see bug 419591.
- // (but we need to create a high-lighter, since the focus cell manager does not accept null pointer. The
- // TreeViewerEditor could work without focusCellManager, but would ignore keyboard events in this case.)
- FocusCellHighlighter fch = new FocusCellHighlighter(this) {
- };
- TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(
- this, fch);
-
-
-
- TreeViewerEditor.create(this, focusCellManager, new ColumnViewerEditorActivationStrategy(this) {
- @Override
- protected boolean isEditorActivationEvent(
- ColumnViewerEditorActivationEvent event) {
- // activation will uses F2 (also used by rename-popup, but not taken into account by the latter
- // for model elements for which a direct-editor exists)
- return event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED &&
- event.keyCode == SWT.F2;
- }
- }, ColumnViewerEditor.KEYBOARD_ACTIVATION);
- ColumnViewerEditor editor = this.getColumnViewerEditor();
-
- return editor;
- }
-
- /**
- * @see org.eclipse.ui.navigator.CommonViewer#dispose()
- *
- */
- @Override
- public void dispose() {
- //Remove the custom column viewer editor which causes NPE after dispose
- //ViewerEditor cannot be nulled or disposed, so we just recreate a default one
- setColumnViewerEditor(super.createViewerEditor());
- super.dispose();
- }
-
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.jface.viewers.ColumnViewerEditor;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
+import org.eclipse.jface.viewers.FocusCellHighlighter;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.jface.viewers.TreeViewerEditor;
+import org.eclipse.jface.viewers.TreeViewerFocusCellManager;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;
+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EReferenceTreeElement;
+import org.eclipse.papyrus.views.modelexplorer.matching.HashCodeCalculus;
+import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.IReferencable;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
+import org.eclipse.ui.navigator.CommonDragAdapter;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * this class was created in order to access to the drop adapter
+ *
+ */
+@SuppressWarnings("restriction")
+public class CustomCommonViewer extends CommonViewer {
+ protected CommonDropAdapter dropAdapter;
+
+ public CustomCommonViewer(String aViewerId, Composite aParent, int aStyle) {
+ super(aViewerId, aParent, aStyle);
+ // TODO Auto-generated constructor stub
+ setComparer(new IElementComparer() {
+
+ public int hashCode(Object element) {
+ if (element instanceof EObjectTreeElement) {
+ EObject eObject = ((EObjectTreeElement) element).getEObject();
+ return HashCodeCalculus.getHashCode(eObject);
+ }
+
+ if (element instanceof EReferenceTreeElement) {
+ EObject eParent = ((EReferenceTreeElement) element).getParent().getEObject();
+ EReference eref = ((EReferenceTreeElement) element).getEReference();
+ return HashCodeCalculus.getHashCode(eParent, eref);
+ }
+ if (element instanceof IReferencable) {
+ IReferencable ref = (IReferencable) element;
+ return ref.getElementBehind().hashCode();
+ }
+ if (element instanceof IMatchingItem) {
+ IMatchingItem matchItem = (IMatchingItem) element;
+ return matchItem.matchingItemHashcode();
+ }
+ return element.hashCode();
+ }
+
+ public boolean equals(Object a, Object b) {
+ if (a instanceof IMatchingItem) {
+ return ((IMatchingItem) a).matchingItemEquals(b);
+ }
+
+ if (b != null) {
+ return b.equals(a);
+ }
+ return false;
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void initDragAndDrop() {
+ dropAdapter = null;
+ int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+
+ CommonDragAdapter dragAdapter = createDragAdapter();
+ addDragSupport(operations, dragAdapter.getSupportedDragTransfers(), dragAdapter);
+ dropAdapter = createDropAdapter();
+ addDropSupport(operations, dropAdapter.getSupportedDropTransfers(), dropAdapter);
+
+ NavigatorDnDService dnd = (NavigatorDnDService) getNavigatorContentService().getDnDService();
+ dnd.setDropAdaptor(dropAdapter);
+ }
+
+ /**
+ * get the listener in order to parameterize during the runtime the drop
+ *
+ * @return the dropadapter
+ */
+ public CommonDropAdapter getDropAdapter() {
+ return dropAdapter;
+ }
+
+ /**
+ * Overridden to disable cell editor activation by single click, it can be activated by double click instead.
+ */
+ @Override
+ protected ColumnViewerEditor createViewerEditor() {
+ // instantiate abstract focus cell high-lighter as dummy object for focus manager. The sub class
+ // FocusCellOwnerDrawHighlighter would break multi-selections in Papyrus, see bug 419591.
+ // (but we need to create a high-lighter, since the focus cell manager does not accept null pointer. The
+ // TreeViewerEditor could work without focusCellManager, but would ignore keyboard events in this case.)
+ FocusCellHighlighter fch = new FocusCellHighlighter(this) {
+ };
+ TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(
+ this, fch);
+
+
+
+ TreeViewerEditor.create(this, focusCellManager, new ColumnViewerEditorActivationStrategy(this) {
+ @Override
+ protected boolean isEditorActivationEvent(
+ ColumnViewerEditorActivationEvent event) {
+ // activation will uses F2 (also used by rename-popup, but not taken into account by the latter
+ // for model elements for which a direct-editor exists)
+ return event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED &&
+ event.keyCode == SWT.F2;
+ }
+ }, ColumnViewerEditor.KEYBOARD_ACTIVATION);
+ ColumnViewerEditor editor = this.getColumnViewerEditor();
+
+ return editor;
+ }
+
+ /**
+ * @see org.eclipse.ui.navigator.CommonViewer#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ //Remove the custom column viewer editor which causes NPE after dispose
+ //ViewerEditor cannot be nulled or disposed, so we just recreate a default one
+ setColumnViewerEditor(super.createViewerEditor());
+ super.dispose();
+ }
+
} \ No newline at end of file
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IPageBookViewPageListener.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IPageBookViewPageListener.java
index 142bf96f65f..ca198787830 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IPageBookViewPageListener.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IPageBookViewPageListener.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2014 Christian W. Damus 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
@@ -8,7 +8,7 @@
*
* Contributors:
* Christian W. Damus - Initial API and implementation
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer;
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java
index 295302b58a1..3bd40a67c97 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2014 CEA LIST, Christian W. Damus, 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
@@ -9,7 +9,7 @@
* Contributors:
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
* Christian W. Damus - bug 454536
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer;
@@ -41,7 +41,7 @@ import com.google.common.collect.Iterators;
/**
* Specific PropertySheetPage for Model Explorer view to contribute to Undo/Redo Edit menu.
- *
+ *
* @author Gabriel Pascual
*
*/
@@ -125,7 +125,7 @@ class ModelExplorerPropertySheetPage extends TabbedPropertySheetPage implements
/**
* Queries whether the current selection includes any element from a resource in the context of the specified {@code context} that is being unloaded.
- *
+ *
* @param context
* the service registry context of an editor that is being unloaded
* @return whether any currently presented input element has already been unloaded (is now a proxy) or is in the given {@code context}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
index be0f262467d..f62485ecdc4 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
@@ -1,1319 +1,1241 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - post refreshes for transaction commit asynchronously (CDO)
- * Christian W. Damus (CEA) - bug 429826
- * Christian W. Damus (CEA) - bug 434635
- * Christian W. Damus (CEA) - bug 437217
- * Christian W. Damus (CEA) - bug 441857
- * Christian W. Damus - bug 450235
- * Christian W. Damus - bug 451683
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.transaction.ResourceSetChangeEvent;
-import org.eclipse.emf.transaction.ResourceSetListener;
-import org.eclipse.emf.transaction.ResourceSetListenerImpl;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.util.Policy;
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerColumn;
-import org.eclipse.jface.window.ToolTip;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.editor.IReloadableEditor;
-import org.eclipse.papyrus.infra.core.editor.reload.EditorReloadAdapter;
-import org.eclipse.papyrus.infra.core.editor.reload.EditorReloadEvent;
-import org.eclipse.papyrus.infra.core.editor.reload.TreeViewerContext;
-import org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListener;
-import org.eclipse.papyrus.infra.core.lifecycleevents.ISaveAndDirtyService;
-import org.eclipse.papyrus.infra.core.resource.IReadOnlyHandler2;
-import org.eclipse.papyrus.infra.core.resource.IReadOnlyListener;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.ReadOnlyEvent;
-import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageLifeCycleEventsListener;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.emf.providers.SemanticFromModelExplorer;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
-import org.eclipse.papyrus.infra.services.navigation.service.NavigationService;
-import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
-import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
-import org.eclipse.papyrus.views.modelexplorer.SharedModelExplorerState.StateChangedEvent;
-import org.eclipse.papyrus.views.modelexplorer.listener.DoubleClickListener;
-import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
-import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem;
-import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem;
-import org.eclipse.papyrus.views.modelexplorer.matching.ReferencableMatchingItem;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.navigator.CommonNavigator;
-import org.eclipse.ui.navigator.CommonViewer;
-import org.eclipse.ui.navigator.CommonViewerSorter;
-import org.eclipse.ui.navigator.IExtensionActivationListener;
-import org.eclipse.ui.navigator.ILinkHelper;
-import org.eclipse.ui.navigator.INavigatorContentService;
-import org.eclipse.ui.navigator.LinkHelperService;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
-
-import com.google.common.base.Supplier;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * Papyrus Model Explorer associated to one {@link IMultiDiagramEditor}.
- * This ModelExplorer is linked to one single {@link IMultiDiagramEditor}. It doesn't change its
- * source when the current Editor change. To allow to explore different Model, use a {@link ModelExplorerPageBookView}.
- *
- */
-public class ModelExplorerView extends CommonNavigator implements IRevealSemanticElement, IEditingDomainProvider, IPageLifeCycleEventsListener {
-
- private SharedModelExplorerState sharedState;
-
- private SharedModelExplorerState.StateChangedListener sharedStateListener;
-
- /**
- * The context of the LabelProviderService used by this view
- *
- * @see {@link LabelProviderService}
- */
- public static final String LABEL_PROVIDER_SERVICE_CONTEXT = "org.eclipse.papyrus.views.modelexplorer.labelProvider.context";
-
- /**
- * The {@link ServicesRegistry} associated to the Editor. This view is associated to the
- * ServicesRegistry rather than to the EditorPart.
- */
- private ServicesRegistry serviceRegistry;
-
- /** The save aservice associated to the editor. */
- private ISaveAndDirtyService saveAndDirtyService;
-
- /** {@link IUndoContext} used to tag command in the commandStack. */
- private IUndoContext undoContext;
-
- /** editing domain used to read/write the model */
- private TransactionalEditingDomain editingDomain;
-
- /** Flag to avoid reentrant call to refresh. */
- private AtomicBoolean isRefreshing = new AtomicBoolean(false);
-
- /**
- * A listener on page (all editors) selection change. This listener is set
- * in {@link ModelExplorerView#init(IViewSite)}. It should be dispose to remove
- * hook to the Eclipse page.
- */
- private ISelectionListener pageSelectionListener = new ISelectionListener() {
-
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- handleSelectionChangedFromDiagramEditor(part, selection);
- }
- };
-
- /**
- * Listener on {@link ISaveAndDirtyService#addInputChangedListener(IEditorInputChangedListener)}
- */
- protected IEditorInputChangedListener editorInputChangedListener = new IEditorInputChangedListener() {
-
- /**
- * This method is called when the editor input is changed from the ISaveAndDirtyService.
- *
- * @see org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListener#editorInputChanged(org.eclipse.ui.part.FileEditorInput)
- *
- * @param fileEditorInput
- */
- public void editorInputChanged(FileEditorInput fileEditorInput) {
- // Change the editor input.
- setPartName(fileEditorInput.getName());
- }
-
- /**
- * The isDirty flag has changed, reflect its new value
- *
- * @see org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListener#isDirtyChanged()
- *
- */
- public void isDirtyChanged() {
- firePropertyChange(IEditorPart.PROP_DIRTY);
- }
- };
-
- /** The {@link IPropertySheetPage} this model explorer will use. */
- private final List<IPropertySheetPage> propertySheetPages = new LinkedList<IPropertySheetPage>();
-
- /**
- *
- * Constructor.
- *
- * @param part
- * The part associated to this ModelExplorer
- */
- public ModelExplorerView(IMultiDiagramEditor part) {
-
- if (part == null) {
- throw new IllegalArgumentException("A part should be provided.");
- }
-
- init(part);
-
- IReloadableEditor.Adapter.getAdapter(part).addEditorReloadListener(new EditorReloadAdapter() {
-
- @Override
- public void editorAboutToReload(EditorReloadEvent event) {
- // Stash expansion and selection state of the common viewer
- event.putContext(new ModelExplorerTreeViewerContext(getCommonViewer()));
-
- deactivate();
- }
-
- @Override
- public void editorReloaded(EditorReloadEvent event) {
- init(event.getEditor());
-
- activate();
-
- initCommonViewer(getCommonViewer());
-
- // Restore expansion and selection state of the common viewer
- ((TreeViewerContext<?>) event.getContext()).restore(getCommonViewer());
- }
- });
- }
-
- private void init(IMultiDiagramEditor editor) {
- // Try to get the ServicesRegistry
- serviceRegistry = editor.getServicesRegistry();
- if (serviceRegistry == null) {
- throw new IllegalArgumentException("The editor should have a ServiceRegistry.");
- }
-
- // Get required services from ServicesRegistry
- try {
- saveAndDirtyService = serviceRegistry.getService(ISaveAndDirtyService.class);
- undoContext = serviceRegistry.getService(IUndoContext.class);
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- }
-
- /**
- * Handle a selection change in the editor.
- *
- * @param part
- * @param selection
- */
- private void handleSelectionChangedFromDiagramEditor(IWorkbenchPart part, ISelection selection) {
- // Handle selection from diagram editor
- if (isLinkingEnabled()) {
- if (part instanceof IEditorPart) {
- if (selection instanceof IStructuredSelection) {
- Iterator<?> selectionIterator = ((IStructuredSelection) selection).iterator();
- ArrayList<Object> semanticElementList = new ArrayList<Object>();
- while (selectionIterator.hasNext()) {
- Object currentSelection = selectionIterator.next();
- Object semanticElement = EMFHelper.getEObject(currentSelection);
- if (semanticElement != null) {
- semanticElementList.add(semanticElement);
- }
-
- }
- revealSemanticElement(semanticElementList);
-
- }
-
- }
-
- // Selections from the Model Explorer result in a part from the ModelExplorerPageBookView instance which is not an IEditorPart
- if (part instanceof ModelExplorerPageBookView && !selection.isEmpty()) {
- if (selection instanceof IStructuredSelection) {
- // Extracted from org.eclipse.ui.internal.navigator.actions.LinkEditorAction activateEditorJob
- // the problem was that multi-element selections were disabled as only selections of 1 could clear the condition size()==1
- IStructuredSelection sSelection = (IStructuredSelection) selection;
- LinkHelperService linkService = getLinkHelperService();
- ILinkHelper[] helpers = linkService.getLinkHelpersFor(sSelection.getFirstElement()); // LinkHelper in org.eclipse.papyrus.views.modelexplorer
- if (helpers.length > 0) {
- helpers[0].activateEditor(part.getSite().getPage(), sSelection);
- }
- }
- }
- }
- }
-
- /**
- * look for the path the list of element (comes from the content provider) to go the eObject
- *
- * @param eobject
- * that we look for.
- * @param objects
- * a list of elements where eobject can be wrapped.
- * @return the list of modelElementItem ( from the root to the element that wrap the eobject)
- */
- protected List<Object> searchPath(EObject eobject, List<Object> objects) {
- SemanticFromModelExplorer semanticGetter = new SemanticFromModelExplorer();
- List<Object> path = new ArrayList<Object>();
- ITreeContentProvider contentProvider = (ITreeContentProvider) getCommonViewer().getContentProvider();
- // IPageMngr iPageMngr = EditorUtils.getIPageMngr();
- IPageManager iPageMngr;
- try {
- iPageMngr = ServiceUtils.getInstance().getIPageManager(serviceRegistry);
- } catch (ServiceException e) {
- // This shouldn't happen.
- return Collections.emptyList();
- }
- Object[] result = iPageMngr.allPages().toArray();
- List<Object> editors = Arrays.asList(result);
-
-
- for (Object o : objects) {
- // Search matches in this level
- if (!editors.contains(o)) {
- if (eobject.equals(EMFHelper.getEObject(o))) {
- path.add(o);
- return path;
- }
- }
-
- // Find childs only for feature container
- for (int i = 0; i < contentProvider.getChildren(o).length; i++) {
- Object treeItem = contentProvider.getChildren(o)[i];
-
- List<Object> tmppath = new ArrayList<Object>();
- Object element = semanticGetter.getSemanticElement(treeItem);
- if (element != null) {
- if (element instanceof EReference) {
- if (((EReference) element).isContainment() && (!((EReference) element).isDerived())) {
- List<Object> childs = new ArrayList<Object>();
- childs.add(treeItem);
- tmppath = searchPath(eobject, childs);
- }
- }
-
- else {
- if (element instanceof EObject) {
- List<Object> childs = new ArrayList<Object>();
- childs.add(treeItem);
- tmppath = searchPath(eobject, childs);
- }
- }
- }
-
- // if tmppath contains the wrapped eobject we have find the good path
- if (tmppath.size() > 0) {
- if (eobject.equals((EMFHelper.getEObject((tmppath.get(tmppath.size() - 1)))))) {
- path.add(o);
- path.addAll(tmppath);
- return path;
- }
- }
- }
- }
-
- return new ArrayList<Object>();
- }
-
-
- /**
- * {@inheritDoc}
- */
- // FIXME Use of internal class (NavigatorContentService) - in the hope that the bug gets fixed soon.
- @Override
- protected CommonViewer createCommonViewerObject(Composite aParent) {
- CommonViewer viewer = new CustomCommonViewer(getViewSite().getId(), aParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
-
- initCommonViewer(viewer);
-
- viewer.getNavigatorContentService().getActivationService().addExtensionActivationListener(new IExtensionActivationListener() {
-
- public void onExtensionActivation(String aViewerId, String[] theNavigatorExtensionIds, boolean isActive) {
- sharedState.updateNavigatorContentExtensions(theNavigatorExtensionIds, isActive);
- }
- });
-
- ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
-
- return viewer;
- }
-
- private void installEMFFacetTreePainter(Tree tree) {
- // Install the EMFFacet Custom Tree Painter
- // org.eclipse.papyrus.infra.emf.Activator.getDefault().getCustomizationManager().installCustomPainter(tree);
-
- // The EMF Facet MeasureItem Listener is incompatible with the NavigatorDecoratingLabelProvider. Remove it.
- // Symptoms: ModelElementItems with an EMF Facet Overlay have a small selection size
- // Removal also fixes bug 400012: no scrollbar although tree is larger than visible area
- Collection<Listener> listenersToRemove = new LinkedList<Listener>();
- for (Listener listener : tree.getListeners(SWT.MeasureItem)) {
- if (listener.getClass().getName().contains("org.eclipse.papyrus.emf.facet.infra.browser.uicore.internal.CustomTreePainter")) {
- listenersToRemove.add(listener);
- }
- }
-
- for (Listener listener : listenersToRemove) {
- tree.removeListener(SWT.MeasureItem, listener);
- }
- }
-
- private void initCommonViewer(CommonViewer viewer) {
- // enable tool-tips
- // workaround for bug 311827: the Common Viewer always uses NavigatorDecoratingLabelProvider
- // as a wrapper for the LabelProvider provided by the application. The NavigatorDecoratingLabelProvider
- // does not delegate tooltip related functions but defines them as empty.
-
- Object input = getInitialInput();
- ILabelProvider labelProvider = null;
-
- if (input instanceof ServicesRegistry) {
- ServicesRegistry registry = (ServicesRegistry) input;
- try {
- labelProvider = registry.getService(LabelProviderService.class).getLabelProvider(LABEL_PROVIDER_SERVICE_CONTEXT);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
-
- labelProvider = new DecoratingLabelProviderWTooltips(labelProvider, (ServicesRegistry) input);
- }
-
- if (labelProvider == null) {
- labelProvider = new LabelProvider();
- }
-
- viewer.setLabelProvider(labelProvider); // add for decorator and tooltip support
- }
-
- @Override
- public void createPartControl(Composite aParent) {
- super.createPartControl(aParent);
-
- getCommonViewer().setSorter(null);
- ((CustomCommonViewer) getCommonViewer()).getDropAdapter().setFeedbackEnabled(true);
- getCommonViewer().addDoubleClickListener(new DoubleClickListener(new Supplier<ServicesRegistry>() {
- public ServicesRegistry get() {
- return serviceRegistry;
- }
- }));
-
- Tree tree = getCommonViewer().getTree();
-
- tree.addKeyListener(new KeyListener() {
-
- public void keyReleased(KeyEvent e) {
- if (e.keyCode == SWT.ALT) {
- exitItem();
- }
- }
-
- public void keyPressed(KeyEvent e) {
- if (e.keyCode != SWT.ALT) {
- return;
- }
-
- Tree tree = getCommonViewer().getTree();
-
- // Generate a basic mouse event
- Event event = new Event();
- event.widget = tree;
- event.stateMask = SWT.ALT;
-
- Point absoluteTreeLocation = tree.toDisplay(new Point(0, 0));
-
- event.x = tree.getDisplay().getCursorLocation().x - absoluteTreeLocation.x;
- event.y = tree.getDisplay().getCursorLocation().y - absoluteTreeLocation.y;
-
- MouseEvent mouseEvent = new MouseEvent(event);
- if (isEnterState(mouseEvent)) {
- enterItem(currentItem);
- }
- }
- });
-
- tree.addMouseListener(new MouseAdapter() {
-
- @Override
- public void mouseUp(MouseEvent e) {
- if ((e.stateMask & SWT.ALT) == 0) {
- return;
- }
-
- TreeItem currentItem = getTreeItem(e);
- if (currentItem != null) {
- Object data = currentItem.getData();
- try {
- NavigationService service = serviceRegistry.getService(NavigationService.class);
- List<NavigableElement> navigableElements = service.getNavigableElements(data);
-
- // TODO: Implement a priority on NavigableElements and navigate the element with the highest priority
- for (NavigableElement navigableElement : navigableElements) {
- if (navigableElement.isEnabled()) {
- service.navigate(navigableElement);
- }
- }
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- }
- }
- });
-
- tree.addMouseMoveListener(new MouseMoveListener() {
-
- public void mouseMove(MouseEvent e) {
-
- if (isExitState(e)) {
- exitItem();
- }
-
- if (isEnterState(e)) {
- enterItem(currentItem);
- }
-
- }
-
- });
-
- installEMFFacetTreePainter(tree);
- try {
- ISashWindowsContainer sashWindowsContainer = serviceRegistry.getService(ISashWindowsContainer.class);
- sashWindowsContainer.addPageLifeCycleListener(this);
- } catch (ServiceException ex) {
- // Ignore
- }
-
- if (sharedState != null) {
- initSharedState(sharedState);
- }
- }
-
- @Override
- protected CommonViewer createCommonViewer(Composite aParent) {
- CommonViewer viewer = super.createCommonViewer(aParent);
- ViewerColumn column = (ViewerColumn) viewer.getTree().getData(Policy.JFACE + ".columnViewer");
- column.setEditingSupport(new DirectEditorEditingSupport(viewer));
- return viewer;
- }
-
-
- TreeItem currentItem;
-
- SelectionMenu selectionMenu;
-
- private boolean isExitState(MouseEvent e) {
- if (currentItem == null) {
- return false;
- }
-
- TreeItem item = getTreeItem(e);
- if (item == null) {
- return true;
- }
-
- if (item != currentItem) {
- return true;
- }
-
- if ((e.stateMask & SWT.ALT) == 0) {
- return true;
- }
-
- return false;
- }
-
- private boolean isEnterState(MouseEvent e) {
- TreeItem item = getTreeItem(e);
- if (item == currentItem) {
- return false;
- }
-
- if (item == null) {
- return false;
- }
-
- if ((e.stateMask & SWT.ALT) == 0) {
- return false;
- }
-
- currentItem = item;
-
- return true;
- }
-
- private void disposeCurrentMenu() {
- if (selectionMenu != null) {
- selectionMenu.dispose();
- selectionMenu = null;
- }
- }
-
- private void exitItem() {
- currentItem = null;
- disposeCurrentMenu();
- }
-
- private void enterItem(TreeItem item) {
- try {
- final NavigationService navigation = serviceRegistry.getService(NavigationService.class);
- disposeCurrentMenu();
- selectionMenu = navigation.createNavigationList(item.getData(), item.getParent());
- if (selectionMenu == null) {
- return;
- }
-
- selectionMenu.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- if (event.getSelection().isEmpty()) {
- return;
- }
- Object selectedElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
- if (selectedElement instanceof NavigableElement) {
- NavigableElement navigableElement = (NavigableElement) selectedElement;
- if (navigableElement.isEnabled()) {
- navigation.navigate((NavigableElement) selectedElement);
- exitItem();
- }
- }
- }
- });
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- }
-
- private TreeItem getTreeItem(MouseEvent e) {
- return ((Tree) e.widget).getItem(new Point(e.x, e.y));
- }
-
-
- /**
- * Return the control used to render this View
- *
- * @see org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.IPageBookNestableViewPart#getControl()
- *
- * @return the main control of the navigator viewer
- */
- public Control getControl() {
- return getCommonViewer().getControl();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void init(IViewSite site, IMemento aMemento) throws PartInitException {
- super.init(site, aMemento);
-
- activate();
-
- // Self-listen for property changes
- addPropertyListener(new IPropertyListener() {
-
- public void propertyChanged(Object source, int propId) {
- switch (propId) {
- case IS_LINKING_ENABLED_PROPERTY:
- // Propagate to other instances
- sharedState.setLinkingEnabled(isLinkingEnabled());
- break;
- }
- }
- });
- }
-
- /**
- * {@link ResourceSetListener} to listen and react to changes in the
- * resource set.
- */
- private final ResourceSetListener resourceSetListener = new ResourceSetListenerImpl() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void resourceSetChanged(ResourceSetChangeEvent event) {
- super.resourceSetChanged(event);
- handleResourceSetChanged(event);
- }
- };
-
- /** cache variable with last transaction which triggered a refresh */
- private Transaction lastTrans = null;
-
- /**
- * Run in a UI thread to avoid non UI thread exception.
- *
- * @param event
- */
- private void handleResourceSetChanged(ResourceSetChangeEvent event) {
- // avoid refreshing N times for the same transaction (called for each object in resource)
- Transaction curTrans = event.getTransaction();
- if (lastTrans != null && lastTrans.equals(curTrans)) {
- return;
- }
- lastTrans = curTrans;
-
- scheduleRefresh();
- }
-
- private Runnable refreshRunnable;
-
- /**
- * Thread-safe
- * Schedule a runnable which will refresh the view if necessary
- */
- protected void scheduleRefresh() {
- final Runnable schedule;
-
- synchronized (this) {
- if (refreshRunnable == null) {
- // No refresh is yet pending. Schedule one
- schedule = createRefreshRunnable();
- refreshRunnable = schedule;
- } else {
- schedule = null;
- }
- }
-
- if (schedule != null) {
- Control control = getControl();
- Display display = ((control == null) || control.isDisposed()) ? null : control.getDisplay();
-
- if (display != null) {
- // Don't need to schedule a refresh if we have no control or it's disposed
- display.asyncExec(schedule);
- }
- }
- }
-
- private Runnable createRefreshRunnable() {
- return new Runnable() {
-
- public void run() {
- // Only run if I'm still pending
- synchronized (ModelExplorerView.this) {
- if (refreshRunnable != this) {
- return;
- }
-
- refreshRunnable = null;
- }
-
- refreshInUIThread();
- }
- };
- }
-
- /**
- * Thread-safe method to hurry up a pending refresh of the Model Explorer view (if any), synchronously.
- * When this method returns, then either the explorer has been refreshed or it doesn't need to be.
- */
- protected void syncRefresh() {
- final Runnable pending;
-
- synchronized (this) {
- pending = refreshRunnable;
- }
-
- if (pending != null) {
- Control control = getControl();
- Display display = ((control == null) || control.isDisposed()) ? null : control.getDisplay();
-
- if (display != null) {
- // Don't need to execute a refresh if we have no control or it's disposed
- display.syncExec(pending);
- }
- }
- }
-
- /**
- * refresh the view.
- */
- protected void refreshInUIThread() {
- // Need to refresh, even if (temporarily) invisible
- // (Better alternative?: store refresh event and execute once visible again)
- if (getControl().isDisposed()) {
- return;
- }
-
- // avoid reentrant call
- // Refresh only of we are not already refreshing.
- if (isRefreshing.compareAndSet(false, true)) {
- if (!getCommonViewer().isBusy()) {
- getCommonViewer().refresh();
- }
-
- isRefreshing.set(false);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Object getInitialInput() {
-
- if (serviceRegistry != null) {
- return serviceRegistry;
- } else {
- return super.getInitialInput();
- }
-
- }
-
- /**
- * Activate specified Part.
- */
- private void activate() {
- try {
- this.editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
-
- // Set Viewer input if it already exist
- if (getCommonViewer() != null) {
- getCommonViewer().setInput(serviceRegistry);
- }
- editingDomain.addResourceSetListener(resourceSetListener);
- IReadOnlyHandler2 readOnlyHandler = AdapterUtils.adapt(editingDomain, IReadOnlyHandler2.class, null);
- if (readOnlyHandler != null) {
- readOnlyHandler.addReadOnlyListener(createReadOnlyListener());
- }
- } catch (ServiceException e) {
- // Can't get EditingDomain, skip
- }
-
- // listen to change events
- getSite().getPage().addSelectionListener(pageSelectionListener);
-
- // Listen to isDirty flag
- saveAndDirtyService.addInputChangedListener(editorInputChangedListener);
-
- if (this.getCommonViewer() != null) {
- // Force a refresh
- Display display = getControl().getDisplay();
- if (display == Display.getCurrent()) {
- refreshInUIThread();
- } else {
- // Hmm. We should be on the UI thread
- Activator.log.warn("Model Explorer activated on a non-UI thread."); //$NON-NLS-1$
- scheduleRefresh();
- }
- }
- }
-
- /**
- * Deactivate the Model Explorer.
- */
- private void deactivate() {
- // deactivate global handler
- if (Activator.log.isDebugEnabled()) {
- Activator.log.debug("deactivate ModelExplorerView"); //$NON-NLS-1$
- }
-
- try {
- ISashWindowsContainer sashWindowsContainer = serviceRegistry.getService(ISashWindowsContainer.class);
- if (sashWindowsContainer != null) {
- sashWindowsContainer.removePageLifeCycleListener(this);
- }
- } catch (ServiceException ex) {
- // Ignore
- }
-
- // Stop listening on change events
- getSite().getPage().removeSelectionListener(pageSelectionListener);
- // Stop Listening to isDirty flag
- saveAndDirtyService.removeInputChangedListener(editorInputChangedListener);
-
- if (editingDomain != null) {
- editingDomain.removeResourceSetListener(resourceSetListener);
- editingDomain = null;
- }
-
- saveAndDirtyService = null;
- undoContext = null;
- editingDomain = null;
- editingDomain = null;
- lastTrans = null;
- }
-
- /**
- * Invoked internally to clear the common viewer's associate listener in order to promote garbage collection.
- */
- void aboutToDispose() {
- final CommonViewer viewer = getCommonViewer();
- if ((viewer.getTree() != null) && !viewer.getTree().isDisposed()) {
- viewer.setInput(null);
-
- // Kick the NavigatorContentService to clear the cache in its StructuredViewerManager that leaks all of our tree elements
- INavigatorContentService contentService = getNavigatorContentService();
- if (contentService instanceof IExtensionActivationListener) {
- ((IExtensionActivationListener) getNavigatorContentService()).onExtensionActivation(contentService.getViewerId(), new String[0], false);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dispose() {
-
- // Stop if we are already disposed
- if (isDisposed()) {
- return;
- }
-
- if ((sharedStateListener != null) && (sharedState != null)) {
- sharedState.removeListener(sharedStateListener);
- }
-
- if (getSite() != null) {
- getSite().getPage().removeSelectionListener(pageSelectionListener);
- }
-
- deactivate();
-
- for (IPropertySheetPage propertySheetPage : this.propertySheetPages) {
- propertySheetPage.dispose();
- }
-
- propertySheetPages.clear();
-
- pageSelectionListener = null;
-
- super.dispose();
-
- // Clean up properties to help GC
-
- }
-
- /**
- * Return true if the component is already disposed.
- *
- * @return
- */
- public boolean isDisposed() {
- // use editorPart as flag
- return saveAndDirtyService == null;
- }
-
- /**
- * Retrieves the {@link IPropertySheetPage} that his Model Explorer uses.
- *
- * @return
- */
- private IPropertySheetPage getPropertySheetPage() {
- try {
- final IMultiDiagramEditor multiDiagramEditor = ServiceUtils.getInstance().getService(IMultiDiagramEditor.class, serviceRegistry);
-
- if (multiDiagramEditor != null) {
- if (multiDiagramEditor instanceof ITabbedPropertySheetPageContributor) {
- ITabbedPropertySheetPageContributor contributor = (ITabbedPropertySheetPageContributor) multiDiagramEditor;
- IPropertySheetPage propertySheetPage = new TabbedPropertySheetPage(contributor);
- this.propertySheetPages.add(propertySheetPage);
- return propertySheetPage;
- }
- }
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- return null;
- }
-
- /**
- * in order to see element if the property view
- */
- @Override
- @SuppressWarnings("rawtypes")
- public Object getAdapter(Class adapter) {
- if (IPropertySheetPage.class.equals(adapter)) {
- return getPropertySheetPage();
- }
-
- if (IUndoContext.class == adapter) {
- // Return the IUndoContext of associated model.
- return undoContext;
- }
-
- if (ISaveablePart.class.equals(adapter)) {
- try {
- return serviceRegistry.getService(IMultiDiagramEditor.class);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- return saveAndDirtyService;
- }
-
- if (ServicesRegistry.class == adapter) {
- return serviceRegistry;
- }
-
- return super.getAdapter(adapter);
- }
-
- /**
- * {@inheritDoc}
- *
- * @return the EditingDomain used by the properties view
- */
- public EditingDomain getEditingDomain() {
- return editingDomain;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void selectReveal(ISelection selection) {
- syncRefresh();
- if (getCommonViewer() != null) {
- getCommonViewer().setSelection(selection, true);
- }
- }
-
- public void revealSemanticElement(List<?> elementList) {
- // Ensure that the ModelExplorer is refreshed before
- // trying to display an element. Useful if the element has just been created,
- // and the model explorer has not yet been refreshed
- syncRefresh();
- reveal(elementList, getCommonViewer());
- }
-
- /**
- * Expands the given CommonViewer to reveal the given elements
- *
- * @param elementList
- * The elements to reveal
- * @param commonViewer
- * The CommonViewer they are to be revealed in
- */
- public static void reveal(Iterable<?> elementList, final CommonViewer commonViewer) {
- ArrayList<IMatchingItem> matchingItemsToSelect = new ArrayList<IMatchingItem>();
- // filter out non EMF objects
- Iterable<EObject> list = Iterables.filter(elementList, EObject.class);
-
- for (EObject currentEObject : list) {
- matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject));
-
- // the content provider exist?
- if (commonViewer.getContentProvider() != null) {
- // retrieve the ancestors to reveal them
- // and allow the selection of the object
- ArrayList<EObject> parents = new ArrayList<EObject>();
- EObject tmp = currentEObject.eContainer();
- while (tmp != null) {
- parents.add(tmp);
- tmp = tmp.eContainer();
- }
-
- Iterable<EObject> reverseParents = Lists.reverse(parents);
-
- // reveal the resource if necessary
- Resource r = null;
- if (!parents.isEmpty()) {
- r = parents.get(parents.size() - 1).eResource();
- } else {
- r = currentEObject.eResource();
- }
-
- if (r != null) {
- final ResourceSet rs = r.getResourceSet();
- final Resource resource = r;
- if (rs instanceof ModelSet && AdditionalResourcesModel.isAdditionalResource((ModelSet) rs, r.getURI())) {
- commonViewer.getControl().getDisplay().syncExec(new Runnable() {
-
- public void run() {
- commonViewer.expandToLevel(new ReferencableMatchingItem(rs), 1);
- commonViewer.expandToLevel(new ReferencableMatchingItem(resource), 1);
- }
- });
-
- }
- }
-
- /*
- * reveal the ancestors tree using expandToLevel on each of them
- * in the good order. This is a lot faster than going through the whole tree
- * using getChildren of the ContentProvider since our Viewer uses a Hashtable
- * to keep track of the revealed elements.
- *
- * However we need to use a dedicated MatchingItem to do the matching,
- * and a specific comparer in our viewer so than the equals of MatchingItem is
- * used in priority.
- *
- * Please refer to MatchingItem for more infos.
- */
- EObject previousParent = null;
- for (EObject parent : reverseParents) {
- if (parent.eContainingFeature() != null && previousParent != null) {
- commonViewer.expandToLevel(new LinkItemMatchingItem(previousParent, parent.eContainmentFeature()), 1);
- }
-
- final IMatchingItem itemToExpand = new ModelElementItemMatchingItem(parent);
-
- commonViewer.getControl().getDisplay().syncExec(new Runnable() {
-
- public void run() {
- commonViewer.expandToLevel(itemToExpand, 1);
- }
- });
-
- previousParent = parent;
- }
-
- final IMatchingItem itemToExpand = new LinkItemMatchingItem(currentEObject.eContainer(), currentEObject.eContainmentFeature());
-
- commonViewer.getControl().getDisplay().syncExec(new Runnable() {
-
- public void run() {
- commonViewer.expandToLevel(itemToExpand, 1);
- }
- });
- }
- }
-
- selectReveal(new StructuredSelection(matchingItemsToSelect), commonViewer);
- }
-
- /**
- * Selects the given ISelection in the given CommonViwer
- *
- * @param structuredSelection
- * The ISelection to select
- * @param commonViewer
- * The ComonViewer to select it in
- */
- public static void selectReveal(final ISelection structuredSelection, final Viewer commonViewer) {
- Display.getDefault().syncExec(new Runnable() {
-
- public void run() {
- commonViewer.setSelection(structuredSelection, true);
- }
- });
- }
-
- /**
- * Selects and, if possible, reveals the given ISelection in the given CommonViwer
- *
- * @param selection
- * The ISelection to select
- * @param viewer
- * The ComonViewer to select it in
- */
- public static void reveal(final ISelection selection, final CommonViewer viewer) {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection structured = (IStructuredSelection) selection;
- reveal(Lists.newArrayList(structured.iterator()), viewer);
- } else {
- viewer.getControl().getDisplay().syncExec(new Runnable() {
-
- public void run() {
- viewer.setSelection(selection);
- }
- });
- }
- }
-
- public void pageOpened(IPage page) {
- refreshTree();
- }
-
- public void pageClosed(IPage page) {
- refreshTree();
- }
-
- private void refreshTree() {
- Display.getDefault().asyncExec(new Runnable() {
-
- public void run() {
- if (getCommonViewer().getControl() == null || getCommonViewer().getControl().isDisposed()) {
- return;
- }
- getCommonViewer().refresh(true);
- // Force redraw to refresh facet overlay
- getCommonViewer().getTree().redraw();
- }
- });
- }
-
- public void pageChanged(IPage newPage) {
- // Nothing
- }
-
- public void pageActivated(IPage page) {
- // Nothing
- }
-
- public void pageDeactivated(IPage page) {
- // Nothing
- }
-
- public void pageAboutToBeOpened(IPage page) {
- // Nothing
- }
-
- public void pageAboutToBeClosed(IPage page) {
- // Nothing
- }
-
- private IReadOnlyListener createReadOnlyListener() {
- return new IReadOnlyListener() {
-
- public void readOnlyStateChanged(ReadOnlyEvent event) {
- switch (event.getEventType()) {
- case ReadOnlyEvent.RESOURCE_READ_ONLY_STATE_CHANGED:
- scheduleRefresh();
- break;
- case ReadOnlyEvent.OBJECT_READ_ONLY_STATE_CHANGED:
- CommonViewer viewer = getCommonViewer();
- if ((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
- viewer.refresh(event.getObject());
- }
- break;
- default:
- Activator.log.warn("Unsupported read-only event type: " + event.getEventType());
- break;
- }
- }
- };
- }
-
- void setSharedState(SharedModelExplorerState state) {
- if (this.sharedState != null) {
- this.sharedState.removeListener(getSharedStateListener());
- }
-
- this.sharedState = state;
-
- if (state != null) {
- state.addListener(getSharedStateListener());
- initSharedState(state);
- }
- }
-
- void initSharedState(SharedModelExplorerState state) {
- setLinkingEnabled(state.isLinkingEnabled());
- setAlphaSorted(state.isAlphaSorted());
- }
-
- void setAlphaSorted(boolean sorted) {
- CommonViewer viewer = getCommonViewer();
- if ((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
- if (sorted) {
- viewer.setSorter(new CommonViewerSorter());
- if (viewer instanceof CustomCommonViewer) {
- ((CustomCommonViewer) viewer).getDropAdapter().setFeedbackEnabled(false);
- }
- } else {
- viewer.setSorter(null);
- if (viewer instanceof CustomCommonViewer) {
- ((CustomCommonViewer) viewer).getDropAdapter().setFeedbackEnabled(true);
- }
- }
- }
- }
-
- SharedModelExplorerState.StateChangedListener getSharedStateListener() {
- if (sharedStateListener == null) {
- sharedStateListener = new SharedModelExplorerState.StateChangedListener() {
-
- private volatile Runnable contentUpdate;
-
- public void sharedStateChanged(StateChangedEvent event) {
- switch (event.getEventType()) {
- case StateChangedEvent.LINKING_ENABLED:
- setLinkingEnabled(event.getSource().isLinkingEnabled());
- break;
- case StateChangedEvent.ALPHA_SORTED:
- setAlphaSorted(event.getSource().isAlphaSorted());
- break;
- case StateChangedEvent.CONTENT_EXTENSIONS:
- if (contentUpdate == null) {
- getCommonViewer().getControl().getDisplay().asyncExec(getContentUpdate());
- }
- break;
- }
- }
-
- private Runnable getContentUpdate() {
- if (contentUpdate == null) {
- contentUpdate = new Runnable() {
-
- public void run() {
- CommonViewer viewer = getCommonViewer();
- if ((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
- viewer.getNavigatorContentService().getActivationService().activateExtensions(sharedState.getNavigatorContentExtensions(), true);
- }
-
- // I am no longer pending
- contentUpdate = null;
- }
- };
- }
- return contentUpdate;
- }
- };
- }
-
- return sharedStateListener;
- }
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - post refreshes for transaction commit asynchronously (CDO)
+ * Christian W. Damus (CEA) - bug 429826
+ * Christian W. Damus (CEA) - bug 434635
+ * Christian W. Damus (CEA) - bug 437217
+ * Christian W. Damus (CEA) - bug 441857
+ * Christian W. Damus - bug 450235
+ * Christian W. Damus - bug 451683
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListener;
+import org.eclipse.emf.transaction.ResourceSetListenerImpl;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.util.Policy;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerColumn;
+import org.eclipse.jface.window.ToolTip;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.editor.IReloadableEditor;
+import org.eclipse.papyrus.infra.core.editor.reload.EditorReloadAdapter;
+import org.eclipse.papyrus.infra.core.editor.reload.EditorReloadEvent;
+import org.eclipse.papyrus.infra.core.editor.reload.TreeViewerContext;
+import org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListener;
+import org.eclipse.papyrus.infra.core.lifecycleevents.ISaveAndDirtyService;
+import org.eclipse.papyrus.infra.core.resource.IReadOnlyHandler2;
+import org.eclipse.papyrus.infra.core.resource.IReadOnlyListener;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ReadOnlyEvent;
+import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageLifeCycleEventsListener;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.emf.providers.SemanticFromModelExplorer;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigationService;
+import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.views.modelexplorer.SharedModelExplorerState.StateChangedEvent;
+import org.eclipse.papyrus.views.modelexplorer.listener.DoubleClickListener;
+import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.ReferencableMatchingItem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.navigator.CommonViewerSorter;
+import org.eclipse.ui.navigator.IExtensionActivationListener;
+import org.eclipse.ui.navigator.ILinkHelper;
+import org.eclipse.ui.navigator.INavigatorContentService;
+import org.eclipse.ui.navigator.LinkHelperService;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import com.google.common.base.Supplier;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+/**
+ * Papyrus Model Explorer associated to one {@link IMultiDiagramEditor}.
+ * This ModelExplorer is linked to one single {@link IMultiDiagramEditor}. It doesn't change its
+ * source when the current Editor change. To allow to explore different Model, use a {@link ModelExplorerPageBookView}.
+ *
+ */
+public class ModelExplorerView extends CommonNavigator implements IRevealSemanticElement, IEditingDomainProvider, IPageLifeCycleEventsListener {
+
+ private SharedModelExplorerState sharedState;
+
+ private SharedModelExplorerState.StateChangedListener sharedStateListener;
+
+ /**
+ * The context of the LabelProviderService used by this view
+ *
+ * @see {@link LabelProviderService}
+ */
+ public static final String LABEL_PROVIDER_SERVICE_CONTEXT = "org.eclipse.papyrus.views.modelexplorer.labelProvider.context";
+
+ /**
+ * The {@link ServicesRegistry} associated to the Editor. This view is associated to the
+ * ServicesRegistry rather than to the EditorPart.
+ */
+ private ServicesRegistry serviceRegistry;
+
+ /** The save aservice associated to the editor. */
+ private ISaveAndDirtyService saveAndDirtyService;
+
+ /** {@link IUndoContext} used to tag command in the commandStack. */
+ private IUndoContext undoContext;
+
+ /** editing domain used to read/write the model */
+ private TransactionalEditingDomain editingDomain;
+
+ /** Flag to avoid reentrant call to refresh. */
+ private AtomicBoolean isRefreshing = new AtomicBoolean(false);
+
+ /** Currently selected tree item */
+ private TreeItem currentItem;
+
+ /** Navigation menu for selected tree item */
+ private NavigationMenu navigationMenu;
+
+ /**
+ * A listener on page (all editors) selection change. This listener is set
+ * in {@link ModelExplorerView#init(IViewSite)}. It should be dispose to remove
+ * hook to the Eclipse page.
+ */
+ private ISelectionListener pageSelectionListener = new ISelectionListener() {
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ handleSelectionChangedFromDiagramEditor(part, selection);
+ }
+ };
+
+ /**
+ * Listener on {@link ISaveAndDirtyService#addInputChangedListener(IEditorInputChangedListener)}
+ */
+ protected IEditorInputChangedListener editorInputChangedListener = new IEditorInputChangedListener() {
+
+ /**
+ * This method is called when the editor input is changed from the ISaveAndDirtyService.
+ *
+ * @see org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListener#editorInputChanged(org.eclipse.ui.part.FileEditorInput)
+ *
+ * @param fileEditorInput
+ */
+ public void editorInputChanged(FileEditorInput fileEditorInput) {
+ // Change the editor input.
+ setPartName(fileEditorInput.getName());
+ }
+
+ /**
+ * The isDirty flag has changed, reflect its new value
+ *
+ * @see org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListener#isDirtyChanged()
+ *
+ */
+ public void isDirtyChanged() {
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ };
+
+ /** The {@link IPropertySheetPage} this model explorer will use. */
+ private final List<IPropertySheetPage> propertySheetPages = new LinkedList<IPropertySheetPage>();
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param part
+ * The part associated to this ModelExplorer
+ */
+ public ModelExplorerView(IMultiDiagramEditor part) {
+
+ if (part == null) {
+ throw new IllegalArgumentException("A part should be provided.");
+ }
+
+ init(part);
+
+ IReloadableEditor.Adapter.getAdapter(part).addEditorReloadListener(new EditorReloadAdapter() {
+
+ @Override
+ public void editorAboutToReload(EditorReloadEvent event) {
+ // Stash expansion and selection state of the common viewer
+ event.putContext(new ModelExplorerTreeViewerContext(getCommonViewer()));
+
+ deactivate();
+ }
+
+ @Override
+ public void editorReloaded(EditorReloadEvent event) {
+ init(event.getEditor());
+
+ activate();
+
+ initCommonViewer(getCommonViewer());
+
+ // Restore expansion and selection state of the common viewer
+ ((TreeViewerContext<?>) event.getContext()).restore(getCommonViewer());
+ }
+ });
+ }
+
+ private void init(IMultiDiagramEditor editor) {
+ // Try to get the ServicesRegistry
+ serviceRegistry = editor.getServicesRegistry();
+ if (serviceRegistry == null) {
+ throw new IllegalArgumentException("The editor should have a ServiceRegistry.");
+ }
+
+ // Get required services from ServicesRegistry
+ try {
+ saveAndDirtyService = serviceRegistry.getService(ISaveAndDirtyService.class);
+ undoContext = serviceRegistry.getService(IUndoContext.class);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * Handle a selection change in the editor.
+ *
+ * @param part
+ * @param selection
+ */
+ private void handleSelectionChangedFromDiagramEditor(IWorkbenchPart part, ISelection selection) {
+ // Handle selection from diagram editor
+ if (isLinkingEnabled()) {
+ if (part instanceof IEditorPart) {
+ if (selection instanceof IStructuredSelection) {
+ Iterator<?> selectionIterator = ((IStructuredSelection) selection).iterator();
+ ArrayList<Object> semanticElementList = new ArrayList<Object>();
+ while (selectionIterator.hasNext()) {
+ Object currentSelection = selectionIterator.next();
+ Object semanticElement = EMFHelper.getEObject(currentSelection);
+ if (semanticElement != null) {
+ semanticElementList.add(semanticElement);
+ }
+
+ }
+ revealSemanticElement(semanticElementList);
+
+ }
+
+ }
+
+ // Selections from the Model Explorer result in a part from the ModelExplorerPageBookView instance which is not an IEditorPart
+ if (part instanceof ModelExplorerPageBookView && !selection.isEmpty()) {
+ if (selection instanceof IStructuredSelection) {
+ // Extracted from org.eclipse.ui.internal.navigator.actions.LinkEditorAction activateEditorJob
+ // the problem was that multi-element selections were disabled as only selections of 1 could clear the condition size()==1
+ IStructuredSelection sSelection = (IStructuredSelection) selection;
+ LinkHelperService linkService = getLinkHelperService();
+ ILinkHelper[] helpers = linkService.getLinkHelpersFor(sSelection.getFirstElement()); // LinkHelper in org.eclipse.papyrus.views.modelexplorer
+ if (helpers.length > 0) {
+ helpers[0].activateEditor(part.getSite().getPage(), sSelection);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * look for the path the list of element (comes from the content provider) to go the eObject
+ *
+ * @param eobject
+ * that we look for.
+ * @param objects
+ * a list of elements where eobject can be wrapped.
+ * @return the list of modelElementItem ( from the root to the element that wrap the eobject)
+ */
+ protected List<Object> searchPath(EObject eobject, List<Object> objects) {
+ SemanticFromModelExplorer semanticGetter = new SemanticFromModelExplorer();
+ List<Object> path = new ArrayList<Object>();
+ ITreeContentProvider contentProvider = (ITreeContentProvider) getCommonViewer().getContentProvider();
+ // IPageMngr iPageMngr = EditorUtils.getIPageMngr();
+ IPageManager iPageMngr;
+ try {
+ iPageMngr = ServiceUtils.getInstance().getIPageManager(serviceRegistry);
+ } catch (ServiceException e) {
+ // This shouldn't happen.
+ return Collections.emptyList();
+ }
+ Object[] result = iPageMngr.allPages().toArray();
+ List<Object> editors = Arrays.asList(result);
+
+
+ for (Object o : objects) {
+ // Search matches in this level
+ if (!editors.contains(o)) {
+ if (eobject.equals(EMFHelper.getEObject(o))) {
+ path.add(o);
+ return path;
+ }
+ }
+
+ // Find childs only for feature container
+ for (int i = 0; i < contentProvider.getChildren(o).length; i++) {
+ Object treeItem = contentProvider.getChildren(o)[i];
+
+ List<Object> tmppath = new ArrayList<Object>();
+ Object element = semanticGetter.getSemanticElement(treeItem);
+ if (element != null) {
+ if (element instanceof EReference) {
+ if (((EReference) element).isContainment() && (!((EReference) element).isDerived())) {
+ List<Object> childs = new ArrayList<Object>();
+ childs.add(treeItem);
+ tmppath = searchPath(eobject, childs);
+ }
+ }
+
+ else {
+ if (element instanceof EObject) {
+ List<Object> childs = new ArrayList<Object>();
+ childs.add(treeItem);
+ tmppath = searchPath(eobject, childs);
+ }
+ }
+ }
+
+ // if tmppath contains the wrapped eobject we have find the good path
+ if (tmppath.size() > 0) {
+ if (eobject.equals((EMFHelper.getEObject((tmppath.get(tmppath.size() - 1)))))) {
+ path.add(o);
+ path.addAll(tmppath);
+ return path;
+ }
+ }
+ }
+ }
+
+ return new ArrayList<Object>();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ // FIXME Use of internal class (NavigatorContentService) - in the hope that the bug gets fixed soon.
+ @Override
+ protected CommonViewer createCommonViewerObject(Composite aParent) {
+ CommonViewer viewer = new CustomCommonViewer(getViewSite().getId(), aParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+
+ initCommonViewer(viewer);
+
+ viewer.getNavigatorContentService().getActivationService().addExtensionActivationListener(new IExtensionActivationListener() {
+
+ public void onExtensionActivation(String aViewerId, String[] theNavigatorExtensionIds, boolean isActive) {
+ sharedState.updateNavigatorContentExtensions(theNavigatorExtensionIds, isActive);
+ }
+ });
+
+ ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
+
+ return viewer;
+ }
+
+ private void installEMFFacetTreePainter(Tree tree) {
+ // Install the EMFFacet Custom Tree Painter
+ // org.eclipse.papyrus.infra.emf.Activator.getDefault().getCustomizationManager().installCustomPainter(tree);
+
+ // The EMF Facet MeasureItem Listener is incompatible with the NavigatorDecoratingLabelProvider. Remove it.
+ // Symptoms: ModelElementItems with an EMF Facet Overlay have a small selection size
+ // Removal also fixes bug 400012: no scrollbar although tree is larger than visible area
+ Collection<Listener> listenersToRemove = new LinkedList<Listener>();
+ for (Listener listener : tree.getListeners(SWT.MeasureItem)) {
+ if (listener.getClass().getName().contains("org.eclipse.papyrus.emf.facet.infra.browser.uicore.internal.CustomTreePainter")) {
+ listenersToRemove.add(listener);
+ }
+ }
+
+ for (Listener listener : listenersToRemove) {
+ tree.removeListener(SWT.MeasureItem, listener);
+ }
+ }
+
+ private void initCommonViewer(CommonViewer viewer) {
+ // enable tool-tips
+ // workaround for bug 311827: the Common Viewer always uses NavigatorDecoratingLabelProvider
+ // as a wrapper for the LabelProvider provided by the application. The NavigatorDecoratingLabelProvider
+ // does not delegate tooltip related functions but defines them as empty.
+
+ Object input = getInitialInput();
+ ILabelProvider labelProvider = null;
+
+ if (input instanceof ServicesRegistry) {
+ ServicesRegistry registry = (ServicesRegistry) input;
+ try {
+ labelProvider = registry.getService(LabelProviderService.class).getLabelProvider(LABEL_PROVIDER_SERVICE_CONTEXT);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+
+ labelProvider = new DecoratingLabelProviderWTooltips(labelProvider, (ServicesRegistry) input);
+ }
+
+ if (labelProvider == null) {
+ labelProvider = new LabelProvider();
+ }
+
+ viewer.setLabelProvider(labelProvider); // add for decorator and tooltip support
+ }
+
+ @Override
+ public void createPartControl(Composite aParent) {
+ super.createPartControl(aParent);
+
+ getCommonViewer().setSorter(null);
+ ((CustomCommonViewer) getCommonViewer()).getDropAdapter().setFeedbackEnabled(true);
+ getCommonViewer().addDoubleClickListener(new DoubleClickListener(new Supplier<ServicesRegistry>() {
+ public ServicesRegistry get() {
+ return serviceRegistry;
+ }
+ }));
+
+ try {
+ navigationMenu = serviceRegistry.getService(NavigationService.class).createNavigationList();
+ if (navigationMenu != null) {
+ navigationMenu.setServicesRegistry(serviceRegistry);
+ navigationMenu.setParentShell(this.getControl().getShell());
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+
+ Tree tree = getCommonViewer().getTree();
+
+ tree.addKeyListener(new KeyListener() {
+
+ public void keyReleased(KeyEvent e) {
+ if (navigationMenu != null) {
+ if (e.keyCode == SWT.ALT) {
+ navigationMenu.exitItem();
+ }
+ }
+ }
+
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode != SWT.ALT) {
+ return;
+ }
+
+ if (navigationMenu != null) {
+ Tree tree = getCommonViewer().getTree();
+
+ // Generate a basic mouse event
+ Event event = new Event();
+ event.widget = tree;
+ event.stateMask = SWT.ALT;
+
+ Point absoluteTreeLocation = tree.toDisplay(new Point(0, 0));
+
+ event.x = tree.getDisplay().getCursorLocation().x - absoluteTreeLocation.x;
+ event.y = tree.getDisplay().getCursorLocation().y - absoluteTreeLocation.y;
+
+ MouseEvent mouseEvent = new MouseEvent(event);
+ navigationMenu.handleRequest(mouseEvent, getTreeItem(mouseEvent));
+ }
+ }
+ });
+
+ tree.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if ((e.stateMask & SWT.ALT) == 0) {
+ return;
+ }
+
+ TreeItem currentItem = getTreeItem(e);
+ if (currentItem != null) {
+ Object data = currentItem.getData();
+ try {
+ NavigationService service = serviceRegistry.getService(NavigationService.class);
+ List<NavigableElement> navigableElements = service.getNavigableElements(data);
+
+ // TODO: Implement a priority on NavigableElements and navigate the element with the highest priority
+ for (NavigableElement navigableElement : navigableElements) {
+ if (navigableElement.isEnabled()) {
+ service.navigate(navigableElement);
+ }
+ }
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+ }
+ }
+ });
+
+ tree.addMouseMoveListener(new MouseMoveListener() {
+
+ public void mouseMove(MouseEvent e) {
+ if (navigationMenu != null) {
+ navigationMenu.handleRequest(e, getTreeItem(e));
+ }
+ }
+
+ });
+
+ installEMFFacetTreePainter(tree);
+ try {
+ ISashWindowsContainer sashWindowsContainer = serviceRegistry.getService(ISashWindowsContainer.class);
+ sashWindowsContainer.addPageLifeCycleListener(this);
+ } catch (ServiceException ex) {
+ // Ignore
+ }
+
+ if (sharedState != null) {
+ initSharedState(sharedState);
+ }
+ }
+
+ @Override
+ protected CommonViewer createCommonViewer(Composite aParent) {
+ CommonViewer viewer = super.createCommonViewer(aParent);
+ ViewerColumn column = (ViewerColumn) viewer.getTree().getData(Policy.JFACE + ".columnViewer");
+ column.setEditingSupport(new DirectEditorEditingSupport(viewer));
+ return viewer;
+ }
+
+ private TreeItem getTreeItem(MouseEvent e) {
+ return ((Tree) e.widget).getItem(new Point(e.x, e.y));
+ }
+
+
+ /**
+ * Return the control used to render this View
+ *
+ * @see org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.IPageBookNestableViewPart#getControl()
+ *
+ * @return the main control of the navigator viewer
+ */
+ public Control getControl() {
+ return getCommonViewer().getControl();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void init(IViewSite site, IMemento aMemento) throws PartInitException {
+ super.init(site, aMemento);
+
+ activate();
+
+ // Self-listen for property changes
+ addPropertyListener(new IPropertyListener() {
+
+ public void propertyChanged(Object source, int propId) {
+ switch (propId) {
+ case IS_LINKING_ENABLED_PROPERTY:
+ // Propagate to other instances
+ sharedState.setLinkingEnabled(isLinkingEnabled());
+ break;
+ }
+ }
+ });
+ }
+
+ /**
+ * {@link ResourceSetListener} to listen and react to changes in the
+ * resource set.
+ */
+ private final ResourceSetListener resourceSetListener = new ResourceSetListenerImpl() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+ super.resourceSetChanged(event);
+ handleResourceSetChanged(event);
+ }
+ };
+
+ /** cache variable with last transaction which triggered a refresh */
+ private Transaction lastTrans = null;
+
+ /**
+ * Run in a UI thread to avoid non UI thread exception.
+ *
+ * @param event
+ */
+ private void handleResourceSetChanged(ResourceSetChangeEvent event) {
+ // avoid refreshing N times for the same transaction (called for each object in resource)
+ Transaction curTrans = event.getTransaction();
+ if (lastTrans != null && lastTrans.equals(curTrans)) {
+ return;
+ }
+ lastTrans = curTrans;
+
+ scheduleRefresh();
+ }
+
+ private Runnable refreshRunnable;
+
+ /**
+ * Thread-safe
+ * Schedule a runnable which will refresh the view if necessary
+ */
+ protected void scheduleRefresh() {
+ final Runnable schedule;
+
+ synchronized (this) {
+ if (refreshRunnable == null) {
+ // No refresh is yet pending. Schedule one
+ schedule = createRefreshRunnable();
+ refreshRunnable = schedule;
+ } else {
+ schedule = null;
+ }
+ }
+
+ if (schedule != null) {
+ Control control = getControl();
+ Display display = ((control == null) || control.isDisposed()) ? null : control.getDisplay();
+
+ if (display != null) {
+ // Don't need to schedule a refresh if we have no control or it's disposed
+ display.asyncExec(schedule);
+ }
+ }
+ }
+
+ private Runnable createRefreshRunnable() {
+ return new Runnable() {
+
+ public void run() {
+ // Only run if I'm still pending
+ synchronized (ModelExplorerView.this) {
+ if (refreshRunnable != this) {
+ return;
+ }
+
+ refreshRunnable = null;
+ }
+
+ refreshInUIThread();
+ }
+ };
+ }
+
+ /**
+ * Thread-safe method to hurry up a pending refresh of the Model Explorer view (if any), synchronously.
+ * When this method returns, then either the explorer has been refreshed or it doesn't need to be.
+ */
+ protected void syncRefresh() {
+ final Runnable pending;
+
+ synchronized (this) {
+ pending = refreshRunnable;
+ }
+
+ if (pending != null) {
+ Control control = getControl();
+ Display display = ((control == null) || control.isDisposed()) ? null : control.getDisplay();
+
+ if (display != null) {
+ // Don't need to execute a refresh if we have no control or it's disposed
+ display.syncExec(pending);
+ }
+ }
+ }
+
+ /**
+ * refresh the view.
+ */
+ protected void refreshInUIThread() {
+ // Need to refresh, even if (temporarily) invisible
+ // (Better alternative?: store refresh event and execute once visible again)
+ if (getControl().isDisposed()) {
+ return;
+ }
+
+ // avoid reentrant call
+ // Refresh only of we are not already refreshing.
+ if (isRefreshing.compareAndSet(false, true)) {
+ if (!getCommonViewer().isBusy()) {
+ getCommonViewer().refresh();
+ }
+
+ isRefreshing.set(false);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getInitialInput() {
+
+ if (serviceRegistry != null) {
+ return serviceRegistry;
+ } else {
+ return super.getInitialInput();
+ }
+
+ }
+
+ /**
+ * Activate specified Part.
+ */
+ private void activate() {
+ try {
+ this.editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
+
+ // Set Viewer input if it already exist
+ if (getCommonViewer() != null) {
+ getCommonViewer().setInput(serviceRegistry);
+ }
+ editingDomain.addResourceSetListener(resourceSetListener);
+ IReadOnlyHandler2 readOnlyHandler = AdapterUtils.adapt(editingDomain, IReadOnlyHandler2.class, null);
+ if (readOnlyHandler != null) {
+ readOnlyHandler.addReadOnlyListener(createReadOnlyListener());
+ }
+ } catch (ServiceException e) {
+ // Can't get EditingDomain, skip
+ }
+
+ // listen to change events
+ getSite().getPage().addSelectionListener(pageSelectionListener);
+
+ // Listen to isDirty flag
+ saveAndDirtyService.addInputChangedListener(editorInputChangedListener);
+
+ if (this.getCommonViewer() != null) {
+ // Force a refresh
+ Display display = getControl().getDisplay();
+ if (display == Display.getCurrent()) {
+ refreshInUIThread();
+ } else {
+ // Hmm. We should be on the UI thread
+ Activator.log.warn("Model Explorer activated on a non-UI thread."); //$NON-NLS-1$
+ scheduleRefresh();
+ }
+ }
+ }
+
+ /**
+ * Deactivate the Model Explorer.
+ */
+ private void deactivate() {
+ // deactivate global handler
+ if (Activator.log.isDebugEnabled()) {
+ Activator.log.debug("deactivate ModelExplorerView"); //$NON-NLS-1$
+ }
+
+ try {
+ ISashWindowsContainer sashWindowsContainer = serviceRegistry.getService(ISashWindowsContainer.class);
+ if (sashWindowsContainer != null) {
+ sashWindowsContainer.removePageLifeCycleListener(this);
+ }
+ } catch (ServiceException ex) {
+ // Ignore
+ }
+
+ // Stop listening on change events
+ getSite().getPage().removeSelectionListener(pageSelectionListener);
+ // Stop Listening to isDirty flag
+ saveAndDirtyService.removeInputChangedListener(editorInputChangedListener);
+
+ if (editingDomain != null) {
+ editingDomain.removeResourceSetListener(resourceSetListener);
+ editingDomain = null;
+ }
+
+ saveAndDirtyService = null;
+ undoContext = null;
+ editingDomain = null;
+ editingDomain = null;
+ lastTrans = null;
+ }
+
+ /**
+ * Invoked internally to clear the common viewer's associate listener in order to promote garbage collection.
+ */
+ void aboutToDispose() {
+ final CommonViewer viewer = getCommonViewer();
+ if ((viewer.getTree() != null) && !viewer.getTree().isDisposed()) {
+ viewer.setInput(null);
+
+ // Kick the NavigatorContentService to clear the cache in its StructuredViewerManager that leaks all of our tree elements
+ INavigatorContentService contentService = getNavigatorContentService();
+ if (contentService instanceof IExtensionActivationListener) {
+ ((IExtensionActivationListener) getNavigatorContentService()).onExtensionActivation(contentService.getViewerId(), new String[0], false);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+
+ // Stop if we are already disposed
+ if (isDisposed()) {
+ return;
+ }
+
+ if ((sharedStateListener != null) && (sharedState != null)) {
+ sharedState.removeListener(sharedStateListener);
+ }
+
+ if (getSite() != null) {
+ getSite().getPage().removeSelectionListener(pageSelectionListener);
+ }
+
+ deactivate();
+
+ for (IPropertySheetPage propertySheetPage : this.propertySheetPages) {
+ propertySheetPage.dispose();
+ }
+
+ propertySheetPages.clear();
+
+ pageSelectionListener = null;
+
+ super.dispose();
+
+ // Clean up properties to help GC
+
+ }
+
+ /**
+ * Return true if the component is already disposed.
+ *
+ * @return
+ */
+ public boolean isDisposed() {
+ // use editorPart as flag
+ return saveAndDirtyService == null;
+ }
+
+ /**
+ * Retrieves the {@link IPropertySheetPage} that his Model Explorer uses.
+ *
+ * @return
+ */
+ private IPropertySheetPage getPropertySheetPage() {
+ try {
+ final IMultiDiagramEditor multiDiagramEditor = ServiceUtils.getInstance().getService(IMultiDiagramEditor.class, serviceRegistry);
+
+ if (multiDiagramEditor != null) {
+ if (multiDiagramEditor instanceof ITabbedPropertySheetPageContributor) {
+ ITabbedPropertySheetPageContributor contributor = (ITabbedPropertySheetPageContributor) multiDiagramEditor;
+ IPropertySheetPage propertySheetPage = new TabbedPropertySheetPage(contributor);
+ this.propertySheetPages.add(propertySheetPage);
+ return propertySheetPage;
+ }
+ }
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+ return null;
+ }
+
+ /**
+ * in order to see element if the property view
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class adapter) {
+ if (IPropertySheetPage.class.equals(adapter)) {
+ return getPropertySheetPage();
+ }
+
+ if (IUndoContext.class == adapter) {
+ // Return the IUndoContext of associated model.
+ return undoContext;
+ }
+
+ if (ISaveablePart.class.equals(adapter)) {
+ try {
+ return serviceRegistry.getService(IMultiDiagramEditor.class);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+ return saveAndDirtyService;
+ }
+
+ if (ServicesRegistry.class == adapter) {
+ return serviceRegistry;
+ }
+
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return the EditingDomain used by the properties view
+ */
+ public EditingDomain getEditingDomain() {
+ return editingDomain;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void selectReveal(ISelection selection) {
+ syncRefresh();
+ if (getCommonViewer() != null) {
+ getCommonViewer().setSelection(selection, true);
+ }
+ }
+
+ public void revealSemanticElement(List<?> elementList) {
+ // Ensure that the ModelExplorer is refreshed before
+ // trying to display an element. Useful if the element has just been created,
+ // and the model explorer has not yet been refreshed
+ syncRefresh();
+ reveal(elementList, getCommonViewer());
+ }
+
+ /**
+ * Expands the given CommonViewer to reveal the given elements
+ *
+ * @param elementList
+ * The elements to reveal
+ * @param commonViewer
+ * The CommonViewer they are to be revealed in
+ */
+ public static void reveal(Iterable<?> elementList, final CommonViewer commonViewer) {
+ ArrayList<IMatchingItem> matchingItemsToSelect = new ArrayList<IMatchingItem>();
+ // filter out non EMF objects
+ Iterable<EObject> list = Iterables.filter(elementList, EObject.class);
+
+ for (EObject currentEObject : list) {
+ matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject));
+
+ // the content provider exist?
+ if (commonViewer.getContentProvider() != null) {
+ // retrieve the ancestors to reveal them
+ // and allow the selection of the object
+ ArrayList<EObject> parents = new ArrayList<EObject>();
+ EObject tmp = currentEObject.eContainer();
+ while (tmp != null) {
+ parents.add(tmp);
+ tmp = tmp.eContainer();
+ }
+
+ Iterable<EObject> reverseParents = Lists.reverse(parents);
+
+ // reveal the resource if necessary
+ Resource r = null;
+ if (!parents.isEmpty()) {
+ r = parents.get(parents.size() - 1).eResource();
+ } else {
+ r = currentEObject.eResource();
+ }
+
+ if (r != null) {
+ final ResourceSet rs = r.getResourceSet();
+ final Resource resource = r;
+ if (rs instanceof ModelSet && AdditionalResourcesModel.isAdditionalResource((ModelSet) rs, r.getURI())) {
+ commonViewer.getControl().getDisplay().syncExec(new Runnable() {
+
+ public void run() {
+ commonViewer.expandToLevel(new ReferencableMatchingItem(rs), 1);
+ commonViewer.expandToLevel(new ReferencableMatchingItem(resource), 1);
+ }
+ });
+
+ }
+ }
+
+ /*
+ * reveal the ancestors tree using expandToLevel on each of them
+ * in the good order. This is a lot faster than going through the whole tree
+ * using getChildren of the ContentProvider since our Viewer uses a Hashtable
+ * to keep track of the revealed elements.
+ *
+ * However we need to use a dedicated MatchingItem to do the matching,
+ * and a specific comparer in our viewer so than the equals of MatchingItem is
+ * used in priority.
+ *
+ * Please refer to MatchingItem for more infos.
+ */
+ EObject previousParent = null;
+ for (EObject parent : reverseParents) {
+ if (parent.eContainingFeature() != null && previousParent != null) {
+ commonViewer.expandToLevel(new LinkItemMatchingItem(previousParent, parent.eContainmentFeature()), 1);
+ }
+
+ final IMatchingItem itemToExpand = new ModelElementItemMatchingItem(parent);
+
+ commonViewer.getControl().getDisplay().syncExec(new Runnable() {
+
+ public void run() {
+ commonViewer.expandToLevel(itemToExpand, 1);
+ }
+ });
+
+ previousParent = parent;
+ }
+
+ final IMatchingItem itemToExpand = new LinkItemMatchingItem(currentEObject.eContainer(), currentEObject.eContainmentFeature());
+
+ commonViewer.getControl().getDisplay().syncExec(new Runnable() {
+
+ public void run() {
+ commonViewer.expandToLevel(itemToExpand, 1);
+ }
+ });
+ }
+ }
+
+ selectReveal(new StructuredSelection(matchingItemsToSelect), commonViewer);
+ }
+
+ /**
+ * Selects the given ISelection in the given CommonViwer
+ *
+ * @param structuredSelection
+ * The ISelection to select
+ * @param commonViewer
+ * The ComonViewer to select it in
+ */
+ public static void selectReveal(final ISelection structuredSelection, final Viewer commonViewer) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ commonViewer.setSelection(structuredSelection, true);
+ }
+ });
+ }
+
+ /**
+ * Selects and, if possible, reveals the given ISelection in the given CommonViwer
+ *
+ * @param selection
+ * The ISelection to select
+ * @param viewer
+ * The ComonViewer to select it in
+ */
+ public static void reveal(final ISelection selection, final CommonViewer viewer) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structured = (IStructuredSelection) selection;
+ reveal(Lists.newArrayList(structured.iterator()), viewer);
+ } else {
+ viewer.getControl().getDisplay().syncExec(new Runnable() {
+
+ public void run() {
+ viewer.setSelection(selection);
+ }
+ });
+ }
+ }
+
+ public void pageOpened(IPage page) {
+ refreshTree();
+ }
+
+ public void pageClosed(IPage page) {
+ refreshTree();
+ }
+
+ private void refreshTree() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ if (getCommonViewer().getControl() == null || getCommonViewer().getControl().isDisposed()) {
+ return;
+ }
+ getCommonViewer().refresh(true);
+ // Force redraw to refresh facet overlay
+ getCommonViewer().getTree().redraw();
+ }
+ });
+ }
+
+ public void pageChanged(IPage newPage) {
+ // Nothing
+ }
+
+ public void pageActivated(IPage page) {
+ // Nothing
+ }
+
+ public void pageDeactivated(IPage page) {
+ // Nothing
+ }
+
+ public void pageAboutToBeOpened(IPage page) {
+ // Nothing
+ }
+
+ public void pageAboutToBeClosed(IPage page) {
+ // Nothing
+ }
+
+ private IReadOnlyListener createReadOnlyListener() {
+ return new IReadOnlyListener() {
+
+ public void readOnlyStateChanged(ReadOnlyEvent event) {
+ switch (event.getEventType()) {
+ case ReadOnlyEvent.RESOURCE_READ_ONLY_STATE_CHANGED:
+ scheduleRefresh();
+ break;
+ case ReadOnlyEvent.OBJECT_READ_ONLY_STATE_CHANGED:
+ CommonViewer viewer = getCommonViewer();
+ if ((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
+ viewer.refresh(event.getObject());
+ }
+ break;
+ default:
+ Activator.log.warn("Unsupported read-only event type: " + event.getEventType());
+ break;
+ }
+ }
+ };
+ }
+
+ void setSharedState(SharedModelExplorerState state) {
+ if (this.sharedState != null) {
+ this.sharedState.removeListener(getSharedStateListener());
+ }
+
+ this.sharedState = state;
+
+ if (state != null) {
+ state.addListener(getSharedStateListener());
+ initSharedState(state);
+ }
+ }
+
+ void initSharedState(SharedModelExplorerState state) {
+ setLinkingEnabled(state.isLinkingEnabled());
+ setAlphaSorted(state.isAlphaSorted());
+ }
+
+ void setAlphaSorted(boolean sorted) {
+ CommonViewer viewer = getCommonViewer();
+ if ((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
+ if (sorted) {
+ viewer.setSorter(new CommonViewerSorter());
+ if (viewer instanceof CustomCommonViewer) {
+ ((CustomCommonViewer) viewer).getDropAdapter().setFeedbackEnabled(false);
+ }
+ } else {
+ viewer.setSorter(null);
+ if (viewer instanceof CustomCommonViewer) {
+ ((CustomCommonViewer) viewer).getDropAdapter().setFeedbackEnabled(true);
+ }
+ }
+ }
+ }
+
+ SharedModelExplorerState.StateChangedListener getSharedStateListener() {
+ if (sharedStateListener == null) {
+ sharedStateListener = new SharedModelExplorerState.StateChangedListener() {
+
+ private volatile Runnable contentUpdate;
+
+ public void sharedStateChanged(StateChangedEvent event) {
+ switch (event.getEventType()) {
+ case StateChangedEvent.LINKING_ENABLED:
+ setLinkingEnabled(event.getSource().isLinkingEnabled());
+ break;
+ case StateChangedEvent.ALPHA_SORTED:
+ setAlphaSorted(event.getSource().isAlphaSorted());
+ break;
+ case StateChangedEvent.CONTENT_EXTENSIONS:
+ if (contentUpdate == null) {
+ getCommonViewer().getControl().getDisplay().asyncExec(getContentUpdate());
+ }
+ break;
+ }
+ }
+
+ private Runnable getContentUpdate() {
+ if (contentUpdate == null) {
+ contentUpdate = new Runnable() {
+
+ public void run() {
+ CommonViewer viewer = getCommonViewer();
+ if ((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
+ viewer.getNavigatorContentService().getActivationService().activateExtensions(sharedState.getNavigatorContentExtensions(), true);
+ }
+
+ // I am no longer pending
+ contentUpdate = null;
+ }
+ };
+ }
+ return contentUpdate;
+ }
+ };
+ }
+
+ return sharedStateListener;
+ }
} \ No newline at end of file
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java
index b63b4abf38b..9f1257e2ed0 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java
@@ -486,10 +486,10 @@ public class NavigatorUtils {
T result = null;
if (o instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) o;
- result = (T) adaptable.getAdapter(theClass);
+ result = adaptable.getAdapter(theClass);
}
if (result == null) {
- result = (T) Platform.getAdapterManager().getAdapter(o, theClass);
+ result = Platform.getAdapterManager().getAdapter(o, theClass);
}
if (result == null && theClass.isInstance(o)) {
result = (T) o;
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actionprovider/UndoRedoActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actionprovider/UndoRedoActionProvider.java
index b968376d08a..a470fd159aa 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actionprovider/UndoRedoActionProvider.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actionprovider/UndoRedoActionProvider.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2014 CEA LIST, Christian W. Damus, 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
@@ -9,7 +9,7 @@
* Contributors:
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
* Christian W. Damus - bug 450536
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.actionprovider;
@@ -34,7 +34,7 @@ import org.eclipse.ui.operations.UndoActionHandler;
/**
* Action Provider to provide Redo/Undo action trough workbench menu.
- *
+ *
* @author Gabriel Pascual
*
*/
@@ -122,7 +122,7 @@ public class UndoRedoActionProvider extends AbstractCommonActionProvider impleme
* <p>
* Synchronise handlers after a Command stack's change.
* </p>
- *
+ *
* @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(java.util.EventObject)
*
* @param event
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actions/GenericTransformer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actions/GenericTransformer.java
index 830db10e477..1265300a6e4 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actions/GenericTransformer.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/actions/GenericTransformer.java
@@ -1,443 +1,443 @@
-/***************************************************
- * Copyright (c) 2010 Atos Origin.
-
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- ****************************************************/
-package org.eclipse.papyrus.views.modelexplorer.actions;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
-import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CommandStack;
-import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.gef.requests.GroupRequest;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.ui.services.editor.EditorService;
-import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewRefactorHelper;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.LayoutConstraint;
-import org.eclipse.gmf.runtime.notation.Location;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.views.modelexplorer.Activator;
-import org.eclipse.papyrus.views.modelexplorer.commands.EObjectInheritanceCopyCommand;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * The Class GenericTransformer. Permits to transform an eobject of eclass to
- * another eclass
- */
-public class GenericTransformer {
-
- /** The factories to create eObjects */
- private static HashMap<String, AdapterFactory> factories = new HashMap<String, AdapterFactory>();
-
- /** extension to recover factories */
- private static final String EXT_FACTORIES = "org.eclipse.emf.edit.itemProviderAdapterFactories";
-
- /** title of the warning dialog */
- private static final String WARNING_TITLE = "Problems during transformation";
-
- /** message of the warning dialog */
- private static final String WARNING_MSG = "It seems the transformation you want to perform can't be executed";
-
- /** command to execute the whole transformation */
- private CompositeCommand globalCommand;
-
- /** element to transform */
- private EObject element;
-
- /** views referencing the element */
- private Set<View> referencingViews = new HashSet<View>();
-
- /** command to execute the model transformation */
- private EObjectInheritanceCopyCommand commandModel;
-
- /** whether the graphical edit parts must also be transformed */
- private boolean graphCopy = true;
-
- /** the command to import new graphical edit parts */
- private ImporterCommand importerCommand;
-
- /**
- * Instantiates a new generic transformer.
- *
- * @param currentNode
- * the current node
- */
- public GenericTransformer(AbstractGraphicalEditPart currentNode) {
- this(currentNode, true);
- }
-
- /**
- * Instantiates a new generic transformer. and specify if we have to perform
- * graphical copy
- *
- * @param currentNode
- * the current node
- * @param graphCopy
- * the graph copy
- */
- public GenericTransformer(AbstractGraphicalEditPart currentNode, boolean graphCopy) {
- this.graphCopy = graphCopy;
- if (currentNode != null) {
- Object model = currentNode.getModel();
- if (model instanceof View) {
- this.element = ((View) model).getElement();
- }
- }
- }
-
- /**
- * Instantiates a new generic transformer.
- *
- * @param currentEobject
- * the current eobject
- */
- public GenericTransformer(EObject currentEobject) {
- this.element = currentEobject;
- }
-
- /**
- * Transform the element to the given eclass.
- *
- * @param eclass
- * the targeted eclass
- */
- public void transform(EClass eclass) {
-
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editor = page.getActiveEditor();
- CommandStack stack = (CommandStack) editor.getAdapter(CommandStack.class);
- globalCommand = new CompositeCommand("Generic Transformation");
-
- if (graphCopy) {
- if (element != null) {
- EReference[] features = { NotationPackage.eINSTANCE.getView_Element() };
- Collection<?> views = EMFCoreUtil.getReferencers(element, features);
- for (Object view : views) {
- if (view instanceof View) {
- referencingViews.add((View) view);
- }
- }
- }
- }
- if (stack != null) {
- // maybe extension point for stereotypes
- EObject model = (EObject) AdapterFactoryEditingDomain.unwrap(element);
- // get mixed editing domain to do transaction
- TransactionalEditingDomain domain = (TransactionalEditingDomain) EMFHelper.resolveEditingDomain(model);
- commandModel = new EObjectInheritanceCopyCommand(model, eclass, domain);
- globalCommand.add(commandModel);
- if (graphCopy) {
- importerCommand = new ImporterCommand(domain);
- if (importerCommand.canExecute()) {
- globalCommand.add(importerCommand);
- }
-
- }
- if (globalCommand.canExecute()) {
- try {
- // drop caches about input element
- ECrossReferenceAdapter cross = ECrossReferenceAdapter.getCrossReferenceAdapter(element);
- if (cross != null) {
- cross.unsetTarget(element);
- }
- stack.execute(new ICommandProxy(globalCommand));
- } catch (Exception e) {
- MessageDialog.openWarning(Display.getDefault().getActiveShell(), WARNING_TITLE, WARNING_MSG);
- e.printStackTrace();
- }
- } else {
- MessageDialog.openWarning(Display.getDefault().getActiveShell(), WARNING_TITLE, WARNING_MSG);
- }
- }
- }
-
- /**
- * The Class ImporterCommand. permits to add the importer in the compound
- * command
- */
- private class ImporterCommand extends AbstractTransactionalCommand {
-
- /**
- * Constructor.
- *
- * @param domain
- * transactional editing domain
- */
- public ImporterCommand(TransactionalEditingDomain domain) {
- super(domain, "Import graphical nodes", null);
- }
-
- /**
- * Execute the command
- *
- * @param monitor
- * progress monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- graphCopy(null, commandModel.getResultEobject());
- return CommandResult.newOKCommandResult();
- }
-
- /**
- * Graph copy, make a drag and drop of the new object on all diagrams
- *
- * @param diagramDomain
- * the mixed domain
- * @param target
- * the target
- * @param globalCommand2
- * @param graphElement
- * the graph element
- * @param oldLocation
- * the old location
- * @param editpart
- * the editpart
- */
- private void graphCopy(IDiagramEditDomain domain, EObject target) {
- for (View graphElement : referencingViews) {
- View parent = ViewUtil.getContainerView(graphElement);
- if (parent == null || graphElement.getDiagram() == null) {
- // this is an orphaned view. Skip it
- continue;
- }
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- // Get the edit part of the diagram containing the view.
- DiagramEditPart diagramEditPart = null;
- IEditorPart activeEditorPart = page.getActiveEditor();
- if (activeEditorPart instanceof IDiagramWorkbenchPart) {
- if (graphElement.getDiagram().equals(((IDiagramWorkbenchPart) activeEditorPart).getDiagram())) {
- diagramEditPart = ((IDiagramWorkbenchPart) activeEditorPart).getDiagramEditPart();
- }
- }
- if (diagramEditPart == null) {
- // search in other editor parts than the active one
- List<?> editorParts = EditorService.getInstance().getRegisteredEditorParts();
- for (Object editorPart : editorParts) {
- if (editorPart instanceof IDiagramWorkbenchPart) {
- if (graphElement.getDiagram().equals(((IDiagramWorkbenchPart) editorPart).getDiagram())) {
- diagramEditPart = ((IDiagramWorkbenchPart) editorPart).getDiagramEditPart();
- }
- }
- }
- }
-
- if (diagramEditPart != null) {
- EditPart containerPart = (EditPart) diagramEditPart.getViewer().getEditPartRegistry().get(parent);
- // create the new transformed view
- DropObjectsRequest req = new DropObjectsRequest();
- req.setObjects(Collections.singletonList(target));
- if (graphElement instanceof Node) {
- LayoutConstraint constraint = ((Node) graphElement).getLayoutConstraint();
- if (constraint instanceof Location) {
- Location location = (Location) constraint;
- req.setLocation(new Point(location.getX(), location.getY()));
- }
- }
- if (req.getLocation() == null) {
- req.setLocation(new Point());
- }
- Command partCreationCmd = containerPart.getCommand(req);
- partCreationCmd.execute();
- View newView = null;
- if (partCreationCmd instanceof ICommandProxy) {
- CommandResult res = ((ICommandProxy) partCreationCmd).getICommand().getCommandResult();
- Object newValue = res.getReturnValue();
- if (newValue instanceof Collection<?>) {
- for (Object value : (Collection<?>) newValue) {
- if (value instanceof ViewDescriptor) {
- newView = (View) ((ViewDescriptor) value).getAdapter(View.class);
- }
- }
- } else if (newValue instanceof ViewDescriptor) {
- newView = (View) ((ViewDescriptor) newValue).getAdapter(View.class);
- }
- }
- // with ViewRefactorHelper, copy view properties on the old
- // one
- if (newView != null) {
- ViewTransformerHelper helper = new ViewTransformerHelper(diagramEditPart.getDiagramPreferencesHint());
- helper.copyMixedViewFeatures(graphElement, newView);
- }
- // delete the old view
- GroupRequest deleteReq = new GroupRequest(org.eclipse.gef.RequestConstants.REQ_DELETE);
- EditPart oldPart = (EditPart) diagramEditPart.getViewer().getEditPartRegistry().get(graphElement);
- Command partDeletionCmd = oldPart.getCommand(deleteReq);
- partDeletionCmd.execute();
- }
- }
-
- }
-
- }
-
- /**
- * ViewTransformerHelper allow to refactor a view to copy properties from
- * another view
- */
- private static class ViewTransformerHelper extends ViewRefactorHelper {
-
- /**
- * Constructor.
- *
- * @param preferencesHint
- * the diagram preferences hint
- */
- public ViewTransformerHelper(PreferencesHint preferencesHint) {
- super(preferencesHint);
- }
-
- /**
- * Copy common features from a view to another
- *
- * @param oldView
- * the old view to copy from
- * @param newView
- * the new view to copy to
- */
- public void copyMixedViewFeatures(View oldView, View newView) {
- if (oldView instanceof Diagram && newView instanceof Diagram) {
- copyDiagramFeatures((Diagram) oldView, (Diagram) newView);
- } else if (oldView instanceof Node && newView instanceof Node) {
- copyNodeFeatures((Node) oldView, (Node) newView);
- } else if (oldView instanceof Edge && newView instanceof Edge) {
- copyEdgeFeatures((Edge) oldView, (Edge) newView);
- } else {
- copyViewFeatures(oldView, newView);
- }
- }
-
- }
-
- /**
- * Gets all the super types.
- *
- * @param class1
- * the class
- *
- * @return super types
- */
- public static HashSet<EClass> getAllSuperTypes(EClass class1) {
- HashSet<EClass> results = new HashSet<EClass>();
- results.addAll(class1.getEAllSuperTypes());
- return results;
- }
-
- /**
- * Gets the factory from uri.
- *
- * @param uri
- * the uri
- *
- * @return the factory
- */
- public static AdapterFactory getFactory(String uri) {
- AdapterFactory factory = factories.get(uri);
- if (factory == null) {
- IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(EXT_FACTORIES);
- for (IConfigurationElement e : extensions) {
- if (uri.equals(e.getAttribute("uri"))) {
- try {
- factory = (AdapterFactory) e.createExecutableExtension("class");
- if (factory != null) {
- factories.put(uri, factory);
- }
- } catch (CoreException e1) {
- // do nothing
- }
- }
- }
- }
- return factory;
- }
-
- /**
- * Checks if a transformation is possible.
- *
- * @param eclass
- * the eclass
- *
- * @return the multi status
- */
- public MultiStatus isTransformationPossible(EClass eclass) {
- MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, 0, "Type incompatibility", null);
- if (element != null) {
- Collection<Setting> usages = EMFHelper.getUsages(element);
- if (usages != null) {
- for (EStructuralFeature.Setting nonNavigableInverseReference : usages) {
- EStructuralFeature structuralFeature = nonNavigableInverseReference.getEStructuralFeature();
- if (!(nonNavigableInverseReference.getEObject() instanceof View)) {
- boolean compatible = EObjectInheritanceCopyCommand.isCompatible(structuralFeature.getEType(), eclass);
- if (!compatible) {
- String econtainer = structuralFeature.eContainer() instanceof EClassifier ? ((EClassifier) structuralFeature.eContainer()).getName() + " ( " + nonNavigableInverseReference.getEObject().toString() + " )" : structuralFeature
- .eContainer().toString();
- Status s = new Status(IStatus.WARNING, Activator.PLUGIN_ID, String.format("an element typed %s references your selection, we can not assign instead of your selection an object typed %s", econtainer, eclass.getName()));
- result.add(s);
- }
- }
- }
- }
- }
- return result;
- }
-
-}
+/***************************************************
+ * Copyright (c) 2010 Atos Origin.
+
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ *
+ ****************************************************/
+package org.eclipse.papyrus.views.modelexplorer.actions;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.ui.services.editor.EditorService;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewRefactorHelper;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.LayoutConstraint;
+import org.eclipse.gmf.runtime.notation.Location;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.views.modelexplorer.Activator;
+import org.eclipse.papyrus.views.modelexplorer.commands.EObjectInheritanceCopyCommand;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The Class GenericTransformer. Permits to transform an eobject of eclass to
+ * another eclass
+ */
+public class GenericTransformer {
+
+ /** The factories to create eObjects */
+ private static HashMap<String, AdapterFactory> factories = new HashMap<String, AdapterFactory>();
+
+ /** extension to recover factories */
+ private static final String EXT_FACTORIES = "org.eclipse.emf.edit.itemProviderAdapterFactories";
+
+ /** title of the warning dialog */
+ private static final String WARNING_TITLE = "Problems during transformation";
+
+ /** message of the warning dialog */
+ private static final String WARNING_MSG = "It seems the transformation you want to perform can't be executed";
+
+ /** command to execute the whole transformation */
+ private CompositeCommand globalCommand;
+
+ /** element to transform */
+ private EObject element;
+
+ /** views referencing the element */
+ private Set<View> referencingViews = new HashSet<View>();
+
+ /** command to execute the model transformation */
+ private EObjectInheritanceCopyCommand commandModel;
+
+ /** whether the graphical edit parts must also be transformed */
+ private boolean graphCopy = true;
+
+ /** the command to import new graphical edit parts */
+ private ImporterCommand importerCommand;
+
+ /**
+ * Instantiates a new generic transformer.
+ *
+ * @param currentNode
+ * the current node
+ */
+ public GenericTransformer(AbstractGraphicalEditPart currentNode) {
+ this(currentNode, true);
+ }
+
+ /**
+ * Instantiates a new generic transformer. and specify if we have to perform
+ * graphical copy
+ *
+ * @param currentNode
+ * the current node
+ * @param graphCopy
+ * the graph copy
+ */
+ public GenericTransformer(AbstractGraphicalEditPart currentNode, boolean graphCopy) {
+ this.graphCopy = graphCopy;
+ if (currentNode != null) {
+ Object model = currentNode.getModel();
+ if (model instanceof View) {
+ this.element = ((View) model).getElement();
+ }
+ }
+ }
+
+ /**
+ * Instantiates a new generic transformer.
+ *
+ * @param currentEobject
+ * the current eobject
+ */
+ public GenericTransformer(EObject currentEobject) {
+ this.element = currentEobject;
+ }
+
+ /**
+ * Transform the element to the given eclass.
+ *
+ * @param eclass
+ * the targeted eclass
+ */
+ public void transform(EClass eclass) {
+
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editor = page.getActiveEditor();
+ CommandStack stack = editor.getAdapter(CommandStack.class);
+ globalCommand = new CompositeCommand("Generic Transformation");
+
+ if (graphCopy) {
+ if (element != null) {
+ EReference[] features = { NotationPackage.eINSTANCE.getView_Element() };
+ Collection<?> views = EMFCoreUtil.getReferencers(element, features);
+ for (Object view : views) {
+ if (view instanceof View) {
+ referencingViews.add((View) view);
+ }
+ }
+ }
+ }
+ if (stack != null) {
+ // maybe extension point for stereotypes
+ EObject model = (EObject) AdapterFactoryEditingDomain.unwrap(element);
+ // get mixed editing domain to do transaction
+ TransactionalEditingDomain domain = (TransactionalEditingDomain) EMFHelper.resolveEditingDomain(model);
+ commandModel = new EObjectInheritanceCopyCommand(model, eclass, domain);
+ globalCommand.add(commandModel);
+ if (graphCopy) {
+ importerCommand = new ImporterCommand(domain);
+ if (importerCommand.canExecute()) {
+ globalCommand.add(importerCommand);
+ }
+
+ }
+ if (globalCommand.canExecute()) {
+ try {
+ // drop caches about input element
+ ECrossReferenceAdapter cross = ECrossReferenceAdapter.getCrossReferenceAdapter(element);
+ if (cross != null) {
+ cross.unsetTarget(element);
+ }
+ stack.execute(new ICommandProxy(globalCommand));
+ } catch (Exception e) {
+ MessageDialog.openWarning(Display.getDefault().getActiveShell(), WARNING_TITLE, WARNING_MSG);
+ e.printStackTrace();
+ }
+ } else {
+ MessageDialog.openWarning(Display.getDefault().getActiveShell(), WARNING_TITLE, WARNING_MSG);
+ }
+ }
+ }
+
+ /**
+ * The Class ImporterCommand. permits to add the importer in the compound
+ * command
+ */
+ private class ImporterCommand extends AbstractTransactionalCommand {
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * transactional editing domain
+ */
+ public ImporterCommand(TransactionalEditingDomain domain) {
+ super(domain, "Import graphical nodes", null);
+ }
+
+ /**
+ * Execute the command
+ *
+ * @param monitor
+ * progress monitor
+ * @param info
+ * the info
+ * @return the command result
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ graphCopy(null, commandModel.getResultEobject());
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ * Graph copy, make a drag and drop of the new object on all diagrams
+ *
+ * @param diagramDomain
+ * the mixed domain
+ * @param target
+ * the target
+ * @param globalCommand2
+ * @param graphElement
+ * the graph element
+ * @param oldLocation
+ * the old location
+ * @param editpart
+ * the editpart
+ */
+ private void graphCopy(IDiagramEditDomain domain, EObject target) {
+ for (View graphElement : referencingViews) {
+ View parent = ViewUtil.getContainerView(graphElement);
+ if (parent == null || graphElement.getDiagram() == null) {
+ // this is an orphaned view. Skip it
+ continue;
+ }
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ // Get the edit part of the diagram containing the view.
+ DiagramEditPart diagramEditPart = null;
+ IEditorPart activeEditorPart = page.getActiveEditor();
+ if (activeEditorPart instanceof IDiagramWorkbenchPart) {
+ if (graphElement.getDiagram().equals(((IDiagramWorkbenchPart) activeEditorPart).getDiagram())) {
+ diagramEditPart = ((IDiagramWorkbenchPart) activeEditorPart).getDiagramEditPart();
+ }
+ }
+ if (diagramEditPart == null) {
+ // search in other editor parts than the active one
+ List<?> editorParts = EditorService.getInstance().getRegisteredEditorParts();
+ for (Object editorPart : editorParts) {
+ if (editorPart instanceof IDiagramWorkbenchPart) {
+ if (graphElement.getDiagram().equals(((IDiagramWorkbenchPart) editorPart).getDiagram())) {
+ diagramEditPart = ((IDiagramWorkbenchPart) editorPart).getDiagramEditPart();
+ }
+ }
+ }
+ }
+
+ if (diagramEditPart != null) {
+ EditPart containerPart = (EditPart) diagramEditPart.getViewer().getEditPartRegistry().get(parent);
+ // create the new transformed view
+ DropObjectsRequest req = new DropObjectsRequest();
+ req.setObjects(Collections.singletonList(target));
+ if (graphElement instanceof Node) {
+ LayoutConstraint constraint = ((Node) graphElement).getLayoutConstraint();
+ if (constraint instanceof Location) {
+ Location location = (Location) constraint;
+ req.setLocation(new Point(location.getX(), location.getY()));
+ }
+ }
+ if (req.getLocation() == null) {
+ req.setLocation(new Point());
+ }
+ Command partCreationCmd = containerPart.getCommand(req);
+ partCreationCmd.execute();
+ View newView = null;
+ if (partCreationCmd instanceof ICommandProxy) {
+ CommandResult res = ((ICommandProxy) partCreationCmd).getICommand().getCommandResult();
+ Object newValue = res.getReturnValue();
+ if (newValue instanceof Collection<?>) {
+ for (Object value : (Collection<?>) newValue) {
+ if (value instanceof ViewDescriptor) {
+ newView = (View) ((ViewDescriptor) value).getAdapter(View.class);
+ }
+ }
+ } else if (newValue instanceof ViewDescriptor) {
+ newView = (View) ((ViewDescriptor) newValue).getAdapter(View.class);
+ }
+ }
+ // with ViewRefactorHelper, copy view properties on the old
+ // one
+ if (newView != null) {
+ ViewTransformerHelper helper = new ViewTransformerHelper(diagramEditPart.getDiagramPreferencesHint());
+ helper.copyMixedViewFeatures(graphElement, newView);
+ }
+ // delete the old view
+ GroupRequest deleteReq = new GroupRequest(org.eclipse.gef.RequestConstants.REQ_DELETE);
+ EditPart oldPart = (EditPart) diagramEditPart.getViewer().getEditPartRegistry().get(graphElement);
+ Command partDeletionCmd = oldPart.getCommand(deleteReq);
+ partDeletionCmd.execute();
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * ViewTransformerHelper allow to refactor a view to copy properties from
+ * another view
+ */
+ private static class ViewTransformerHelper extends ViewRefactorHelper {
+
+ /**
+ * Constructor.
+ *
+ * @param preferencesHint
+ * the diagram preferences hint
+ */
+ public ViewTransformerHelper(PreferencesHint preferencesHint) {
+ super(preferencesHint);
+ }
+
+ /**
+ * Copy common features from a view to another
+ *
+ * @param oldView
+ * the old view to copy from
+ * @param newView
+ * the new view to copy to
+ */
+ public void copyMixedViewFeatures(View oldView, View newView) {
+ if (oldView instanceof Diagram && newView instanceof Diagram) {
+ copyDiagramFeatures((Diagram) oldView, (Diagram) newView);
+ } else if (oldView instanceof Node && newView instanceof Node) {
+ copyNodeFeatures((Node) oldView, (Node) newView);
+ } else if (oldView instanceof Edge && newView instanceof Edge) {
+ copyEdgeFeatures((Edge) oldView, (Edge) newView);
+ } else {
+ copyViewFeatures(oldView, newView);
+ }
+ }
+
+ }
+
+ /**
+ * Gets all the super types.
+ *
+ * @param class1
+ * the class
+ *
+ * @return super types
+ */
+ public static HashSet<EClass> getAllSuperTypes(EClass class1) {
+ HashSet<EClass> results = new HashSet<EClass>();
+ results.addAll(class1.getEAllSuperTypes());
+ return results;
+ }
+
+ /**
+ * Gets the factory from uri.
+ *
+ * @param uri
+ * the uri
+ *
+ * @return the factory
+ */
+ public static AdapterFactory getFactory(String uri) {
+ AdapterFactory factory = factories.get(uri);
+ if (factory == null) {
+ IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(EXT_FACTORIES);
+ for (IConfigurationElement e : extensions) {
+ if (uri.equals(e.getAttribute("uri"))) {
+ try {
+ factory = (AdapterFactory) e.createExecutableExtension("class");
+ if (factory != null) {
+ factories.put(uri, factory);
+ }
+ } catch (CoreException e1) {
+ // do nothing
+ }
+ }
+ }
+ }
+ return factory;
+ }
+
+ /**
+ * Checks if a transformation is possible.
+ *
+ * @param eclass
+ * the eclass
+ *
+ * @return the multi status
+ */
+ public MultiStatus isTransformationPossible(EClass eclass) {
+ MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, 0, "Type incompatibility", null);
+ if (element != null) {
+ Collection<Setting> usages = EMFHelper.getUsages(element);
+ if (usages != null) {
+ for (EStructuralFeature.Setting nonNavigableInverseReference : usages) {
+ EStructuralFeature structuralFeature = nonNavigableInverseReference.getEStructuralFeature();
+ if (!(nonNavigableInverseReference.getEObject() instanceof View)) {
+ boolean compatible = EObjectInheritanceCopyCommand.isCompatible(structuralFeature.getEType(), eclass);
+ if (!compatible) {
+ String econtainer = structuralFeature.eContainer() instanceof EClassifier ? ((EClassifier) structuralFeature.eContainer()).getName() + " ( " + nonNavigableInverseReference.getEObject().toString() + " )" : structuralFeature
+ .eContainer().toString();
+ Status s = new Status(IStatus.WARNING, Activator.PLUGIN_ID, String.format("an element typed %s references your selection, we can not assign instead of your selection an object typed %s", econtainer, eclass.getName()));
+ result.add(s);
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java
index 2b349b6cfcc..9ac3d52fb3e 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java
@@ -1,441 +1,441 @@
-/*******************************************************************************
- * Copyright (c) 2009 Conselleria de Infraestructuras y Transporte, Generalitat
- * de la Comunitat Valenciana . 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:
- * Francisco Javier Cano Muñoz (Prodevelop) - initial api contribution
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Improve the searchText widget
- *
- *
- ******************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.dialog;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.dialogs.TrayDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
-import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
-import org.eclipse.papyrus.infra.widgets.editors.StringEditor;
-import org.eclipse.papyrus.views.modelexplorer.LinkNode;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-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.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.navigator.CommonNavigator;
-import org.eclipse.ui.navigator.CommonViewer;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * A dialog that allows searching elements in the Model navigator by name.
- *
- * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano Munoz</a>
- *
- * @author cedric dumoulin
- */
-// @Unused
-// The QuickSearch feature is disabled since the new Search feature is available (0.10)
-public class NavigatorSearchDialog extends TrayDialog {
-
- private ITreeContentProvider contentProvider = null;
-
- private ILabelProvider labelProvider = null;
-
- private Object root = null;
-
- private ISelectionProvider viewer = null;
-
- private List<Object> matchedObjects = Collections.emptyList();
-
- protected int currentIndex = 0;
-
- private Label matchesLabel;
-
- private StringEditor searchText;
-
- private Button backButton;
-
- private Button nextButton;
-
- private Button caseButton;
-
- /**
- *
- * Constructor.
- *
- * @param shell
- * @param modelNavigator
- * @deprecated Use {@link #NavigatorSearchDialog(Shell, TreeViewer)}
- */
- @Deprecated
- public NavigatorSearchDialog(Shell shell, CommonNavigator modelNavigator) {
- super(shell);
- IContentProvider cprovider = modelNavigator.getCommonViewer().getContentProvider();
- if (cprovider instanceof ITreeContentProvider) {
- contentProvider = (ITreeContentProvider) cprovider;
- }
- root = modelNavigator.getCommonViewer().getInput();
- viewer = modelNavigator.getCommonViewer();
- labelProvider = (ILabelProvider) modelNavigator.getCommonViewer().getLabelProvider();
-
- }
-
- /**
- * Constructor.
- *
- * @param shell
- * Shell used to show this Dialog
- * @param viewer
- * @param contentProvider
- * @param labelProvider
- * @param root
- */
- public NavigatorSearchDialog(Shell shell, TreeViewer viewer) {
- super(shell);
- this.viewer = viewer;
- try {
- this.labelProvider = (ILabelProvider) viewer.getLabelProvider();
- this.contentProvider = (ITreeContentProvider) viewer.getContentProvider();
- } catch (ClassCastException e) {
- // Content or label provider are not of appropriate type.
- // let them null
- }
- this.root = viewer.getInput();
- }
-
-
- /**
- * Constructor.
- *
- * @param shell
- * Shell used to show this Dialog
- * @param viewer
- * @param contentProvider
- * @param labelProvider
- * @param root
- */
- public NavigatorSearchDialog(Shell shell, Viewer viewer, ITreeContentProvider contentProvider, ILabelProvider labelProvider, Object root) {
- super(shell);
- this.viewer = viewer;
- this.contentProvider = contentProvider;
- this.labelProvider = labelProvider;
- this.root = root;
- }
-
- /**
- * Sets a new selection for the associated {@link ISelectionProvider} and optionally makes it visible.
- * <p>
- * Subclasses must implement this method.
- * </p>
- *
- * @param selection
- * the new selection
- * @param reveal
- * <code>true</code> if the selection is to be made
- * visible, and <code>false</code> otherwise
- */
- private void fireSetSelection(ISelection selection, boolean reveal) {
- // Note : if we want to force reveal, it is possible to check if
- // selectionProvider instanceof Viewer, and then call selectionProvider.setSelection(selection, true).
- // By default a TreeViewer reveal the selection.
- if (viewer instanceof CommonViewer) {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection structured = (IStructuredSelection) selection;
- ModelExplorerView.reveal(Iterables.transform(Lists.newArrayList(structured.iterator()), new Function<Object, EObject>() {
-
- public EObject apply(Object arg0) {
- return EMFHelper.getEObject(arg0);
- }
- }), (CommonViewer) viewer);
- }
- } else if (viewer instanceof Viewer) {
- Viewer view = (Viewer) viewer;
- view.setSelection(selection, true);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
- * .Composite)
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite background = new Composite(parent, SWT.None);
- GridData bgData = new GridData(GridData.FILL_BOTH);
- bgData.minimumWidth = 300;
- background.setLayoutData(bgData);
- GridLayout bgLayout = new GridLayout();
- bgLayout.numColumns = 2;
- background.setLayout(bgLayout);
-
- createSearchTextComposite(background);
-
- getShell().setText("Search");
- return background;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
- * .swt.widgets.Composite)
- */
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
-
- backButton = createButton(parent, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false);
- nextButton = createButton(parent, IDialogConstants.NEXT_ID, IDialogConstants.NEXT_LABEL, false);
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
-
- backButton.setEnabled(false);
- nextButton.setEnabled(false);
-
- nextButton.addSelectionListener(new SelectionListener() {
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- public void widgetSelected(SelectionEvent e) {
- if (currentIndex >= matchedObjects.size() - 1) {
- currentIndex = 0;
- } else {
- currentIndex++;
- }
- fireSetSelection(new StructuredSelection(matchedObjects.get(currentIndex)), true);
- }
-
- });
-
- backButton.addSelectionListener(new SelectionListener() {
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- public void widgetSelected(SelectionEvent e) {
- if (currentIndex <= 0) {
- currentIndex = matchedObjects.size() - 1;
- } else {
- currentIndex--;
- }
- fireSetSelection(new StructuredSelection(matchedObjects.get(currentIndex)), true);
- }
-
- });
- }
-
- @Override
- protected boolean isResizable() {
- return true;
- }
-
- private void createSearchTextComposite(Composite background) {
- Label searchLabel = new Label(background, SWT.None);
- searchLabel.setText("Search:");
- searchLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
-
- searchText = new StringEditor(background, SWT.SEARCH);
- searchText.setFocus();
- searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- searchText.addCommitListener(getCommitListener());
- searchText.setValidateOnDelay(true);
-
- caseButton = new Button(background, SWT.CHECK);
- caseButton.setText("Case sensitive?");
- GridData caseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- caseButtonData.horizontalSpan = 2;
- caseButton.setSelection(false);
- caseButton.setLayoutData(caseButtonData);
- caseButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateMatches();
- }
-
- });
-
- Label resultsLabel = new Label(background, SWT.None);
- resultsLabel.setText("Results:");
- resultsLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
-
- matchesLabel = new Label(background, SWT.None);
- matchesLabel.setText("No matchings.");
- matchesLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
-
- }
-
- protected void clearMatches() {
- matchedObjects = Collections.emptyList();
- currentIndex = 0;
- backButton.setEnabled(false);
- nextButton.setEnabled(false);
- matchesLabel.setText("");
- }
-
- private void updateMatches() {
- if (contentProvider == null && labelProvider == null) {
- return;
- }
-
- String pattern = (String) searchText.getValue();
- if (pattern.length() == 0) {
- clearMatches();
- return;
- }
-
- if (!caseButton.getSelection()) {
- pattern = pattern.toUpperCase();
- }
-
- launchSearch(pattern, contentProvider.getElements(root));
-
- // Update matches label
- matchesLabel.setText(matchedObjects.size() + " matches found");
-
- // Select first match and update buttons
- if (!matchedObjects.isEmpty()) {
- fireSetSelection(new StructuredSelection(matchedObjects.get(0)), true);
- nextButton.setEnabled(true);
- backButton.setEnabled(true);
- } else {
- nextButton.setEnabled(false);
- backButton.setEnabled(false);
- }
-
- }
-
- protected void launchSearch(final String pattern, final Object[] root) {
- final boolean caseSensitive = caseButton.getSelection();
-
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
- try {
- dialog.run(true, true, new IRunnableWithProgress() {
-
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- matchedObjects = searchPattern(pattern, caseSensitive, Arrays.asList(root), monitor);
- currentIndex = 0;
- }
- });
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- private List<Object> searchPattern(String pattern, boolean caseSensitive, List<Object> objects, IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Collections.emptyList();
- }
-
- List<Object> matches = new ArrayList<Object>();
-
- List<Object> children = new ArrayList<Object>();
- String objectLabel;
-
- for (Object o : objects) {
- // Search matches in this level
- if (!(o instanceof Diagram)) {
- objectLabel = caseSensitive ? labelProvider.getText(o) : labelProvider.getText(o).toUpperCase();
-
- if (objectLabel.contains(pattern)) {
- matches.add(o);
- }
- EObject parentEObj = getAdapter(o, EObject.class);
-
- for (int i = 0; i < contentProvider.getChildren(o).length; i++) {
- Object child = contentProvider.getChildren(o)[i];
- // If child can be adapted into a LinkNode, find its referenced EObjects
- if (getAdapter(child, LinkNode.class) != null) {
- for (Object referencedObject : contentProvider.getChildren(child)) {
- EObject referencedEObject = EMFHelper.getEObject(referencedObject);
- if (referencedEObject != null && (parentEObj == null || parentEObj.equals(referencedEObject.eContainer()))) {
- children.add(referencedObject);
- }
- }
- }
- // If it is an EObject, add it to the list
- else {
- EObject eObject = EMFHelper.getEObject(child);
- if (eObject != null && eObject.eContainer() != null && (parentEObj == null || eObject.eContainer().equals(parentEObj))) {
- children.add(child);
- }
- }
- }
- }
- }
- if (!children.isEmpty()) {
- matches.addAll(searchPattern(pattern, caseSensitive, children, monitor));
- }
-
- return matches;
- }
-
- @SuppressWarnings("unchecked")
- public <T> T getAdapter(Object object, Class<? extends T> toAdapt) {
- T result = null;
- if (object instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable) object;
- result = (T) adaptable.getAdapter(toAdapt);
- }
- if (result == null) {
- result = (T) Platform.getAdapterManager().getAdapter(object, toAdapt);
- }
- return result;
- }
-
- protected ICommitListener getCommitListener() {
- return new ICommitListener() {
-
- private String lastValue = "";
-
- public void commit(AbstractEditor editor) {
- String newValue = (String) searchText.getValue();
- if (!lastValue.equals(newValue)) {
- lastValue = newValue;
- updateMatches();
- }
- }
- };
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 Conselleria de Infraestructuras y Transporte, Generalitat
+ * de la Comunitat Valenciana . 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:
+ * Francisco Javier Cano Muñoz (Prodevelop) - initial api contribution
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Improve the searchText widget
+ *
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.dialog;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
+import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
+import org.eclipse.papyrus.infra.widgets.editors.StringEditor;
+import org.eclipse.papyrus.views.modelexplorer.LinkNode;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+/**
+ * A dialog that allows searching elements in the Model navigator by name.
+ *
+ * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano Munoz</a>
+ *
+ * @author cedric dumoulin
+ */
+// @Unused
+// The QuickSearch feature is disabled since the new Search feature is available (0.10)
+public class NavigatorSearchDialog extends TrayDialog {
+
+ private ITreeContentProvider contentProvider = null;
+
+ private ILabelProvider labelProvider = null;
+
+ private Object root = null;
+
+ private ISelectionProvider viewer = null;
+
+ private List<Object> matchedObjects = Collections.emptyList();
+
+ protected int currentIndex = 0;
+
+ private Label matchesLabel;
+
+ private StringEditor searchText;
+
+ private Button backButton;
+
+ private Button nextButton;
+
+ private Button caseButton;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param shell
+ * @param modelNavigator
+ * @deprecated Use {@link #NavigatorSearchDialog(Shell, TreeViewer)}
+ */
+ @Deprecated
+ public NavigatorSearchDialog(Shell shell, CommonNavigator modelNavigator) {
+ super(shell);
+ IContentProvider cprovider = modelNavigator.getCommonViewer().getContentProvider();
+ if (cprovider instanceof ITreeContentProvider) {
+ contentProvider = (ITreeContentProvider) cprovider;
+ }
+ root = modelNavigator.getCommonViewer().getInput();
+ viewer = modelNavigator.getCommonViewer();
+ labelProvider = (ILabelProvider) modelNavigator.getCommonViewer().getLabelProvider();
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param shell
+ * Shell used to show this Dialog
+ * @param viewer
+ * @param contentProvider
+ * @param labelProvider
+ * @param root
+ */
+ public NavigatorSearchDialog(Shell shell, TreeViewer viewer) {
+ super(shell);
+ this.viewer = viewer;
+ try {
+ this.labelProvider = (ILabelProvider) viewer.getLabelProvider();
+ this.contentProvider = (ITreeContentProvider) viewer.getContentProvider();
+ } catch (ClassCastException e) {
+ // Content or label provider are not of appropriate type.
+ // let them null
+ }
+ this.root = viewer.getInput();
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param shell
+ * Shell used to show this Dialog
+ * @param viewer
+ * @param contentProvider
+ * @param labelProvider
+ * @param root
+ */
+ public NavigatorSearchDialog(Shell shell, Viewer viewer, ITreeContentProvider contentProvider, ILabelProvider labelProvider, Object root) {
+ super(shell);
+ this.viewer = viewer;
+ this.contentProvider = contentProvider;
+ this.labelProvider = labelProvider;
+ this.root = root;
+ }
+
+ /**
+ * Sets a new selection for the associated {@link ISelectionProvider} and optionally makes it visible.
+ * <p>
+ * Subclasses must implement this method.
+ * </p>
+ *
+ * @param selection
+ * the new selection
+ * @param reveal
+ * <code>true</code> if the selection is to be made
+ * visible, and <code>false</code> otherwise
+ */
+ private void fireSetSelection(ISelection selection, boolean reveal) {
+ // Note : if we want to force reveal, it is possible to check if
+ // selectionProvider instanceof Viewer, and then call selectionProvider.setSelection(selection, true).
+ // By default a TreeViewer reveal the selection.
+ if (viewer instanceof CommonViewer) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structured = (IStructuredSelection) selection;
+ ModelExplorerView.reveal(Iterables.transform(Lists.newArrayList(structured.iterator()), new Function<Object, EObject>() {
+
+ public EObject apply(Object arg0) {
+ return EMFHelper.getEObject(arg0);
+ }
+ }), (CommonViewer) viewer);
+ }
+ } else if (viewer instanceof Viewer) {
+ Viewer view = (Viewer) viewer;
+ view.setSelection(selection, true);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite background = new Composite(parent, SWT.None);
+ GridData bgData = new GridData(GridData.FILL_BOTH);
+ bgData.minimumWidth = 300;
+ background.setLayoutData(bgData);
+ GridLayout bgLayout = new GridLayout();
+ bgLayout.numColumns = 2;
+ background.setLayout(bgLayout);
+
+ createSearchTextComposite(background);
+
+ getShell().setText("Search");
+ return background;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
+ * .swt.widgets.Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+
+ backButton = createButton(parent, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false);
+ nextButton = createButton(parent, IDialogConstants.NEXT_ID, IDialogConstants.NEXT_LABEL, false);
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+
+ backButton.setEnabled(false);
+ nextButton.setEnabled(false);
+
+ nextButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ if (currentIndex >= matchedObjects.size() - 1) {
+ currentIndex = 0;
+ } else {
+ currentIndex++;
+ }
+ fireSetSelection(new StructuredSelection(matchedObjects.get(currentIndex)), true);
+ }
+
+ });
+
+ backButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ if (currentIndex <= 0) {
+ currentIndex = matchedObjects.size() - 1;
+ } else {
+ currentIndex--;
+ }
+ fireSetSelection(new StructuredSelection(matchedObjects.get(currentIndex)), true);
+ }
+
+ });
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ private void createSearchTextComposite(Composite background) {
+ Label searchLabel = new Label(background, SWT.None);
+ searchLabel.setText("Search:");
+ searchLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+
+ searchText = new StringEditor(background, SWT.SEARCH);
+ searchText.setFocus();
+ searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ searchText.addCommitListener(getCommitListener());
+ searchText.setValidateOnDelay(true);
+
+ caseButton = new Button(background, SWT.CHECK);
+ caseButton.setText("Case sensitive?");
+ GridData caseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+ caseButtonData.horizontalSpan = 2;
+ caseButton.setSelection(false);
+ caseButton.setLayoutData(caseButtonData);
+ caseButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateMatches();
+ }
+
+ });
+
+ Label resultsLabel = new Label(background, SWT.None);
+ resultsLabel.setText("Results:");
+ resultsLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+
+ matchesLabel = new Label(background, SWT.None);
+ matchesLabel.setText("No matchings.");
+ matchesLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
+
+ }
+
+ protected void clearMatches() {
+ matchedObjects = Collections.emptyList();
+ currentIndex = 0;
+ backButton.setEnabled(false);
+ nextButton.setEnabled(false);
+ matchesLabel.setText("");
+ }
+
+ private void updateMatches() {
+ if (contentProvider == null && labelProvider == null) {
+ return;
+ }
+
+ String pattern = (String) searchText.getValue();
+ if (pattern.length() == 0) {
+ clearMatches();
+ return;
+ }
+
+ if (!caseButton.getSelection()) {
+ pattern = pattern.toUpperCase();
+ }
+
+ launchSearch(pattern, contentProvider.getElements(root));
+
+ // Update matches label
+ matchesLabel.setText(matchedObjects.size() + " matches found");
+
+ // Select first match and update buttons
+ if (!matchedObjects.isEmpty()) {
+ fireSetSelection(new StructuredSelection(matchedObjects.get(0)), true);
+ nextButton.setEnabled(true);
+ backButton.setEnabled(true);
+ } else {
+ nextButton.setEnabled(false);
+ backButton.setEnabled(false);
+ }
+
+ }
+
+ protected void launchSearch(final String pattern, final Object[] root) {
+ final boolean caseSensitive = caseButton.getSelection();
+
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
+ try {
+ dialog.run(true, true, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ matchedObjects = searchPattern(pattern, caseSensitive, Arrays.asList(root), monitor);
+ currentIndex = 0;
+ }
+ });
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private List<Object> searchPattern(String pattern, boolean caseSensitive, List<Object> objects, IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return Collections.emptyList();
+ }
+
+ List<Object> matches = new ArrayList<Object>();
+
+ List<Object> children = new ArrayList<Object>();
+ String objectLabel;
+
+ for (Object o : objects) {
+ // Search matches in this level
+ if (!(o instanceof Diagram)) {
+ objectLabel = caseSensitive ? labelProvider.getText(o) : labelProvider.getText(o).toUpperCase();
+
+ if (objectLabel.contains(pattern)) {
+ matches.add(o);
+ }
+ EObject parentEObj = getAdapter(o, EObject.class);
+
+ for (int i = 0; i < contentProvider.getChildren(o).length; i++) {
+ Object child = contentProvider.getChildren(o)[i];
+ // If child can be adapted into a LinkNode, find its referenced EObjects
+ if (getAdapter(child, LinkNode.class) != null) {
+ for (Object referencedObject : contentProvider.getChildren(child)) {
+ EObject referencedEObject = EMFHelper.getEObject(referencedObject);
+ if (referencedEObject != null && (parentEObj == null || parentEObj.equals(referencedEObject.eContainer()))) {
+ children.add(referencedObject);
+ }
+ }
+ }
+ // If it is an EObject, add it to the list
+ else {
+ EObject eObject = EMFHelper.getEObject(child);
+ if (eObject != null && eObject.eContainer() != null && (parentEObj == null || eObject.eContainer().equals(parentEObj))) {
+ children.add(child);
+ }
+ }
+ }
+ }
+ }
+ if (!children.isEmpty()) {
+ matches.addAll(searchPattern(pattern, caseSensitive, children, monitor));
+ }
+
+ return matches;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getAdapter(Object object, Class<? extends T> toAdapt) {
+ T result = null;
+ if (object instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) object;
+ result = adaptable.getAdapter(toAdapt);
+ }
+ if (result == null) {
+ result = Platform.getAdapterManager().getAdapter(object, toAdapt);
+ }
+ return result;
+ }
+
+ protected ICommitListener getCommitListener() {
+ return new ICommitListener() {
+
+ private String lastValue = "";
+
+ public void commit(AbstractEditor editor) {
+ String newValue = (String) searchText.getValue();
+ if (!lastValue.equals(newValue)) {
+ lastValue = newValue;
+ updateMatches();
+ }
+ }
+ };
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java
index e58fd269246..cdc02e5420c 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractModelExplorerHandler.java
@@ -1,163 +1,163 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.handler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * This provides facilities to get the TransactionEditingDomain and the PageManager from the Model Explorer
- *
- *
- *
- */
-public abstract class AbstractModelExplorerHandler extends AbstractHandler {
-
- /**
- * Returns the
- *
- * @return
- * the current editing domain
- */
- protected TransactionalEditingDomain getEditingDomain() {
- TransactionalEditingDomain editingDomain = null;
- try {
- editingDomain = org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
- } catch (ServiceException e) {
- // we are closing the editor, so the model explorer has nothing to display
- // e.printStackTrace();
- }
- return editingDomain;
- }
-
- /**
- * Returns the page manager
- *
- * @return
- * the page manager
- */
- protected IPageManager getPageManager() {
- IPageManager pageManager = null;
- try {
- pageManager = ServiceUtilsForActionHandlers.getInstance().getIPageManager();
- } catch (ServiceException e) {
- // we are closing the editor, so the model explorer has nothing to display
- // e.printStackTrace();
- }
- return pageManager;
- }
-
- /**
- * Adapt the specified object to the requested type, if possible.
- * Return null if the object can't be adapted.
- *
- * @param object
- * @param expectedClassType
- * @return The adapted object, or null.
- */
- @SuppressWarnings("unchecked")
- private <T> T adapt(Object object, Class<T> expectedClassType) {
-
-
- EObject eobject = EMFHelper.getEObject(object);
-
- if (eobject != null && expectedClassType.isInstance(eobject)) {
- return (T) eobject;
- }
-
-
-
- // Try global mechanism
- {
- T ele = (T) Platform.getAdapterManager().getAdapter(object, expectedClassType);
- if (ele != null) {
- return ele;
- }
- // Try as EObject if the expectedClasType is sub-type of EObject.
- if (EObject.class.isAssignableFrom(expectedClassType)) {
- // to EObject
- eobject = (EObject) Platform.getAdapterManager().getAdapter(object, EObject.class);
-
- if (eobject != null && expectedClassType.isInstance(eobject)) {
-
- return (T) eobject;
- }
- }
- }
- // Can't be adapted
- return null;
-
- }
-
- /**
- * Filter the list, and only retain objects that can be adapted to the specified type
- *
- * @param objects
- * @param class1
- * @return
- */
- private <T> List<T> getAllElementAdaptedToType(List<Object> list, Class<T> expectedClassType) {
-
- List<T> res = new ArrayList<T>();
-
- for (Object cur : list) {
-
- T adapted = adapt(cur, expectedClassType);
- if (adapted != null) {
- res.add(adapted);
- }
- }
- return res;
- }
-
- /**
- * Get all selected element of the specified type.
- *
- * @param expectedType
- * @return
- * @throws ExecutionException
- */
- @SuppressWarnings("unchecked")
- protected <T> List<T> getCurrentSelectionAdaptedToType(ExecutionEvent event, Class<T> expectedType) throws ExecutionException {
-
- // Get selection from the workbench
- ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
-
- // Get the selected objects according to the type of the selected
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- return getAllElementAdaptedToType(structuredSelection.toList(), expectedType);
- } else if (selection instanceof TreeSelection) {
- TreeSelection treeSelection = (TreeSelection) selection;
- return getAllElementAdaptedToType(treeSelection.toList(), expectedType);
-
- }
- return null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * This provides facilities to get the TransactionEditingDomain and the PageManager from the Model Explorer
+ *
+ *
+ *
+ */
+public abstract class AbstractModelExplorerHandler extends AbstractHandler {
+
+ /**
+ * Returns the
+ *
+ * @return
+ * the current editing domain
+ */
+ protected TransactionalEditingDomain getEditingDomain() {
+ TransactionalEditingDomain editingDomain = null;
+ try {
+ editingDomain = org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ } catch (ServiceException e) {
+ // we are closing the editor, so the model explorer has nothing to display
+ // e.printStackTrace();
+ }
+ return editingDomain;
+ }
+
+ /**
+ * Returns the page manager
+ *
+ * @return
+ * the page manager
+ */
+ protected IPageManager getPageManager() {
+ IPageManager pageManager = null;
+ try {
+ pageManager = ServiceUtilsForActionHandlers.getInstance().getIPageManager();
+ } catch (ServiceException e) {
+ // we are closing the editor, so the model explorer has nothing to display
+ // e.printStackTrace();
+ }
+ return pageManager;
+ }
+
+ /**
+ * Adapt the specified object to the requested type, if possible.
+ * Return null if the object can't be adapted.
+ *
+ * @param object
+ * @param expectedClassType
+ * @return The adapted object, or null.
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T adapt(Object object, Class<T> expectedClassType) {
+
+
+ EObject eobject = EMFHelper.getEObject(object);
+
+ if (eobject != null && expectedClassType.isInstance(eobject)) {
+ return (T) eobject;
+ }
+
+
+
+ // Try global mechanism
+ {
+ T ele = Platform.getAdapterManager().getAdapter(object, expectedClassType);
+ if (ele != null) {
+ return ele;
+ }
+ // Try as EObject if the expectedClasType is sub-type of EObject.
+ if (EObject.class.isAssignableFrom(expectedClassType)) {
+ // to EObject
+ eobject = Platform.getAdapterManager().getAdapter(object, EObject.class);
+
+ if (eobject != null && expectedClassType.isInstance(eobject)) {
+
+ return (T) eobject;
+ }
+ }
+ }
+ // Can't be adapted
+ return null;
+
+ }
+
+ /**
+ * Filter the list, and only retain objects that can be adapted to the specified type
+ *
+ * @param objects
+ * @param class1
+ * @return
+ */
+ private <T> List<T> getAllElementAdaptedToType(List<Object> list, Class<T> expectedClassType) {
+
+ List<T> res = new ArrayList<T>();
+
+ for (Object cur : list) {
+
+ T adapted = adapt(cur, expectedClassType);
+ if (adapted != null) {
+ res.add(adapted);
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Get all selected element of the specified type.
+ *
+ * @param expectedType
+ * @return
+ * @throws ExecutionException
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> List<T> getCurrentSelectionAdaptedToType(ExecutionEvent event, Class<T> expectedType) throws ExecutionException {
+
+ // Get selection from the workbench
+ ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
+
+ // Get the selected objects according to the type of the selected
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ return getAllElementAdaptedToType(structuredSelection.toList(), expectedType);
+ } else if (selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection) selection;
+ return getAllElementAdaptedToType(treeSelection.toList(), expectedType);
+
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java
index 65a418bc1e7..2de12e791ce 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java
@@ -73,7 +73,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan
/**
* Return if the parameter is page.
- *
+ *
* @param current
* @return
*/
@@ -97,7 +97,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan
* elements.
* @param selectedElements elements to delete
* @return the composite deletion command for current selection
- *
+ *
* @TODO : Manage possible Diagrams listed in the selection
*
* </pre>
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java
index 5ff9e7ee1bf..ff9e5eae1bf 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/PasteHandler.java
@@ -59,7 +59,7 @@ public class PasteHandler extends AbstractCommandHandler {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#computeEnabled()
*/
@Override
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java
index e08f794eb21..3b2f5c0b1c4 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java
@@ -1,122 +1,122 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 450235
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.listener;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenable;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.views.modelexplorer.Activator;
-import org.eclipse.papyrus.views.modelexplorer.Messages;
-
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-
-/**
- * this class is a listener in charge to manage double on element of the model explorer
- *
- */
-public class DoubleClickListener implements IDoubleClickListener {
-
- private final Supplier<ServicesRegistry> servicesRegistry;
-
- /**
- * Initializes me with a fixed service registry.
- *
- * @param servicesRegistry a service registry
- *
- * @deprecated The editor that the Model Explorer views can change dynamically, replacing its service registry. Use the {@link #DoubleClickListener(Supplier)} constructor instead to account for the variability of the registry.
- */
- @Deprecated
- public DoubleClickListener(ServicesRegistry servicesRegistry) {
- this(Suppliers.ofInstance(servicesRegistry));
- }
-
- /**
- * Initializes me with a variable service registry.
- *
- * @param servicesRegistrySupplier a supplier of a dynamically variable service registry
- */
- public DoubleClickListener(Supplier<ServicesRegistry> servicesRegistrySupplier) {
- this.servicesRegistry = servicesRegistrySupplier;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
- *
- */
- public void doubleClick(DoubleClickEvent event) {
- ISelection selection = event.getSelection();
- final IPageManager pageManager;
- // get the page Manager
- try {
- pageManager = ServiceUtils.getInstance().getIPageManager(servicesRegistry.get());
- } catch (Exception e) {
- Activator.log.error(Messages.DoubleClickListener_Error_NoLoadManagerToOpen, e);
- return;
- }
-
- if (pageManager != null) {
- if (selection instanceof IStructuredSelection) {
- Iterator<?> iter = ((IStructuredSelection) selection).iterator();
- final List<EObject> pagesToOpen = new LinkedList<EObject>();
- EObject pageToSelect = null;
- while (iter.hasNext()) {
- Object currentObject = iter.next();
- EObject diag = EMFHelper.getEObject(currentObject);
-
- if (isPage(diag, pageManager)) {
- // Note that Diagram migration is triggered by the Diagram Editor.
- // Try to open the diagram, even if it is currently invalid. The editor might be able to repair it
- if (pageManager.isOpen(diag)) {
- pageToSelect = diag;
- } else {
- pagesToOpen.add(diag);
- }
- }
- }
-
- if (!pagesToOpen.isEmpty()) {
- for (EObject page : pagesToOpen) {
- pageManager.openPage(page);
- }
- } else if (pageToSelect != null) {
- pageManager.selectPage(pageToSelect);
- }
- }
-
- }
- }
-
- protected boolean isPage(EObject element, IPageManager pageManager) {
- if (pageManager.allPages().contains(element)) {
- return true;
- }
-
- Object openable = Platform.getAdapterManager().getAdapter(element, IOpenable.class);
- return openable instanceof IOpenable;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 450235
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.listener;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenable;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.views.modelexplorer.Activator;
+import org.eclipse.papyrus.views.modelexplorer.Messages;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+
+/**
+ * this class is a listener in charge to manage double on element of the model explorer
+ *
+ */
+public class DoubleClickListener implements IDoubleClickListener {
+
+ private final Supplier<ServicesRegistry> servicesRegistry;
+
+ /**
+ * Initializes me with a fixed service registry.
+ *
+ * @param servicesRegistry a service registry
+ *
+ * @deprecated The editor that the Model Explorer views can change dynamically, replacing its service registry. Use the {@link #DoubleClickListener(Supplier)} constructor instead to account for the variability of the registry.
+ */
+ @Deprecated
+ public DoubleClickListener(ServicesRegistry servicesRegistry) {
+ this(Suppliers.ofInstance(servicesRegistry));
+ }
+
+ /**
+ * Initializes me with a variable service registry.
+ *
+ * @param servicesRegistrySupplier a supplier of a dynamically variable service registry
+ */
+ public DoubleClickListener(Supplier<ServicesRegistry> servicesRegistrySupplier) {
+ this.servicesRegistry = servicesRegistrySupplier;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
+ *
+ */
+ public void doubleClick(DoubleClickEvent event) {
+ ISelection selection = event.getSelection();
+ final IPageManager pageManager;
+ // get the page Manager
+ try {
+ pageManager = ServiceUtils.getInstance().getIPageManager(servicesRegistry.get());
+ } catch (Exception e) {
+ Activator.log.error(Messages.DoubleClickListener_Error_NoLoadManagerToOpen, e);
+ return;
+ }
+
+ if (pageManager != null) {
+ if (selection instanceof IStructuredSelection) {
+ Iterator<?> iter = ((IStructuredSelection) selection).iterator();
+ final List<EObject> pagesToOpen = new LinkedList<EObject>();
+ EObject pageToSelect = null;
+ while (iter.hasNext()) {
+ Object currentObject = iter.next();
+ EObject diag = EMFHelper.getEObject(currentObject);
+
+ if (isPage(diag, pageManager)) {
+ // Note that Diagram migration is triggered by the Diagram Editor.
+ // Try to open the diagram, even if it is currently invalid. The editor might be able to repair it
+ if (pageManager.isOpen(diag)) {
+ pageToSelect = diag;
+ } else {
+ pagesToOpen.add(diag);
+ }
+ }
+ }
+
+ if (!pagesToOpen.isEmpty()) {
+ for (EObject page : pagesToOpen) {
+ pageManager.openPage(page);
+ }
+ } else if (pageToSelect != null) {
+ pageManager.selectPage(pageToSelect);
+ }
+ }
+
+ }
+ }
+
+ protected boolean isPage(EObject element, IPageManager pageManager) {
+ if (pageManager.allPages().contains(element)) {
+ return true;
+ }
+
+ Object openable = Platform.getAdapterManager().getAdapter(element, IOpenable.class);
+ return openable instanceof IOpenable;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java
index 163c6e6e6f2..24d2ac90e1e 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java
@@ -37,7 +37,7 @@ public class DefaultTreeViewerSorting implements ITreeViewerSorting {
ITreeViewerSorting result = null;
if (part != null) {
- result = (ITreeViewerSorting) part.getAdapter(ITreeViewerSorting.class);
+ result = part.getAdapter(ITreeViewerSorting.class);
}
if (result == null) {

Back to the top