Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2011-11-02 09:38:54 +0000
committercletavernie2011-11-02 09:38:54 +0000
commitf371b929b8e4498a1a2794dbbbdc7bfeca62f21b (patch)
tree0d1dd052402fd55afba2664f07bf37b2747e145f /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src
parente0f6f4b4729c4bd0c7747a6423cc4de5f4f6d59c (diff)
downloadorg.eclipse.papyrus-f371b929b8e4498a1a2794dbbbdc7bfeca62f21b.tar.gz
org.eclipse.papyrus-f371b929b8e4498a1a2794dbbbdc7bfeca62f21b.tar.xz
org.eclipse.papyrus-f371b929b8e4498a1a2794dbbbdc7bfeca62f21b.zip
362162: [Architecture - Refactoring] The plug-ins should be renamed to match their layer's qualified name
https://bugs.eclipse.org/bugs/show_bug.cgi?id=362162
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Activator.java98
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java141
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java66
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java37
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java29
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java27
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java43
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Messages.java31
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java66
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java154
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java216
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java98
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/BackNavigateHandler.java54
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/NextNavigateHandler.java53
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/TopNavigateHandler.java105
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/UpNavigateHandler.java93
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/messages.properties8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java37
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java40
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java49
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/Messages.java27
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/MultiDiagramDialog.java176
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/PropertyTester.java77
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/messages.properties6
24 files changed, 1731 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Activator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Activator.java
new file mode 100644
index 00000000000..08a476750a8
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Activator.java
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * 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.navigation;
+
+import org.eclipse.papyrus.navigation.preference.NavigationPreferenceInitializer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.navigation"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ NavigationPreferenceInitializer preferenceInitializer = new NavigationPreferenceInitializer();
+ preferenceInitializer.initializeDefaultPreferences();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the active workbench shell
+ *
+ * @return the active workbench shell
+ */
+ public static Shell getActiveWorkbenchShell() {
+ IWorkbenchWindow workBenchWindow = getActiveWorkbenchWindow();
+ if(workBenchWindow == null) {
+ return null;
+ }
+ return workBenchWindow.getShell();
+ }
+
+ /**
+ * Returns the active workbench window
+ *
+ * @return the active workbench window
+ */
+ public static IWorkbenchWindow getActiveWorkbenchWindow() {
+ if(getDefault() == null) {
+ return null;
+ }
+ IWorkbench workBench = getDefault().getWorkbench();
+ if(workBench == null) {
+ return null;
+ }
+ return workBench.getActiveWorkbenchWindow();
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java
new file mode 100644
index 00000000000..4843b43c427
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import java.util.Collections;
+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.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.core.extension.commands.ICreationCondition;
+import org.eclipse.papyrus.core.utils.BusinessModelResolver;
+import org.eclipse.papyrus.core.utils.DiResourceSet;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.ui.toolbox.dialog.InformationDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This command handler will try to create a diagram on the currently selected
+ * element, using navigation if necessary. The action is always available and
+ * the check is done in the run to avoid heavy navigation computation on each
+ * selection change.
+ *
+ * @author mvelten
+ *
+ */
+public abstract class CreateDiagramWithNavigationHandler extends AbstractHandler {
+
+ private ICreationCondition creationCondition;
+
+ private ICreationCommand creationCommand;
+
+ public CreateDiagramWithNavigationHandler(ICreationCommand creationCommand, ICreationCondition creationCondition) {
+ super();
+ this.creationCommand = creationCommand;
+ this.creationCondition = creationCondition;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ NavigableElement navElement = getNavigableElementWhereToCreateDiagram();
+
+ if(navElement == null) {
+ InformationDialog dialog = new InformationDialog(Display.getCurrent().getActiveShell(), "Impossible diagram creation", "It is not possible to create this diagram on the selected element.", null, null, SWT.OK, MessageDialog.WARNING, new String[]{ IDialogConstants.OK_LABEL });
+ dialog.open();
+ } else {
+ createDiagram(navElement);
+ }
+ return null;
+ }
+
+ private NavigableElement getNavigableElementWhereToCreateDiagram() {
+ EObject selectedElement = getSelectedElement();
+
+ if(selectedElement != null) {
+ // First check if the current element can host the requested diagram
+ if(creationCondition.create(selectedElement)) {
+ return new ExistingNavigableElement(selectedElement, null);
+ } else {
+ List<NavigableElement> navElements = NavigationHelper.getInstance().getAllNavigableElements(selectedElement);
+ // this will sort elements by navigation depth
+ Collections.sort(navElements);
+
+ for(NavigableElement navElement : navElements) {
+ // ignore existing elements because we want a hierarchy to
+ // be created if it is not on the current element
+ if(navElement instanceof CreatedNavigableElement && creationCondition.create(navElement.getElement())) {
+ return navElement;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private void createDiagram(NavigableElement navElement) {
+ DiResourceSet diResourceSet = EditorUtils.getDiResourceSet();
+
+ if(navElement != null && diResourceSet != null) {
+ try {
+ CompositeCommand command = NavigationHelper.getLinkCreateAndOpenNavigableDiagramCommand(navElement, creationCommand, null, diResourceSet);
+ diResourceSet.getTransactionalEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ private EObject getSelectedElement() {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ if(selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection)selection).getFirstElement();
+ return resolveSemanticObject(obj);
+ }
+ return null;
+ }
+
+ /**
+ * Resolve semantic element
+ *
+ * @param object
+ * the object to resolve
+ * @return <code>null</code> or the semantic element associated to the
+ * specified object
+ */
+ protected EObject resolveSemanticObject(Object object) {
+ if(object instanceof EObject) {
+ return (EObject)object;
+ }
+ Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(object);
+ if(businessObject instanceof EObject) {
+ return (EObject)businessObject;
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java
new file mode 100644
index 00000000000..907f0436f25
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+/**
+ * This class represents an element that have been created by the navigation.
+ * This element is not currently linked to the model, but it can be by using
+ * linkToModel if the user decides to navigate to it, to create a diagram on it
+ * for example.
+ *
+ * @author mvelten
+ *
+ */
+public class CreatedNavigableElement extends NavigableElement {
+
+ protected NavigableElement previousNavigableElement = null;
+
+ private IModelLinker modelLinker = null;
+
+ private IBaseNameSetter baseNameSetter = null;
+
+ /**
+ * This constructor initiates a navigable element from a newly created
+ * element. This element is not directly linked to its container.
+ * linkToModel() needs to be defined and call when you want to link it.
+ *
+ * @param element
+ * @param previousNavigableElement
+ */
+ public CreatedNavigableElement(EObject element, NavigableElement previousNavigableElement, EStructuralFeature feature, IModelLinker modelLinker, IBaseNameSetter baseNameSetter) {
+ super(element, previousNavigableElement, feature);
+ this.previousNavigableElement = previousNavigableElement;
+ this.modelLinker = modelLinker;
+ this.baseNameSetter = baseNameSetter;
+ }
+
+ public NavigableElement getPreviousNavigableElement() {
+ return previousNavigableElement;
+ }
+
+ public void linkToModel() {
+ if(modelLinker != null) {
+ modelLinker.linkToModel(getElement());
+ }
+ }
+
+ public void setBaseName(String base) {
+ if(baseNameSetter != null) {
+ baseNameSetter.setBaseName(base, getElement());
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java
new file mode 100644
index 00000000000..729569f9947
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+/**
+ * This class represents an element that already exists in the navigated model.
+ *
+ * @author mvelten
+ *
+ */
+public class ExistingNavigableElement extends NavigableElement {
+
+ /**
+ * This constructor initiates a navigable element from an existing model
+ * element.
+ *
+ * @param element
+ */
+ public ExistingNavigableElement(EObject element, EStructuralFeature feature) {
+ super(element, feature);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java
new file mode 100644
index 00000000000..6b03450c0b5
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * This interface allows to set the base name of an element. The base can then
+ * be used to derive a more useful name, containing the name of the element type
+ * for example.
+ *
+ * @author mvelten
+ *
+ */
+public interface IBaseNameSetter {
+
+ public void setBaseName(String base, EObject toName);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java
new file mode 100644
index 00000000000..464844fee65
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * This interface is used to link an element to the original model.
+ *
+ * @author mvelten
+ *
+ */
+public interface IModelLinker {
+
+ public void linkToModel(EObject toLink);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java
new file mode 100644
index 00000000000..c07a1347174
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java
@@ -0,0 +1,43 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * This interface defines a navigation rule.
+ *
+ * @author mvelten
+ *
+ */
+public interface INavigationRule {
+
+ /**
+ * Tests if an element is supported by this rule.
+ *
+ * @param element
+ * @return
+ */
+ public boolean handle(EObject element);
+
+ /**
+ * Retrieve a list of the next possible navigation possibilities.
+ *
+ * @param currentNavElement
+ * @return a list of navigable elements
+ */
+ public List<NavigableElement> getNextPossibleElements(NavigableElement currentNavElement);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Messages.java
new file mode 100644
index 00000000000..76b96a2430c
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/Messages.java
@@ -0,0 +1,31 @@
+package org.eclipse.papyrus.navigation;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.navigation.messages"; //$NON-NLS-1$
+
+ public static String DoubleClickNavigationText;
+
+ public static String Explicit_ImplicitNavigation_Text;
+
+ public static String ExplicitNavigation_Text;
+
+ public static String No_Navigation_Text;
+
+ public static String DecoratorVisibilityText;
+
+ public static String DecoratorDisabled_Text;
+
+ public static String DisplayOnly_Text;
+
+ public static String Everywhere_Text;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java
new file mode 100644
index 00000000000..a776559f333
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+/**
+ * This class represents an element which can be accessed from an other element
+ * throught a feature using defined navigation rules.
+ *
+ * @author mvelten
+ *
+ */
+public abstract class NavigableElement implements Comparable<NavigableElement> {
+
+ private EObject element = null;
+
+ private EStructuralFeature feature = null;
+
+ private int depth = 0;
+
+ public NavigableElement(EObject element, EStructuralFeature feature) {
+ this.element = element;
+ this.feature = feature;
+ }
+
+ public NavigableElement(EObject element, NavigableElement previousNavigableElement, EStructuralFeature feature) {
+ this(element, feature);
+ if(previousNavigableElement != null) {
+ this.depth = previousNavigableElement.getDepth() + 1;
+ }
+ }
+
+ public EObject getElement() {
+ return element;
+ }
+
+ public EStructuralFeature getFeature() {
+ return feature;
+ }
+
+ /**
+ * Retrieve the navigation depth.
+ *
+ * @return the navigation depth
+ */
+ public int getDepth() {
+ return depth;
+ }
+
+ public int compareTo(NavigableElement o) {
+ return getDepth() - o.getDepth();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java
new file mode 100644
index 00000000000..5b5d5f0f705
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java
@@ -0,0 +1,154 @@
+/*****************************************************************************
+ * 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:
+ * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+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.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.core.utils.DiResourceSet;
+import org.eclipse.papyrus.core.utils.OpenDiagramCommand;
+
+public class NavigationHelper {
+
+ private static class NavigationHelperHolder {
+
+ public static final NavigationHelper instance = new NavigationHelper();
+ }
+
+ public static NavigationHelper getInstance() {
+ return NavigationHelperHolder.instance;
+ }
+
+ private static final String EXTENSION_ID = "org.eclipse.papyrus.navigation.navigationRules";
+
+ private static final String NAVIGATIONRULE_ID = "navigationRule";
+
+ private static final String RULE_ID = "rule";
+
+ private List<INavigationRule> navigationRules = new LinkedList<INavigationRule>();
+
+ private NavigationHelper() {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+ for(IConfigurationElement configElement : configElements) {
+ if(NAVIGATIONRULE_ID.equals(configElement.getName())) {
+ try {
+ Object obj = configElement.createExecutableExtension(RULE_ID);
+ if(obj instanceof INavigationRule) {
+ navigationRules.add((INavigationRule)obj);
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+ }
+
+ private void addNextNavigableElements(NavigableElement currentNavElement, List<NavigableElement> navElements) {
+
+ navElements.add(currentNavElement);
+
+ for(INavigationRule navigationRule : navigationRules) {
+ if(navigationRule.handle(currentNavElement.getElement())) {
+ List<NavigableElement> nextNavigableElements = navigationRule.getNextPossibleElements(currentNavElement);
+ for(NavigableElement nextNavigableElement : nextNavigableElements) {
+ addNextNavigableElements(nextNavigableElement, navElements);
+ }
+ }
+ }
+ }
+
+ /**
+ * get all navigation possibilities (existing or "to create" elements) from
+ * the specified element.
+ *
+ * @param element
+ * the element
+ * @return a list of navigation possibilities
+ */
+ public List<NavigableElement> getAllNavigableElements(EObject element) {
+ ArrayList<NavigableElement> navElements = new ArrayList<NavigableElement>();
+ if(element != null) {
+ addNextNavigableElements(new ExistingNavigableElement(element, null), navElements);
+ }
+ return navElements;
+ }
+
+ /**
+ * This method link the created element with its parent and browse the
+ * hierarchy to link the parents between them. Ultimately the hierarchy will
+ * be attached to an {@link ExistingNavigableElement}, so to the original
+ * model.
+ *
+ * @param createdNavElement
+ */
+ public static void linkToModel(CreatedNavigableElement createdNavElement) {
+ NavigableElement navElement = createdNavElement;
+ while(navElement instanceof CreatedNavigableElement) {
+ CreatedNavigableElement cne = (CreatedNavigableElement)navElement;
+ cne.linkToModel();
+ navElement = cne.getPreviousNavigableElement();
+ }
+ }
+
+ /**
+ * Same behavior as {@link NavigationHelper#linkToModel(CreatedNavigableElement)} but set the
+ * base name of the elements.
+ *
+ * @param createdNavElement
+ * @param base
+ */
+ public static void setBaseName(CreatedNavigableElement createdNavElement, String base) {
+ NavigableElement navElement = createdNavElement;
+ while(navElement instanceof CreatedNavigableElement) {
+ CreatedNavigableElement cne = (CreatedNavigableElement)navElement;
+ cne.setBaseName(base);
+ navElement = cne.getPreviousNavigableElement();
+ }
+ }
+
+ public static CompositeCommand getLinkCreateAndOpenNavigableDiagramCommand(final NavigableElement navElement, ICreationCommand creationCommandInterface, final String diagramName, DiResourceSet diResourceSet) {
+ CompositeCommand compositeCommand = new CompositeCommand("Create diagram");
+
+ if(navElement instanceof CreatedNavigableElement) {
+ compositeCommand.add(new AbstractTransactionalCommand(diResourceSet.getTransactionalEditingDomain(), "Create hierarchy", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ NavigationHelper.linkToModel((CreatedNavigableElement)navElement);
+ NavigationHelper.setBaseName((CreatedNavigableElement)navElement, "");
+ return CommandResult.newOKCommandResult();
+ }
+ });
+ }
+
+ ICommand createDiagCommand = creationCommandInterface.getCreateDiagramCommand(diResourceSet, navElement.getElement(), diagramName);
+ compositeCommand.add(createDiagCommand);
+ compositeCommand.add(new OpenDiagramCommand(diResourceSet.getTransactionalEditingDomain(), createDiagCommand));
+
+ return compositeCommand;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java
new file mode 100644
index 00000000000..27ab0aa2d42
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java
@@ -0,0 +1,216 @@
+/*****************************************************************************
+ * Copyright (c) 2010-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.navigation.decorator;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
+import org.eclipse.papyrus.core.utils.DiResourceSet;
+import org.eclipse.papyrus.navigation.ExistingNavigableElement;
+import org.eclipse.papyrus.navigation.NavigableElement;
+import org.eclipse.papyrus.navigation.NavigationHelper;
+import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant;
+import org.eclipse.papyrus.preferences.Activator;
+import org.eclipse.papyrus.ui.toolbox.draw2d.ManuallyDrawnShortcutDecorationFigure;
+import org.eclipse.swt.graphics.Color;
+
+public class NavigationDecorator extends AbstractDecorator implements Adapter {
+
+ private static final String EXTENSION_ID = "org.eclipse.papyrus.navigation.navigationColorProviders";
+
+ private static final String COLORPROVIDER_ID = "navigationColorProvider";
+
+ private static final String PROVIDER_ID = "provider";
+
+ private static List<IColorProvider> navigationColorProviders = new LinkedList<IColorProvider>();
+
+ static {
+ // Reading data from plugins
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+ for(IConfigurationElement configElement : configElements) {
+ if(COLORPROVIDER_ID.equals(configElement.getName())) {
+ try {
+ Object obj = configElement.createExecutableExtension(PROVIDER_ID);
+ if(obj instanceof IColorProvider) {
+ navigationColorProviders.add((IColorProvider)obj);
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+ }
+
+ private Set<Resource> listenedNotationResources = new HashSet<Resource>();
+
+ private ManuallyDrawnShortcutDecorationFigure shortcutFigure = new ManuallyDrawnShortcutDecorationFigure();
+
+ private IGraphicalEditPart gep = null;
+
+ private boolean displayOnly;
+
+ public NavigationDecorator(IDecoratorTarget decoratorTarget) {
+ super(decoratorTarget);
+ decoratorTarget.installDecorator("navigationDecorator", this);
+ shortcutFigure.setVisible(false);
+
+ String decoratorVisibility = Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY);
+ displayOnly = INavigationPreferenceConstant.DISPLAY_ONLY.equals(decoratorVisibility);
+ }
+
+ @Override
+ public void deactivate() {
+ super.deactivate();
+ removeListenerFromAllResources();
+ }
+
+ public void activate() {
+ EditPart editPart = (EditPart)getDecoratorTarget().getAdapter(EditPart.class);
+ if(editPart instanceof IGraphicalEditPart) {
+ gep = (IGraphicalEditPart)editPart;
+
+ if(editPart instanceof ShapeEditPart) {
+ setDecoration(getDecoratorTarget().addShapeDecoration(shortcutFigure, IDecoratorTarget.Direction.NORTH_EAST, -5, displayOnly));
+ } else if(editPart instanceof ConnectionEditPart) {
+ setDecoration(getDecoratorTarget().addConnectionDecoration(shortcutFigure, 20, displayOnly));
+ }
+ }
+ refresh();
+ }
+
+ public void refresh() {
+ if(gep != null) {
+ View view = gep.getNotationView();
+ EObject element = gep.resolveSemanticElement();
+
+ removeListenerFromAllResources();
+
+ Diagram currentDiagram = null;
+ if(view != null) {
+ currentDiagram = view.getDiagram();
+ }
+
+ if(currentDiagram != null) {
+ addResourceListener(currentDiagram.eResource());
+ }
+
+ List<NavigableElement> navElements = NavigationHelper.getInstance().getAllNavigableElements(element);
+
+ Color shortcutColor = null;
+
+ for(NavigableElement navElement : navElements) {
+ if(navElement instanceof ExistingNavigableElement) {
+ EObject eObj = navElement.getElement();
+ Resource res = eObj.eResource();
+ if(res != null && res.getResourceSet() instanceof DiResourceSet) {
+ Resource notationResource = ((DiResourceSet)res.getResourceSet()).getAssociatedNotationResource(eObj);
+
+ addResourceListener(notationResource);
+
+ List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagramsFromNotationResource(eObj, notationResource);
+
+ if(associatedDiagrams != null) {
+ for(Diagram diag : associatedDiagrams) {
+ addResourceListener(diag.eResource());
+ if(!diag.equals(currentDiagram)) {
+ for(IColorProvider provider : navigationColorProviders) {
+ Color color = provider.getBackground(navElement);
+ if(color != null) {
+ if(shortcutColor == null) {
+ shortcutColor = color;
+ } else if(!shortcutColor.equals(color)) {
+ // more than one color for this
+ // element :
+ // just use white in this case
+ shortcutColor = ColorConstants.white;
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(shortcutColor == null) {
+ shortcutFigure.setVisible(false);
+ } else {
+ shortcutFigure.setVisible(true);
+ shortcutFigure.setBackgroundColor(shortcutColor);
+ }
+ }
+ }
+
+ private void addResourceListener(Resource r) {
+ if(r != null) {
+ synchronized(listenedNotationResources) {
+ if(listenedNotationResources.add(r)) {
+ r.eAdapters().add(this);
+ }
+ }
+ }
+ }
+
+ private void removeListenerFromAllResources() {
+ synchronized(listenedNotationResources) {
+ for(Resource r : listenedNotationResources) {
+ r.eAdapters().remove(this);
+ }
+ listenedNotationResources.clear();
+ }
+ }
+
+ public void notifyChanged(Notification notification) {
+ if(!notification.isTouch() && notification.getFeatureID(Resource.class) == Resource.RESOURCE__CONTENTS) {
+ refresh();
+ }
+ }
+
+ Notifier notifier;
+
+ public Notifier getTarget() {
+ return notifier;
+ }
+
+ public void setTarget(Notifier newTarget) {
+ notifier = newTarget;
+ }
+
+ public boolean isAdapterForType(Object type) {
+ return false;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java
new file mode 100644
index 00000000000..4812a674be5
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java
@@ -0,0 +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.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.navigation.preference.INavigationPreferenceConstant;
+import org.eclipse.papyrus.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.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);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/BackNavigateHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/BackNavigateHandler.java
new file mode 100644
index 00000000000..eb3f3df020f
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/BackNavigateHandler.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.navigation.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * handler for Up command
+ *
+ */
+public class BackNavigateHandler extends AbstractHandler {
+
+ private IEditorPart editor;
+
+ private IPageMngr pageMngr;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ editor = HandlerUtil.getActiveEditor(event);
+
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ EditingDomain editingDomain = papyrusEditor.getEditingDomain();
+ if(editingDomain instanceof TransactionalEditingDomain) {
+ try {
+ pageMngr = papyrusEditor.getServicesRegistry().getService(IPageMngr.class);
+ pageMngr.openPrevious();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/NextNavigateHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/NextNavigateHandler.java
new file mode 100644
index 00000000000..4a3d3bb8f7d
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/NextNavigateHandler.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.navigation.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * handler for Next command
+ *
+ */
+public class NextNavigateHandler extends AbstractHandler {
+
+ private IEditorPart editor;
+
+ private IPageMngr pageMngr;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ editor = HandlerUtil.getActiveEditor(event);
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ EditingDomain editingDomain = papyrusEditor.getEditingDomain();
+ if(editingDomain instanceof TransactionalEditingDomain) {
+ try {
+ pageMngr = papyrusEditor.getServicesRegistry().getService(IPageMngr.class);
+ pageMngr.openNext();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/TopNavigateHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/TopNavigateHandler.java
new file mode 100644
index 00000000000..50fc5fbe1f4
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/TopNavigateHandler.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.navigation.handlers;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
+import org.eclipse.papyrus.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.core.utils.OpenDiagramCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.navigation.Activator;
+import org.eclipse.papyrus.navigation.utils.MultiDiagramDialog;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.window.Window;
+
+/**
+ * handler for Up command
+ *
+ */
+public class TopNavigateHandler extends AbstractHandler {
+
+ private IEditorPart editor;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ editor = HandlerUtil.getActiveEditor(event);
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ EObject parent = papyrusEditor.getDiagram().getElement().eContainer();
+ List<List<Diagram>> diagramsTemp = new Vector<List<Diagram>>();
+ List<Diagram> diagrams = Collections.emptyList();
+ List<Diagram> associatedDiag = Collections.emptyList();
+ if(parent != null) {
+ while(parent != null) {
+ associatedDiag = DiagramsUtil.getAssociatedDiagrams(parent, null);
+ if(!associatedDiag.isEmpty()) {
+ diagramsTemp.add(associatedDiag);
+ }
+ parent = parent.eContainer();
+ }
+
+ while(diagrams.size() == 0 && diagramsTemp.size() != 0) {
+ diagrams = diagramsTemp.get(diagramsTemp.size() - 1);
+ diagramsTemp.remove(diagramsTemp.size() - 1);
+
+ }
+ openDialog(papyrusEditor, diagrams);
+
+ }
+ }
+ return null;
+ }
+
+ /**
+ * open the diagram if there is just one or open a dialog to choose the
+ * diagram to open if there is more than one
+ *
+ * @param papyrusEditor
+ * @param diagrams
+ */
+ private void openDialog(CoreMultiDiagramEditor papyrusEditor, List<Diagram> diagrams) {
+ if(diagrams != null) {
+ if(diagrams.size() == 1) {
+ openDiagram(papyrusEditor, diagrams.get(0));
+ } else if(diagrams.size() > 1) {
+ MultiDiagramDialog multiDiagramDialog = new MultiDiagramDialog(Activator.getActiveWorkbenchShell(), diagrams);
+ if(multiDiagramDialog.open() == Window.OK) {
+ openDiagram(papyrusEditor, diagrams.get(multiDiagramDialog.getSelectedDiagram()));
+ }
+ }
+ }
+ }
+
+ /**
+ * open a dialog to choose which diagram have to be opened
+ *
+ * @param papyrusEditor
+ * @param diagram
+ */
+ private void openDiagram(CoreMultiDiagramEditor papyrusEditor, Diagram diagram) {
+ if(papyrusEditor.getEditingDomain() instanceof TransactionalEditingDomain) {
+ TransactionalEditingDomain domain = (TransactionalEditingDomain)papyrusEditor.getEditingDomain();
+ OpenDiagramCommand openDiagramCommand = new OpenDiagramCommand(domain, diagram);
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(openDiagramCommand));
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/UpNavigateHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/UpNavigateHandler.java
new file mode 100644
index 00000000000..2e595addb94
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/handlers/UpNavigateHandler.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.navigation.handlers;
+
+import java.util.Collections;
+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.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
+import org.eclipse.papyrus.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.core.utils.OpenDiagramCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.navigation.Activator;
+import org.eclipse.papyrus.navigation.utils.MultiDiagramDialog;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.window.Window;
+
+/**
+ * handler for Up command
+ *
+ */
+public class UpNavigateHandler extends AbstractHandler {
+
+ private IEditorPart editor;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ editor = HandlerUtil.getActiveEditor(event);
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ EObject parent = papyrusEditor.getDiagram().getElement().eContainer();
+ List<Diagram> diagrams = Collections.emptyList();
+ if(parent != null) {
+ while(parent != null && diagrams.size() == 0) {
+ diagrams = DiagramsUtil.getAssociatedDiagrams(parent, null);
+ parent = parent.eContainer();
+ }
+ openDialog(papyrusEditor, diagrams);
+
+ }
+ }
+ return null;
+ }
+
+ /**
+ * open the diagram if there is just one or open a dialog to choose the
+ * diagram to open if there is more than one
+ *
+ * @param papyrusEditor
+ * @param diagrams
+ */
+ private void openDialog(CoreMultiDiagramEditor papyrusEditor, List<Diagram> diagrams) {
+ if(diagrams != null) {
+ if(diagrams.size() == 1) {
+ openDiagram(papyrusEditor, diagrams.get(0));
+ } else if(diagrams.size() > 1) {
+ MultiDiagramDialog multiDiagramDialog = new MultiDiagramDialog(Activator.getActiveWorkbenchShell(), diagrams);
+ if(multiDiagramDialog.open() == Window.OK) {
+ openDiagram(papyrusEditor, diagrams.get(multiDiagramDialog.getSelectedDiagram()));
+ }
+ }
+ }
+ }
+
+ /**
+ * open a dialog to choose which diagram have to be opened
+ *
+ * @param papyrusEditor
+ * @param diagram
+ */
+ private void openDiagram(CoreMultiDiagramEditor papyrusEditor, Diagram diagram) {
+ if(papyrusEditor.getEditingDomain() instanceof TransactionalEditingDomain) {
+ TransactionalEditingDomain domain = (TransactionalEditingDomain)papyrusEditor.getEditingDomain();
+ OpenDiagramCommand openDiagramCommand = new OpenDiagramCommand(domain, diagram);
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(openDiagramCommand));
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/messages.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/messages.properties
new file mode 100644
index 00000000000..53387152a23
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/messages.properties
@@ -0,0 +1,8 @@
+DoubleClickNavigationText=Navigation by double click:
+Explicit_ImplicitNavigation_Text=Explicit + Implicit navigation (if there is no default hyperlink, heuristic are used to propose navigation)
+ExplicitNavigation_Text=Explicit Navigation (use default hyperlinks)
+No_Navigation_Text=No Navigation
+DecoratorVisibilityText=Visibility of the navigation decorator (colored arrow):
+DecoratorDisabled_Text=Disabled
+DisplayOnly_Text=Only appears on displayed diagrams, not on exports and prints
+Everywhere_Text=Everywhere
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java
new file mode 100644
index 00000000000..bdaba3dc752
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * 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.navigation.preference;
+
+/**
+ * Constant to use for the management of navigation preference
+ */
+
+public interface INavigationPreferenceConstant {
+
+ public String PAPYRUS_NAVIGATION_DOUBLECLICK_KIND = "PAPYRUS_NAVIGATION_DOUBLECLICK_KIND";
+
+ public String NO_NAVIGATION = "NO_NAVIGATION";
+
+ public String EXPLICIT_NAVIGATION = "EXPLICIT_NAVIGATION";
+
+ public String EXPLICIT_IMPLICIT_NAVIGATION = "EXPLICIT_IMPLICIT_NAVIGATION";
+
+ public String PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY = "PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY";
+
+ public String DISABLED = "DISABLED";
+
+ public String DISPLAY_ONLY = "DISPLAY_ONLY";
+
+ public String EVERYWHERE = "EVERYWHERE";
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java
new file mode 100644
index 00000000000..e6755c35572
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.navigation.preference;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.preferences.Activator;
+
+/**
+ * This preference initializer initializes Navigation preferences
+ */
+public class NavigationPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /**
+ * Initialize default preferences
+ */
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = getPreferenceStore();
+ store.setDefault(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND, INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION);
+ store.setDefault(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY, INavigationPreferenceConstant.DISPLAY_ONLY);
+ }
+
+ /**
+ * Get the preference store
+ */
+ protected IPreferenceStore getPreferenceStore() {
+ return Activator.getDefault().getPreferenceStore();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java
new file mode 100644
index 00000000000..8071f5e8884
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * 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.navigation.preference;
+
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.papyrus.navigation.Messages;
+import org.eclipse.papyrus.preferences.Activator;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * preference page for the navigation It proposes to choose among 3
+ * possibilities: no navigation, explicit navigation, or explicit + implicit
+ * naviagation
+ *
+ */
+public class NavigationPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ protected RadioGroupFieldEditor dblClkFieldEditor;
+
+ protected RadioGroupFieldEditor decoratorVisibilityFieldEditor;
+
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ dblClkFieldEditor = new RadioGroupFieldEditor(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND, Messages.DoubleClickNavigationText, 1, new String[][]{ { Messages.No_Navigation_Text, INavigationPreferenceConstant.NO_NAVIGATION }, { Messages.ExplicitNavigation_Text, INavigationPreferenceConstant.EXPLICIT_NAVIGATION }, { Messages.Explicit_ImplicitNavigation_Text, INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION } }, getFieldEditorParent());
+ addField(dblClkFieldEditor);
+ dblClkFieldEditor.setPreferenceStore(Activator.getDefault().getPreferenceStore());
+
+ decoratorVisibilityFieldEditor = new RadioGroupFieldEditor(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DECORATOR_VISIBILITY, Messages.DecoratorVisibilityText, 1, new String[][]{ { Messages.DecoratorDisabled_Text, INavigationPreferenceConstant.DISABLED }, { Messages.DisplayOnly_Text, INavigationPreferenceConstant.DISPLAY_ONLY }, { Messages.Everywhere_Text, INavigationPreferenceConstant.EVERYWHERE } }, getFieldEditorParent());
+ addField(decoratorVisibilityFieldEditor);
+ decoratorVisibilityFieldEditor.setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/Messages.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/Messages.java
new file mode 100644
index 00000000000..a521f925a9f
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/Messages.java
@@ -0,0 +1,27 @@
+package org.eclipse.papyrus.navigation.utils;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.navigation.utils.messages"; //$NON-NLS-1$
+
+ public static String MultiDiagramDialog_0;
+
+ public static String MultiDiagramDialog_1;
+
+ public static String IS_BACK_POSSIBLE;
+
+ public static String IS_NEXT_POSSIBLE;
+
+ public static String IS_UP_POSSIBLE;
+
+ public static String IS_TOP_POSSIBLE;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/MultiDiagramDialog.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/MultiDiagramDialog.java
new file mode 100644
index 00000000000..2f3cdef1f61
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/MultiDiagramDialog.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.navigation.utils;
+
+import java.util.List;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.MoDiscoLabelProvider;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.jface.viewers.TableViewer;
+
+/**
+ * This class Provide a dialog filled with a list of reachable diagrams
+ *
+ * @author aradouan
+ *
+ */
+public class MultiDiagramDialog extends Dialog {
+
+ private List<Diagram> diagrams;
+
+ private Composite dialogComposite;
+
+ protected int selectedDiagram;
+
+ private Table table;
+
+ private TableViewer list;
+
+ public int getSelectedDiagram() {
+ return selectedDiagram;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(Messages.MultiDiagramDialog_0);
+ }
+
+ public MultiDiagramDialog(Shell parentShell, List<Diagram> diagrams) {
+ super(parentShell);
+ this.diagrams = diagrams;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ dialogComposite = (Composite)super.createDialogArea(parent);
+ parent.setLayout(new GridLayout());
+ dialogComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createDialogComposite();
+ createDialogContents(dialogComposite);
+ hookListeners();
+ loadData();
+ defaultSelection();
+
+ return dialogComposite;
+ }
+
+ private void createDialogContents(Composite parent) {
+ dialogComposite.setLayout(new GridLayout(1, false));
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new FillLayout(SWT.HORIZONTAL));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+
+ Label lblDiagrams = new Label(composite, SWT.NONE);
+ lblDiagrams.setText(Messages.MultiDiagramDialog_1);
+
+ Composite composite_1 = new Composite(parent, SWT.NONE);
+ composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ composite_1.setLayout(new GridLayout(1, false));
+
+ list = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
+ list.setUseHashlookup(true);
+ table = list.getTable();
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ list.setLabelProvider(new MoDiscoLabelProvider());
+ list.setContentProvider(new IStructuredContentProvider() {
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof List) {
+ return ((List)inputElement).toArray();
+ } else {
+ return new Object[]{ inputElement };
+ }
+ }
+ });
+ }
+
+ private void createDialogComposite() {
+ GridData dialogLayoutData = new GridData(GridData.FILL_BOTH);
+ dialogComposite.setLayoutData(dialogLayoutData);
+
+ }
+
+ private void hookListeners() {
+ table.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ MultiDiagramDialog.this.selectedDiagram = table.getSelectionIndex();
+ }
+
+ });
+ }
+
+ private void loadData() {
+ list.setInput(diagrams);
+ }
+
+ private void defaultSelection() {
+ boolean found = false;
+ IPageMngr pageMngr;
+ try {
+ pageMngr = EditorUtils.getServiceRegistry().getService(IPageMngr.class);
+
+ for(Diagram diagram : diagrams) {
+ if(pageMngr.isOpen(diagram)) {
+ table.select(diagrams.indexOf(diagram));
+ found = true;
+ break;
+ }
+ }
+
+ if(!found) {
+ int diagFound = 0;
+ int diagFoundTemp = 0;
+ for(Diagram diagram : diagrams) {
+ diagFoundTemp = pageMngr.isInHsitory(diagram);
+ if(diagFoundTemp > diagFound) {
+ diagFound = diagFoundTemp;
+ table.select(diagrams.indexOf(diagram));
+ found = true;
+ }
+ }
+ }
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+
+ if(!found) {
+ table.select(0);
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/PropertyTester.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/PropertyTester.java
new file mode 100644
index 00000000000..46d3d41a57d
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/PropertyTester.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS) - test property to enable or disable Navigation Icons
+ *******************************************************************************/
+package org.eclipse.papyrus.navigation.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
+import org.eclipse.papyrus.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.services.ServicesRegistry;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.navigation.Activator;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+
+public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
+
+ @SuppressWarnings("deprecation")
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ boolean result = false;
+
+ ServicesRegistry serviceRegistry = EditorUtils.getServiceRegistry();
+ if(serviceRegistry != null && Messages.IS_BACK_POSSIBLE.equals(property)) {
+ try {
+ IPageMngr pageMngr = serviceRegistry.getService(IPageMngr.class);
+ result = pageMngr.hasPreviousHistory();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+
+ } else if(serviceRegistry != null && Messages.IS_NEXT_POSSIBLE.equals(property)) {
+ try {
+ IPageMngr pageMngr = serviceRegistry.getService(IPageMngr.class);
+ result = pageMngr.hasNextHistory();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+
+ } else if(Messages.IS_UP_POSSIBLE.equals(property) || Messages.IS_TOP_POSSIBLE.equals(property)) {
+ IWorkbenchWindow activeWorkbenchWindow = Activator.getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow != null)
+ {
+ IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
+ if (activePage != null)
+ {
+ IEditorPart editor = activePage.getActiveEditor();
+ if(editor instanceof CoreMultiDiagramEditor) {
+ CoreMultiDiagramEditor papyrusEditor = (CoreMultiDiagramEditor)editor;
+ EObject parent = null;
+ if(papyrusEditor.getDiagram() != null && papyrusEditor.getDiagram().getElement() != null) {
+ parent = papyrusEditor.getDiagram().getElement().eContainer();
+ }
+
+ if(parent != null) {
+ while(parent != null && !result) {
+ result = !DiagramsUtil.getAssociatedDiagrams(parent, null).isEmpty();
+ parent = parent.eContainer();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/messages.properties b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/messages.properties
new file mode 100644
index 00000000000..c230b60594c
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.navigation/src/org/eclipse/papyrus/navigation/utils/messages.properties
@@ -0,0 +1,6 @@
+MultiDiagramDialog_0=Diagrams
+MultiDiagramDialog_1=Select a diagram :
+IS_BACK_POSSIBLE=isBackCommandPossible
+IS_NEXT_POSSIBLE=isNextCommandPossible
+IS_UP_POSSIBLE=isUpCommandPossible
+IS_TOP_POSSIBLE=isTopCommandPossible

Back to the top