Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/.classpath7
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/.project28
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF10
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/about.html28
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/build.properties10
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/plugin.properties12
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/plugin.xml6
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd82
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java66
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java36
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java29
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java27
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java43
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java66
-rw-r--r--plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java150
16 files changed, 608 insertions, 0 deletions
diff --git a/plugins/core/org.eclipse.papyrus.navigation/.classpath b/plugins/core/org.eclipse.papyrus.navigation/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/.project b/plugins/core/org.eclipse.papyrus.navigation/.project
new file mode 100644
index 00000000000..9e5180418f0
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.navigation</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/.settings/org.eclipse.jdt.core.prefs b/plugins/core/org.eclipse.papyrus.navigation/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..07082ae85ea
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Mon Jan 24 11:06:16 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF b/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..6c8128acde1
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+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
+Export-Package: org.eclipse.papyrus.navigation
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
diff --git a/plugins/core/org.eclipse.papyrus.navigation/about.html b/plugins/core/org.eclipse.papyrus.navigation/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/build.properties b/plugins/core/org.eclipse.papyrus.navigation/build.properties
new file mode 100644
index 00000000000..0f3e2a44a41
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/build.properties
@@ -0,0 +1,10 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ schema/,\
+ plugin.properties,\
+ about.html
+src.includes = about.html,\
+ schema/
diff --git a/plugins/core/org.eclipse.papyrus.navigation/plugin.properties b/plugins/core/org.eclipse.papyrus.navigation/plugin.properties
new file mode 100644
index 00000000000..fcdcaf2ad07
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/plugin.properties
@@ -0,0 +1,12 @@
+#################################################################################
+# Copyright (c) 2010 Atos Origin.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Atos Origin - Initial API and Implementation
+##################################################################################
+pluginName=Papyrus navigation (Incubation)
+providerName=Eclipse Modeling Project
diff --git a/plugins/core/org.eclipse.papyrus.navigation/plugin.xml b/plugins/core/org.eclipse.papyrus.navigation/plugin.xml
new file mode 100644
index 00000000000..8c6bb246824
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/plugin.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="navigationRule" name="navigationRule" schema="schema/navigationRule.exsd"/>
+
+</plugin>
diff --git a/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd
new file mode 100644
index 00000000000..35950d12e92
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/schema/navigationRule.exsd
@@ -0,0 +1,82 @@
+<?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="navigationRule" name="navigationRule"/>
+ </appinfo>
+ <documentation>
+ This extension point allows to register navigation rules so they can be used by the navigation handler.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="navigationRule" 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="navigationRule">
+ <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"/>
+ </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/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/CreatedNavigableElement.java
new file mode 100644
index 00000000000..0c7ad6373f6
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java
new file mode 100644
index 00000000000..8fee9ecf790
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/ExistingNavigableElement.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * 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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/IBaseNameSetter.java
new file mode 100644
index 00000000000..0fc0a136eea
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/IModelLinker.java
new file mode 100644
index 00000000000..464844fee65
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/INavigationRule.java
new file mode 100644
index 00000000000..c07a1347174
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.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/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigableElement.java
new file mode 100644
index 00000000000..837374b2052
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.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/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
new file mode 100644
index 00000000000..7fb3c2dd1df
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.navigation/src/org/eclipse/papyrus/navigation/NavigationHelper.java
@@ -0,0 +1,150 @@
+/*****************************************************************************
+ * 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 NAVIGATIONRULE_EXTENSION_ID = "org.eclipse.papyrus.navigation.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(NAVIGATIONRULE_EXTENSION_ID);
+ for(IConfigurationElement configElement : configElements) {
+ Object obj;
+ try {
+ 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;
+ }
+}

Back to the top