Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormvelten2011-05-17 09:26:11 +0000
committermvelten2011-05-17 09:26:11 +0000
commit8f4acc26a0d9ba84e1cb211fb8c3678d957762e8 (patch)
tree49dfe6640f75b06b7a5f828c2f7a66aa0b14ca8a /plugins/core/org.eclipse.papyrus.navigation
parent5491a6e6bc0da8b36b29f3333e47a876d36126a6 (diff)
downloadorg.eclipse.papyrus-8f4acc26a0d9ba84e1cb211fb8c3678d957762e8.tar.gz
org.eclipse.papyrus-8f4acc26a0d9ba84e1cb211fb8c3678d957762e8.tar.xz
org.eclipse.papyrus-8f4acc26a0d9ba84e1cb211fb8c3678d957762e8.zip
REOPENED - bug 334262: [General] Navigation and integration with the creation diagram service
https://bugs.eclipse.org/bugs/show_bug.cgi?id=334262 Add navigation decorator, using GMF mechanism. There is now an option to choose whether you want to display it everywhere, only on display or not at all. Some generic ui related components has been moved to ui.toolbox and factorized. CreateDiagramWithNavigationHandler has been moved from uml common to navigation so it can be used easily outside of UML.
Diffstat (limited to 'plugins/core/org.eclipse.papyrus.navigation')
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF7
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/plugin.xml13
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/schema/navigationColorProviders.exsd86
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/schema/navigationDecoratorRules.exsd111
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/schema/navigationRules.exsd (renamed from plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd)11
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Activator.java2
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java140
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Messages.java12
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java19
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java217
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java95
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/messages.properties8
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java6
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java1
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java31
15 files changed, 730 insertions, 29 deletions
diff --git a/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF b/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF
index be2aa638a7b..19f18888057 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF
+++ b/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF
@@ -4,9 +4,12 @@ Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.papyrus.navigation;singleton:=true
Bundle-Version: 0.8.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Require-Bundle: org.eclipse.papyrus.core,
- org.eclipse.papyrus.preferences;bundle-version="0.8.0"
+Require-Bundle: org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport,
+ org.eclipse.papyrus.preferences;bundle-version="0.8.0",
+ org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0",
+ org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0"
Export-Package: org.eclipse.papyrus.navigation,
+ org.eclipse.papyrus.navigation.decorator,
org.eclipse.papyrus.navigation.preference
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/plugins/core/org.eclipse.papyrus.navigation/plugin.xml b/plugins/core/org.eclipse.papyrus.navigation/plugin.xml
index 3ebd23699dc..21227caf819 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/plugin.xml
+++ b/plugins/core/org.eclipse.papyrus.navigation/plugin.xml
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
- <extension-point id="navigationRule" name="navigationRule" schema="schema/navigationRule.exsd"/>
+ <extension-point id="navigationRules" name="navigationRules" schema="schema/navigationRules.exsd"/>
+ <extension-point id="navigationDecoratorRules" name="navigationDecoratorRules" schema="schema/navigationDecoratorRules.exsd"/>
+ <extension-point id="navigationColorProviders" name="navigationColorProviders" schema="schema/navigationColorProviders.exsd"/>
<extension
point="org.eclipse.ui.preferencePages">
<page
@@ -17,6 +19,15 @@
class="org.eclipse.papyrus.navigation.preference.NavigationPreferenceInitializer">
</initializer>
</extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.decoratorProviders">
+ <decoratorProvider
+ class="org.eclipse.papyrus.navigation.decorator.NavigationDecoratorProvider">
+ <Priority
+ name="Medium">
+ </Priority>
+ </decoratorProvider>
+ </extension>
</plugin>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/schema/navigationColorProviders.exsd b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationColorProviders.exsd
new file mode 100644
index 00000000000..9ac9da2c940
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationColorProviders.exsd
@@ -0,0 +1,86 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.navigation" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.navigation" id="navigationColorProviders" name="navigationColorProviders"/>
+ </appinfo>
+ <documentation>
+ Color provider used by the decorator to set the color of the navigation arrow.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="navigationColorProvider"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="navigationColorProvider">
+ <annotation>
+ <documentation>
+ Color provider used by the decorator to set the color of the navigation arrow.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="provider" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.IColorProvider"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ 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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/schema/navigationDecoratorRules.exsd b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationDecoratorRules.exsd
new file mode 100644
index 00000000000..eab5400d3b5
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationDecoratorRules.exsd
@@ -0,0 +1,111 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.navigation" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.navigation" id="navigationDecoratorRules" name="navigationDecoratorRules"/>
+ </appinfo>
+ <documentation>
+ Allow to specify classes where the navigation decorator should be used.
+Navigation computation can be intensive so the decorator is not registered on each element.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="decoratedClass" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="forbiddenClass" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="decoratedClass">
+ <annotation>
+ <documentation>
+ Elements of this class should have the navigation decorator.
+It uses instanceof so all the subclasses are also decorated.
+You can use forbiddenClass to restrict this behavior.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="forbiddenClass">
+ <annotation>
+ <documentation>
+ Elements of this class should not have the navigation decorator.
+It uses instanceof so all the subclasses are also forbidden.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ 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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRules.exsd
index 35950d12e92..8a588bd3ba2 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd
+++ b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRules.exsd
@@ -3,7 +3,7 @@
<schema targetNamespace="org.eclipse.papyrus.navigation" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
- <meta.schema plugin="org.eclipse.papyrus.navigation" id="navigationRule" name="navigationRule"/>
+ <meta.schema plugin="org.eclipse.papyrus.navigation" id="navigationRules" name="navigationRules"/>
</appinfo>
<documentation>
This extension point allows to register navigation rules so they can be used by the navigation handler.
@@ -48,12 +48,17 @@
</element>
<element name="navigationRule">
+ <annotation>
+ <documentation>
+ Contribute a navigation rule to the navigation handler.
+see INavigationRule for more informations.
+ </documentation>
+ </annotation>
<complexType>
<attribute name="rule" type="string">
<annotation>
<documentation>
- Contribute a navigation rule to the navigation handler.
-see INavigationRule for more informations.
+
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.papyrus.navigation.INavigationRule"/>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Activator.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Activator.java
index 5923ca738c2..709769ac16a 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Activator.java
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Activator.java
@@ -11,9 +11,9 @@
* 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.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
diff --git a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java
new file mode 100644
index 00000000000..a4eccc050a4
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/CreateDiagramWithNavigationHandler.java
@@ -0,0 +1,140 @@
+/*****************************************************************************
+ * 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.core.utils.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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Messages.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Messages.java
index 98157f5f0ca..76b96a2430c 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Messages.java
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/Messages.java
@@ -6,13 +6,21 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.papyrus.navigation.messages"; //$NON-NLS-1$
- public static String DoubleClickNaviagationText;
+ public static String DoubleClickNavigationText;
public static String Explicit_ImplicitNavigation_Text;
public static String ExplicitNavigation_Text;
- public static String No_Naviagation_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);
diff --git a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java
index 7fb3c2dd1df..7f27fe6fe2c 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java
@@ -44,7 +44,9 @@ public class NavigationHelper {
return NavigationHelperHolder.instance;
}
- private static final String NAVIGATIONRULE_EXTENSION_ID = "org.eclipse.papyrus.navigation.navigationRule";
+ 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";
@@ -52,15 +54,16 @@ public class NavigationHelper {
private NavigationHelper() {
// Reading data from plugins
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(NAVIGATIONRULE_EXTENSION_ID);
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
for(IConfigurationElement configElement : configElements) {
- Object obj;
- try {
- obj = configElement.createExecutableExtension(RULE_ID);
- if(obj instanceof INavigationRule) {
- navigationRules.add((INavigationRule)obj);
+ if (NAVIGATIONRULE_ID.equals(configElement.getName())) {
+ try {
+ Object obj = configElement.createExecutableExtension(RULE_ID);
+ if(obj instanceof INavigationRule) {
+ navigationRules.add((INavigationRule)obj);
+ }
+ } catch (CoreException e) {
}
- } catch (CoreException e) {
}
}
}
diff --git a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java
new file mode 100644
index 00000000000..52fe8e7390d
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecorator.java
@@ -0,0 +1,217 @@
+/*****************************************************************************
+ * 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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java
new file mode 100644
index 00000000000..a0263c37e97
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/decorator/NavigationDecoratorProvider.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * 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.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 IGraphicalEditPart) {
+ 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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/messages.properties b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/messages.properties
index 733e5c8d131..53387152a23 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/messages.properties
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/messages.properties
@@ -1,4 +1,8 @@
-DoubleClickNaviagationText=Navigation by double click:
+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_Naviagation_Text=No Navigation
+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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java
index 1ad87af058b..4a226f35fd7 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/INavigationPreferenceConstant.java
@@ -22,4 +22,10 @@ public interface INavigationPreferenceConstant {
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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java
index 7d3aa9e2cf5..76434387149 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferenceInitializer.java
@@ -28,6 +28,7 @@ public class NavigationPreferenceInitializer extends AbstractPreferenceInitializ
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);
}
/**
diff --git a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java
index cbfce4e0a84..ce440e5b37d 100644
--- a/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/preference/NavigationPreferencePage.java
@@ -13,13 +13,9 @@
package org.eclipse.papyrus.navigation.preference;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.navigation.Messages;
import org.eclipse.papyrus.preferences.Activator;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -31,25 +27,40 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
*/
public class NavigationPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
- protected RadioGroupFieldEditor radioGroupFieldEditor;
+ protected RadioGroupFieldEditor dblClkFieldEditor;
+ protected RadioGroupFieldEditor decoratorVisibilityFieldEditor;
+
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
@Override
protected void createFieldEditors() {
- radioGroupFieldEditor = new RadioGroupFieldEditor(
+ dblClkFieldEditor = new RadioGroupFieldEditor(
INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND,
- Messages.DoubleClickNaviagationText,
+ Messages.DoubleClickNavigationText,
1,
new String[][] {
- {Messages.No_Naviagation_Text,INavigationPreferenceConstant.NO_NAVIGATION},
+ {Messages.No_Navigation_Text,INavigationPreferenceConstant.NO_NAVIGATION},
{Messages.ExplicitNavigation_Text,INavigationPreferenceConstant.EXPLICIT_NAVIGATION},
{Messages.Explicit_ImplicitNavigation_Text,INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION}
},
getFieldEditorParent());
- addField(radioGroupFieldEditor);
- radioGroupFieldEditor.setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ 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());
}
}

Back to the top