Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Li2016-04-20 17:45:24 +0000
committerGerrit Code Review @ Eclipse.org2016-05-02 18:20:43 +0000
commited02dace3b024be692341d925e65caf06f57144b (patch)
tree2fc88ec8c8c916316802d9e9bca7f686c298979b /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation
parent8cbc706919d1f69aa676d3407ae0c34ac7e24fb8 (diff)
downloadorg.eclipse.papyrus-ed02dace3b024be692341d925e65caf06f57144b.tar.gz
org.eclipse.papyrus-ed02dace3b024be692341d925e65caf06f57144b.tar.xz
org.eclipse.papyrus-ed02dace3b024be692341d925e65caf06f57144b.zip
Bug 491077 - [Usability] Make the current alt-navigation menu easier to
access - Move navigable elements and their sub-menus from alt-menu to "Navigate" popup menu - The "Navigate" menu already exists in the diagrams popup menu - The "Navigate" menu is added in the tools group of the model explorer popup menu - Move parents/children, targets/sources from "More..." to navigable elements in alt-menu and popup menu - Clicking on a navigable element in alt-menu goes directly to the first found view or model explorer otherwise. The first found view cannot be the view that triggered the alt-menu. - Add model explorer icon - Cleanup Change-Id: I91853623c5e6fccae24f2eddbd2367bd94ece929 Signed-off-by: Shuai Li <shuai.li@cea.fr>
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/icons/ModelExplorer.gifbin0 -> 114 bytes
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/plugin.xml28
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/Activator.java3
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/DefaultNavigationMenu.java16
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuMouseTrackListener.java30
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/menu/listener/SelectionMenuSelectionChangedListener.java20
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DiagramDynamicNavigate.java137
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigate.java132
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigateLabelProvider.java104
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/ModelExplorerDynamicNavigate.java136
10 files changed, 574 insertions, 32 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/icons/ModelExplorer.gif b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/icons/ModelExplorer.gif
new file mode 100644
index 00000000000..acb63823aa3
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/icons/ModelExplorer.gif
Binary files differ
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 4b28c900086..24cf67ab522 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
@@ -47,6 +47,34 @@
menu="org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu">
</menu>
</extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup?after=tools">
+ <menu
+ id="org.eclipse.papyrus.infra.services.navigation.ui.popup.navigate"
+ label="Navigate"
+ tooltip="Navigate from this element">
+ <dynamic
+ class="org.eclipse.papyrus.infra.gmfdiag.navigation.ui.ModelExplorerDynamicNavigate"
+ id="org.eclipse.papyrus.infra.gmfdiag.navigation.ui.popup.modelExplorerDynamicNavigate">
+ </dynamic>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
+ <menu
+ id="navigateMenu"
+ label="Navigate">
+ <dynamic
+ class="org.eclipse.papyrus.infra.gmfdiag.navigation.ui.DiagramDynamicNavigate"
+ id="org.eclipse.papyrus.infra.gmfdiag.navigation.ui.popup.diagramDynamicNavigate">
+ </dynamic>
+ </menu>
+ </menuContribution>
+ </extension>
<!--commented for the build Juno M4, because perspective doesn't work-->
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/Activator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/Activator.java
index 0bb77bd9de9..b1ba94d9635 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/Activator.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/Activator.java
@@ -29,6 +29,8 @@ public class Activator extends AbstractUIPlugin {
public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.gmfdiag.navigation"; //$NON-NLS-1$
public static final String IMG_SEPARATOR = "separator"; //$NON-NLS-1$
+
+ public static final String IMG_MODEL_EXPLORER = "modelexplorer"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
@@ -99,6 +101,7 @@ public class Activator extends AbstractUIPlugin {
super.initializeImageRegistry(reg);
reg.put(IMG_SEPARATOR, imageDescriptorFromPlugin(PLUGIN_ID, "icons/separator.gif")); //$NON-NLS-1$
+ reg.put(IMG_MODEL_EXPLORER, imageDescriptorFromPlugin(PLUGIN_ID, "icons/ModelExplorer.gif")); //$NON-NLS-1$
}
public Image getIcon(String key) {
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
index c52d22d9f86..5686a217f81 100644
--- 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
@@ -23,6 +23,7 @@ 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.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.services.BadStateException;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
@@ -73,6 +74,8 @@ public class DefaultNavigationMenu implements NavigationMenu {
private WrappingLabel lastWrappingLabel;
private static boolean altReleasedPostNavigation = true;
+
+ private View selectedView;
public class NavigationMenuInitializationException extends Exception {
private static final long serialVersionUID = 1094797103244873186L;
@@ -279,7 +282,7 @@ public class DefaultNavigationMenu implements NavigationMenu {
}
// Add "More..." button
- navigationMenuElements.add(new MoreButton());
+ //navigationMenuElements.add(new MoreButton());
// The semantic element
EObject umlElement = EMFHelper.getEObject(source);
@@ -296,6 +299,7 @@ public class DefaultNavigationMenu implements NavigationMenu {
wasUnderlined = false;
if (source instanceof IGraphicalEditPart) {
+ selectedView = ((IGraphicalEditPart) source).getPrimaryView();
IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) source;
IFigure figure = graphicalEditPart.getFigure();
if (figure instanceof WrappingLabel) {
@@ -303,11 +307,13 @@ public class DefaultNavigationMenu implements NavigationMenu {
wasUnderlined = lastWrappingLabel.isTextUnderlined();
lastWrappingLabel.setTextUnderline(!wasUnderlined);
}
+ } else {
+ selectedView = null;
}
selectionMenu.addSelectionChangedListener(new SelectionMenuSelectionChangedListener(DefaultNavigationMenu.this, selectionMenu, navigationMenuElements, umlElement, subMenus));
selectionMenu.addKeyListener(new NavigationMenuKeyListener(this));
- selectionMenu.addMouseTrackListener(new SelectionMenuMouseTrackListener(DefaultNavigationMenu.this, selectionMenu, subMenus, umlElement));
+ //selectionMenu.addMouseTrackListener(new SelectionMenuMouseTrackListener(DefaultNavigationMenu.this, selectionMenu, subMenus, umlElement));
}
public void addContextualMenus(List<Object> navigationMenuElements, Object umlElement) {
@@ -341,7 +347,7 @@ public class DefaultNavigationMenu implements NavigationMenu {
}
if (viewerSearchService != null) {
- return viewerSearchService.getViewersInCurrentModel(element, null, false, true);
+ return viewerSearchService.getViewersInCurrentModel(element, null, false, onlyOpened);
}
}
@@ -560,6 +566,10 @@ public class DefaultNavigationMenu implements NavigationMenu {
Activator.log.error(e);
}
}
+
+ public View getSelectedView() {
+ return selectedView;
+ }
/**
* @see org.eclipse.papyrus.infra.services.navigation.service.NavigationMenu#setParentShell(org.eclipse.swt.widgets.Shell)
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
index 7451095feee..23d5c70e472 100644
--- 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
@@ -99,35 +99,7 @@ public class SelectionMenuMouseTrackListener implements MouseTrackListener {
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) {
+ if (hoveredItem instanceof NavigationSubMenuButton) {
SelectionMenu dynamicSelectionMenu = new SelectionMenu(selectionMenu.getShell(), event.getSource(), cursorPosition);
dynamicSelectionMenu.setLabelProvider(new SelectionMenuLabelProvider());
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
index 1319d09ebad..f96e166b3ca 100644
--- 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
@@ -14,9 +14,12 @@
package org.eclipse.papyrus.infra.gmfdiag.navigation.menu.listener;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -88,6 +91,23 @@ public class SelectionMenuSelectionChangedListener implements ISelectionChangedL
}
if (selectedElement instanceof NavigableElement) {
+ // Get views that represent the selectedElement is represented
+ List<Object> viewsToSelect = navigationMenu.getViewsToSelect((NavigableElement) selectedElement, false);
+
+ // If the selected view triggered the menu, check that it is not in the list of views to navigate to
+ if (viewsToSelect != null && !viewsToSelect.isEmpty()) {
+ if (navigationMenu.getSelectedView() != null) {
+ viewsToSelect.removeAll(Collections.singleton(navigationMenu.getSelectedView()));
+ }
+
+ if (!viewsToSelect.isEmpty()) {
+ // Navigate to the first view of the list that represents the selectedElement
+ navigationMenu.revealObject(viewsToSelect.get(0));
+ return;
+ }
+ }
+
+ // No views to navigate to => go to model explorer
navigationMenu.showInModelExplorer((NavigableElement) selectedElement);
} else if (selectedElement instanceof HyperlinkButton) {
((HyperlinkButton) selectedElement).getAction().run();
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DiagramDynamicNavigate.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DiagramDynamicNavigate.java
new file mode 100644
index 00000000000..59930962701
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DiagramDynamicNavigate.java
@@ -0,0 +1,137 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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.ui;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.emf.utils.ServiceUtilsForEObject;
+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.NavigationService;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A dynamic menu of Navigate, which will provide navigable element contribution items for views in a diagram
+ */
+public class DiagramDynamicNavigate extends DynamicNavigate {
+ View selectedView;
+
+ @Override
+ public void fill(Menu menu, int index) {
+ EObject selectedObject = getSelection();
+
+ if (navigationService != null) {
+ List<NavigableElement> navigableElements = navigationService.getNavigableElements(selectedObject);
+
+ if (navigableElements != null) {
+ for (final NavigableElement navigableElement : navigableElements) {
+ List<Object> viewsToSelect = getViewsToSelect(navigableElement, false);
+
+ MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
+ menuItem.setText(navigableElement.getLabel());
+ menuItem.setImage(navigableElement.getImage());
+ menuItem.setToolTipText(navigableElement.getDescription());
+ menuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ showInModelExplorer(navigableElement);
+ }
+ });
+
+ menuItem.setMenu(new Menu(menuItem));
+ Menu subMenu = menuItem.getMenu();
+
+ MenuItem subMenuItem = new MenuItem(subMenu, SWT.CHECK);
+ subMenuItem.setText("Model Explorer");
+ subMenuItem.setImage(Activator.getDefault().getIcon(Activator.IMG_MODEL_EXPLORER));
+ subMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ showInModelExplorer(navigableElement);
+ }
+ });
+
+ for (final Object view : viewsToSelect) {
+ if (view instanceof EObject && selectedView != view) {
+ MenuItem subMenuViewItem = new MenuItem(subMenu, SWT.CHECK);
+ subMenuViewItem.setText(DynamicNavigateLabelProvider.getText(view));
+ subMenuViewItem.setToolTipText(DynamicNavigateLabelProvider.getToolTipText(view));
+ subMenuViewItem.setImage(DynamicNavigateLabelProvider.getImage(view));
+ subMenuViewItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ revealObject(view);
+ }
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.navigation.ui.DynamicNavigate#getSelection()
+ *
+ * @return
+ */
+ protected EObject getSelection() {
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow != null) {
+ ISelection selection = activeWorkbenchWindow.getSelectionService().getSelection();
+ if (false == selection instanceof IStructuredSelection) {
+ return null;
+ }
+ for (Object object : ((IStructuredSelection) selection).toList()) {
+ if (false == object instanceof IGraphicalEditPart) {
+ continue;
+ }
+ if (object instanceof DiagramEditPart) {
+ continue;
+ }
+ View view = ((IGraphicalEditPart) object).getNotationView();
+ if (view.getEAnnotation("Shortcut") != null) {
+ continue;
+ }
+
+ try {
+ ServicesRegistry registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(view);
+ if (registry != null) {
+ navigationService = registry.getService(NavigationService.class);
+ this.selectedView = view;
+ return EMFHelper.getEObject(object);
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ return null;
+ }
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigate.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigate.java
new file mode 100644
index 00000000000..f91494e3a47
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigate.java
@@ -0,0 +1,132 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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.ui;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.navigation.menu.DefaultNavigationMenu.NavigationMenuInitializationException;
+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.NavigationService;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.infra.services.viewersearch.impl.ViewerSearchService;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A dynamic menu of Navigate, which will provide navigable element contribution items
+ */
+public abstract class DynamicNavigate extends ContributionItem {
+ NavigationService navigationService;
+
+ /**
+ * Get selected eObject
+ *
+ * @return eObject or null
+ */
+ protected abstract EObject getSelection();
+
+ /**
+ * Show a navigable element in the model explorer
+ *
+ * @param navigableElement
+ * The navigable element to show in the model explorer
+ */
+ public void showInModelExplorer(NavigableElement navigableElement) {
+ Object semanticElement = null;
+ if (navigableElement instanceof ExtendedNavigableElement) {
+ semanticElement = ((ExtendedNavigableElement) navigableElement).getSemanticElement();
+ }
+
+ if (semanticElement != null) {
+ try {
+ navigationService.navigate(semanticElement, "org.eclipse.papyrus.views.modelexplorer.navigation.target");
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ * Reveal a view object (i.e. notation element).
+ * Currently only diagrams are supported.
+ *
+ * @param object
+ * The view object to reveal
+ */
+ public void revealObject(Object object) {
+ if (object instanceof EObject) {
+ try {
+ OpenElementService service = ServiceUtilsForEObject.getInstance().getService(OpenElementService.class, (EObject) object);
+ service.openElement((EObject) object);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+ }
+
+ /**
+ * Get views representing a navigable element
+ *
+ * @param navElement
+ * The navigable element represented in views
+ * @param onlyOpened
+ * Only opened views are returned
+ * @return
+ * List of views representing the navigable element
+ */
+ 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 = ServiceUtilsForEObject.getInstance().getService(ViewerSearchService.class, element);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ if (viewerSearchService != null) {
+ return viewerSearchService.getViewersInCurrentModel(element, null, false, onlyOpened);
+ }
+ }
+
+ return new LinkedList<Object>();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigateLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigateLabelProvider.java
new file mode 100644
index 00000000000..40d01dee4ac
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/DynamicNavigateLabelProvider.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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.ui;
+
+import org.eclipse.emf.ecore.EObject;
+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.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.navigation.Activator;
+import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Label provider for navigation popup menu
+ *
+ */
+public class DynamicNavigateLabelProvider {
+ protected static boolean isLocalLabelProvider;
+
+ public static String getText(Object element) {
+ if (element instanceof NavigableElement) {
+ return ((NavigableElement) element).getLabel();
+ } else if (element instanceof EObject) {
+ return getName((EObject) element);
+ }
+
+ return element.toString();
+ }
+
+ public static Image getImage(Object element) {
+ if (element instanceof EObject) {
+ ILabelProvider labelProvider = getLabelProvider((EObject) element);
+
+ if (labelProvider != null) {
+ Image icon = null;
+ icon = labelProvider.getImage(element);
+
+ if (isLocalLabelProvider) {
+ labelProvider.dispose();
+ }
+
+ return icon;
+ }
+ }
+
+ return null;
+ }
+
+ public static String getToolTipText(Object element) {
+ if (element instanceof EObject) {
+ return getName((EObject) element);
+ }
+
+ return element.toString();
+ }
+
+ protected static 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 static 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();
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/ModelExplorerDynamicNavigate.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/ModelExplorerDynamicNavigate.java
new file mode 100644
index 00000000000..07a8d9025a4
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/infra/gmfdiag/navigation/ui/ModelExplorerDynamicNavigate.java
@@ -0,0 +1,136 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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.ui;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.emf.utils.ServiceUtilsForEObject;
+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.NavigationService;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A dynamic menu of Navigate, which will provide navigable element contribution items for the model explorer
+ */
+public class ModelExplorerDynamicNavigate extends DynamicNavigate {
+ @Override
+ public void fill(Menu menu, int index) {
+ EObject selectedObject = getSelection();
+
+ if (navigationService != null) {
+ List<NavigableElement> navigableElements = navigationService.getNavigableElements(selectedObject);
+
+ if (navigableElements != null) {
+ for (final NavigableElement navigableElement : navigableElements) {
+ List<Object> viewsToSelect = getViewsToSelect(navigableElement, false);
+
+ if (viewsToSelect == null || viewsToSelect.isEmpty()) {
+ // TODO make this flexible, instead of hard coded...
+ if (navigableElement.getLabel().startsWith("Go to element (")) {
+ continue; // Ignore default navigable element provided by ElementNavigationContributor if there are no views for it
+ }
+ }
+
+ MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
+ menuItem.setText(navigableElement.getLabel());
+ menuItem.setImage(navigableElement.getImage());
+ menuItem.setToolTipText(navigableElement.getDescription());
+ menuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ showInModelExplorer(navigableElement);
+ }
+ });
+
+ menuItem.setMenu(new Menu(menuItem));
+ Menu subMenu = menuItem.getMenu();
+
+ // TODO make this flexible, instead of hard coded...
+ if (!navigableElement.getLabel().startsWith("Go to element (")) {
+ MenuItem subMenuItem = new MenuItem(subMenu, SWT.CHECK);
+ subMenuItem.setText("Model Explorer");
+ subMenuItem.setImage(Activator.getDefault().getIcon(Activator.IMG_MODEL_EXPLORER));
+ subMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ showInModelExplorer(navigableElement);
+ }
+ });
+ }
+
+ for (final Object view : viewsToSelect) {
+ if (view instanceof EObject) {
+ MenuItem subMenuViewItem = new MenuItem(subMenu, SWT.CHECK);
+ subMenuViewItem.setText(DynamicNavigateLabelProvider.getText(view));
+ subMenuViewItem.setToolTipText(DynamicNavigateLabelProvider.getToolTipText(view));
+ subMenuViewItem.setImage(DynamicNavigateLabelProvider.getImage(view));
+ subMenuViewItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ revealObject(view);
+ }
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.navigation.ui.DynamicNavigate#getSelection()
+ *
+ * @return
+ */
+ protected EObject getSelection() {
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ if (selectionService == null) {
+ return null;
+ }
+ ISelection selection = selectionService.getSelection();
+
+ if (selection == null || selection.isEmpty()) {
+ return null;
+ }
+
+ if (selection instanceof IStructuredSelection) {
+ Object selectedobject = ((IStructuredSelection) selection).getFirstElement();
+ EObject selectedEObject = EMFHelper.getEObject(selectedobject);
+
+ try {
+ ServicesRegistry registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(selectedEObject);
+ if (registry != null) {
+ navigationService = registry.getService(NavigationService.class);
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+
+ return selectedEObject;
+ }
+ return null;
+ }
+}

Back to the top