Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Le Menez2016-02-02 09:39:11 +0000
committerPatrick Tessier2016-10-20 13:19:55 +0000
commitb451aa3ec1afeb759fe2293840a322f61e4d07f0 (patch)
treeaebe6e1de9d3751218dcc6d613d6c97869c389b9 /extraplugins
parent4050371ec3c56720bd678581cd7dec87aed9311b (diff)
downloadorg.eclipse.papyrus-b451aa3ec1afeb759fe2293840a322f61e4d07f0.tar.gz
org.eclipse.papyrus-b451aa3ec1afeb759fe2293840a322f61e4d07f0.tar.xz
org.eclipse.papyrus-b451aa3ec1afeb759fe2293840a322f61e4d07f0.zip
Bug 465308: [Refactoring] A refactoring tool should be made available
https://bugs.eclipse.org/bugs/show_bug.cgi?id=465308 - need to fix the imoossibility to view successive changes on the compare window and their diagram views if the model is not saved between them - issue with the generated code of the UMLDiagramEditor that does not check if the current thread is a UI thread before firing the changes - still needs a better viewer for the possible mutations of the selected elements - nedd to implement a scope mechanism to give the user the possibility to transform multiple models at once (imported mutated element) - need to implement a new page warning the user of the consequences of the transformation - removed the dependency to a specific provider in order to create the element views - placed the test plugin in the junit folder - added some missing comments and headers - new way to retrieve possible mutations and better performances for the replace tool - first draft of the doc files and finished javadoc Change-Id: Ie45b7af6a4c2d027691f12c2ac52749575398049 Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr>
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/.classpath7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/.project28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/META-INF/MANIFEST.MF29
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/about.html28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/build.properties8
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.html123
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.mediawiki134
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.html37
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.mediawiki38
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/example-model.pngbin0 -> 2707 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/preview-page.pngbin0 -> 74233 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/refactored-model.pngbin0 -> 3381 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/validity-page.pngbin0 -> 66415 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/wizard-refactoring.pngbin0 -> 19522 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_dev_guide.xml6
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_user_guide.xml11
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/Papyrus_16x16.gifbin0 -> 561 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/refactor.pngbin0 -> 786 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.properties14
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.xml102
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/pom.xml54
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/Activator.java118
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/AbstractPapyrusTransformation.java126
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/IPreviewablePapyrusChange.java38
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusChange.java246
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoring.java255
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringCommand.java65
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringOperation.java87
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringValidationStatusContext.java46
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/UndoPapyrusChange.java110
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractAllModelTransformation.java45
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractChoiceOnUIParticipantsTransformation.java111
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractSelectedElementsTransformation.java46
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/Messages.java67
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/messages.properties37
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/AbstractTransformationOnElement.java72
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ITransformationOnElement.java34
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusCompositeChange.java247
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusRefactoringOnElementChange.java93
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ReplaceTransformationOnElement.java167
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringPreview.java194
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringWizard.java60
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusStatusContextViewer.java114
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/ReplaceRefactoring.java173
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/util/PapyrusRefactoringUtils.java296
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.classpath7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.project28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/META-INF/MANIFEST.MF38
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/about.html28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/build.properties8
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/images/mutate.pngbin0 -> 42166 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate-toc.xml6
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.html9
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.mediawiki11
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/icons/refactor.pngbin0 -> 786 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.properties16
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.xml44
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/pom.xml54
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/Activator.java74
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/handler/MutationHandler.java37
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/helper/MutationTransformation.java559
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/Messages.java37
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/messages.properties7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElemenetTypeContentProvider.java75
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElementTypeLabelProvider.java72
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/ui/MutationRefactoring.java416
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ElementCreationUtils.java67
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ModelNotationUtils.java260
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.classpath7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.project28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/META-INF/MANIFEST.MF22
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/about.html28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/build.properties8
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/refactor.pngbin0 -> 786 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/transformationIcon.gifbin0 -> 279 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.properties16
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.xml36
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/pom.xml16
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/Activator.java84
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/handler/SelectQVTTransformationHandler.java36
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/popup/actions/SelectQVTTransformation.java171
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.classpath7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.project28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/META-INF/MANIFEST.MF19
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/about.html28
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/build.properties8
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/images/replace.pngbin0 -> 36747 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace-toc.xml6
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.html12
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.mediawiki11
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/icons/refactor.pngbin0 -> 786 bytes
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.properties16
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.xml44
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/pom.xml54
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/Activator.java67
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/handler/ReplaceHandler.java38
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/Messages.java38
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/messages.properties8
-rw-r--r--extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/ui/ReplaceRefactoring.java202
103 files changed, 6386 insertions, 0 deletions
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.classpath b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.classpath
new file mode 100644
index 00000000000..eca7bdba8f0
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.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/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.project b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.project
new file mode 100644
index 00000000000..97cbc8353d8
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.refactoring</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/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.settings/org.eclipse.jdt.core.prefs b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..0c68a61dca8
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/META-INF/MANIFEST.MF b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..dded4cd6e33
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/META-INF/MANIFEST.MF
@@ -0,0 +1,29 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.refactoring;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-Activator: org.eclipse.papyrus.refactoring.Activator
+Require-Bundle: org.eclipse.ui;bundle-version="3.107.0",
+ org.eclipse.core.runtime;bundle-version="3.12.0",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.8.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.7.0",
+ org.eclipse.papyrus.infra.core;bundle-version="2.0.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="2.0.0",
+ org.eclipse.papyrus.uml.search.ui;bundle-version="1.2.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="2.0.0",
+ org.eclipse.papyrus.infra.services.validation;bundle-version="2.0.0",
+ org.eclipse.team.ui;bundle-version="3.8.0",
+ org.eclipse.compare;bundle-version="3.6.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.8.0",
+ org.eclipse.help;bundle-version="3.6.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %vendorName
+Bundle-Localization: plugin
+Export-Package: org.eclipse.papyrus.refactoring,
+ org.eclipse.papyrus.refactoring.core,
+ org.eclipse.papyrus.refactoring.helper,
+ org.eclipse.papyrus.refactoring.refactoringOnElement,
+ org.eclipse.papyrus.refactoring.ui,
+ org.eclipse.papyrus.refactoring.util
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/about.html b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/about.html
new file mode 100644
index 00000000000..d35d5aed64c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/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/extraplugins/refactoring/org.eclipse.papyrus.refactoring/build.properties b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/build.properties
new file mode 100644
index 00000000000..69d0f2e3ef2
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ icons/,\
+ about.html
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.html b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.html
new file mode 100644
index 00000000000..5898c558c6d
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.html
@@ -0,0 +1,123 @@
+<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
+<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>
+<body>
+ <h1 id="How_to_implement_your_own_Papyrus_refactoring">How to implement your own Papyrus refactoring</h1>
+ <h2 id="Introduction">Introduction</h2>
+ <p>The PRF (Papyrus Refactoring Framework) helps developers to create undoable and previewable Papyrus model refactorings. The PRF also warns the user if the transformation invalidates the model.</p>
+ <p>In this page you will learn how to implement your own Papyrus transformation using the PRF.</p>
+
+ <h2 id="Implementing_the_transformation">Implementing the transformation</h2>
+ <p><b>Before beginning the implementation you need to add the dependencies:</b> <i>org.eclipse.papyrus.infra.refactoring</i>, <i>org.eclipse.papyrus.infra.core</i>,<i>org.eclipse.ltk.core.refactoring</i>, <i>org.eclipse.ltk.ui.refactoring</i>.</p>
+ <p>Then you have to do is to implement a class which extends <i>AbstractPapyrusTransformation</i> (which is a <i>WizardPage</i>).</p>
+ <p>In the constructor you have to indicate the human readable name of your transformation.</p><p>Then you need to implement the following methods:</p>
+ <ul>
+ <li><pre> public void createControl(Composite parent);</pre> In this method you have to implement the control which will be displayed in the UI refactoring wizard. You are are responsible for ensuring the created control can be accessed via <i>getControl()</i>, typically you instantiate your <i>composite</i> and set the control like this: <i>setControl(composite)</i></li>
+ </ul>
+ <ul>
+ <li><pre>public RefactoringStatus checkFinalConditions();</pre> This method is called when the user clicks on the "OK" or "Preview" button. Here you check that all conditions are fulfilled to execute the transformation. Typically you verify that all the informations needed to do the transformation are given by the user. You have to return a <a href="http://help.eclipse.org/neon/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ltk/core/refactoring/RefactoringStatus.html">RefactoringStatus</a>.</li>
+ </ul>
+ <p> Example:
+ <pre> // In this example we assume that the String newString has to be given by the user in the UI.
+ RefactoringStatus status = new RefactoringStatus; // When a RefactoringStatus is instantiated his severity is 'OK'.
+ if(fNewString==null){
+ status.addFatalError("You have to indicate the new string"); // We add a fatal error indicating to the user that he has to enter the new string if he wants to execute the refactoring.
+ } </pre>
+ </p>
+ <ul>
+ <li><pre>public void execute(ModelSet modelSetToTransform);</pre> Here you will implement your transformation. The transformation has to be done on the parameter modelSetToTransform which is a ModelSet, <b>if you don't respect this rule the preview tool won't work properly</b>.</li>
+ </ul>
+ <p>Furthermore you may override the method <i>checkInitialConditions()</i> if you need to check some conditions before opening the UI. In the example below we verify the user has selected at least one element.</p><pre>
+ public RefactoringStatus checkInitialConditions(){
+ if(PapyrusRefactoringUtils.getSelectedElements().size()==0){
+ status.addFatalError("You have to select at least one element");
+ }
+ }
+ </pre>
+ <p>Moreover you inherit the field <i>fModelSet</i>,it represents the ModelSet on which the transformation will be done. You can use it in the <i>checkInitialConditions(), checkFinalConditions()</i> or even <i>createControl()</i> methods.</p>
+
+ <h2 id="Helper_classes">Helper classes</h2>
+ <p>The PRF also provides helper classes, which extend <i>AbstractPapyrusTransformation</i>, if you want to implement a refactoring that execute the same transformation on each element from a specified list of <i>EObject</i>.</p>
+ <p>Fist of all, you need to implement the <i>ITransformationOnElement</i> interface.
+ In the <i>transformationToExecute(EObject element)</i> you have to implement a transformation that applies itself on the given <i>EObject</i> in parameter.</p>
+ <p>In the example below, if the element is a NamedElement we change his name to "toto".</p>
+ <pre>
+ public void transformationToExecute(EObject element){
+ if(element instanceof NamedElement){
+ ((NamedElement)element).setName("toto");
+ }
+ }
+ </pre>
+ <p>Then you override one the following helper classes:</p>
+ <ul>
+ <li><i>AbstractTransformationOnElement</i>, in this case you will have to implement the methods:<pre>public Collection&lt;EObject&gt; getElementsListToTransform(); //In this method you have to return the list of <i>EObject</i> on which you want to apply your transformation.</pre><pre>public ITransformationOnElement getTransformationOnElement();//Here you will return your implementation of the <i>ITransformationOnElement</i> interface. </pre> </li>
+ </ul>
+ <ul>
+ <li><i>AbstractAllModelTransformation</i>, this class extends <i>AbstractTransformationOnElement</i> but the <i>getElementsListToTransform()</i> method is already implemented it returns the list of all the <i>EObject</i> of the model. You will only need to implement the <i> getTransformationOnElement()</i> method.</li>
+ </ul>
+ <ul>
+ <li><i>AbstractSelectedElementsTransformation</i>, this class is similar to <i>AbstractAllModelTransformation</i> except that the <i>EObject</i> on which the transformation will be applied is the list of the selected elements by the user.</li>
+ </ul>
+ <p>If you decide to override one of this helper classes you won't have to override the <i>execute()</i> method but you still need to implement the <i>createControl()</i>, <i>checkFinalConditions</i>, and maybe <i>checkFinalConditions</i> methods.
+ By overriding one of this classes, the user will be able, in the preview page, to check the elements on which he really wants the refactoring to be applied.</p>
+
+ <h2 id="Util_class">Util class</h2>
+ <p>To facilitate the implementation of your refactoring you can use the <i>PapyrusRefactoringUtils</i> class.
+ You can use, from this class, the following methods: </p>
+ <ul>
+ <li><i>getUMLRoot(ModelSet modelSet);</i> Return the UML Root if this ModelSet have an UML Model, null otherwise.</li>
+ </ul>
+ <ul>
+ <li><i>getAllElements(ModelSet modelSet);</i> Return all the semantic elements from this ModelSet.</li>
+ </ul>
+ <ul>
+ <li><i>getSelectedElements(ModelSet modelSet);</i> Return the selected elements in the Papyrus Editor or in the Model Explorer.</li>
+ </ul>
+ <ul>
+ <li><i>searchElements(EClass[] participantsTypes, ModelSet modelSet);</i> Return all the instances of the metaclasses given in <i>participantsTypes</i>, in the given ModelSet.</li>
+ </ul>
+ <ul>
+ <li><i>findEObjectInModelSet(EObject target,ModelSet modelSet);</i> Return the corresponding EObject (which will be a clone of the <i>target</i> parameter) in the wanted ModelSet. You may use this method in your transformation implementation if you want to use,in the <i>execute</i> method an EObject, you have not gotten neither from the <i>modelSetToTransform</i> parameter.</li>
+ </ul>
+
+ <h2 id="Launching_the_refactoring">Launching the refactoring</h2>
+ <p>First you have to instantiate a <i>PapyrusRefactoringOperation</i>, then you trigger the <i>run</i> method where you want to launch your Papyrus refactoring, for example in a handler. <pre>PapyrusRefactoringOperation operation=new PapyrusRefactoringOperation(myPapyrusTransformation);
+ operation.run();
+ </pre></p>
+
+ <h2 id="Add_an_entry_to_the_refactoring_menu">Add an entry to the refactoring menu</h2>
+ <p>A menu, named "Model Refactor", is available in the Papyrus Editor and Model Explorer contextual menus. It's id is: "org.eclipse.papyrus.refactoring.menu". If you want to add a menu entry for you refactoring in the "Model Refactor" menu, you will have to contribute to the "org.eclipse.ui.menus" extension point.
+ The following example adds an entry for a refactoring named "MyRefactoring".</p>
+ <pre>&lt;extension point="org.eclipse.ui.menus"&gt;
+ &lt;menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.refactoring.menu?after=additions"&gt;
+ &lt;command
+ commandId="org.eclipse.papyrus.refactoring.MyRefactoring.command"
+ id="MyRefactoring"
+ label="MyRefactoring"
+ style="push"&gt;
+ &lt;/command&gt;
+ &lt;/menuContribution&gt;
+ &lt;/extension&gt;
+ &lt;extension
+ point="org.eclipse.ui.commands"&gt;
+ &lt;command
+ id="org.eclipse.papyrus.refactoring.MyRefactoring.command"
+ name="MyRefactoringCommand"&gt;
+ &lt;/command&gt;
+ &lt;/extension&gt;
+ &lt;extension
+ point="org.eclipse.ui.handlers"&gt;
+ &lt;handler
+ class="org.eclipse.papyrus.refactoring.MyRefactoring.MyRefactoringHandler"
+ commandId="org.eclipse.papyrus.refactoring.MyRefactoring.command"&gt;
+ </pre><pre> &lt;/handler&gt;
+ &lt;/extension&gt;
+ </pre>
+ <p>Typically, in the handler your launch the refactoring (see the section before).</p>
+
+ <h2 id="Add_your_refactoring_user_documentation">Add your refactoring user documentation</h2>
+ <p>To add your refactoring user help to the available refactorings list in the context help, put
+ '../org.eclipse.papyrus.infra.refactoring.doc/resource/refactoring_user_guide.xml#refactoring_list' in the anchor field.</p>
+</body>
+</html> \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.mediawiki b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.mediawiki
new file mode 100644
index 00000000000..4b8d3fe9865
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_doc.mediawiki
@@ -0,0 +1,134 @@
+=How to implement your own Papyrus refactoring=
+
+
+==Introduction==
+
+The PRF (Papyrus Refactoring Framework) helps developers to create undoable and previewable Papyrus model refactorings. The PRF also warns the user if the transformation invalidates the model.
+
+In this page you will learn how to implement your own Papyrus transformation using the PRF.
+
+
+==Implementing the transformation==
+
+'''Before beginning the implementation you need to add the dependencies:''' ''org.eclipse.papyrus.infra.refactoring'', ''org.eclipse.papyrus.infra.core'',''org.eclipse.ltk.core.refactoring'', ''org.eclipse.ltk.ui.refactoring''.
+
+Then you have to do is to implement a class which extends ''AbstractPapyrusTransformation'' (which is a ''WizardPage'').
+
+In the constructor you have to indicate the human readable name of your transformation.
+
+Then you need to implement the following methods:
+
+* <pre> public void createControl(Composite parent);</pre> In this method you have to implement the control which will be displayed in the UI refactoring wizard. You are are responsible for ensuring the created control can be accessed via ''getControl()'', typically you instantiate your ''composite'' and set the control like this: ''setControl(composite)''
+
+* <pre>public RefactoringStatus checkFinalConditions();</pre> This method is called when the user clicks on the "OK" or "Preview" button. Here you check that all conditions are fulfilled to execute the transformation. Typically you verify that all the informations needed to do the transformation are given by the user. You have to return a [http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fltk%2Fcore%2Frefactoring%2FRefactoringStatus.html RefactoringStatus].
+
+ Example:
+ <pre> // In this example we assume that the String newString has to be given by the user in the UI.
+ RefactoringStatus status = new RefactoringStatus; // When a RefactoringStatus is instantiated his severity is 'OK'.
+ if(fNewString==null){
+ status.addFatalError("You have to indicate the new string"); // We add a fatal error indicating to the user that he has to enter the new string if he wants to execute the refactoring.
+ } </pre>
+
+* <pre>public void execute(ModelSet modelSetToTransform);</pre> Here you will implement your transformation. The transformation has to be done on the parameter modelSetToTransform which is a ModelSet, '''if you don't respect this rule the preview tool won't work properly'''.
+
+
+Furthermore you may override the method ''checkInitialConditions()'' if you need to check some conditions before opening the UI. In the example below we verify the user has selected at least one element.
+
+<pre>
+public RefactoringStatus checkInitialConditions(){
+if(PapyrusRefactoringUtils.getSelectedElements().size()==0){
+ status.addFatalError("You have to select at least one element");
+ }
+} </pre>
+
+Moreover you inherit the field ''fModelSet'',it represents the ModelSet on which the transformation will be done. You can use it in the ''checkInitialConditions(), checkFinalConditions()'' or even ''createControl()'' methods.
+
+==Helper classes==
+
+The PRF also provides helper classes, which extend ''AbstractPapyrusTransformation'', if you want to implement a refactoring that execute the same transformation on each element from a specified list of ''EObject''.
+
+Fist of all, you need to implement the ''ITransformationOnElement'' interface.
+In the ''transformationToExecute(EObject element)'' you have to implement a transformation that applies itself on the given ''EObject'' in parameter.
+
+In the example below, if the element is a NamedElement we change his name to "toto".
+<pre>
+ public void transformationToExecute(EObject element){
+ if(element instanceof NamedElement){
+ ((NamedElement)element).setName("toto");
+ }
+ }
+</pre>
+
+Then you override one the following helper classes:
+
+* ''AbstractTransformationOnElement'', in this case you will have to implement the methods:<pre>public Collection<EObject> getElementsListToTransform(); //In this method you have to return the list of ''EObject'' on which you want to apply your transformation.</pre><pre>public ITransformationOnElement getTransformationOnElement();//Here you will return your implementation of the ''ITransformationOnElement'' interface. </pre>
+
+*''AbstractAllModelTransformation'', this class extends ''AbstractTransformationOnElement'' but the ''getElementsListToTransform()'' method is already implemented it returns the list of all the ''EObject'' of the model. You will only need to implement the '' getTransformationOnElement()'' method.
+
+*''AbstractSelectedElementsTransformation'', this class is similar to ''AbstractAllModelTransformation'' except that the ''EObject'' on which the transformation will be applied is the list of the selected elements by the user.
+
+
+If you decide to override one of this helper classes you won't have to override the ''execute()'' method but you still need to implement the ''createControl()'', ''checkFinalConditions'', and maybe ''checkFinalConditions'' methods.
+By overriding one of this classes, the user will be able, in the preview page, to check the elements on which he really wants the refactoring to be applied.
+
+==Util class==
+
+To facilitate the implementation of your refactoring you can use the ''PapyrusRefactoringUtils'' class.
+You can use, from this class, the following methods:
+
+*''getUMLRoot(ModelSet modelSet);'' Return the UML Root if this ModelSet have an UML Model, null otherwise.
+
+*''getAllElements(ModelSet modelSet);'' Return all the semantic elements from this ModelSet.
+
+*''getSelectedElements(ModelSet modelSet);'' Return the selected elements in the Papyrus Editor or in the Model Explorer.
+
+*''searchElements(EClass[] participantsTypes, ModelSet modelSet);'' Return all the instances of the metaclasses given in ''participantsTypes'', in the given ModelSet.
+
+*''findEObjectInModelSet(EObject target,ModelSet modelSet);'' Return the corresponding EObject (which will be a clone of the ''target'' parameter) in the wanted ModelSet. You may use this method in your transformation implementation if you want to use,in the ''execute'' method an EObject, you have not gotten neither from the ''modelSetToTransform'' parameter.
+
+==Launching the refactoring==
+
+First you have to instantiate a ''PapyrusRefactoringOperation'', then you trigger the ''run'' method where you want to launch your Papyrus refactoring, for example in a handler. <pre>PapyrusRefactoringOperation operation=new PapyrusRefactoringOperation(myPapyrusTransformation);
+operation.run();
+</pre>
+
+==Add an entry to the refactoring menu==
+
+A menu, named "Model Refactor", is available in the Papyrus Editor and Model Explorer contextual menus. It's id is: "org.eclipse.papyrus.refactoring.menu". If you want to add a menu entry for you refactoring in the "Model Refactor" menu, you will have to contribute to the "org.eclipse.ui.menus" extension point.
+The following example adds an entry for a refactoring named "MyRefactoring".
+
+ <extension point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.refactoring.menu?after=additions">
+ <command
+ commandId="org.eclipse.papyrus.refactoring.MyRefactoring.command"
+ id="MyRefactoring"
+ label="MyRefactoring"
+ style="push">
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.papyrus.refactoring.MyRefactoring.command"
+ name="MyRefactoringCommand">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.refactoring.MyRefactoring.MyRefactoringHandler"
+ commandId="org.eclipse.papyrus.refactoring.MyRefactoring.command">
+
+ </handler>
+ </extension>
+
+
+Typically, in the handler your launch the refactoring (see the section before).
+
+==Add your refactoring user documentation==
+
+To add your refactoring user help to the available refactorings list in the context help, put
+'../org.eclipse.papyrus.infra.refactoring.doc/resource/refactoring_user_guide.xml#refactoring_list' in the anchor field. \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.html b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.html
new file mode 100644
index 00000000000..a30042064bd
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.html
@@ -0,0 +1,37 @@
+<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
+<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>
+<body>
+ <p>In this documentation we will execute a refactoring which renames to "Test_refactoring" the UML::NamedElement of a model. We will execute this refactoring on the following model: </p>
+ <p><img border="0" src="images/example-model.png"/></p>
+
+ <h1 id="Model_refactor">Model refactor</h1>
+ <p>As you can see in the following image, the user can choose between displaying a preview of the impact the refactoring will have on the model or executing the transformation directly.</p>
+ <p><img border="0" src="images/wizard-refactoring.png"/></p>
+ <ul>
+ <li>A area: If the user clicks on the 'OK' button, the transformation will be directly executed.</li>
+ </ul>
+ <ul>
+ <li>B area: If the user chooses to click on the 'Preview' button, a preview of the impact the transformation will have on the model will be displayed.</li>
+ </ul>
+
+ <h1 id="Preview_page">Preview page</h1>
+ <p>The following image illustrate the preview page.</p>
+ <p><img border="0" src="images/preview-page.png"/></p>
+ <ul>
+ <li>In the A area the user is able to select the changes he really wants to apply. Only the checked changes will be applied. For refactorings which execute the same transformation on each element from a specified list (here the list of elements are the selected ones, and for each one we change its name), there is one change for each element. For refactorings more general only one change is created.</li>
+ </ul>
+ <ul>
+ <li>In the B area a comparison between the original model and the refactored model is displayed. Here we can see that this transformation changes the name to "Test_refactoring" of each element.</li>
+ </ul>
+ <ul>
+ <li>In the C area the user can decide to execute the transformation by clicking on the 'OK' button, canceling the refactoring or going back to the home page refactoring.</li>
+ </ul>
+ <p>In our example if we decide to execute the refactoring the model will be: </p>
+ <p><img border="0" src="images/refactored-model.png"/></p>
+
+ <h1 id="Model_validity">Model validity</h1>
+ <p>Before applying the transformation, if the refactoring will affects the validity of the model the Papyrus refactoring tool warns the user and gives him the list of the problems the refactoring will cause.</p>
+ <p><img border="0" src="images/validity-page.png"/></p>
+ <p>In our case after the refactoring, two UML::Class in the same container will have the same name (and the same qualified name so). The Papyrus refactoring tool warns about this problem.</p>
+</body>
+</html> \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.mediawiki b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.mediawiki
new file mode 100644
index 00000000000..a9bf00742fb
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/Dev_user.mediawiki
@@ -0,0 +1,38 @@
+In this documentation we will execute a refactoring which renames to "Test_refactoring" the UML::NamedElement of a model. We will execute this refactoring on the following model:
+
+[[image:images/example-model.png]]
+
+=Model refactor=
+
+As you can see in the following image, the user can choose between displaying a preview of the impact the refactoring will have on the model or executing the transformation directly.
+
+[[image:images/wizard-refactoring.png]]
+
+*A area: If the user clicks on the 'OK' button, the transformation will be directly executed.
+
+*B area: If the user chooses to click on the 'Preview' button, a preview of the impact the transformation will have on the model will be displayed.
+
+=Preview page=
+
+The following image illustrate the preview page.
+
+[[image:images/preview-page.png]]
+
+*In the A area the user is able to select the changes he really wants to apply. Only the checked changes will be applied. For refactorings which execute the same transformation on each element from a specified list (here the list of elements are the selected ones, and for each one we change its name), there is one change for each element. For refactorings more general only one change is created.
+
+*In the B area a comparison between the original model and the refactored model is displayed. The left side of the compare viewer shows the refactored model, the right side shows the original.
+Here we can see that this transformation changes the name to "Test_refactoring" of each element.
+
+*In the C area the user can decide to execute the transformation by clicking on the 'OK' button, canceling the refactoring or going back to the home page refactoring.
+
+In our example if we decide to execute the refactoring the model will be:
+
+[[image:images/refactored-model.png]]
+
+=Model validity=
+
+Before applying the transformation, if the refactoring will affects the validity of the model the Papyrus refactoring tool warns the user and gives him the list of the problems the refactoring will cause.
+
+[[image:images/validity-page.png]]
+
+In our case after the refactoring, two UML::Class in the same container will have the same name (and the same qualified name so). The Papyrus refactoring tool warns about this problem. \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/example-model.png b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/example-model.png
new file mode 100644
index 00000000000..81d2fc640df
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/example-model.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/preview-page.png b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/preview-page.png
new file mode 100644
index 00000000000..2161c4329f9
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/preview-page.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/refactored-model.png b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/refactored-model.png
new file mode 100644
index 00000000000..c36ee25a916
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/refactored-model.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/validity-page.png b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/validity-page.png
new file mode 100644
index 00000000000..3369922a002
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/validity-page.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/wizard-refactoring.png b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/wizard-refactoring.png
new file mode 100644
index 00000000000..f7ee9c9b811
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/images/wizard-refactoring.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_dev_guide.xml b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_dev_guide.xml
new file mode 100644
index 00000000000..47539a621cb
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_dev_guide.xml
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<toc label="How to implement your own Papyrus refactoring" link_to="../../../plugins/doc/org.eclipse.papyrus.infra.doc/toc.xml#PapyrusDocDev" topic="doc/Dev_doc.html">
+ <topic href="doc/Dev_doc.html" label="How to implement your own Papyrus refactoring">
+ </topic>
+
+</toc>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_user_guide.xml b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_user_guide.xml
new file mode 100644
index 00000000000..fcafc102743
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/doc/refactoring_user_guide.xml
@@ -0,0 +1,11 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<toc label="Model Refactor" link_to="../../../plugins/doc/org.eclipse.papyrus.infra.doc/toc.xml#PapyrusDocUser" topic="doc/Dev_user.html">
+ <topic href="doc/Dev_user.html" label="Model Refactor">
+ <topic href="resource/Dev_user.html" label="Model Refactor Wizard">
+ </topic>
+ <topic label="Available Refactorings">
+ <anchor id="refactoring_list"/>
+ </topic>
+ </topic>
+
+</toc>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/Papyrus_16x16.gif b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/Papyrus_16x16.gif
new file mode 100644
index 00000000000..8a31f458379
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/Papyrus_16x16.gif
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/refactor.png b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/refactor.png
new file mode 100644
index 00000000000..049da9f00bd
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/icons/refactor.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.properties b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.properties
new file mode 100644
index 00000000000..677c201ba35
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.properties
@@ -0,0 +1,14 @@
+# Copyright (c) 2015 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:
+# Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - initial API and implementation
+
+pluginName=Papyrus Refactoring Core
+vendorName=Eclipse Modeling Project
+
+refactoringContribution.label=Refactor
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.xml b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.xml
new file mode 100644
index 00000000000..94e2a464766
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/plugin.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <!-- <extension
+ point="org.eclipse.search.searchPages">
+ <page
+ canSearchEnclosingProjects="true"
+ class="org.eclipse.papyrus.refactoring.ui.RefactoringPapyrusSearchPage"
+ enabled="true"
+ extensions="di:99"
+ icon="icons/PapyrusSearch.png"
+ id="org.eclipse.papyrus.search.ui.pages.PapyrusSearchPage"
+ label="%searchPageLabel"
+ showScopeSection="true">
+ </page>
+ </extension> -->
+ <extension
+ point="org.eclipse.ltk.ui.refactoring.changePreviewViewers">
+ <changePreviewViewer
+ class="org.eclipse.papyrus.refactoring.ui.PapyrusRefactoringPreview"
+ id="org.eclipse.papyrus.refactoring.changePreviewViewer">
+ <enablement>
+ <instanceof
+ value="org.eclipse.papyrus.refactoring.core.IPreviewablePapyrusChange">
+ </instanceof>
+ </enablement>
+ </changePreviewViewer>
+ </extension>
+ <extension
+ point="org.eclipse.ltk.ui.refactoring.statusContextViewers">
+ <statusContextViewer
+ class="org.eclipse.papyrus.refactoring.ui.PapyrusStatusContextViewer"
+ id="org.eclipse.papyrus.infra.refactoring.statusContextViewer">
+ <enablement>
+ <instanceof
+ value="org.eclipse.papyrus.refactoring.core.PapyrusRefactoringValidationStatusContext">
+ </instanceof>
+ </enablement>
+ </statusContextViewer>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup?after=org.eclipse.papyrus.views.modelexplorer.popup.validation">
+ <menu
+ icon="icons/Papyrus_16x16.gif"
+ id="org.eclipse.papyrus.refactoring.menu"
+ label="%refactoringContribution.label">
+ <visibleWhen>
+ <or>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ <count
+ value="+">
+ </count>
+ </or>
+ </visibleWhen>
+ </menu>
+ </menuContribution>
+
+ <menuContribution
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu?after=org.eclipse.papyrus.views.modelexplorer.popup.validation">
+ <menu
+ icon="icons/Papyrus_16x16.gif"
+ id="org.eclipse.papyrus.refactoring.menu"
+ label="%refactoringContribution.label">
+ <visibleWhen>
+ <or>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ <count
+ value="+">
+ </count>
+ </or>
+ </visibleWhen>
+ </menu>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.help.toc">
+ <toc
+ file="doc/refactoring_user_guide.xml"
+ primary="false">
+ </toc>
+ <toc
+ file="doc/refactoring_dev_guide.xml"
+ primary="true">
+ </toc>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/pom.xml b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/pom.xml
new file mode 100644
index 00000000000..2e852fb3785
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.eclipse.papyrus.refactoring</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <groupId>org.eclipse.papyrus</groupId>
+ <packaging>eclipse-plugin</packaging>
+ <parent>
+ <relativePath>../../../releng/extra</relativePath>
+ <groupId>org.eclipse.papyrus</groupId>
+ <artifactId>org.eclipse.papyrus.extra.releng</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.mylyn.docs</groupId>
+ <artifactId>org.eclipse.mylyn.wikitext.core.maven</artifactId>
+ <configuration>
+ <sourceFolder>doc</sourceFolder>
+ <outputFolder>${project.build.directory}/site/generated-eclipse-help</outputFolder>
+ <!-- copyrightNotice>${help.copyrightNotice}</copyrightNotice>
+ <title>${help.documentTitle}</title-->
+ <multipleOutputFiles>false</multipleOutputFiles>
+ <navigationImages>true</navigationImages>
+ <formatOutput>true</formatOutput>
+ <htmlFilenameFormat>$1.html</htmlFilenameFormat>
+ <xmlFilenameFormat>$1-toc.xml</xmlFilenameFormat>
+ <helpPrefix>target/site/generated-eclipse-help</helpPrefix>
+ <!-- stylesheetUrls>
+ <param>styles/main.css</param>
+ </stylesheetUrls-->
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>eclipse-help</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.mylyn.docs</groupId>
+ <artifactId>org.eclipse.mylyn.wikitext.mediawiki.core</artifactId>
+ <version>${mylyn.wikitext.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/Activator.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/Activator.java
new file mode 100644
index 00000000000..e2e9724424d
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/Activator.java
@@ -0,0 +1,118 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.refactoring"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ public static Image shellImage;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ // shellImage = getImage("icons/Papyrus_16x16.gif");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ log = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Get the image from its path in the current plugin
+ *
+ * @param path
+ * @return
+ * The {@link #org.eclipse.swt.graphics.Image image}
+ */
+ public Image getImage(String path) {
+ return getImage(PLUGIN_ID, path);
+ }
+
+ /**
+ * Get the image from its path in the specified plugin
+ *
+ * @param pluginId
+ * @param path
+ * @return
+ * The {@link #org.eclipse.swt.graphics.Image image}
+ */
+ public Image getImage(String pluginId, String path) {
+ final ImageRegistry registry = getImageRegistry();
+ String key = pluginId + "/" + path; //$NON-NLS-1$
+ Image image = registry.get(key);
+ if (image == null) {
+ registry.put(key, AbstractUIPlugin.imageDescriptorFromPlugin(pluginId, path));
+ image = registry.get(key);
+ }
+ return image;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in relative path.
+ *
+ * @param path
+ * @return the image descriptor
+ */
+ public ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/AbstractPapyrusTransformation.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/AbstractPapyrusTransformation.java
new file mode 100644
index 00000000000..f5ee0934e1b
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/AbstractPapyrusTransformation.java
@@ -0,0 +1,126 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Class to be subclassed by clients who want to implement their own refactoring.
+ * Represents a specific transformation in the Papyrus refactoring tool.
+ *
+ * <p>
+ * The {@link #checkFinalConditions} method is called when the 'OK' or 'Preview' button is pressed. If the requested conditions for executing
+ * this transformation are fulfilled the {@link #execute} method is called.
+ * </p>
+ *
+ * @see org.eclipse.ltk.core.refactoring.RefactoringStatus
+ * @see org.eclipse.jface.wizard.IWizardPage
+ */
+public abstract class AbstractPapyrusTransformation extends UserInputWizardPage {
+
+ /** The {@link ModelSet} on which the transformation will be done. */
+ protected ModelSet fModelSet;
+
+ /** The element selected to transform */
+ protected EObject fElementToTransform;
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * The label provided to the transformation
+ */
+ public AbstractPapyrusTransformation(String label) {
+ super(label);
+
+ }
+
+ /**
+ * Check the conditions before opening the UI page of this refactoring.
+ * The default status is 'OK'. Clients may override this method if they have some initial conditions to check.
+ *
+ * @return refactoring status if the initial conditions are fulfilled or not. If the status is <code>RefactoringStatus#FATAL</code>
+ * the refactoring is considered as not being executable.
+ */
+ public RefactoringStatus checkInitialConditions() {
+ return new RefactoringStatus();
+ }
+
+ /**
+ * Checks if all conditions for executing this transformation are fulfilled. This method is called after the {@link #checkInitialConditions},
+ * when the 'OK' or 'Preview' button is pressed to check if we can execute the transformation.
+ *
+ * @return refactoring status if the final conditions are fulfilled or not.If the status is <code>RefactoringStatus#FATAL</code>
+ * the refactoring is considered as not being executable.
+ */
+ public abstract RefactoringStatus checkFinalConditions();
+
+ /**
+ *
+ */
+ /**
+ * Method where the source code of the transformation has to be implemented.
+ * If all conditions are fulfilled this method is called to execute this Papyrus transformation.
+ * The transformation has to be done on modelSetToTransform parameter (which is an instance of ModelSet).
+ *
+ * @param modelSetToTransform
+ */
+ public abstract void execute(ModelSet modelSetToTransform);
+
+ /**
+ * Construct the UI for this transformation
+ *
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ * The shell in which to create it
+ */
+ @Override
+ public abstract void createControl(Composite parent);
+
+
+
+ /**
+ * @return true if it is possible to launch the refactoring, false otherwise.
+ */
+ public boolean isEnable() {
+ if (checkInitialConditions().getSeverity() == RefactoringStatus.OK) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Set the modelSet in order to fetch it later
+ *
+ * @param modelSet
+ */
+ public void setModelSet(ModelSet modelSet) {
+ fModelSet = modelSet;
+ }
+
+ /**
+ * Set the element to transform in order to fetch it later
+ *
+ * @param elementToTransform
+ */
+ public void setElementToTransform(EObject elementToTransform) {
+ fElementToTransform = elementToTransform;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/IPreviewablePapyrusChange.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/IPreviewablePapyrusChange.java
new file mode 100644
index 00000000000..4a25e968b0f
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/IPreviewablePapyrusChange.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.core.resources.IFile;
+
+/**
+ * Interface to present comparison between two files.
+ *
+ * @noimplement This class is not intended to be implemented by clients.
+ *
+ */
+public interface IPreviewablePapyrusChange {
+
+ /**
+ *
+ * @return The preview "di" file.
+ */
+ public IFile getPreviewFile();
+
+ /**
+ *
+ * @return The original "di" file.
+ */
+ public IFile getInitialFile();
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusChange.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusChange.java
new file mode 100644
index 00000000000..94ab493a40d
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusChange.java
@@ -0,0 +1,246 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import java.io.IOException;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelsReader;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.emf.utils.ResourceUtils;
+import org.eclipse.papyrus.refactoring.Activator;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+
+
+/**
+ * A {@link Change} for Papyrus refactoring.
+ *
+ * @noextend This class is not intended to be extended by clients.
+ *
+ */
+public class PapyrusChange extends Change implements IPreviewablePapyrusChange {
+
+ /** The ModelSet on which we apply the change. */
+ protected ModelSet fModelSet;
+
+ /** The Papyrus Refactoring to execute. */
+ protected AbstractPapyrusTransformation fPapyrusRefactoringTransformation;
+
+ /** The name of the refactoring. */
+ private final String fName;
+
+ /** The preview modelSet containing the change used to compare it to the original in the compare view */
+ private ModelSet fPreviewModelSet;
+
+ /** The element to change */
+ private Object fElementToTransform;
+
+ /**
+ * Constructor.
+ *
+ * @param papyrusRefactoringTransformation
+ * The transformation to execute
+ * @param name
+ * The tag associated to the transformation
+ * @param modelSet
+ * The modelSet containing the element to transform
+ */
+ public PapyrusChange(AbstractPapyrusTransformation papyrusRefactoringTransformation, String name, ModelSet modelSet) {
+ fName = name;
+ fModelSet = modelSet;
+ fPapyrusRefactoringTransformation = papyrusRefactoringTransformation;
+ fElementToTransform = papyrusRefactoringTransformation.fElementToTransform;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ RefactoringStatus status = new RefactoringStatus();
+ try {
+ pm.beginTask(Messages.PAPYRUSCHANGE_CHECKVALIDITY, 3);
+ if (fModelSet == null) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(Messages.PAPYRUSCHANGE_MODELOPEN_ERROR));
+ }
+ return status;
+ } finally {
+ pm.done();
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ return performRefactor(fModelSet, Messages.PAPYRUSCHANGE_SET_PERFORM);
+ }
+
+ /**
+ * Apply the refactoring on the given ModelSet
+ *
+ * @param modelSet
+ * The ModelSet on which we do the refactoring.
+ * @return
+ */
+ protected Change performRefactor(ModelSet modelSet, String label) {
+ final TransactionalEditingDomain editingDomain = modelSet.getTransactionalEditingDomain();
+ // final PapyrusRefactoringCommand refactoringCommand = new PapyrusRefactoringCommand(editingDomain, fPapyrusRefactoringTransformation, modelSet);
+ final PapyrusRefactoringCommand emfOperation = new PapyrusRefactoringCommand(editingDomain, fPapyrusRefactoringTransformation, modelSet, label + fName);
+
+ try {
+ emfOperation.execute(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+
+ return new UndoPapyrusChange(emfOperation, fElementToTransform, fName);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getModifiedElement() {
+ // return fModelSet;
+ return fElementToTransform;
+ }
+
+ // TODO a proper clone, so as to get the preview working !
+ /**
+ * Clones the current modelSet to apply it the Changes
+ *
+ * @return
+ * The preview modelSet
+ */
+ public ModelSet getChangePreviewModelSet() {
+ ModelSet previewModelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(previewModelSet);
+ try {
+ previewModelSet.loadModels(fModelSet.getURIWithoutExtension());
+
+ } catch (ModelMultiException e) {
+ Activator.log.error(e);
+ }
+
+ return previewModelSet;
+ // getPreviewFile();
+ // return fPreviewModelSet;
+ }
+
+ /**
+ * Creates a copy of the original ModelSet and execute the refactoring on it.
+ *
+ * @return A preview file of the refactoring which shows the refactoring effects.
+ */
+ @Override
+ public IFile getPreviewFile() {
+ String nameProject = Messages.PAPYRUSCHANGE_PREVIEWPROJECT_NAME;
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ IProject project = root.getProject(nameProject);
+ // System.err.println("getPreviewFile");
+
+ try {
+ if (!project.exists()) {
+ project.create(null);
+ }
+ project.open(null);
+ } catch (CoreException e1) {
+ Activator.log.error(e1);
+ }
+
+ IPath path = new Path(project.getFullPath().toString() + Messages.PAPYRUSCHANGE_PREVIEWMODEL_NAME);
+ IFile previewFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ fModelSet.saveCopy(path.removeFileExtension());
+ ModelSet previewModelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(previewModelSet);
+ // System.err.println("initPreviewModelSet");
+
+ try {
+ previewModelSet.loadModels(URI.createPlatformResourceURI(path.toString(), true));
+
+ } catch (ModelMultiException e) {
+ Activator.log.error(e);
+ }
+
+ performRefactor(previewModelSet, Messages.PAPYRUSCHANGE_PREVIEW_PERFORM);
+
+ try {
+ // modelSetForPreviewFile.saveAs(URI.createPlatformResourceURI(path.toString(), true));
+ previewModelSet.saveAs(URI.createPlatformResourceURI(path.toString(), true));
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ // Assert.isNotNull(modelSetForPreviewFile, Messages.PAPYRUSCHANGE_PREVIEWCREATION_ERROR);
+ Assert.isNotNull(previewModelSet, Messages.PAPYRUSCHANGE_PREVIEWCREATION_ERROR);
+
+ return previewFile;
+ }
+
+
+ /**
+ * Return the original "di" file.
+ */
+ @Override
+ public IFile getInitialFile() {
+ // Resource diResource = DiModelUtils.getDiResource(fModelSet);
+ Resource diResource = ((DiModel) fModelSet.getModel(DiModel.DI_MODEL_ID)).getResource();
+ IFile file = ResourceUtils.getFile(diResource);
+
+ return file;
+ }
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoring.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoring.java
new file mode 100644
index 00000000000..ae437b06d0c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoring.java
@@ -0,0 +1,255 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.services.validation.internal.EcoreDiagnostician;
+import org.eclipse.papyrus.refactoring.Activator;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.AbstractTransformationOnElement;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.PapyrusCompositeChange;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * This class represents the {@link Refactoring} for Papyrus refactoring.
+ *
+ * @noextend This class is not intended to be extended by clients.
+ *
+ */
+@SuppressWarnings("restriction")
+public class PapyrusRefactoring extends Refactoring {
+
+ /** The human readable name */
+ protected String fName;
+
+ /** The ModelSet to be modified */
+ protected ModelSet fModelSet;
+
+ /** The {@link AbstractPapyrusTransformation} corresponding to this Papyrus refactoring */
+ protected AbstractPapyrusTransformation fPapyrusRefactoringTransformation;
+
+ /** Parameter used to remove duplicates when running the diagnostic on the preview and the getting the related change */
+ private Change change;
+
+ /**
+ * A {@link Runnable} to check final conditions before executing the transformation
+ */
+ private class FinalConditionsRunnable implements Runnable {
+
+ private RefactoringStatus finalRefactoringStatus;
+
+ @Override
+ public void run() {
+ finalRefactoringStatus = fPapyrusRefactoringTransformation.checkFinalConditions();
+ }
+
+ public RefactoringStatus getfinalRefactoringStatus() {
+ return finalRefactoringStatus;
+ }
+ }
+
+ /**
+ * A {@link Runnable} to check initial conditions before executing the transformation
+ */
+ private class InitialConditionsRunnable implements Runnable {
+
+ private RefactoringStatus initialRefactoringStatus;
+
+ @Override
+ public void run() {
+ initialRefactoringStatus = fPapyrusRefactoringTransformation.checkInitialConditions();
+ }
+
+ public RefactoringStatus getInitialRefactoringStatus() {
+ return initialRefactoringStatus;
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name
+ * The name associated to this transformation
+ * @param modelSet
+ * The modelSet to modify
+ * @param papyrusRefactoringTransformation
+ * The transformation to execute (rename, mutation,...)
+ */
+ public PapyrusRefactoring(String name, ModelSet modelSet, AbstractPapyrusTransformation papyrusRefactoringTransformation) {
+ fName = name;
+ fModelSet = modelSet;
+ fPapyrusRefactoringTransformation = papyrusRefactoringTransformation;
+ }
+
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * Verify that the modelSet to transform has been provided prior to the execution
+ *
+ * @see org.eclipse.ltk.core.refactoring.Refactoring#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
+ *
+ * @param pm
+ * @return
+ * OK status if the modelSet was provided, null otherwise
+ * @throws CoreException
+ * @throws OperationCanceledException
+ */
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+
+ RefactoringStatus status = new RefactoringStatus();
+
+ try {
+ pm.beginTask(Messages.PAPYRUSREFACTORING_CHECKPRECONDITIONS, 1);
+ if (fModelSet == null) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(Messages.PAPYRUSREFACTORING_RESOURCEOPEN_ERROR));
+
+ } else {
+ InitialConditionsRunnable initialConditionsRunnable = new InitialConditionsRunnable();
+ Display.getDefault().syncExec(initialConditionsRunnable);
+ // Display.getDefault().asyncExec(initialConditionsRunnable);
+ return initialConditionsRunnable.getInitialRefactoringStatus();
+ }
+
+ } finally {
+ pm.done();
+ }
+
+ return null;
+ }
+
+ /**
+ * Verify that the transformation has not been canceled and that the transformation executed itself without errors
+ *
+ * @see org.eclipse.ltk.core.refactoring.Refactoring#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor)
+ *
+ * @param pm
+ * @return
+ * @throws CoreException
+ * @throws OperationCanceledException
+ */
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+
+ try {
+ pm.beginTask(Messages.PAPYRUSREFACTORING_MODELVALIDITY, 2);
+ FinalConditionsRunnable finalConditionRunnable = new FinalConditionsRunnable();
+ Display.getDefault().syncExec(finalConditionRunnable);
+ // Display.getDefault().asyncExec(finalConditionRunnable);
+
+ RefactoringStatus status = finalConditionRunnable.getfinalRefactoringStatus();
+
+ if (status.getSeverity() != RefactoringStatus.FATAL) {
+ Diagnostic diagnostic = diagnosticRefactoring();
+
+ if (diagnostic != null && diagnostic.getSeverity() != Diagnostic.OK) {
+ status.addError(Messages.PAPYRUSREFACTORING_MODELVALIDITY_ERROR, new PapyrusRefactoringValidationStatusContext(diagnostic));
+ }
+ }
+
+ return status;
+
+ } finally {
+ pm.done();
+ }
+
+ }
+
+ /**
+ * Verify if the refactoring will affect the model validity.
+ *
+ * @return a Diagnostic of the impact of the refactoring.
+ */
+ private Diagnostic diagnosticRefactoring() {
+ ModelSet previewModelSet = null;
+ if (fPapyrusRefactoringTransformation instanceof AbstractTransformationOnElement) {
+ change = new PapyrusCompositeChange((AbstractTransformationOnElement) fPapyrusRefactoringTransformation, fModelSet);
+ // previewModelSet = change.getCompositePreviewModelSet();
+ previewModelSet = ((PapyrusCompositeChange) change).getChangePreviewModelSet();
+ } else {
+ change = new PapyrusChange(fPapyrusRefactoringTransformation, fName, fModelSet);
+ previewModelSet = ((PapyrusChange) change).getChangePreviewModelSet();
+ }
+
+ if (previewModelSet != null) {
+ UmlModel umlModel = UmlUtils.getUmlModel(previewModelSet);
+ if (umlModel != null) {
+ EObject root;
+ try {
+ root = umlModel.lookupRoot();
+ TransactionalEditingDomain domain = previewModelSet.getTransactionalEditingDomain();
+ EcoreDiagnostician diagnostician = new EcoreDiagnostician();
+ AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain) domain).getAdapterFactory() : null;
+ diagnostician.initialize(adapterFactory, new NullProgressMonitor());
+
+ return diagnostician.validate(root);
+ } catch (NotFoundException e) {
+ Activator.log.error(e);
+ }
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ try {
+ pm.beginTask(Messages.PAPYRUSREFACTORING_EXECUTE, 1);
+
+ if (fPapyrusRefactoringTransformation instanceof AbstractTransformationOnElement) {
+ fPapyrusRefactoringTransformation.setModelSet(fModelSet);
+ // PapyrusCompositeChange compositeChange = new PapyrusCompositeChange((AbstractTransformationOnElement) fPapyrusRefactoringTransformation, fModelSet);
+ // return compositeChange;
+ } else {
+ // PapyrusChange change = new PapyrusChange(fPapyrusRefactoringTransformation, fName, fModelSet);
+ // return change;
+ }
+
+ return change;
+
+ } finally {
+ pm.done();
+ }
+ }
+
+
+
+ /**
+ * @return The corresponding {@link AbstractPapyrusTransformation}
+ */
+ public AbstractPapyrusTransformation getPapyrusTransformation() {
+ return fPapyrusRefactoringTransformation;
+ }
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringCommand.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringCommand.java
new file mode 100644
index 00000000000..1cbb949516d
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringCommand.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.AbstractEMFOperation;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+
+/**
+ * A {@link RecordingCommand} to execute a Papyrus refactoring transformation
+ *
+ * @noextend This class is not intended to be extended by clients.
+ */
+public class PapyrusRefactoringCommand extends AbstractEMFOperation {
+
+ /** The modelSet to transform */
+ private ModelSet fModelSet;
+
+ /** The papyrus transformation to execute */
+ protected AbstractPapyrusTransformation fPapyrusRefactoringTransformation;
+
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * The editingDomain used to executed the command
+ * @param papyrusRefactoringTransformation
+ * The transformation to execute inside the command
+ * @param modelSet
+ * The modelSet to change
+ * @param label
+ * The label of the command
+ */
+ public PapyrusRefactoringCommand(TransactionalEditingDomain domain, AbstractPapyrusTransformation papyrusRefactoringTransformation,
+ ModelSet modelSet, String label) {
+ super(domain, label);
+ fPapyrusRefactoringTransformation = papyrusRefactoringTransformation;
+ fPapyrusRefactoringTransformation.setModelSet(modelSet);
+ fModelSet = modelSet;
+ }
+
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ fPapyrusRefactoringTransformation.execute(fModelSet);
+ return null;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringOperation.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringOperation.java
new file mode 100644
index 00000000000..f2b237b2d11
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringOperation.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.refactoring.ui.PapyrusRefactoringWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Activate the refactoring cycle.
+ *
+ * @noextend This class is not intended to be extended by clients.
+ */
+public class PapyrusRefactoringOperation {
+
+ /** The papyrus transformation to execute */
+ private AbstractPapyrusTransformation fPapyrusTransformation;
+
+ /**
+ * Constructor.
+ *
+ * @param PapyrusTransformation
+ * The transformation linked to this operation
+ */
+ public PapyrusRefactoringOperation(AbstractPapyrusTransformation PapyrusTransformation) {
+ fPapyrusTransformation = PapyrusTransformation;
+ }
+
+ /**
+ * Create the refactoring linked to the transformation, then create the wizard related to this refactoring, then the operation to run
+ * {@link org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.RefactoringWizardOpenOperation(RefactoringWizard wizard)}
+ *
+ */
+ public void run() {
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ ModelSet modelSet = getModelSet();
+ fPapyrusTransformation.setModelSet(modelSet);
+ String label = fPapyrusTransformation.getName();
+ PapyrusRefactoring currentRefactoring = new PapyrusRefactoring(label, modelSet, fPapyrusTransformation);
+ PapyrusRefactoringWizard refactoringWizard = new PapyrusRefactoringWizard(currentRefactoring, label);
+ RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(refactoringWizard);
+
+ try {
+ operation.run(win.getShell(), label);
+ } catch (InterruptedException e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+
+ /**
+ * Get the model which is the target of this refactoring operation
+ *
+ * @return
+ * The modelSet to transform
+ */
+ public ModelSet getModelSet() {
+ try {
+ ModelSet modelSet = org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers.getInstance().getModelSet(null);
+ return modelSet;
+
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringValidationStatusContext.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringValidationStatusContext.java
new file mode 100644
index 00000000000..447713cec41
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/PapyrusRefactoringValidationStatusContext.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.ltk.core.refactoring.RefactoringStatusContext;
+import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
+
+/**
+ * {@link RefactoringStatusContext} for annotating a the {@link RefactoringStatusEntry} linked to
+ * the verification of the model validity after the refactoring.
+ *
+ */
+public class PapyrusRefactoringValidationStatusContext extends RefactoringStatusContext {
+
+ /** The {@link Diagnostic} that represents the model validity after the refactoring. */
+ private Diagnostic fDiagnostic;
+
+
+ public PapyrusRefactoringValidationStatusContext(Diagnostic diagnostic) {
+ fDiagnostic = diagnostic;
+ }
+
+ public Diagnostic getfDiagnostic() {
+ return fDiagnostic;
+ }
+
+ @Override
+ public Object getCorrespondingElement() {
+ return fDiagnostic;
+ }
+
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/UndoPapyrusChange.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/UndoPapyrusChange.java
new file mode 100644
index 00000000000..428ac046aed
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/core/UndoPapyrusChange.java
@@ -0,0 +1,110 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.core;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.emf.workspace.AbstractEMFOperation;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+
+
+/**
+ * This class manages the undo operation of the transformation based on the LTK refactoring framework
+ *
+ * @noextend This class is not intended to be extended by clients.
+ *
+ */
+public class UndoPapyrusChange extends Change {
+
+ /** The EMFOperation encappsulating the execution of the Change to enable a proper undo */
+ private AbstractEMFOperation emfOperation;
+
+ /** The name of the executed command */
+ private String fName;
+
+ /** The element to transform through the execution of the change */
+ private Object fElementToTransform;
+
+ /** Boolean used to mark if the change can be undone or not */
+ private boolean fCanUndo;
+
+ private static final String CHECKING_CONDITIONS = Messages.UNDOPAPYRUSCHANGE_VALIDITYCHECK;
+
+ private static final String INVALID_UNDO = Messages.UNDOPAPYRUSCHANGE_ERROR;
+
+ /**
+ * Constructor.
+ *
+ * @param emfOperation
+ * The operation rewinded by the change
+ * @param elementToTransform
+ * The element rewinded
+ * @param elementName
+ * The name of the rewinded element
+ */
+ public UndoPapyrusChange(AbstractEMFOperation emfOperation, Object elementToTransform, String elementName) {
+ this.emfOperation = emfOperation;
+ this.fName = elementName;
+ this.fElementToTransform = elementToTransform;
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ try {
+ emfOperation.undo(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ Activator.log.error(e);
+ }
+
+ // Can't only return null if the command needs to be redone
+ // This undoChange undo the previous one
+ return new UndoPapyrusChange(emfOperation, fElementToTransform, fName);
+ }
+
+ @Override
+ public String getName() {
+ return fName + "_ChangeUndo"; // $NON-NLS-0$
+ }
+
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ fCanUndo = emfOperation.canUndo();
+ }
+
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ RefactoringStatus status = new RefactoringStatus();
+ try {
+ pm.beginTask(CHECKING_CONDITIONS, 1);
+ if (!fCanUndo) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(INVALID_UNDO));
+ }
+ return status;
+ } finally {
+ pm.done();
+ }
+ }
+
+ @Override
+ public Object getModifiedElement() {
+ return fElementToTransform;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractAllModelTransformation.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractAllModelTransformation.java
new file mode 100644
index 00000000000..93cb1a77850
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractAllModelTransformation.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.helper;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.AbstractTransformationOnElement;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+
+/**
+ * Clients who want to implement a Papyrus Refactoring which affects all the model elements may override this class.
+ * By overriding this class you don't need to override {@link #getElementsListToTransform()}
+ *
+ */
+public abstract class AbstractAllModelTransformation extends AbstractTransformationOnElement {
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * The name of the user input page (name of the transformation)
+ */
+ public AbstractAllModelTransformation(String label) {
+ super(label);
+ }
+
+ @Override
+ public Collection<EObject> getElementsListToTransform() {
+ return PapyrusRefactoringUtils.getAllElements(fModelSet);
+ }
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractChoiceOnUIParticipantsTransformation.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractChoiceOnUIParticipantsTransformation.java
new file mode 100644
index 00000000000..556f43da96e
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractChoiceOnUIParticipantsTransformation.java
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.helper;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.AbstractTransformationOnElement;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * This class offers a generic graphical interface which gives the user the possibility to choose the kind of refactoring he wants.
+ * He can choose between doing the refactor on:
+ * - All the elements of the current Papyrus model
+ * - Selected elements on the Papyrus Editor
+ */
+public abstract class AbstractChoiceOnUIParticipantsTransformation extends AbstractTransformationOnElement {
+
+ /** Combobox containing the scope of the transformation to execute */
+ protected Combo fSelectParticipants;
+
+ private static final int ALL_MODEL_REFACTOR = 0;
+
+ private static final int SELECTED_ELEMENTS_REFACTOR = 1;
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * The name of the user input page (name of the transformation)
+ */
+ public AbstractChoiceOnUIParticipantsTransformation(String label) {
+ super(label);
+ }
+
+ /**
+ * Create the specific input of this Papyrus Refactoring Wizard Page
+ *
+ * @param parent
+ */
+ public abstract void createContent(Composite parent);
+
+
+ @Override
+ public void createControl(Composite parent) {
+ Composite result = new Composite(parent, SWT.NONE);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ result.setLayout(layout);
+ setControl(result);
+ Label label = new Label(result, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
+ label.setText(Messages.REFACTORINGPAGE_SCOPE_LABEL);
+
+ fSelectParticipants = new Combo(result, SWT.VERTICAL | SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
+ fSelectParticipants.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1));
+ fSelectParticipants.add(Messages.REFACTORINGPAGE_SCOPE_MODEL);
+ fSelectParticipants.add(Messages.REFACTORINGPAGE_SCOPE_SELECTION);
+ // Default selection
+ fSelectParticipants.select(ALL_MODEL_REFACTOR);
+
+
+ Composite composite = new Composite(result, SWT.NONE);
+ GridLayout layout2 = new GridLayout();
+ layout2.numColumns = 1;
+ composite.setLayout(layout2);
+
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
+ data.verticalIndent = 8;
+ composite.setLayoutData(data);
+
+ createContent(composite);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.refactoring.refactoringOnElement.AbstractTransformationOnElement#getElementsListToTransform()
+ *
+ * @return
+ * The elements found inside the scope of the transformation
+ */
+ @Override
+ public Collection<EObject> getElementsListToTransform() {
+ if (fSelectParticipants.getSelectionIndex() == ALL_MODEL_REFACTOR) {
+ return PapyrusRefactoringUtils.getAllElements(fModelSet);
+ } else if (fSelectParticipants.getSelectionIndex() == SELECTED_ELEMENTS_REFACTOR) {
+ return PapyrusRefactoringUtils.getSelectedElements(fModelSet);
+ }
+ return null;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractSelectedElementsTransformation.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractSelectedElementsTransformation.java
new file mode 100644
index 00000000000..e3888933815
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/helper/AbstractSelectedElementsTransformation.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.helper;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.AbstractTransformationOnElement;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+
+
+/**
+ * Clients who want to implement a Papyrus Refactoring which affects only the selected elements by the user may override this class.
+ * By overriding this class you don't need to override {@link #getElementsListToTransform()}
+ *
+ */
+public abstract class AbstractSelectedElementsTransformation extends AbstractTransformationOnElement {
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * The name of the user input page (name of the transformation)
+ */
+ public AbstractSelectedElementsTransformation(String label) {
+ super(label);
+ }
+
+ @Override
+ public Collection<EObject> getElementsListToTransform() {
+ return PapyrusRefactoringUtils.getSelectedElements(fModelSet);
+ }
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/Messages.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/Messages.java
new file mode 100644
index 00000000000..e9e08428f69
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/Messages.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.refactoring.messages.messages"; //$NON-NLS-1$
+
+ public static String PAPYRUSCHANGE_CHECKVALIDITY;
+ public static String PAPYRUSCHANGE_MODELOPEN_ERROR;
+ public static String PAPYRUSCHANGE_PREVIEWPROJECT_NAME;
+ public static String PAPYRUSCHANGE_PREVIEWMODEL_NAME;
+ public static String PAPYRUSCHANGE_PREVIEWCREATION_ERROR;
+ public static String PAPYRUSCHANGE_PREVIEW_PERFORM;
+ public static String PAPYRUSCHANGE_SET_PERFORM;
+
+ public static String PAPYRUSREFACTORING_CHECKPRECONDITIONS;
+ public static String PAPYRUSREFACTORING_RESOURCEOPEN_ERROR;
+ public static String PAPYRUSREFACTORING_MODELVALIDITY;
+ public static String PAPYRUSREFACTORING_MODELVALIDITY_ERROR;
+ public static String PAPYRUSREFACTORING_EXECUTE;
+
+ public static String UNDOPAPYRUSCHANGE_ERROR;
+ public static String UNDOPAPYRUSCHANGE_EXECUTE;
+ public static String UNDOPAPYRUSCHANGE_VALIDITYCHECK;
+
+ public static String REFACTORINGPAGE_SCOPE_LABEL;
+ public static String REFACTORINGPAGE_SCOPE_MODEL;
+ public static String REFACTORINGPAGE_SCOPE_SELECTION;
+
+ public static String PAPYRUSCOMPOSITECHANGE_CHANGELABEL_BEGIN;
+ public static String PAPYRUSCOMPOSITECHANGE_CHANGELABEL_END;
+ public static String PAPYRUSCOMPOSITECHANGE_PREVIEWPROJECT_NAME;
+ public static String PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_NAME;
+ public static String PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_CREATIONERROR;
+
+ public static String PAPYRUSREFACTORPREVIEW_CHANGEDMODEL;
+ public static String PAPYRUSREFACTORPREVIEW_ORIGINALMODEL;
+ public static String PAPYRUSREFACTORPREVIEW_CHANGEDETAILS;
+
+ public static String PAPYRUSREFACTORING_REPLACE_LABEL;
+ public static String REFACTORINGPAGE_REPLACE_HINT;
+ public static String REFACTORINGPAGE_REPLACE_EQUALERROR;
+ public static String REFACTORINGPAGE_REPLACE_ORIGINALSTRINGLABEL;
+ public static String REFACTORINGPAGE_REPLACE_TOREPLACESTRINGLABEL;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/messages.properties b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/messages.properties
new file mode 100644
index 00000000000..ba2f1b85369
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/messages/messages.properties
@@ -0,0 +1,37 @@
+PAPYRUSCHANGE_CHECKVALIDITY=Checking validity of the transformation
+PAPYRUSCHANGE_MODELOPEN_ERROR=Impossible to open the model
+PAPYRUSCHANGE_PREVIEWPROJECT_NAME=.org.eclipse.papyrus.infra.refactoring.projectForPreview
+PAPYRUSCHANGE_PREVIEWMODEL_NAME=/previewFile.di
+PAPYRUSCHANGE_PREVIEWCREATION_ERROR=Error during the creation of the preview model
+PAPYRUSCHANGE_PREVIEW_PERFORM=Perform Change on Preview_
+PAPYRUSCHANGE_SET_PERFORM=Perform Change on Set_
+
+PAPYRUSREFACTORING_CHECKPRECONDITIONS=Checking preconditions
+PAPYRUSREFACTORING_RESOURCEOPEN_ERROR=Error opening resource
+PAPYRUSREFACTORING_MODELVALIDITY=Checking conditions and model validity
+PAPYRUSREFACTORING_MODELVALIDITY_ERROR=After executing this refactoring the model won't be valid
+PAPYRUSREFACTORING_EXECUTE=Operating transformation
+
+UNDOPAPYRUSCHANGE_ERROR=Can not undo this operation
+UNDOPAPYRUSCHANGE_EXECUTE=Performing undo
+UNDOPAPYRUSCHANGE_VALIDITYCHECK=Checking validity conditions
+
+REFACTORINGPAGE_SCOPE_LABEL=Apply refactor on:
+REFACTORINGPAGE_SCOPE_MODEL=All model
+REFACTORINGPAGE_SCOPE_SELECTION=Selected elements
+
+PAPYRUSCOMPOSITECHANGE_CHANGELABEL_BEGIN=<
+PAPYRUSCOMPOSITECHANGE_CHANGELABEL_END=>
+PAPYRUSCOMPOSITECHANGE_PREVIEWPROJECT_NAME=.org.eclipse.papyrus.infra.refactoring.projectForPreview
+PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_NAME=/previewFile.di
+PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_CREATIONERROR=Error during the creation of the preview model
+
+PAPYRUSREFACTORPREVIEW_CHANGEDMODEL=Refactored model
+PAPYRUSREFACTORPREVIEW_ORIGINALMODEL=Original model
+PAPYRUSREFACTORPREVIEW_CHANGEDETAILS=Details
+
+PAPYRUSREFACTORING_REPLACE_LABEL=Replace
+REFACTORINGPAGE_REPLACE_HINT=Please indicate the new value which should replace the original.
+REFACTORINGPAGE_REPLACE_EQUALERROR=Original and new strings are same.
+REFACTORINGPAGE_REPLACE_ORIGINALSTRINGLABEL=&Replace:
+REFACTORINGPAGE_REPLACE_TOREPLACESTRINGLABEL=&With:
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/AbstractTransformationOnElement.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/AbstractTransformationOnElement.java
new file mode 100644
index 00000000000..71778a69f11
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/AbstractTransformationOnElement.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.refactoringOnElement;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.refactoring.core.AbstractPapyrusTransformation;
+
+/**
+ * Clients who want to apply a transformation on a specified list of element should override this class
+ *
+ */
+public abstract class AbstractTransformationOnElement extends AbstractPapyrusTransformation {
+
+ public static final int ALL_MODEL_REFACTOR = 0;
+ public static final int SELECTED_ELEMENTS_REFACTOR = 1;
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * The name of the user input page (name of the transformation)
+ */
+ public AbstractTransformationOnElement(String label) {
+ super(label);
+ }
+
+
+ @Override
+ public void execute(ModelSet modelSetToTransform) {
+ if (fElementToTransform != null) {
+ // TODO return a status if the operations resulting in the mutation cannot be done
+ // e.g. an association in an artifact
+ transformElement(fElementToTransform);
+ }
+ }
+
+ /** Return the list of elements which may be affected by the refactoring */
+ public abstract Collection<EObject> getElementsListToTransform();
+
+ /** @return The implementation of {@link ITransformationOnElement} */
+ public abstract ITransformationOnElement getTransformationOnElement();
+
+ /**
+ *
+ * @param elementToTransform
+ * the element that will be transformed.
+ */
+ private void transformElement(EObject elementToTransform) {
+ ITransformationOnElement refactoring = getTransformationOnElement();
+ refactoring.transformationToExecute(elementToTransform);
+ }
+
+ @Override
+ public void setElementToTransform(EObject elementToTransform) {
+ fElementToTransform = elementToTransform;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ITransformationOnElement.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ITransformationOnElement.java
new file mode 100644
index 00000000000..cc96d04a7d6
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ITransformationOnElement.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.refactoringOnElement;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * Interface to be implemented by clients who override {@link AbstractTransformationOnElement}
+ *
+ */
+public abstract interface ITransformationOnElement {
+
+
+ /**
+ * Runs the transformation using the given element.
+ *
+ * @param element
+ * the {@link EObject} on which the transformation will be done.
+ */
+ public void transformationToExecute(EObject element);
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusCompositeChange.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusCompositeChange.java
new file mode 100644
index 00000000000..e2f5b0f1b0f
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusCompositeChange.java
@@ -0,0 +1,247 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.refactoringOnElement;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+//import org.eclipse.emf.compare.Comparison;
+//import org.eclipse.emf.compare.EMFCompare;
+//import org.eclipse.emf.compare.scope.DefaultComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelsReader;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.emf.utils.ResourceUtils;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
+import org.eclipse.papyrus.refactoring.core.IPreviewablePapyrusChange;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * {@link CompositeChange} for managing {@link AbstractTransformationOnElement}.
+ * It is composed of {@link PapyrusRefactoringOnElementChange}.
+ *
+ */
+public class PapyrusCompositeChange extends CompositeChange implements IPreviewablePapyrusChange {
+
+ /** The ModelSet on which we apply the change */
+ private ModelSet fModelSet;
+
+ /** The Papyrus Refactoring to execute */
+ private AbstractTransformationOnElement fPapyrusRefactoringTransformation;
+
+ /** The virtual {@link ModelSet} on which we executed the refactoring. */
+ private ModelSet fPreviewModelSet;
+
+ /** The Change to execute */
+ private Change perfomChange;
+
+
+ /**
+ * Constructor.
+ *
+ * @param papyrusRefactoringPage
+ * The page contributed to the Refactoring wizard
+ * @param modelSet
+ * The modelSet to which w eapply the Change
+ */
+ public PapyrusCompositeChange(AbstractTransformationOnElement papyrusRefactoringPage, ModelSet modelSet) {
+ super(papyrusRefactoringPage.getName());
+ fPapyrusRefactoringTransformation = papyrusRefactoringPage;
+ fModelSet = modelSet;
+
+ // Display.getDefault().syncExec(new Runnable() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ initChanges();
+ }
+ });
+
+ // fPreviewModelSet = initPreviewModelSet();
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ Display.getDefault().syncExec(new Runnable() {
+ // Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ perfomChange = PapyrusCompositeChange.super.perform(pm);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+
+ return perfomChange;
+ }
+
+ /**
+ * Create the {@link PapyrusRefactoringOnElementChange} that correspond to this refactoring.
+ */
+ private void initChanges() {
+ createAllChanges();
+
+ // The following part slows the programm considerably without adding a lot of value as the empty changes are nearly non existant
+ // Executing the comparator for each change takes about .5s per change
+ // A possible solution could be to execute them in multiple threads but there need to be sufficient cores on the user's end
+
+ // ModelSet initialModelSet = fModelSet;
+ // EMFCompare comparator = EMFCompare.builder().build();
+ //
+ // for (Change change : getChildren()) {
+ // if (change instanceof PapyrusRefactoringOnElementChange) {
+ // PapyrusRefactoringOnElementChange changeToProceed = (PapyrusRefactoringOnElementChange) change;
+ // ModelSet changeModelSet = changeToProceed.getChangePreviewModelSet();
+ //
+ // Comparison comparison = comparator.compare(new DefaultComparisonScope(initialModelSet, changeModelSet, null));
+ //
+ // // If there is any difference between the original model and the refactored model, this change doesn't modify the model so it is useless, we can delete it.
+ // if (comparison.getDifferences().size() == 0) {
+ // System.err.println("initChanges " + changeToProceed.getModifiedElement());
+ // remove(changeToProceed);
+ // }
+ // }
+ // }
+ }
+
+ /**
+ * Create one {@link PapyrusRefactoringOnElementChange} for each element from {@link AbstractTransformationOnElement#getElementsListToTransform()}.
+ */
+ private void createAllChanges() {
+
+ for (EObject element : fPapyrusRefactoringTransformation.getElementsListToTransform()) {
+ LabelProviderService labelProvider = new LabelProviderServiceImpl();
+ String elementText = Messages.PAPYRUSCOMPOSITECHANGE_CHANGELABEL_BEGIN + element.eClass().getName() + Messages.PAPYRUSCOMPOSITECHANGE_CHANGELABEL_END
+ + labelProvider.getLabelProvider().getText(element);
+
+ // Create the PapyrusRefactoringOnElementChange
+ PapyrusRefactoringOnElementChange change = new PapyrusRefactoringOnElementChange(fPapyrusRefactoringTransformation, elementText, fModelSet, element);
+
+ // Add it to this CompositeChange
+ this.add(change);
+ }
+
+ }
+
+ // TODO a proper clone, so as to get the preview working !
+ /**
+ * Clones the current modelSet to apply it the Changes
+ *
+ * @return
+ * The preview modelSet
+ */
+ public ModelSet getChangePreviewModelSet() {
+ ModelSet previewModelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(previewModelSet);
+ try {
+ previewModelSet.loadModels(fModelSet.getURIWithoutExtension());
+
+ } catch (ModelMultiException e) {
+ Activator.log.error(e);
+ }
+
+ return previewModelSet;
+ // getPreviewFile();
+ // return fPreviewModelSet;
+ }
+
+ /**
+ * Creates a copy of the original ModelSet and execute the refactoring on it.
+ *
+ * @return A preview file of the refactoring which shows the refactoring effects.
+ */
+ @Override
+ public IFile getPreviewFile() {
+ String nameProject = Messages.PAPYRUSCOMPOSITECHANGE_PREVIEWPROJECT_NAME;
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ IProject project = root.getProject(nameProject);
+ // System.err.println("getPreviewFile");
+
+ try {
+ if (!project.exists()) {
+ project.create(null);
+ }
+ project.open(null);
+ } catch (CoreException e1) {
+ Activator.log.error(e1);
+ }
+
+ IPath path = new Path(project.getFullPath().toString() + Messages.PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_NAME);
+ IFile previewFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ fModelSet.saveCopy(path.removeFileExtension());
+ ModelSet previewModelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(previewModelSet);
+ // System.err.println("initPreviewModelSet");
+
+ try {
+ previewModelSet.loadModels(URI.createPlatformResourceURI(path.toString(), true));
+ } catch (ModelMultiException e) {
+ Activator.log.error(e);
+ }
+
+ for (Change changeChild : getChildren()) {
+ if (changeChild.isEnabled()) {
+ ((PapyrusRefactoringOnElementChange) changeChild).performRefactor(previewModelSet, Messages.PAPYRUSCHANGE_PREVIEW_PERFORM);
+ }
+ }
+
+ try {
+ // modelSetForPreviewFile.saveAs(URI.createPlatformResourceURI(path.toString(), true));
+ previewModelSet.saveAs(URI.createPlatformResourceURI(path.toString(), true));
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ // Assert.isNotNull(moelSetForPreviewFile, Messages.PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_CREATIONERROR);
+ Assert.isNotNull(previewModelSet, Messages.PAPYRUSCOMPOSITECHANGE_PREVIEWMODEL_CREATIONERROR);
+ fPreviewModelSet = previewModelSet;
+
+ return previewFile;
+ }
+
+
+ @Override
+ public IFile getInitialFile() {
+ // Resource diResource = DiModelUtils.getDiResource(fModelSet);
+ Resource diResource = ((DiModel) fModelSet.getModel(DiModel.DI_MODEL_ID)).getResource();
+ IFile file = ResourceUtils.getFile(diResource);
+
+ return file;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusRefactoringOnElementChange.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusRefactoringOnElementChange.java
new file mode 100644
index 00000000000..bceab430eb5
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/PapyrusRefactoringOnElementChange.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.refactoringOnElement;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.refactoring.core.IPreviewablePapyrusChange;
+import org.eclipse.papyrus.refactoring.core.PapyrusChange;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+
+/**
+ * A {@link Change} for managing the transformation of a specified element.
+ */
+public class PapyrusRefactoringOnElementChange extends PapyrusChange {
+
+ /** The element to transform */
+ private EObject fElementToApplyChange;
+
+
+ /**
+ * Constructor.
+ *
+ * @param papyrusRefactoringTransformation
+ * The transformation to execute
+ * @param name
+ * The name of the transformation
+ * @param modelSet
+ * The modelSet containing the element to transform
+ * @param elementToTransform
+ * The element to transform
+ */
+ public PapyrusRefactoringOnElementChange(AbstractTransformationOnElement papyrusRefactoringTransformation, String name, ModelSet modelSet, EObject elementToTransform) {
+ super(papyrusRefactoringTransformation, name, modelSet);
+ fModelSet = modelSet;
+ fElementToApplyChange = elementToTransform;
+ }
+
+ /**
+ * Override the perform of the original LTK Refactoring to substitute the PapyrusChange one
+ *
+ * @see org.eclipse.papyrus.refactoring.core.PapyrusChange#performRefactor(org.eclipse.papyrus.infra.core.resource.ModelSet, java.lang.String)
+ *
+ * @param modelSet
+ * The modelSet containing the element to transform
+ * @param label
+ * The label of the transformation
+ * @return
+ * The change computed for the transformation
+ */
+ @Override
+ protected Change performRefactor(ModelSet modelSet, String label) {
+ EObject elementToApplyRefactoring = PapyrusRefactoringUtils.findEObjectInModelSet(fElementToApplyChange, modelSet);
+ ((AbstractTransformationOnElement) fPapyrusRefactoringTransformation).setElementToTransform(elementToApplyRefactoring);
+
+ return super.performRefactor(modelSet, label);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.refactoring.core.PapyrusChange#getPreviewFile()
+ *
+ * @return
+ * The modified model's IFile
+ */
+ @Override
+ public IFile getPreviewFile() {
+ return ((IPreviewablePapyrusChange) getParent()).getPreviewFile();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.refactoring.core.PapyrusChange#getModifiedElement()
+ *
+ * @return
+ * The element to modify
+ */
+ @Override
+ public Object getModifiedElement() {
+ return fElementToApplyChange;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ReplaceTransformationOnElement.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ReplaceTransformationOnElement.java
new file mode 100644
index 00000000000..26826ec0464
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/refactoringOnElement/ReplaceTransformationOnElement.java
@@ -0,0 +1,167 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.refactoringOnElement;
+
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery;
+import org.eclipse.papyrus.views.search.regex.PatternHelper;
+import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+import org.eclipse.papyrus.views.search.results.AttributeMatch;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * Class used to replace Strings in the model depending on the scope previously selected by the user
+ *
+ */
+public class ReplaceTransformationOnElement implements ITransformationOnElement {
+
+ /** The {@link AbstractResultEntry} list representing textual matches with the String pattern to be replaced */
+ private Set<AbstractResultEntry> fAttributeMatchList;
+
+ /** The {@link AbstractPapyrusQuery} representing the search of matches */
+ private AbstractPapyrusQuery fQuery;
+
+ /** The string that should replace the String pattern to be replaced */
+ private String fNewString;
+
+
+ /**
+ * Constructor.
+ *
+ * @param toProcess
+ * The results of the query
+ * @param query
+ * The {@link org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery PapyrusQuery} used to get the occurrences to replace
+ * @param newString
+ * The string to replace in the selected scope
+ */
+ public ReplaceTransformationOnElement(Set<AbstractResultEntry> toProcess, AbstractPapyrusQuery query, String newString) {
+ fAttributeMatchList = toProcess;
+ fQuery = query;
+ fNewString = newString;
+ }
+
+ /**
+ * Verify that the string can indeed be replaced in the parsed element
+ *
+ * @see org.eclipse.papyrus.refactoring.refactoringOnElement.ITransformationOnElement#transformationToExecute(org.eclipse.emf.ecore.EObject)
+ *
+ * @param element
+ * Executes the replacement in all the occurrences of the string in the provided element wherever possible
+ */
+ @Override
+ public void transformationToExecute(EObject element) {
+ for (AbstractResultEntry match : fAttributeMatchList) {
+ if (match.getSource() instanceof EObject && match instanceof AttributeMatch) {
+ AttributeMatch attributeMatch = (AttributeMatch) match;
+ if (EcoreUtil.equals(element, (EObject) match.getSource())) {
+ Object attributeObject = attributeMatch.getMetaAttribute();
+ // Object attributeObject = attributeMatch.getSource();
+
+ if (attributeObject instanceof EAttribute) {
+ EAttribute eAttribute = (EAttribute) attributeObject;
+ // This test is to prevent any attempt to edit a non-existent feature or a non changeable feature
+ if (element.eGet(eAttribute, true) != null && eAttribute.isChangeable()) {
+ Object value = element.eGet(eAttribute);
+
+ if (value != null) {
+ if (value instanceof String) {
+ String originalvalue = (String) value;
+ Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
+
+ String newValue = computeReplacementString(pattern, originalvalue, fNewString);
+
+ element.eSet(eAttribute, newValue);
+ }
+ }
+ }
+ }
+
+ else if (attributeObject instanceof Property) {
+ Property source = (Property) attributeObject;
+ Class containingClass = source.getClass_();
+
+ if (containingClass instanceof Stereotype) {
+ if (element instanceof Element) {
+ Stereotype stereotype = ((Element) element).getAppliedStereotype(containingClass.getQualifiedName());
+ Object tagValue = ((Element) element).getValue(stereotype, source.getName());
+ if (tagValue instanceof String) {
+ Object value = tagValue;
+
+ if (value != null) {
+ if (value instanceof String) {
+ String originalvalue = (String) value;
+ Pattern pattern = PatternHelper.getInstance().createPattern(fQuery.getSearchQueryText(), fQuery.isCaseSensitive(), fQuery.isRegularExpression());
+
+ String newValue = computeReplacementString(pattern, originalvalue, fNewString);
+
+ ((Element) element).setValue(stereotype, source.getName(), newValue);
+
+ }
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Compute the replacement
+ *
+ * @param pattern
+ * The pattern that we will us to compute the replacement.
+ * @param originalText
+ * The String to be modified.
+ * @param replacementText
+ * The String to append.
+ * @return The new String.
+ */
+ private String computeReplacementString(Pattern pattern, String originalText, String replacementText) throws PatternSyntaxException {
+ if (pattern != null) {
+ try {
+
+ Matcher matcher = pattern.matcher(originalText);
+ StringBuffer sb = new StringBuffer();
+ matcher.reset();
+ if (matcher.find()) {
+ matcher.appendReplacement(sb, replacementText);
+ } else {
+ return null;
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ } catch (IndexOutOfBoundsException ex) {
+ throw new PatternSyntaxException(ex.getLocalizedMessage(), replacementText, -1);
+ }
+ }
+ return replacementText;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringPreview.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringPreview.java
new file mode 100644
index 00000000000..73db088e2ed
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringPreview.java
@@ -0,0 +1,194 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.ui;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.internal.CompareContainer;
+import org.eclipse.compare.internal.CompareUIPlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput;
+import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
+import org.eclipse.papyrus.refactoring.Activator;
+import org.eclipse.papyrus.refactoring.core.IPreviewablePapyrusChange;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ViewForm;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Point;
+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.Display;
+import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
+import org.eclipse.team.internal.ui.synchronize.SaveablesCompareEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The purpose of this class is to show the user the differences between the original model and the model after the transformation.
+ *
+ */
+@SuppressWarnings("restriction")
+public class PapyrusRefactoringPreview implements IChangePreviewViewer {
+
+ /** Main composite of the preview page */
+ private ViewForm fComposite;
+
+ /** Change storing the intial and preview file */
+ private IPreviewablePapyrusChange fChange;
+
+ /** Control used to manipulate the page's previewed content */
+ private Control fPreviewControl;
+
+ /** Resource from the preview model retrieved from the previewed change */
+ private IFile fPreviewResource;
+
+ /** Resource from the original model retrieved from the previewed change */
+ private IFile fOriginalResource;
+
+
+ @Override
+ public void createControl(Composite parent) {
+
+ if (fComposite == null) {
+ fComposite = new ViewForm(parent, SWT.NONE);
+ fComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ fComposite.setLayout(new GridLayout(1, true));
+ }
+
+ }
+
+
+ @Override
+ public Control getControl() {
+ return fComposite;
+ }
+
+
+ @Override
+ public void setInput(ChangePreviewViewerInput input) {
+ if (fPreviewControl != null) {
+ fPreviewControl.dispose();
+ }
+ if (input.getChange() instanceof IPreviewablePapyrusChange) {
+ setChange(input);
+ CompareEditorInput preview = initiateComparison();
+ if (preview != null) {
+ showPreview(preview);
+ }
+ }
+ }
+
+
+ /**
+ * Show the UI comparison between the original model and the refactored model
+ *
+ * @param preview
+ * The {@link CompareEditorInput} for the comparison between the preview model and the original model
+ */
+ private void showPreview(final CompareEditorInput preview) {
+
+ CompareUIPlugin plugin = CompareUIPlugin.getDefault();
+
+
+ if (plugin != null) {
+ if (plugin.compareResultOK(preview, null)) {
+ Runnable runnable = new Runnable() {
+
+ @Override
+ public void run() {
+ CompareConfiguration compareConfiguration = preview.getCompareConfiguration();
+ compareConfiguration.setLeftEditable(false);
+ compareConfiguration.setLeftLabel(Messages.PAPYRUSREFACTORPREVIEW_CHANGEDMODEL);
+ compareConfiguration.setRightEditable(false);
+ compareConfiguration.setRightLabel(Messages.PAPYRUSREFACTORPREVIEW_ORIGINALMODEL);
+
+ preview.setContainer(new CompareContainer());
+
+ fPreviewControl = preview.createContents(fComposite);
+
+ fComposite.setContent(fPreviewControl);
+ }
+ };
+ syncExec(runnable);
+
+ fComposite.getShell().setSize(new Point(1000, 900));
+ }
+ }
+ fPreviewControl.addDisposeListener(new DisposeListener() {
+
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ IProject projectToDestroy = fPreviewResource.getProject();
+ if (projectToDestroy.exists()) {
+ try {
+ projectToDestroy.delete(true, true, new NullProgressMonitor());
+ } catch (CoreException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
+ });
+ }
+
+ /** Sets the change variable from the input */
+ private void setChange(ChangePreviewViewerInput input) {
+ fChange = (IPreviewablePapyrusChange) input.getChange();
+ }
+
+ /** Just an util method */
+ private void syncExec(Runnable runnable) {
+ if (Display.getCurrent() == null) {
+ Display.getDefault().syncExec(runnable);
+ } else {
+ runnable.run();
+ }
+ }
+
+
+ /**
+ * Do the comparison between the original and the refactored model
+ *
+ * @return
+ * the input that enables compare to display the result of the comparison between the original and the refactored model.
+ */
+ private CompareEditorInput initiateComparison() {
+
+ if (fOriginalResource == null) {
+ fOriginalResource = fChange.getInitialFile();
+ }
+
+ fPreviewResource = fChange.getPreviewFile();
+
+ LocalResourceTypedElement initialResource = new LocalResourceTypedElement(fPreviewResource);
+ LocalResourceTypedElement previewResource = new LocalResourceTypedElement(fOriginalResource);
+
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ SaveablesCompareEditorInput preview = new SaveablesCompareEditorInput(null, initialResource, previewResource, page);
+
+ return preview;
+
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringWizard.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringWizard.java
new file mode 100644
index 00000000000..527e3d17f68
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusRefactoringWizard.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.ui;
+
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.papyrus.refactoring.Activator;
+import org.eclipse.papyrus.refactoring.core.PapyrusRefactoring;
+
+/**
+ * {@link RefactoringWizard} for Papyrus Refactoring
+ *
+ * @noextend This class is not intended to be extended by clients.
+ */
+public class PapyrusRefactoringWizard extends RefactoringWizard {
+
+
+ /**
+ * Constructor.
+ *
+ * @param refactoring
+ * The refactoring linked to this wizard (replace, mutate, ...)
+ * @param pageTitle
+ * The default page title
+ */
+ public PapyrusRefactoringWizard(PapyrusRefactoring refactoring, String pageTitle) {
+ super(refactoring, DIALOG_BASED_USER_INTERFACE | SHOW_HELP_CONTROL);
+ setDefaultPageTitle(pageTitle);
+ // Window.setDefaultImage(Activator.shellImage);
+ }
+
+ @Override
+ protected void addUserInputPages() {
+ // Adds the user page built with the tranformation by default
+ addPage(((PapyrusRefactoring) getRefactoring()).getPapyrusTransformation());
+ }
+
+ @Override
+ public void setContainer(IWizardContainer wizardContainer) {
+ // Used to deactivate the Help button until the help is created
+ super.setContainer(wizardContainer);
+ if (getContainer() instanceof TrayDialog) {
+ ((TrayDialog) getContainer()).setHelpAvailable(false);
+ }
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusStatusContextViewer.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusStatusContextViewer.java
new file mode 100644
index 00000000000..ad1a735c528
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/PapyrusStatusContextViewer.java
@@ -0,0 +1,114 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.ui;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.ltk.core.refactoring.RefactoringStatusContext;
+import org.eclipse.ltk.ui.refactoring.IStatusContextViewer;
+import org.eclipse.papyrus.refactoring.core.PapyrusRefactoringValidationStatusContext;
+import org.eclipse.papyrus.refactoring.messages.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.ExpandBar;
+import org.eclipse.swt.widgets.ExpandItem;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * Implementation of {@link IStatusContextViewer} to present a {@link PapyrusRefactoringValidationStatusContext} to review potential conflicts
+ *
+ */
+public class PapyrusStatusContextViewer implements IStatusContextViewer {
+
+ /** Page's main composite doubling as the Control for the status page */
+ private Composite fParentComposite;
+
+ /** Child composite */
+ private Composite childDiagComposite;
+
+ /** Expanding the details from the status check */
+ private ExpandBar fBar;
+
+
+ @Override
+ public void createControl(Composite parent) {
+ fParentComposite = new Composite(parent, SWT.BORDER | SWT.FLAT);
+ fParentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ fParentComposite.setLayout(new GridLayout(1, true));
+
+ Composite detailComposite = new Composite(fParentComposite, SWT.BORDER | SWT.FLAT);
+
+ detailComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ detailComposite.setLayout(new GridLayout(1, true));
+
+ Device device = Display.getCurrent();
+
+ fBar = new ExpandBar(detailComposite, SWT.V_SCROLL | SWT.H_SCROLL);
+ fBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ fBar.setBackground(new Color(device, 255, 255, 255));
+ fBar.setForeground(new Color(device, 0, 0, 255));
+
+ // First item
+ childDiagComposite = new Composite(fBar, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
+ layout.verticalSpacing = 10;
+ childDiagComposite.setLayout(layout);
+ childDiagComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+ }
+
+ @Override
+ public Control getControl() {
+ return fParentComposite;
+ }
+
+ @Override
+ public void setInput(RefactoringStatusContext input) {
+ if (input instanceof PapyrusRefactoringValidationStatusContext && fBar == null) {
+ Diagnostic diagnostic = ((PapyrusRefactoringValidationStatusContext) input).getfDiagnostic();
+
+ for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
+ Label label = new Label(childDiagComposite, SWT.NONE);
+ label.setText(childDiagnostic.getMessage());
+ }
+
+ ExpandItem item0 = new ExpandItem(fBar, SWT.V_SCROLL | SWT.H_SCROLL, 0);
+ item0.setText(Messages.PAPYRUSREFACTORPREVIEW_CHANGEDETAILS);
+ item0.setHeight(childDiagComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+ item0.setControl(childDiagComposite);
+
+ item0.setExpanded(false);
+ }
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/ReplaceRefactoring.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/ReplaceRefactoring.java
new file mode 100644
index 00000000000..fd81e136b67
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/ui/ReplaceRefactoring.java
@@ -0,0 +1,173 @@
+/// *****************************************************************************
+// * Copyright (c) 2016 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:
+// * CEA LIST - Initial API and implementation
+// *
+// *****************************************************************************/
+// package org.eclipse.papyrus.refactoring.ui;
+//
+// import java.util.ArrayList;
+// import java.util.Arrays;
+// import java.util.Collection;
+// import java.util.HashSet;
+// import java.util.List;
+// import java.util.Set;
+//
+// import org.eclipse.emf.ecore.EObject;
+// import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+// import org.eclipse.papyrus.refactoring.messages.Messages;
+// import org.eclipse.papyrus.refactoring.refactoringOnElement.AbstractTransformationOnElement;
+// import org.eclipse.papyrus.refactoring.refactoringOnElement.ITransformationOnElement;
+// import org.eclipse.papyrus.refactoring.refactoringOnElement.ReplaceTransformationOnElement;
+// import org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage;
+// import org.eclipse.papyrus.uml.search.ui.query.AbstractPapyrusQuery;
+// import org.eclipse.papyrus.views.search.results.AbstractResultEntry;
+// import org.eclipse.papyrus.views.search.results.AttributeMatch;
+// import org.eclipse.papyrus.views.search.utils.MatchUtils;
+// import org.eclipse.swt.SWT;
+// import org.eclipse.swt.layout.GridData;
+// import org.eclipse.swt.layout.GridLayout;
+// import org.eclipse.swt.widgets.Composite;
+// import org.eclipse.swt.widgets.Label;
+// import org.eclipse.swt.widgets.Text;
+//
+//
+/// **
+// * Refactoring based on the {@link org.eclipse.papyrus.uml.search.ui.pages.PapyrusSearchResultPage}
+// *
+// */
+// @SuppressWarnings("restriction")
+// public class ReplaceRefactoring extends AbstractTransformationOnElement {
+//
+// /** The String to replace the old one */
+// private Text fNewValueText;
+//
+// /** The old String to be replaced */
+// private Text fOldValueText;
+//
+// /** */
+// private PapyrusSearchResultPage fResultPage;
+//
+// private AbstractPapyrusQuery fQuery;
+//
+// private Object[] fSelection;
+//
+// private Set<AbstractResultEntry> fListMatch;
+//
+//
+// /**
+// * Constructor.
+// *
+// * @param resultPage
+// * @param selection
+// */
+// public ReplaceRefactoring(PapyrusSearchResultPage resultPage, Object[] selection) {
+// super(Messages.PAPYRUSREFACTORING_REPLACE_LABEL);
+// fResultPage = resultPage;
+// fSelection = selection;
+// fQuery = (AbstractPapyrusQuery) fResultPage.getInput().getQuery();
+// initListMatches();
+// }
+//
+//
+// private Text createNameField(Composite result) {
+// Text field = new Text(result, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
+// field.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+// return field;
+// }
+//
+//
+// @Override
+// public RefactoringStatus checkFinalConditions() {
+// RefactoringStatus status = new RefactoringStatus();
+//
+// if (fNewValueText.getText().isEmpty()) {
+// status.merge(RefactoringStatus.createFatalErrorStatus(Messages.REFACTORINGPAGE_REPLACE_HINT));
+// } else if (fNewValueText.getText().equals(fQuery.getSearchQueryText())) {
+// status.merge(RefactoringStatus.createFatalErrorStatus(Messages.REFACTORINGPAGE_REPLACE_EQUALERROR));
+// }
+//
+// return status;
+// }
+//
+//
+// @Override
+// public void createControl(Composite parent) {
+//
+// GridLayout layout = new GridLayout();
+//
+// Composite composite = new Composite(parent, SWT.NONE);
+// layout.marginHeight = 0;
+// layout.marginWidth = 0;
+// layout.numColumns = 2;
+// composite.setLayout(layout);
+// composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+//
+// setControl(composite);
+//
+// Label label = new Label(composite, SWT.NONE);
+// label.setText(Messages.REFACTORINGPAGE_REPLACE_ORIGINALSTRINGLABEL);
+// fOldValueText = createNameField(composite);
+// fOldValueText.setFocus();
+// fOldValueText.setText(fQuery.getSearchQueryText());
+// fOldValueText.setEnabled(false);
+//
+// label = new Label(composite, SWT.NONE);
+// label.setText(Messages.REFACTORINGPAGE_REPLACE_TOREPLACESTRINGLABEL);
+//
+// fNewValueText = createNameField(composite);
+//
+// GridData data = new GridData();
+// data.horizontalAlignment = SWT.END;
+//
+// }
+//
+//
+// private void initListMatches() {
+// fListMatch = new HashSet<>();
+// if (fSelection == null) {
+// for (AbstractResultEntry resultEntry : MatchUtils.getMatches(fResultPage.getInput(), false)) {
+// if (resultEntry instanceof AttributeMatch) {
+// fListMatch.add(resultEntry);
+// }
+// }
+// } else {
+// for (Object selected : Arrays.asList(fSelection)) {
+// if (selected instanceof AttributeMatch) {
+// fListMatch.add((AttributeMatch) selected);
+// }
+// }
+// }
+// }
+//
+//
+// @Override
+// public Collection<EObject> getElementsListToTransform() {
+// List<EObject> toProcess = new ArrayList<>();
+// for (AbstractResultEntry match : fListMatch) {
+// if (match.getSource() instanceof EObject) {
+// if (!toProcess.contains(match.getSource())) {
+// toProcess.add((EObject) match.getSource());
+// }
+// }
+// }
+// return toProcess;
+// }
+//
+// @Override
+// public ITransformationOnElement getTransformationOnElement() {
+// return new ReplaceTransformationOnElement(fListMatch, fQuery, fNewValueText.getText());
+// }
+//
+// @Override
+// public String getName() {
+// return Messages.PAPYRUSREFACTORING_REPLACE_LABEL;
+// }
+// }
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/util/PapyrusRefactoringUtils.java b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/util/PapyrusRefactoringUtils.java
new file mode 100644
index 00000000000..58c40215879
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.refactoring/src/org/eclipse/papyrus/refactoring/util/PapyrusRefactoringUtils.java
@@ -0,0 +1,296 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.refactoring.Activator;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+/**
+ * Utils methods used to browse through the UML models and their {@link org.eclipse.papyrus.infra.core.resource.ModelSet ModelSet}
+ *
+ */
+public class PapyrusRefactoringUtils {
+
+
+ /**
+ * Utils methods for refactoring.
+ *
+ * @param modelSet
+ * The provided modelSet
+ * @return
+ * The EObject associated with the root of the model or null
+ */
+ public static EObject getUMLRoot(ModelSet modelSet) {
+ try {
+ UmlModel umlModel = (UmlModel) modelSet.getModelChecked(UmlModel.MODEL_ID);
+ EObject root = umlModel.lookupRoot();
+ return root;
+ } catch (NotFoundException e) {
+ Activator.log.error(e);
+
+ }
+ return null;
+ }
+
+
+ /**
+ * Get the semantic element associated to the specified adapter
+ *
+ * @param semanticAdapter
+ * The provided IAdatptable
+ * @return
+ * The associated EObject or null if none can be found
+ */
+ protected EObject getSemanticElement(IAdaptable semanticAdapter) {
+ if (semanticAdapter == null) {
+ return null;
+ }
+ EObject eObject = semanticAdapter.getAdapter(EObject.class);
+ if (eObject != null) {
+ return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
+ }
+ return null;
+ }
+
+ /**
+ * Fetch the owner of the provided element, if any
+ *
+ * @param element
+ * The provided element
+ * @return
+ * The owner or itself if none can be found
+ */
+ public static Element getOwner(Element element) {
+ Element rootElement = element;
+ while (rootElement.getOwner() != null) {
+ rootElement = rootElement.getOwner();
+ }
+
+ return rootElement;
+ }
+
+
+ private static EObject getRootElement(EObject element) {
+ return EcoreUtil.getRootContainer(element);
+ }
+
+ /**
+ * Get all the elements contained in the provided modelSet
+ *
+ * @param modelSet
+ * The modelSet
+ * @return
+ * All the elements of the given modelSet.
+ */
+ public static Collection<EObject> getAllElements(ModelSet modelSet) {
+ List<EObject> elements = new ArrayList<>();
+ EObject root = getUMLRoot(modelSet);
+ if (root != null) {
+ TreeIterator<EObject> iterator = root.eAllContents();
+ while (iterator.hasNext()) {
+ EObject element = iterator.next();
+ if (element instanceof EObject) {
+ elements.add(element);
+ }
+ }
+ }
+ return elements;
+ }
+
+ /**
+ * Method to get the selected elements in the Papyrus Editor and in the Model Explorer.
+ *
+ * @param modelSet
+ * The modelSet on which we want to get the selected elements.
+ * @return The UML elements selected by the user in the Papyrus editor.
+ */
+ public static Collection<EObject> getSelectedElements(ModelSet modelSet) {
+ Object[] selections = lookupSelectedElements();
+ Collection<EObject> results = new ArrayList<>();
+ Collection<EObject> allElements = getAllElements(modelSet);
+ for (Object selectedObject : selections) {
+
+ EObject selectedElement = null;
+ if (selectedObject instanceof GraphicalEditPart) {
+ Object graphicalElement = ((GraphicalEditPart) selectedObject).getModel();
+ if ((graphicalElement instanceof View) && ((View) graphicalElement).getElement() instanceof EObject) {
+ selectedElement = ((View) graphicalElement).getElement();
+ }
+ } else if (selectedObject instanceof IAdaptable) {
+ EObject selectedEObject = ((IAdaptable) selectedObject).getAdapter(EObject.class);
+ if (selectedEObject instanceof EObject) {
+ selectedElement = selectedEObject;
+ }
+ }
+
+ if (selectedElement != null) {
+ for (EObject modelElement : allElements) {
+ if (EcoreUtil.equals(selectedElement, modelElement)) {
+ results.add(modelElement);
+ break;
+ }
+ }
+ }
+
+ }
+ return results;
+ }
+
+
+ private static Collection<EObject> searchElements(EClass[] participantsTypes, ModelSet modelSet) {
+ Collection<EClass> participantsTypesList = Arrays.asList(participantsTypes);
+ Collection<EObject> results = new HashSet<>();
+ for (EObject modelElement : getAllElements(modelSet)) {
+ if (participantsTypesList.contains(modelElement.eClass())) {
+ results.add(modelElement);
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Search, in a given ModelSet, a specific EObject.
+ *
+ * @param target
+ * The EObject to search.
+ * @param modelSet
+ * The modelSet from which we want the element.
+ * @return The EObject wanted in the given modelSet, null if not found.
+ */
+ public static EObject findEObjectInModelSet(EObject target, ModelSet modelSet) {
+ for (EObject element : PapyrusRefactoringUtils.getAllElements(modelSet)) {
+ if (EcoreUtil.equals(element, target)) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Fetch all the currently selected elements in the active workbench window
+ *
+ * @return
+ * The graphicaly selected elements
+ */
+ private static Object[] lookupSelectedElements() {
+
+ IWorkbenchWindow page = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService service = page.getSelectionService();
+ // set structured selection
+ ISelection selection = service.getSelection();
+
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ return structuredSelection.toArray();
+ } else if (selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection) selection;
+ return treeSelection.toArray();
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Get the associated UID of a selected EObject from the provided modelSet, if any
+ *
+ * @param element
+ * The provided element
+ * @param fModelSet
+ * The provided modelSet in xhich the element should be
+ * @return
+ * The element's UID or null if it deos not exists in the provided modelSet
+ */
+ public static String getRelatedXMIID(EObject element, ModelSet fModelSet) {
+ String oldID = null;
+ for (Resource resource : fModelSet.getResources()) {
+ if (!(resource instanceof UMLResource) || oldID != null) {
+ continue;
+ }
+
+ UMLResource umlResource = (UMLResource) resource;
+ oldID = umlResource.getID(element);
+ }
+
+ return oldID;
+ }
+
+ /**
+ * Retrives the Eobject from its UID and the provided modelSet
+ *
+ * @param XMIID
+ * THe provided UID
+ * @param fModelSet
+ * The provided modelSet in which the element should be referenced by the provided XMIID
+ * @return
+ * The element or null if there is no instance of the provided UID in the modelSet
+ */
+ public static EObject getRelatedElement(String XMIID, ModelSet fModelSet) {
+ EObject eObject = null;
+ for (Resource resource : fModelSet.getResources()) {
+ if (!(resource instanceof UMLResource) || eObject != null) {
+ continue;
+ }
+
+ UMLResource umlResource = (UMLResource) resource;
+ eObject = umlResource.getEObject(XMIID);
+ }
+
+ return eObject;
+ }
+
+
+ private static void setXMIID(Element elementToMutate, EObject newElement, ModelSet fModelSet) {
+ String oldID = getRelatedXMIID(elementToMutate, fModelSet);
+ for (Resource resource : fModelSet.getResources()) {
+ if (!(resource instanceof UMLResource)) {
+ continue;
+ }
+
+ UMLResource umlResource = (UMLResource) resource;
+ if (umlResource.getID(newElement) == null) {
+ continue;
+ }
+
+ umlResource.setID(newElement, oldID);
+ }
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.classpath b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.classpath
new file mode 100644
index 00000000000..098194ca4b7
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.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/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.project b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.project
new file mode 100644
index 00000000000..f1b922ab2b4
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.refactoring.mutation</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/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.settings/org.eclipse.jdt.core.prefs b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f42de363afa
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/META-INF/MANIFEST.MF b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..683ce845cf2
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/META-INF/MANIFEST.MF
@@ -0,0 +1,38 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.uml.refactoring.mutation;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-Activator: org.eclipse.papyrus.uml.refactoring.mutation.Activator
+Require-Bundle: org.eclipse.ui;bundle-version="3.107.0",
+ org.eclipse.core.runtime;bundle-version="3.11.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.6.200",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.200",
+ org.eclipse.uml2.uml;bundle-version="5.1.0",
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.0",
+ org.eclipse.papyrus.uml.service.types;bundle-version="2.0.0",
+ org.eclipse.papyrus.refactoring;bundle-version="0.0.1",
+ org.eclipse.papyrus.infra.gmfdiag.css;bundle-version="1.2.0",
+ org.eclipse.emf.ecore;bundle-version="2.11.0",
+ org.eclipse.emf.transaction;bundle-version="1.9.0",
+ org.eclipse.gmf.runtime.diagram.core;bundle-version="1.7.0",
+ org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.9.0",
+ org.eclipse.gmf.runtime.notation.edit;bundle-version="1.7.0",
+ org.eclipse.papyrus.uml.diagram.usecase;bundle-version="2.0.0",
+ org.eclipse.papyrus.editor;bundle-version="1.2.0",
+ org.eclipse.papyrus.views.modelexplorer.newchild,
+ org.eclipse.papyrus.infra.newchild,
+ org.eclipse.help;bundle-version="3.6.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.papyrus.commands,
+ org.eclipse.papyrus.infra.services.labelprovider.service,
+ org.eclipse.papyrus.infra.services.labelprovider.service.impl,
+ org.eclipse.papyrus.uml.diagram.profile.custom.requests
+Bundle-Vendor: %vendorName
+Bundle-Localization: plugin
+Export-Package: org.eclipse.papyrus.uml.refactoring.mutation.helper,
+ org.eclipse.papyrus.uml.refactoring.mutation.ui,
+ org.eclipse.papyrus.uml.refactoring.mutation.utils
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/about.html b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/about.html
new file mode 100644
index 00000000000..d35d5aed64c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/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/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/build.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/build.properties
new file mode 100644
index 00000000000..69d0f2e3ef2
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ icons/,\
+ about.html
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/images/mutate.png b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/images/mutate.png
new file mode 100644
index 00000000000..c53f93a7372
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/images/mutate.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate-toc.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate-toc.xml
new file mode 100644
index 00000000000..f139ba4494b
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate-toc.xml
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<toc label="Mutate" link_to="../org.eclipse.papyrus.refactoring/doc/refactoring_user_guide.xml#refactoring_list" topic="doc/mutate.html">
+ <topic href="doc/mutate.html" label="Mutate">
+ </topic>
+
+</toc>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.html b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.html
new file mode 100644
index 00000000000..106729ec556
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.html
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>
+<body>
+ <h1 id="Mutate">Mutate</h1>
+ <p>The "mutate" refactoring gives the user the possibility to change the type of an UML element.
+ You can select several elements but they have to be instances of the same type to execute this refactoring. </p>
+ <p>The following image illustrates the Mutate refactoring dialog.</p><p><img border="0" src="images/mutate.png"/> </p>
+ <p>All the types are displayed in a list refined from the selected element and its context. You have to select the type the selected element(s) will be instance(s) of.</p>
+</body>
+</html> \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.mediawiki b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.mediawiki
new file mode 100644
index 00000000000..8ed1aed55e6
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/doc/mutate.mediawiki
@@ -0,0 +1,11 @@
+=Mutate=
+
+The "mutate" refactoring gives the user the possibility to change the type of an UML element.
+You can select several elements but they have to be instances of the same type to execute this refactoring.
+
+The following image illustrates the Mutate refactoring dialog.
+
+
+[[image:images/mutate.png]]
+
+All the types are displayed in a list refined from the selected element and its context. You have to select the new type the selected element(s) will be instance(s) of. \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/icons/refactor.png b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/icons/refactor.png
new file mode 100644
index 00000000000..049da9f00bd
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/icons/refactor.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.properties
new file mode 100644
index 00000000000..96a71dee738
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.properties
@@ -0,0 +1,16 @@
+# Copyright (c) 2015 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:
+# Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - initial API and implementation
+
+pluginName=Papyrus Refactoring Mutation
+vendorName=Eclipse Modeling Project
+
+mutationContribution.label=Mutate
+mutationContribution.tooltip=Mutate an element into another (e.g. Class into Interface)
+mutationCommand.name=MutationCommand \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.xml
new file mode 100644
index 00000000000..e8a6e8cc96b
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/plugin.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.refactoring.menu?after=org.eclipse.papyrus.refactoring.replace.command">
+ <command
+ commandId="org.eclipse.papyrus.refactoring.mutation.command"
+ id="org.eclipse.papyrus.refactoring.mutation"
+ icon="icons/refactor.png"
+ label="%mutationContribution.label"
+ style="push"
+ tooltip="%mutationContribution.tooltip">
+ </command>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.papyrus.refactoring.mutation.command"
+ name="%mutationCommand.name">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.uml.refactoring.mutation.handler.MutationHandler"
+ commandId="org.eclipse.papyrus.refactoring.mutation.command">
+ </handler>
+ </extension>
+
+ <extension
+ point="org.eclipse.help.toc">
+ <toc
+ file="doc/mutate-toc.xml"
+ primary="false">
+ </toc>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/pom.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/pom.xml
new file mode 100644
index 00000000000..5419814d471
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.eclipse.papyrus.uml.refactoring.mutation</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <groupId>org.eclipse.papyrus</groupId>
+ <packaging>eclipse-plugin</packaging>
+ <parent>
+ <relativePath>../../../releng/extra</relativePath>
+ <groupId>org.eclipse.papyrus</groupId>
+ <artifactId>org.eclipse.papyrus.extra.releng</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.mylyn.docs</groupId>
+ <artifactId>org.eclipse.mylyn.wikitext.core.maven</artifactId>
+ <configuration>
+ <sourceFolder>doc</sourceFolder>
+ <outputFolder>${project.build.directory}/site/generated-eclipse-help</outputFolder>
+ <!-- copyrightNotice>${help.copyrightNotice}</copyrightNotice>
+ <title>${help.documentTitle}</title-->
+ <multipleOutputFiles>false</multipleOutputFiles>
+ <navigationImages>true</navigationImages>
+ <formatOutput>true</formatOutput>
+ <htmlFilenameFormat>$1.html</htmlFilenameFormat>
+ <xmlFilenameFormat>$1-toc.xml</xmlFilenameFormat>
+ <helpPrefix>target/site/generated-eclipse-help</helpPrefix>
+ <!-- stylesheetUrls>
+ <param>styles/main.css</param>
+ </stylesheetUrls-->
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>eclipse-help</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.mylyn.docs</groupId>
+ <artifactId>org.eclipse.mylyn.wikitext.mediawiki.core</artifactId>
+ <version>${mylyn.wikitext.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/Activator.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/Activator.java
new file mode 100644
index 00000000000..11b27aeb324
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/Activator.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.mutation"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ public static String REFACTORING_MUTATION_TRACE = "MutationTrace";
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ log = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/handler/MutationHandler.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/handler/MutationHandler.java
new file mode 100644
index 00000000000..a38a0e56515
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/handler/MutationHandler.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.papyrus.refactoring.core.PapyrusRefactoringOperation;
+import org.eclipse.papyrus.uml.refactoring.mutation.ui.MutationRefactoring;
+
+
+/**
+ * Handler called by the dropdown menu to mutate the selected element
+ *
+ */
+public class MutationHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ MutationRefactoring mutationRefactoring = new MutationRefactoring();
+ PapyrusRefactoringOperation operation = new PapyrusRefactoringOperation(mutationRefactoring);
+ operation.run();
+ return null;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/helper/MutationTransformation.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/helper/MutationTransformation.java
new file mode 100644
index 00000000000..6862af59108
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/helper/MutationTransformation.java
@@ -0,0 +1,559 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.helper;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewRefactorHelper;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.SemanticElementAdapter;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.visualtype.VisualTypeService;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.ITransformationOnElement;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+import org.eclipse.papyrus.uml.refactoring.mutation.Activator;
+import org.eclipse.papyrus.uml.refactoring.mutation.utils.ElementCreationUtils;
+import org.eclipse.papyrus.uml.refactoring.mutation.utils.ModelNotationUtils;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.DirectedRelationship;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Relationship;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * Class use to mutate an UML element
+ *
+ */
+public class MutationTransformation extends ViewRefactorHelper implements ITransformationOnElement {
+ /** The ModelSet where the element is defined. */
+ private ModelSet fModelSet;
+
+ /** The {@link IElementEditService} related to the new metaClass. */
+ private IElementEditService fProvider;
+
+ /** The elementType the element will be an instance of. */
+ private IElementType fNewElementType;
+
+ /** The actual metaClass the element is an instance of. */
+ private EClass fOldMetaClass;
+
+ /** The new element created */
+ private EObject newElement;
+
+ /** The new view created */
+ private View newView;
+
+ /** The container of the new element */
+ private EObject fContainer;
+
+
+ /**
+ * Basic Constructor
+ *
+ * @param modelSet
+ * @param metaClassToMutate
+ * @param typeSelected
+ */
+ public MutationTransformation(ModelSet modelSet, EClass metaClassToMutate, IElementType typeSelected) {
+ fModelSet = modelSet;
+ fNewElementType = typeSelected;
+ fOldMetaClass = metaClassToMutate;
+ }
+
+ /**
+ * Constructor used in case of a relationship transformation or if the user wants to specify the container
+ *
+ * @param modelSet
+ * @param metaClassToMutate
+ * @param typeSelected
+ * @param container
+ */
+ public MutationTransformation(ModelSet modelSet, EClass metaClassToMutate, IElementType typeSelected, EObject container) {
+ fModelSet = modelSet;
+ fNewElementType = typeSelected;
+ fOldMetaClass = metaClassToMutate;
+ fContainer = container;
+ }
+
+
+ @Override
+ public void transformationToExecute(EObject element) {
+ if (fContainer != null) {
+ mutateElement(element, fContainer);
+ } else {
+ mutateElement(element, element.eContainer());
+ }
+ }
+
+ /**
+ * Execute the steps to Mutate the element.
+ *
+ * @param oldElement
+ * The {@link EObject} to Mutate.
+ */
+ private void mutateElement(EObject oldElement, EObject parent) {
+
+ if (oldElement.eClass() != fOldMetaClass) {
+ return;
+ }
+
+ fProvider = ElementEditServiceUtils.getCommandProvider(fNewElementType);
+ if (fProvider == null) {
+ return;
+ }
+
+ EObject newElement = createElement(fNewElementType, parent, oldElement);
+ if (newElement == null
+ || !(newElement instanceof Element && oldElement instanceof Element)) {
+ return;
+ }
+
+ Element elementToMutate = (Element) oldElement;
+ Element mutatedElement = (Element) newElement;
+
+ copyAppliedStereotypes(elementToMutate, mutatedElement);
+ copyStructuralFeaturesValue(elementToMutate, mutatedElement);
+
+ reorientRelationship(elementToMutate, mutatedElement);
+ moveOwnedElements(elementToMutate, mutatedElement);
+ updateReferences(elementToMutate, mutatedElement);
+
+ updateNotation(elementToMutate, mutatedElement);
+
+ destroyElement(elementToMutate);
+ this.newElement = newElement;
+
+ }
+
+ /**
+ * Update the *.notation file to add the newElement's view to the model
+ *
+ * @param elementToMutate
+ * The old element
+ * @param newElement
+ * The new element
+ */
+ private void updateNotation(Element elementToMutate, EObject newElement) {
+ View oldView = ModelNotationUtils.getRelatedView(elementToMutate, fModelSet);
+
+ // Create a View corresponding to the new element based on the old configuration
+ if (oldView != null) {
+ if (oldView instanceof Node) {
+ createNewNode((Node) oldView, newElement);
+ }
+ if (oldView instanceof Edge) {
+ createNewEdge((Edge) oldView, newElement);
+ }
+ }
+ }
+
+ /**
+ * Create a new node to replace the old one
+ *
+ * @param oldNode
+ * @param newElement
+ */
+ private void createNewNode(Node oldNode, EObject newElement) {
+ // New view inside its designed container or the default
+ View containerView = ViewUtil.getViewContainer(oldNode);
+ // if (containerView == null) {
+ View containerView2 = fContainer != null ? ModelNotationUtils.getRelatedView(fContainer, fModelSet) : null;
+ // }
+ String visualID = VisualTypeService.getInstance().getNodeType(containerView, newElement);
+
+ Node newNode = ViewService.createNode(containerView, newElement, visualID, getPreferencesHint());
+
+ if (newNode != null) {
+ copyNodeFeatures(oldNode, newNode);
+ addOldVisibleChildren(newNode, ModelNotationUtils.getVisibleChildren(oldNode));
+ }
+
+ newView = newNode;
+ }
+
+
+ /**
+ * Find, if any exists, the corresponding type from *.elementtypeconfigurations in *di.elementtypeconfigurations
+ * used to find and create the visual representation of the element
+ *
+ * @param visualID
+ * @return
+ * The {@link ISpecializationType} corresponding to the {@link IElementType} selected
+ */
+ private ISpecializationType getSpecializationType(String visualID) {
+ // TODO find a better way to filter the found element, e.g. ask the user which he wants
+ for (ISpecializationType specializationType : ElementTypeRegistry.getInstance().getSpecializationsOf(fNewElementType.getId())) {
+ if (!(specializationType instanceof IHintedType)) {
+ continue;
+ }
+
+ IHintedType hintedType = (IHintedType) specializationType;
+ if (hintedType.getSemanticHint().equalsIgnoreCase(visualID)) {
+ // A type has been found
+ return specializationType;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Add the pertinent views to the notation node depending on th previous visibility
+ *
+ * @param newView
+ * @param oldVisibleChildren
+ */
+ private void addOldVisibleChildren(View newView, Set<View> oldVisibleChildren) {
+ EObject newViewElement = newView.getElement();
+ for (View oldViewChild : oldVisibleChildren) {
+ // This in order to filter out the compartments
+ if (!(oldViewChild instanceof Shape || oldViewChild instanceof Edge)) {
+ continue;
+ }
+
+ EObject oldViewChildElement = oldViewChild.getElement();
+ if (newViewElement.eContents().contains(oldViewChildElement)) {
+ String visualID = null;
+ View newViewChild = null;
+ // Iterate on the contents of the node to see who can accommodate the subNode
+ for (Object object : newView.getChildren()) {
+ if (!(object instanceof View) || visualID != null) {
+ continue;
+ }
+
+ newViewChild = (View) object;
+ visualID = VisualTypeService.getInstance().getNodeType(newViewChild, oldViewChildElement);
+ }
+
+ Node newNode = ViewService.createNode(newViewChild, oldViewChildElement, visualID, getPreferencesHint());
+ if (newNode != null) {
+ Node oldNode = oldViewChild instanceof Node ? (Node) oldViewChild : null;
+ if (oldNode != null) {
+ copyNodeFeatures(oldNode, newNode);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Get hte active diagram's editPart from the multi diagram editor
+ *
+ * @return
+ * The active diagram's DiagramEditPart
+ */
+ public DiagramEditPart getHost() {
+ IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ PapyrusMultiDiagramEditor papyrusEditor = editorPart instanceof PapyrusMultiDiagramEditor ? (PapyrusMultiDiagramEditor) editorPart : null;
+ DiagramEditPart diagramEditPart = (DiagramEditPart) papyrusEditor.getAdapter(DiagramEditPart.class);
+
+ return diagramEditPart;
+ }
+
+ /**
+ * Create a new edge to replace the old one
+ *
+ * @param oldEdge
+ * @param newElement
+ */
+ private void createNewEdge(Edge oldEdge, EObject newElement) {
+ // New view inside its designed container or the default
+ View containerView = fContainer != null ? ModelNotationUtils.getRelatedView(fContainer, fModelSet) : ViewUtil.getViewContainer(oldEdge);
+ String visualID = VisualTypeService.getInstance().getLinkType(containerView.getDiagram(), newElement);
+
+ // The IElementTypes required by the creation of a graphical representation are those inside the *di.elementtypesconfigurations
+ // Else the Hint required by the Providers does not match the view and the view and the view wont be created
+ ISpecializationType specializationType = getSpecializationType(visualID);
+ SemanticElementAdapter semanticElementAdapter = new SemanticElementAdapter(newElement, specializationType);
+
+ Edge newEdge = (Edge) ViewService.getInstance().createEdge(semanticElementAdapter, oldEdge.getDiagram(),
+ visualID, ViewUtil.APPEND, getPreferencesHint());
+
+ if (newEdge != null) {
+ // copyEdgeFeatures(oldEdge, newEdge);
+ // copyStructuralFeaturesValue(oldEdge, newEdge);
+ newEdge.setSource(oldEdge.getSource());
+ newEdge.setSourceAnchor(oldEdge.getSourceAnchor());
+ newEdge.setTarget(oldEdge.getTarget());
+ newEdge.setTargetAnchor(oldEdge.getTargetAnchor());
+ newEdge.setBendpoints(oldEdge.getBendpoints());
+ }
+
+ newView = newEdge;
+ }
+
+ /**
+ * Create a new UML element.
+ *
+ * @param elementType
+ * The UML elementType the new element will be instance of.
+ * @param container
+ * Represents the container of the new element to create.
+ * @param elementToMutate
+ * @return The new UML element
+ */
+ private Element createElement(IElementType elementType, EObject container, EObject elementToMutate) {
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container);
+ CreateElementRequest creationRequest = ElementCreationUtils.createElementRequest(fNewElementType, container, elementToMutate, fModelSet);
+
+ ICommand createElementCommand = createCommand(provider, creationRequest);
+ executeCommand(createElementCommand);
+
+ EObject newElement = creationRequest.getNewElement();
+
+ return ((newElement instanceof Element) ? (Element) newElement : null);
+ }
+
+
+ /**
+ * Apply, to a given element, the stereotypes,which are actually applied to an other UML element.
+ *
+ * @param elementToMutate
+ * The element with the wanted stereotypes.
+ * @param newElement
+ * The element on which we will apply the stereotypes.
+ */
+ private void copyAppliedStereotypes(Element elementToMutate, Element newElement) {
+ for (Stereotype stereotype : elementToMutate.getAppliedStereotypes()) {
+ if (newElement.isStereotypeApplicable(stereotype)) {
+ EObject stereotypeApplied = newElement.applyStereotype(stereotype);
+ if (stereotypeApplied instanceof Element) {
+ copyStructuralFeaturesValue(stereotype, (Element) stereotypeApplied);
+ }
+ }
+ }
+ }
+
+ /**
+ * Do a copy/paste of the {@link EStructuralFeature} from a source element to a target element.
+ *
+ * @param elementToMutate
+ * The source element.
+ * @param newElement
+ * The target element.
+ */
+ private void copyStructuralFeaturesValue(Element elementToMutate, Element newElement) {
+ ICommand compositeCommand = null;
+
+ for (EStructuralFeature structuralFeature : elementToMutate.eClass().getEAllStructuralFeatures()) {
+ if (elementToMutate.eGet(structuralFeature) != null
+ && newElement.eClass().getEAllStructuralFeatures().contains(structuralFeature)
+ && !newElement.eClass().getEStructuralFeature(structuralFeature.getFeatureID()).isUnsettable()) {
+
+ Activator.log.trace(Activator.REFACTORING_MUTATION_TRACE, structuralFeature.getName() + ", " + elementToMutate.eGet(structuralFeature));
+ // if (structuralFeature.getName().equalsIgnoreCase("owner") && newElement instanceof DirectedRelationship
+ // && !(elementToMutate instanceof DirectedRelationship) && elementToMutate instanceof Relationship) {
+ // SetRequest setRequest = new SetRequest(newElement, structuralFeature, fContainer);
+ // compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(fProvider, setRequest));
+ // } else {
+ SetRequest setRequest = new SetRequest(newElement, structuralFeature, elementToMutate.eGet(structuralFeature));
+ compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(fProvider, setRequest));
+ // }
+ }
+ }
+
+ executeCommand(compositeCommand);
+ }
+
+ /**
+ * Move each element contained in a sourceElement to a targetElement (if the targetElement can contain the
+ * element owned by the source).
+ *
+ * @param elementToMutate
+ * @param newElement
+ */
+ private void moveOwnedElements(Element elementToMutate, Element newElement) {
+ MoveRequest moveReq;
+ ICommand compositeCommand = null;
+
+ if (fProvider != null) {
+ for (Element ownedElement : elementToMutate.getOwnedElements()) {
+ moveReq = new MoveRequest(TransactionUtil.getEditingDomain(newElement), newElement, ownedElement);
+ compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(fProvider, moveReq));
+ }
+ }
+
+ executeCommand(compositeCommand);
+ }
+
+ /**
+ * Find all usage references of a source element, and set this references to a target element.
+ *
+ * @param elementToMutate
+ * The source element.
+ * @param newElement
+ * The target element.
+ */
+ private void updateReferences(Element elementToMutate, Element newElement) {
+ Collection<Setting> settingReferences = EcoreUtil.UsageCrossReferencer.find(elementToMutate,
+ PapyrusRefactoringUtils.getAllElements(fModelSet));
+ ICommand compositeCommand = null;
+ Set<EObject> cacheUpdatedObjects = new HashSet<>();
+
+ for (Setting setting : settingReferences) {
+ EObject objectToUpdate = setting.getEObject();
+ if (!cacheUpdatedObjects.contains(objectToUpdate)) {
+ cacheUpdatedObjects.add(objectToUpdate);
+ SetRequest setRequest = new SetRequest(setting.getEObject(), setting.getEStructuralFeature(), newElement);
+ compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(fProvider, setRequest));
+ }
+ }
+
+ executeCommand(compositeCommand);
+ }
+
+ /**
+ * Find all the {@link Relationship} in which a source element is involved, then replace this source element
+ * by a target element in each {@link Relationship} found.
+ *
+ * @param elementToMutate
+ * The source element.
+ * @param newElement
+ * The target element.
+ */
+ private void reorientRelationship(Element elementToMutate, Element newElement) {
+ ICommand compositeCommand = null;
+
+ for (Relationship relationship : elementToMutate.getRelationships()) {
+
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relationship);
+ ReorientRelationshipRequest reorientReq;
+ if (relationship instanceof DirectedRelationship) {
+ if (((DirectedRelationship) relationship).getSources().contains(elementToMutate)) {
+ reorientReq = new ReorientRelationshipRequest(TransactionUtil.getEditingDomain(relationship), relationship,
+ newElement, elementToMutate, ReorientRequest.REORIENT_SOURCE);
+ } else {
+ reorientReq = new ReorientRelationshipRequest(TransactionUtil.getEditingDomain(relationship), relationship,
+ newElement, elementToMutate, ReorientRequest.REORIENT_TARGET);
+ }
+
+ if (provider != null && reorientReq != null) {
+ compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(provider, reorientReq));
+ }
+ } else {
+ Element source = (fContainer != null && fContainer instanceof Element) ? (Element) fContainer : relationship.getRelatedElements().get(1);
+
+ if (EcoreUtil.equals(source, elementToMutate)) {
+ reorientReq = new ReorientRelationshipRequest(TransactionUtil.getEditingDomain(relationship), relationship,
+ newElement, elementToMutate, ReorientRequest.REORIENT_SOURCE);
+ } else {
+ reorientReq = new ReorientRelationshipRequest(TransactionUtil.getEditingDomain(relationship), relationship,
+ newElement, elementToMutate, ReorientRequest.REORIENT_TARGET);
+ }
+
+ if (provider != null && reorientReq != null) {
+ compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(provider, reorientReq));
+ }
+ }
+ }
+
+ executeCommand(compositeCommand);
+ }
+
+ /**
+ * Destroy an element
+ *
+ * @param elementToDestroy
+ * The element to destroy.
+ */
+ private void destroyElement(Element elementToDestroy) {
+ DestroyElementRequest destroyReq = new DestroyElementRequest(elementToDestroy, false);
+ ICommand compositeCommand = null;
+
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(elementToDestroy);
+ if (provider != null) {
+ compositeCommand = CompositeCommand.compose(compositeCommand, createCommand(provider, destroyReq));
+ }
+
+ executeCommand(compositeCommand);
+ }
+
+
+
+ /**
+ * Create a command for a given request
+ *
+ * @param request
+ * The request to create the command for.
+ * @return The wanted command.
+ */
+ private ICommand createCommand(IElementEditService provider, AbstractEditCommandRequest request) {
+ ICommand command = provider.getEditCommand(request);
+ return command;
+ }
+
+ /**
+ * If the command is valid, we execute it.
+ *
+ * @param command
+ */
+ private void executeCommand(ICommand command) {
+ if (command != null && command.canExecute() /* && command.canUndo() */) {
+ // try {
+ // command.execute(new NullProgressMonitor(), null);
+ // } catch (ExecutionException e) {
+ // Activator.log.error(e);
+ // }
+ Command emfCommand = GMFtoEMFCommandWrapper.wrap(command);
+ if (emfCommand.canExecute() /* && emfCommand.canUndo() */) {
+ emfCommand.execute();
+ }
+ }
+ }
+
+ public EObject getMutatedElement() {
+ return newElement;
+ }
+
+ public View getMutatedView() {
+ return newView;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/Messages.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/Messages.java
new file mode 100644
index 00000000000..a24d45506bc
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/Messages.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.refactoring.Mutation.messages.messages"; //$NON-NLS-1$
+
+ public static String MUTATIONREFACTORING_PAGETITLE;
+ public static String MUTATIONREFACTORING_SELECTIONLABEL;
+ public static String MUTATIONREFACTORING_SELECTIONWARNING_EMPTY;
+ public static String MUTATIONREFACTORING_SELECTIONWARNING_UNIFORM;
+
+ public static String MUTATIONREFACTORING_PAGEICON;
+ public static String MUTATIONREFACTORING_PAGEICON_TYPE;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/messages.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/messages.properties
new file mode 100644
index 00000000000..569a893c491
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/messages/messages.properties
@@ -0,0 +1,7 @@
+MUTATIONREFACTORING_PAGETITLE=Mutation
+MUTATIONREFACTORING_SELECTIONLABEL=Select the new type
+MUTATIONREFACTORING_SELECTIONWARNING_EMPTY=Select at least one element.
+MUTATIONREFACTORING_SELECTIONWARNING_UNIFORM=All elements selected have to be instances of the same UML metaClass.
+
+MUTATIONREFACTORING_PAGEICON=/icons/full/obj16/
+MUTATIONREFACTORING_PAGEICON_TYPE=.gif \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElemenetTypeContentProvider.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElemenetTypeContentProvider.java
new file mode 100644
index 00000000000..2950f0ef77f
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElemenetTypeContentProvider.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.providers;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Provider used to get the possible types for the mutated element
+ *
+ */
+public class ElemenetTypeContentProvider implements ITreeContentProvider {
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ // Map<IElementType, EObject> elementsToDisaplay = new HashMap<>();
+ @SuppressWarnings("unchecked")
+ HashMap<IElementType, EObject> inputElements = (HashMap<IElementType, EObject>) inputElement;
+ // for (IElementType elementType : inputElements) {
+ // if (!(elementType instanceof IHintedType)) {
+ // continue;
+ // }
+ //
+ // elementsToDisaplay.add(elementType);
+ // }
+
+ return inputElements.entrySet().toArray();
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElementTypeLabelProvider.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElementTypeLabelProvider.java
new file mode 100644
index 00000000000..ed8f6832208
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/providers/ElementTypeLabelProvider.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.providers;
+
+import java.util.Arrays;
+import java.util.Map.Entry;
+
+/**
+ * Label provider used to display the possible types of the mmutated element
+ *
+ */
+import org.eclipse.gmf.runtime.common.ui.services.icon.IconService;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * The label provider used to display the input in the viewer
+ *
+ */
+public class ElementTypeLabelProvider extends LabelProvider {
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof Entry) {
+ Entry entry = (Entry) element;
+ Object key = entry.getKey();
+
+ if (key instanceof IElementType) {
+ IElementType elementType = (IElementType) key;
+
+ return IconService.getInstance().getIcon(elementType);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof Entry) {
+ Entry entry = (Entry) element;
+ Object key = entry.getKey();
+
+ if (key instanceof IElementType) {
+ IElementType elementType = (IElementType) key;
+ String defaultName = elementType.getDisplayName();
+ String name = "";
+ if (defaultName.contains("::")) {
+ name = Arrays.asList(elementType.getDisplayName().split("::")).get(1);
+ } else {
+ name = defaultName;
+ }
+
+ return name;
+ }
+ }
+
+ return "ElementNotFound";
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/ui/MutationRefactoring.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/ui/MutationRefactoring.java
new file mode 100644
index 00000000000..380383e62b6
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/ui/MutationRefactoring.java
@@ -0,0 +1,416 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.ui;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.newchild.CreationMenuRegistry;
+import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.CreationMenu;
+import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.Folder;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.refactoring.Activator;
+import org.eclipse.papyrus.refactoring.helper.AbstractSelectedElementsTransformation;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.ITransformationOnElement;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+import org.eclipse.papyrus.uml.refactoring.mutation.helper.MutationTransformation;
+import org.eclipse.papyrus.uml.refactoring.mutation.messages.Messages;
+import org.eclipse.papyrus.uml.refactoring.mutation.providers.ElemenetTypeContentProvider;
+import org.eclipse.papyrus.uml.refactoring.mutation.providers.ElementTypeLabelProvider;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.uml2.uml.DirectedRelationship;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Relationship;
+
+
+
+/**
+ * Class used to propose the next type of the mutated element through a new wizard page and {@link AbstractSelectedElementsTransformation} used to mutate the selected elements.
+ *
+ */
+@SuppressWarnings("restriction")
+public class MutationRefactoring extends AbstractSelectedElementsTransformation {
+
+ /** The {@link TreeViewer} that displays the UML Meta-Classes in the UI. */
+ private TreeViewer fNewTypeTreeViewer;
+
+ /** The {@link FilteredTree} to help the user to find the UML Meta-class he is looking for. */
+ private FilteredTree fNewMetaClassTree;
+
+ /** The {@link Composite} for this UI. */
+ private Composite mutationComposite;
+
+
+ public MutationRefactoring() {
+ super(Messages.MUTATIONREFACTORING_PAGETITLE);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ mutationComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 1;
+
+ mutationComposite.setLayout(layout);
+ mutationComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ setControl(mutationComposite);
+
+ initElementTypesViewer();
+ }
+
+
+ /**
+ * Initiate and display {@link #fNewTypeTreeViewer}.
+ */
+ private void initElementTypesViewer() {
+ Label newMetaClassLabel = new Label(mutationComposite, SWT.NONE);
+ newMetaClassLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
+ newMetaClassLabel.setText(Messages.MUTATIONREFACTORING_SELECTIONLABEL);
+
+ fNewMetaClassTree = new FilteredTree(mutationComposite, SWT.RIGHT | SWT.V_SCROLL | SWT.H_SCROLL, new PatternFilter(), true);
+ fNewTypeTreeViewer = fNewMetaClassTree.getViewer();
+ GridData listViewerGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
+ listViewerGridData.heightHint = 300;
+
+ fNewMetaClassTree.setLayoutData(listViewerGridData);
+ fNewTypeTreeViewer.setComparator(new ViewerComparator());
+
+ Map<IElementType, EObject> umlTypesInput = new HashMap<>();
+ try {
+ // EObject modelRoot = PapyrusRefactoringUtils.getUMLRoot(fModelSet);
+ // Model model = modelRoot instanceof Model ? (Model) modelRoot : null;
+ // if (model != null) {
+ // for (Profile profile : model.getAllAppliedProfiles()) {
+ // // TODO retrieve the elementTypes according to the applied profiles
+ // }
+ // }
+
+
+ ElementTypeRegistry registry = ElementTypeRegistry.getInstance();
+ EObject elementToMutate = getElementToMutate();
+ EObject elementToMutateParent = elementToMutate.eContainer() != null ? elementToMutate.eContainer() : elementToMutate;
+ IElementType relationshipType = UMLElementTypes.RELATIONSHIP;
+ IClientContext clientContext = TypeContext.getContext();
+ IElementType elementToMutateType = registry.getElementType(elementToMutate, clientContext);
+ boolean elementToMutateIsRelationship = Arrays.asList(elementToMutateType.getAllSuperTypes()).contains(relationshipType);
+
+ Set<IElementType> relationshipTypes = new HashSet<>();
+ Set<IElementType> nodeTypes = new HashSet<>();
+
+ for (Folder folder : CreationMenuRegistry.getInstance().getRootFolder()) {
+ // System.err.println(folder.getLabel() + ", " + folder.eContents().size());
+ for (EObject eObject : folder.eContents()) {
+ if (eObject instanceof CreationMenu) {
+ CreationMenu creationMenu = (CreationMenu) eObject;
+ IElementType menuElementType = registry.getType(creationMenu.getElementTypeIdRef());
+ if (menuElementType == null) {
+ continue;
+ }
+
+ if (Arrays.asList(menuElementType.getAllSuperTypes()).contains(relationshipType)) {
+ relationshipTypes.add(menuElementType);
+ } else {
+ nodeTypes.add(menuElementType);
+ }
+ }
+ }
+ }
+
+ if (elementToMutateIsRelationship) {
+ umlTypesInput = getRelationshipTypes(elementToMutateParent, elementToMutate, relationshipTypes);
+ } else {
+ umlTypesInput = getNodeTypes(elementToMutateParent, elementToMutate, nodeTypes);
+ }
+
+ umlTypesInput.remove(elementToMutateType);
+ // System.err.println("finalMenu, " + umlTypesInput.size());
+
+
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+
+ fNewTypeTreeViewer.setLabelProvider(new ElementTypeLabelProvider());
+ fNewTypeTreeViewer.setContentProvider(new ElemenetTypeContentProvider());
+ fNewTypeTreeViewer.setInput(umlTypesInput);
+
+ }
+
+ /**
+ * Retrieves all the possible relationship that can be created from the selected element's context
+ *
+ * @param elementToMutateParent
+ * The relationship's container
+ * @param elementToMutate
+ * The relationship
+ * @param relationshipTypes
+ * The possible relationship types the are declared in the registry
+ * @return
+ * The filtered relationships to display in the viewer
+ */
+ private Map<IElementType, EObject> getRelationshipTypes(EObject elementToMutateParent, EObject elementToMutate, Set<IElementType> relationshipTypes) {
+ Map<IElementType, EObject> filteredTypes = new HashMap<>();
+
+ Relationship relationshipToMutate = (Relationship) elementToMutate;
+ Element relationshipSource = null;
+ Element relationshipTarget = null;
+ if (relationshipToMutate instanceof DirectedRelationship) {
+ // System.err.println("DirectedRelationship");
+ // System.err.println(relationshipToMutate.getRelatedElements());
+ relationshipSource = ((DirectedRelationship) relationshipToMutate).getSources().get(0);
+ relationshipTarget = ((DirectedRelationship) relationshipToMutate).getTargets().get(0);
+ } else {
+ // System.err.println("Relationship");
+ // System.err.println(relationshipToMutate.getRelatedElements());
+ // This is to check the validity of the create command, hence the inverted ends are not that problematic
+ relationshipSource = relationshipToMutate.getRelatedElements().get(1);
+ relationshipTarget = relationshipToMutate.getRelatedElements().get(0);
+ }
+ // System.err.println(relationshipSource);
+ // System.err.println(relationshipTarget);
+
+ IElementEditService parentProvider = ElementEditServiceUtils.getCommandProvider(elementToMutateParent);
+ IElementEditService sourceProvider = ElementEditServiceUtils.getCommandProvider(relationshipSource);
+ if (parentProvider == null && sourceProvider == null) {
+ return null;
+ }
+
+ for (IElementType elementType : relationshipTypes) {
+ if (parentProvider != null) {
+ ICommand createGMFCommandParent = null;
+ TransactionalEditingDomain editingDomainParent = TransactionUtil.getEditingDomain(elementToMutateParent);
+ CreateRelationshipRequest relationshipParentRequest = new CreateRelationshipRequest(editingDomainParent, elementToMutateParent, relationshipSource, relationshipTarget, elementType);
+ createGMFCommandParent = parentProvider.getEditCommand(relationshipParentRequest);
+
+ if (createGMFCommandParent != null && createGMFCommandParent.canExecute()) {
+ filteredTypes.putIfAbsent(elementType, relationshipSource);
+ }
+ }
+
+ if (sourceProvider != null) {
+ ICommand createGMFCommandSource = null;
+ TransactionalEditingDomain editingDomainSource = TransactionUtil.getEditingDomain(relationshipSource);
+ CreateRelationshipRequest relationshipRequestSource = new CreateRelationshipRequest(editingDomainSource, relationshipSource, relationshipSource, relationshipTarget, elementType);
+ createGMFCommandSource = parentProvider.getEditCommand(relationshipRequestSource);
+
+ if (createGMFCommandSource != null && createGMFCommandSource.canExecute()) {
+ filteredTypes.putIfAbsent(elementType, relationshipSource);
+ }
+ }
+
+ }
+
+ return filteredTypes;
+ }
+
+ /**
+ * Retrieves all the possible nodes that can be created from the element's context
+ *
+ * @param elementToMutateParent
+ * The element's parent
+ * @param elementToMutate
+ * The element
+ * @param nodeTypes
+ * The possible nodes that are declared in the registry
+ * @return
+ * The filtered nodes to be displayed in the viewer
+ */
+ private Map<IElementType, EObject> getNodeTypes(EObject elementToMutateParent, EObject elementToMutate, Set<IElementType> nodeTypes) {
+ Map<IElementType, EObject> filteredTypes = new HashMap<>();
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(elementToMutateParent);
+ if (provider == null) {
+ return null;
+ }
+
+ for (IElementType elementType : nodeTypes) {
+ ICommand createGMFCommand = null;
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(elementToMutate);
+ CreateElementRequest elementRequest = new CreateElementRequest(editingDomain, elementToMutateParent, elementType);
+ createGMFCommand = provider.getEditCommand(elementRequest);
+
+ if (createGMFCommand == null || !createGMFCommand.canExecute()) {
+ continue;
+ }
+ filteredTypes.putIfAbsent(elementType, elementToMutateParent);
+ }
+
+ return filteredTypes;
+ }
+
+ @Override
+ public ITransformationOnElement getTransformationOnElement() {
+ Entry selectedEntry = getTypeSelected(fNewTypeTreeViewer.getSelection());
+ // The null condition is already checked by the finalConditions method
+ IElementType selectedType = (IElementType) selectedEntry.getKey();
+ EObject associatedContainer = selectedEntry.getValue() != null ? (EObject) selectedEntry.getValue() : null;
+
+ MutationTransformation mutation = new MutationTransformation(fModelSet, getMetaClassToMutate(),
+ selectedType, associatedContainer);
+
+ return mutation;
+ }
+
+
+ @Override
+ /**
+ * Check that a meta-class is selected by the user in the {@link #fNewMetaClassTreeViewer}.
+ */
+ public RefactoringStatus checkFinalConditions() {
+ RefactoringStatus status = new RefactoringStatus();
+ if (getTypeSelected(fNewTypeTreeViewer.getSelection()) == null) {
+ status.addFatalError(Messages.MUTATIONREFACTORING_SELECTIONLABEL);
+ }
+
+ return status;
+ }
+
+
+ /**
+ * Verify that the operation can proceed and is not lacking parameters
+ *
+ * @param selection
+ * The selected Type to transform the object into
+ * @return
+ * The {@link IElementType} that represents the new UML element.
+ */
+ private Entry<IElementType, EObject> getTypeSelected(ISelection selection) {
+
+ if (selection instanceof IStructuredSelection) {
+ Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
+ if (selectedElement instanceof Entry) {
+ Entry selectedEntry = (Entry) selectedElement;
+ Object selectedType = selectedEntry.getKey();
+ Object associatedContainer = selectedEntry.getValue();
+
+ if (selectedType instanceof IElementType) {
+ if (associatedContainer instanceof EObject) {
+ return selectedEntry;
+ }
+
+ // We can't simply resolve the provided container therefore fall back on the default transformation
+ selectedEntry.setValue(null);
+ return selectedEntry;
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Retrieves the EClass of the element to mutate
+ *
+ * @return
+ */
+ // We have checked in the checkIntialConditions method that all selected elements are instances of the same
+ // UML metaClass, so to get the EClass to mutate we just need to get the EClass of one element of the selected
+ // elements list.
+ private EClass getMetaClassToMutate() {
+ EObject elementToMutate = getElementToMutate();
+ if (elementToMutate != null) {
+ return elementToMutate.eClass();
+ }
+
+ return null;
+ }
+
+ /**
+ * Retrieves the EObject linked to the element to mutate
+ *
+ * @return
+ */
+ private EObject getElementToMutate() {
+ if (fModelSet != null) {
+ Iterator<EObject> it = PapyrusRefactoringUtils.getSelectedElements(fModelSet).iterator();
+ if (it.hasNext()) {
+ return it.next();
+ }
+ }
+
+ return null;
+ }
+
+
+ @Override
+ /**
+ * Check that at least one element is selected,and that all selected elements are instances of the same UML metaClass.
+ */
+ public RefactoringStatus checkInitialConditions() {
+ RefactoringStatus status = new RefactoringStatus();
+ HashSet<EClass> eClassSelectedList = new HashSet<>();
+ if (PapyrusRefactoringUtils.getSelectedElements(fModelSet).size() == 0) {
+ status.addFatalError(Messages.MUTATIONREFACTORING_SELECTIONWARNING_EMPTY);
+
+ } else {
+ for (EObject element : PapyrusRefactoringUtils.getSelectedElements(fModelSet)) {
+ eClassSelectedList.add(element.eClass());
+ }
+
+ if (eClassSelectedList.size() != 1) {
+ status.addFatalError(Messages.MUTATIONREFACTORING_SELECTIONWARNING_UNIFORM);
+ }
+ }
+
+ return status;
+ }
+
+
+ @Override
+ public String getName() {
+ return Messages.MUTATIONREFACTORING_PAGETITLE;
+ }
+
+ @Override
+ public void performHelp() {
+ // TODO Write the help
+ // http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_help_contexts.html
+ PlatformUI.getWorkbench().getHelpSystem().displayHelp("help context id");
+ }
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ElementCreationUtils.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ElementCreationUtils.java
new file mode 100644
index 00000000000..f4293246560
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ElementCreationUtils.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.uml2.uml.DirectedRelationship;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Relationship;
+
+/**
+ * Utils methods used to create new elements from the old elements when the refactoring occurs
+ *
+ */
+public class ElementCreationUtils {
+
+ /**
+ * Create a new UML element.
+ *
+ * @param elementType
+ * The UML elementType the new element will be instance of.
+ * @param container
+ * Represents the container of the new element to create.
+ * @param elementToMutate
+ * @return The new UML element
+ */
+ public static CreateElementRequest createElementRequest(IElementType elementType, EObject container, EObject elementToMutate, ModelSet fModelSet) {
+
+ TransactionalEditingDomain editingDomain = fModelSet.getTransactionalEditingDomain();
+ if (elementToMutate instanceof Relationship) {
+ Element relationshipSource = null;
+ Element relationshipTarget = null;
+ if (elementToMutate instanceof DirectedRelationship) {
+ relationshipSource = ((DirectedRelationship) elementToMutate).getSources().get(0);
+ relationshipTarget = ((DirectedRelationship) elementToMutate).getTargets().get(0);
+ } else {
+ relationshipSource = ((Relationship) elementToMutate).getRelatedElements().get(1);
+ relationshipTarget = ((Relationship) elementToMutate).getRelatedElements().get(0);
+ }
+
+ return new CreateRelationshipRequest(editingDomain, container, relationshipSource, relationshipTarget, elementType);
+
+ } else {
+
+ return new CreateElementRequest(editingDomain, container, elementType);
+ }
+
+ }
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ModelNotationUtils.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ModelNotationUtils.java
new file mode 100644
index 00000000000..9199e319519
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.mutation/src/org/eclipse/papyrus/uml/refactoring/mutation/utils/ModelNotationUtils.java
@@ -0,0 +1,260 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.mutation.utils;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.notation.Connector;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
+import org.eclipse.papyrus.infra.gmfdiag.css.resource.CSSNotationResource;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Utils methods used to browse through the notation model
+ *
+ */
+public class ModelNotationUtils {
+
+ /**
+ * Retrieves all the {@link org.eclipse.gmf.runtime.notation.Edge edges} of the diagram
+ *
+ * @param cssDiagram
+ * @return
+ * The list of the diagram edges
+ */
+ public static Set<View> getAllEdges(CSSDiagram cssDiagram) {
+ Set<View> allChildren = new HashSet<>();
+ for (Object object : cssDiagram.getEdges()) {
+ if (!(object instanceof Edge)) {
+ continue;
+ }
+
+ Edge view = (Edge) object;
+ allChildren.add(view);
+ allChildren.addAll(getAllEdges(view));
+ }
+
+ return allChildren;
+ }
+
+ /**
+ * Retrieves all the children {@link org.eclipse.gmf.runtime.notation.Edge edges} of the provided View
+ *
+ * @param currentView
+ * @return
+ * The list of the children edges
+ */
+ public static Set<View> getAllEdges(Edge currentView) {
+ Set<View> allChildren = new HashSet<>();
+ for (Object object : currentView.getChildren()) {
+ if (!(object instanceof Edge)) {
+ continue;
+ }
+
+ Edge view = (Edge) object;
+ allChildren.add(view);
+ allChildren.addAll(getAllEdges(view));
+ }
+
+ return allChildren;
+ }
+
+ /**
+ * Retrieves all the {@link org.eclipse.gmf.runtime.notation.View views} of the diagram
+ *
+ * @param cssDiagram
+ * @return
+ * The list of the diagram views
+ */
+ public static Set<View> getAllChildren(CSSDiagram cssDiagram) {
+ Set<View> allChildren = new HashSet<>();
+ for (Object object : cssDiagram.getChildren()) {
+ if (!(object instanceof View)) {
+ continue;
+ }
+
+ View view = (View) object;
+ allChildren.add(view);
+ allChildren.addAll(getAllChildren(view));
+ }
+
+ return allChildren;
+ }
+
+ /**
+ * Retrieves all the children {@link org.eclipse.gmf.runtime.notation.View views} of the provided View
+ *
+ * @param currentView
+ * @return
+ * The list of the children views
+ */
+ public static Set<View> getAllChildren(View currentView) {
+ Set<View> allChildren = new HashSet<>();
+ for (Object object : currentView.getChildren()) {
+ if (!(object instanceof View)) {
+ continue;
+ }
+
+ View view = (View) object;
+ allChildren.add(view);
+ allChildren.addAll(getAllChildren(view));
+ }
+
+ return allChildren;
+ }
+
+ /**
+ * Get all the visible {@link org.eclipse.gmf.runtime.notation.View children} of the old node
+ *
+ * @param oldView
+ * @return
+ * The list of all the views
+ */
+ public static Set<View> getVisibleChildren(View oldView) {
+ Set<View> visibleChildren = new HashSet<>();
+
+ for (Object viewChild : oldView.getVisibleChildren()) {
+ if (!(viewChild instanceof View)) {
+ continue;
+ }
+
+ View view = (View) viewChild;
+ visibleChildren.add(view);
+ visibleChildren.addAll(getVisibleChildren(view));
+ }
+
+ return visibleChildren;
+ }
+
+ /**
+ * Retrive the {@link org.eclipse.gmf.runtime.notation.View View} associated with the provided element in the provided model
+ *
+ * @param element
+ * The {@link org.eclipse.emf.ecore.EObject element} to match
+ * @param fModelSet
+ * The {@link org.eclipse.papyrus.infra.core.resource.ModelSet model} to search
+ * @return
+ * The associated View or null if none can be found
+ */
+ public static View getRelatedView(EObject element, ModelSet fModelSet) {
+
+ NotationModel notationModel = (NotationModel) fModelSet.getModel(NotationModel.MODEL_ID);
+
+ CSSNotationResource notationResource = (CSSNotationResource) notationModel.getResource();
+ for (EObject eObject : notationResource.getContents()) {
+ if (!(eObject instanceof CSSDiagram)) {
+ continue;
+ }
+
+ CSSDiagram cssDiagram = (CSSDiagram) eObject;
+ // if (!(EcoreUtil.equals(element, cssDiagram.getElement()))) {
+ // if (cssDiagram instanceof View) {
+ // // The View has been found in case of the element to mutate is the root model
+ // return cssDiagram;
+ // }
+ // }
+
+ // First iterate through all the Nodes
+ for (Object object : ModelNotationUtils.getAllChildren(cssDiagram)) {
+ if (!(object instanceof Shape)) {
+ continue;
+ }
+
+ Shape shape = (Shape) object;
+ if (!(EcoreUtil.equals(element, shape.getElement()))) {
+ continue;
+ }
+
+ if (object instanceof Node) {
+ // The View has been found
+ return (Node) object;
+ }
+ }
+
+ // Then iterate through all the Edges
+ for (Object object : ModelNotationUtils.getAllEdges(cssDiagram)) {
+ if (!(object instanceof Connector)) {
+ continue;
+ }
+
+ Connector connector = (Connector) object;
+ if (!(EcoreUtil.equals(element, connector.getElement()))) {
+ continue;
+ }
+
+ if (object instanceof Edge) {
+ // The View has been found
+ return (Edge) object;
+ }
+ }
+ }
+
+ // The element has no *.notation representation
+ return null;
+ }
+
+
+ private static String getVisualID(View containerView, EObject newElement, ModelSet modelSet) {
+ // View diagramView = containerView.getDiagram();
+ // Diagram diagram = (Diagram) diagramView;
+ // List<View> children = diagram.getChildren();
+ // String diagramType = diagram.getType();
+ //
+ // DropObjectsRequest dropRequest = new DropObjectsRequest();
+ // RequestUtils.setUseGUI(dropRequest, false);
+ // dropRequest.setObjects(Collections.singletonList(newElement));
+ // dropRequest.setLocation(new Point());
+
+ // DiagramExpansionsRegistry registry = new DiagramExpansionsRegistry();
+ // UseContext useContent = registry.getUsage(diagramType);
+ // ChildrenListRepresentation childrenListRepresentation = registry.mapChildreen.get(diagramType);
+ // List<String> childrenList = childrenListRepresentation.parentChildrenRelation.get(diagramType);
+
+ IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ PapyrusMultiDiagramEditor papyrusEditor = editorPart instanceof PapyrusMultiDiagramEditor ? (PapyrusMultiDiagramEditor) editorPart : null;
+ // DiagramEditPart diagramEditPart = multiDiagramEditor.getDiagramEditPart();
+ // diagramEditPart.getChildren();
+ DiagramEditPart diagramEditPart = (DiagramEditPart) papyrusEditor.getAdapter(DiagramEditPart.class);
+ // List<EditPart> childrenPart = diagramEditPart.getChildren();
+ // for (EditPart editPart : childrenPart) {
+ // GraphicalEditPart graphicalEditPart = editPart instanceof GraphicalEditPart ? (GraphicalEditPart) editPart : null;
+ // if (EcoreUtil.equals(containerView.getElement(), graphicalEditPart.getNotationView().getElement())) {
+ // Command command = graphicalEditPart.getCommand(dropRequest);
+ // editPart.getViewer().getEditDomain().getCommandStack().execute(command);
+ // }
+ // }
+ // if (EcoreUtil.equals(containerView.getElement(), diagramEditPart.getNotationView().getElement())) {
+ // Command command = diagramEditPart.getCommand(dropRequest);
+ // diagramEditPart.getViewer().getEditDomain().getCommandStack().execute(command);
+ // }
+
+
+
+ return null;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.classpath b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.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/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.project b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.project
new file mode 100644
index 00000000000..ebf256381bf
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.refactoring.qvtTransformation</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/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.settings/org.eclipse.jdt.core.prefs b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..3d20f96b316
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed Aug 25 14:15:47 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/META-INF/MANIFEST.MF b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..b6eca214b11
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.uml.refactoring.qvtTransformation;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-Activator: org.eclipse.papyrus.refactoring.qvttransformation.Activator
+Require-Bundle: org.eclipse.ui;bundle-version="3.107.0",
+ org.eclipse.core.runtime;bundle-version="3.11.0",
+ org.eclipse.core.resources;bundle-version="3.9.100",
+ org.eclipse.emf.ecore;bundle-version="2.11.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.8.0",
+ org.eclipse.m2m.qvt.oml;bundle-version="3.5.0",
+ org.eclipse.m2m.qvt.oml.runtime;bundle-version="3.5.0",
+ org.eclipse.m2m.qvt.oml.common;bundle-version="3.5.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.1.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.6.200",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.200",
+ org.eclipse.papyrus.refactoring;bundle-version="0.0.1"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-Vendor: %vendorName
+Bundle-Localization: plugin
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/about.html b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/about.html
new file mode 100644
index 00000000000..d35d5aed64c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/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/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/build.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/build.properties
new file mode 100644
index 00000000000..23d6cb6d05c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/,\
+ plugin.properties,\
+ about.html
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/refactor.png b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/refactor.png
new file mode 100644
index 00000000000..049da9f00bd
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/refactor.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/transformationIcon.gif b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/transformationIcon.gif
new file mode 100644
index 00000000000..2c1ceaf036e
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/icons/transformationIcon.gif
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.properties
new file mode 100644
index 00000000000..fd08ce804d8
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.properties
@@ -0,0 +1,16 @@
+# Copyright (c) 2015 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:
+# Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - initial API and implementation
+
+pluginName=Papyrus Refactoring QvtTransformation
+vendorName=Eclipse Modeling Project
+
+transformationContribution.label=QVT Transformation
+transformationContribution.tooltip=Execute a QVT transformation model selected from the workspace
+transformationCommand.name=QVT Transformation \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.xml
new file mode 100644
index 00000000000..aeaa42c8b8b
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/plugin.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.menus">
+ <!-- <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.refactoring.menu?after=org.eclipse.papyrus.refactoring.mutation">
+ <command
+ commandId="org.eclipse.papyrus.refactoring.qvtTransformation.command"
+ id="org.eclipse.papyrus.refactoring.qvtTransformation.command"
+ icon="icons/refactor.png"
+ label="%transformationContribution.label"
+ style="push"
+ tooltip="%transformationContribution.tooltip">
+ </command>
+ </menuContribution> -->
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.papyrus.refactoring.qvtTransformation.command"
+ name="%transformationCommand.name">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.refactoring.qvttransformation.handler.SelectQVTTransformationHandler"
+ commandId="org.eclipse.papyrus.refactoring.qvtTransformation.command">
+ </handler>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/pom.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/pom.xml
new file mode 100644
index 00000000000..86dc268f8dd
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/pom.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.eclipse.papyrus.uml.refactoring.qvtTransformation</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <groupId>org.eclipse.papyrus</groupId>
+ <packaging>eclipse-plugin</packaging>
+ <parent>
+ <relativePath>../../../releng/extra</relativePath>
+ <groupId>org.eclipse.papyrus</groupId>
+ <artifactId>org.eclipse.papyrus.extra.releng</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+</project>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/Activator.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/Activator.java
new file mode 100644
index 00000000000..52f17a2c028
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/Activator.java
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.qvttransformation;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.qvtTransformation"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ log = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/handler/SelectQVTTransformationHandler.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/handler/SelectQVTTransformationHandler.java
new file mode 100644
index 00000000000..bdc9026015d
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/handler/SelectQVTTransformationHandler.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.qvttransformation.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.papyrus.refactoring.core.PapyrusRefactoringOperation;
+import org.eclipse.papyrus.refactoring.qvttransformation.popup.actions.SelectQVTTransformation;
+
+/**
+ * handler linked to refactoring the dropdown menu for the QVTo transformation
+ *
+ */
+public class SelectQVTTransformationHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ PapyrusRefactoringOperation refactoringOperation = new PapyrusRefactoringOperation(new SelectQVTTransformation());
+ refactoringOperation.run();
+ return null;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/popup/actions/SelectQVTTransformation.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/popup/actions/SelectQVTTransformation.java
new file mode 100644
index 00000000000..0bf911ab6d8
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.qvtTransformation/src/org/eclipse/papyrus/refactoring/qvttransformation/popup/actions/SelectQVTTransformation.java
@@ -0,0 +1,171 @@
+/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.refactoring.qvttransformation.popup.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.m2m.internal.qvt.oml.common.MdaException;
+import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtInterpretedTransformation;
+import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation;
+import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation.TransformationParameter;
+import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation.TransformationParameter.DirectionKind;
+import org.eclipse.m2m.qvt.oml.BasicModelExtent;
+import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
+import org.eclipse.m2m.qvt.oml.ModelExtent;
+import org.eclipse.m2m.qvt.oml.TransformationExecutor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.refactoring.core.AbstractPapyrusTransformation;
+import org.eclipse.papyrus.refactoring.qvttransformation.Activator;
+import org.eclipse.papyrus.refactoring.util.PapyrusRefactoringUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.BaseWorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+/**
+ * This class implements a possible integration of QVTo transformation in Papyrus
+ *
+ */
+@SuppressWarnings("restriction")
+public class SelectQVTTransformation extends AbstractPapyrusTransformation {
+
+ private IFile fTransformationFile;
+ private TreeViewer fViewer;
+ private Composite selectionComposite;
+
+
+ public SelectQVTTransformation() {
+ super("QVT Transformation");
+ }
+
+
+ @Override
+ public RefactoringStatus checkFinalConditions() {
+ RefactoringStatus status = new RefactoringStatus();
+ if (((IStructuredSelection) fViewer.getSelection()).size() == 0) {
+ status.addFatalError("You have to select one \"qvto\" file.");
+ } else if (((IStructuredSelection) fViewer.getSelection()).size() > 1) {
+ status.addFatalError("You can not select several files.");
+ } else {
+ Object selectedElement = ((IStructuredSelection) fViewer.getSelection()).getFirstElement();
+ if (selectedElement instanceof IFile) {
+ fTransformationFile = (IFile) selectedElement;
+ if (!fTransformationFile.getFileExtension().contains("qvt")) {
+ status.addFatalError("You have to select a \"qvto\" file.");
+ }
+ }
+ }
+
+ return status;
+ }
+
+
+ @Override
+ public void execute(ModelSet modelSetToTransform) {
+
+ // Reification of the transformation
+ QvtTransformation transfo = new QvtInterpretedTransformation(fTransformationFile);
+ // Retrieve transformation's parameters
+ List<TransformationParameter> params;
+ try {
+ params = transfo.getParameters();
+
+ // The transformation must have only one parameter.
+ if (params.size() == 1) {
+ // Retrieve first parameter's metamodels
+ List<EPackage> metamodels = params.get(0).getMetamodels();
+
+ // The parameter must be INOUT and it only have UML as metamodel
+ if (params.get(0).getDirectionKind() == DirectionKind.INOUT && metamodels.size() == 1 && metamodels.get(0).getNsPrefix().compareToIgnoreCase("uml") == 0) {
+
+ // Define the command in Papyrus' editing domain
+
+ URI uri = URI.createPlatformResourceURI(fTransformationFile.getFullPath().toString(), true);
+
+ // Create a executor for the transformation
+ TransformationExecutor executor = new TransformationExecutor(uri);
+
+ // Define the input as the model that contains the selected diagramEditPart
+ List<EObject> contents = new ArrayList<EObject>();
+
+ if (PapyrusRefactoringUtils.getSelectedElements(modelSetToTransform).size() == 0) {
+ contents.add(PapyrusRefactoringUtils.getUMLRoot(modelSetToTransform));
+ } else {
+ contents.addAll(PapyrusRefactoringUtils.getSelectedElements(modelSetToTransform));
+ }
+
+
+ ModelExtent input = new BasicModelExtent(contents);
+ // ModelExtent output = new BasicModelExtent();
+
+ ExecutionContextImpl context = new ExecutionContextImpl();
+ // Execute the transformation
+
+ // ExecutionDiagnostic diagnostic = executor.execute(context, input);
+ executor.execute(context, input);
+
+ }
+ }
+ } catch (MdaException e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+
+ @Override
+ public void createControl(Composite parent) {
+
+ selectionComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 1;
+
+ selectionComposite.setLayout(layout);
+ selectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ setControl(selectionComposite);
+
+ fViewer = new TreeViewer(selectionComposite, SWT.FILL);
+ fViewer.setContentProvider(new BaseWorkbenchContentProvider());
+ fViewer.setLabelProvider(new WorkbenchLabelProvider());
+ fViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ Tree treeWidget = fViewer.getTree();
+ treeWidget.setLayoutData(data);
+ treeWidget.setFont(parent.getFont());
+ }
+
+ @Override
+ public void performHelp() {
+ // TODO Write the help
+ // http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_help_contexts.html
+ PlatformUI.getWorkbench().getHelpSystem().displayHelp("help context id");
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.classpath b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.classpath
new file mode 100644
index 00000000000..098194ca4b7
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.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/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.project b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.project
new file mode 100644
index 00000000000..f1a1f592967
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.refactoring.replace</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/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.settings/org.eclipse.jdt.core.prefs b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f42de363afa
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/META-INF/MANIFEST.MF b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..8794cc69ebc
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.uml.refactoring.replace;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-Activator: org.eclipse.papyrus.uml.refactoring.replace.Activator
+Require-Bundle: org.eclipse.ui;bundle-version="3.107.0",
+ org.eclipse.core.runtime;bundle-version="3.11.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.6.200",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.200",
+ org.eclipse.papyrus.uml.search.ui;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.1.0",
+ org.eclipse.papyrus.refactoring;bundle-version="0.0.1",
+ org.eclipse.uml2.uml;bundle-version="5.1.0",
+ org.eclipse.help;bundle-version="3.6.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %vendorName
+Bundle-Localization: plugin
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/about.html b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/about.html
new file mode 100644
index 00000000000..d35d5aed64c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/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/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/build.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/build.properties
new file mode 100644
index 00000000000..2dfc6eae828
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.properties,\
+ plugin.xml,\
+ icons/,\
+ about.html
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/images/replace.png b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/images/replace.png
new file mode 100644
index 00000000000..7ebcbfc693b
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/images/replace.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace-toc.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace-toc.xml
new file mode 100644
index 00000000000..26a1b8a5033
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace-toc.xml
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<toc label="Replace" link_to="../org.eclipse.papyrus.refactoring/doc/refactoring_user_guide.xml#refactoring_list" topic="doc/replace.html">
+ <topic href="doc/replace.html" label="Replace">
+ </topic>
+
+</toc>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.html b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.html
new file mode 100644
index 00000000000..6c2ce2758ea
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.html
@@ -0,0 +1,12 @@
+<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>
+<body>
+ <h1 id="Replace">Replace</h1>
+ <p>The replace refactoring permits to replace all occurrences of a string by another string.</p>
+ <p>The following image illustrates the Replace refactoring dialog.</p><p><img border="0" src="images/replace.png"/></p>
+ <ul>
+ <li>In the A area the user indicates the string to be replaced and the new string which should replace the old.</li>
+ <li>In the B area the user indicates if the refactoring should consider the case when it finds the old string. </li>
+ <li>In the C area the user indicates if the wants to replace only name or all strings.</li>
+ </ul>
+</body>
+</html> \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.mediawiki b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.mediawiki
new file mode 100644
index 00000000000..41f333f5ef5
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/doc/replace.mediawiki
@@ -0,0 +1,11 @@
+=Replace=
+
+The replace refactoring permits to replace all occurrences of a string by another string.
+
+The following image illustrates the Replace refactoring dialog.
+
+[[image:images/replace.png]]
+
+* In the A area the user indicates the string to be replaced and the new string which should replace the old.
+* In the B area the user indicates if the refactoring should consider the case when it finds the old string.
+* In the C area the user indicates if the wants to replace only name or all strings. \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/icons/refactor.png b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/icons/refactor.png
new file mode 100644
index 00000000000..049da9f00bd
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/icons/refactor.png
Binary files differ
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.properties
new file mode 100644
index 00000000000..9e0e186c950
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.properties
@@ -0,0 +1,16 @@
+# Copyright (c) 2015 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:
+# Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - initial API and implementation
+
+pluginName=Papyrus Refactoring Replace
+vendorName=Eclipse Modeling Project
+
+replaceContribution.label=Replace
+replaceContribution.tooltip=Replace the specified Strings in the model
+replaceCommand.name=ReplaceCommand \ No newline at end of file
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.xml
new file mode 100644
index 00000000000..1506692da9c
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/plugin.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.refactoring.menu?after=additions">
+ <command
+ commandId="org.eclipse.papyrus.refactoring.replace.command"
+ id="org.eclipse.papyrus.refactoring.replace.command"
+ icon="icons/refactor.png"
+ label="%replaceContribution.label"
+ style="push"
+ tooltip="%replaceContribution.tooltip">
+ </command>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.papyrus.refactoring.replace.command"
+ name="%replaceCommand.name">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.uml.refactoring.replace.handler.ReplaceHandler"
+ commandId="org.eclipse.papyrus.refactoring.replace.command">
+ </handler>
+ </extension>
+
+ <extension
+ point="org.eclipse.help.toc">
+ <toc
+ file="doc/replace-toc.xml"
+ primary="false">
+ </toc>
+ </extension>
+
+</plugin>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/pom.xml b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/pom.xml
new file mode 100644
index 00000000000..fb7e1200c48
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.eclipse.papyrus.uml.refactoring.replace</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <groupId>org.eclipse.papyrus</groupId>
+ <packaging>eclipse-plugin</packaging>
+ <parent>
+ <relativePath>../../../releng/extra</relativePath>
+ <groupId>org.eclipse.papyrus</groupId>
+ <artifactId>org.eclipse.papyrus.extra.releng</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.mylyn.docs</groupId>
+ <artifactId>org.eclipse.mylyn.wikitext.core.maven</artifactId>
+ <configuration>
+ <sourceFolder>doc</sourceFolder>
+ <outputFolder>${project.build.directory}/site/generated-eclipse-help</outputFolder>
+ <!-- copyrightNotice>${help.copyrightNotice}</copyrightNotice>
+ <title>${help.documentTitle}</title-->
+ <multipleOutputFiles>false</multipleOutputFiles>
+ <navigationImages>true</navigationImages>
+ <formatOutput>true</formatOutput>
+ <htmlFilenameFormat>$1.html</htmlFilenameFormat>
+ <xmlFilenameFormat>$1-toc.xml</xmlFilenameFormat>
+ <helpPrefix>target/site/generated-eclipse-help</helpPrefix>
+ <!-- stylesheetUrls>
+ <param>styles/main.css</param>
+ </stylesheetUrls-->
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>eclipse-help</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.mylyn.docs</groupId>
+ <artifactId>org.eclipse.mylyn.wikitext.mediawiki.core</artifactId>
+ <version>${mylyn.wikitext.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/Activator.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/Activator.java
new file mode 100644
index 00000000000..b87cce6e1a1
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/Activator.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.replace;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.refactoring.replace"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ 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;
+ }
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/handler/ReplaceHandler.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/handler/ReplaceHandler.java
new file mode 100644
index 00000000000..7db4300bb3f
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/handler/ReplaceHandler.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.replace.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.papyrus.refactoring.core.PapyrusRefactoringOperation;
+import org.eclipse.papyrus.uml.refactoring.replace.ui.ReplaceRefactoring;
+
+/**
+ * Replace handler linked to the dropdown menu
+ *
+ */
+public class ReplaceHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ReplaceRefactoring replaceRefactoring = new ReplaceRefactoring();
+ PapyrusRefactoringOperation operation = new PapyrusRefactoringOperation(replaceRefactoring);
+ operation.run();
+ return null;
+ }
+
+
+
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/Messages.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/Messages.java
new file mode 100644
index 00000000000..77fa1c877de
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/Messages.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.replace.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.refactoring.replace.messages.messages"; //$NON-NLS-1$
+
+ public static String REPLACEREFACTORING_PAGELABEL;
+ public static String REPLACEREFACTORING_INITALTEXT;
+ public static String REPLACEREFACTORING_NEWTEXT;
+ public static String REPLACEREFACTORING_INITIALTEXT_LABEL;
+ public static String REPLACEREFACTORING_CASE;
+ public static String REPLACEREFACTORING_NEWTEXT_LABEL;
+ public static String REPLACEREFACTORING_NAMESCOPE;
+ public static String REPLACEREFACTORING_MODELSCOPE;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/messages.properties b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/messages.properties
new file mode 100644
index 00000000000..b6d630c642f
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/messages/messages.properties
@@ -0,0 +1,8 @@
+REPLACEREFACTORING_PAGELABEL=Replace
+REPLACEREFACTORING_INITALTEXT=Please indicate the original value which should be replaced.
+REPLACEREFACTORING_NEWTEXT=Please indicate the new value which should replace the original.
+REPLACEREFACTORING_INITIALTEXT_LABEL=&Replace:
+REPLACEREFACTORING_CASE=Case sensitive
+REPLACEREFACTORING_NEWTEXT_LABEL=&With:
+REPLACEREFACTORING_NAMESCOPE=&Replace only name
+REPLACEREFACTORING_MODELSCOPE=&Replace all strings
diff --git a/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/ui/ReplaceRefactoring.java b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/ui/ReplaceRefactoring.java
new file mode 100644
index 00000000000..7f4e8fd550b
--- /dev/null
+++ b/extraplugins/refactoring/org.eclipse.papyrus.uml.refactoring.replace/src/org/eclipse/papyrus/uml/refactoring/replace/ui/ReplaceRefactoring.java
@@ -0,0 +1,202 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.refactoring.replace.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.refactoring.helper.AbstractChoiceOnUIParticipantsTransformation;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.ITransformationOnElement;
+import org.eclipse.papyrus.refactoring.refactoringOnElement.ReplaceTransformationOnElement;
+import org.eclipse.papyrus.uml.refactoring.replace.messages.Messages;
+import org.eclipse.papyrus.uml.search.ui.query.PapyrusQuery;
+import org.eclipse.papyrus.views.search.scope.ScopeEntry;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ * Refactoring Participant defining the Replace dialog and specifying the methods to call for a replace action
+ *
+ */
+public class ReplaceRefactoring extends AbstractChoiceOnUIParticipantsTransformation {
+
+ /** The field where the user indicates the new string. */
+ private Text fNewValueText;
+
+ /** The field where the user indicates the string to replace. */
+ private Text fOldValueText;
+
+ /** A button to know if the string indicated by the user is case sensitive. */
+ private Button fBtnCaseSensitive;
+
+ /** A button to indicate if we have to replace all strings. */
+ private Button fReplaceAllStringAttributes;
+
+ /** A button to indicate if we have to replace only the name. */
+ private Button fReplaceNameAttribute;
+
+
+ /**
+ * Constructor.
+ *
+ */
+ public ReplaceRefactoring() {
+ super(Messages.REPLACEREFACTORING_PAGELABEL);
+ // super(Messages.ReplaceRefactoring_8);
+ }
+
+ /**
+ * Create a {@link Text} in a composite.
+ *
+ * @param result
+ * The composite where we have to create the {@link Text}.
+ * @return
+ * The {@link Text} created.
+ */
+ private Text createNameField(Composite result) {
+ Text field = new Text(result, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
+ field.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ return field;
+ }
+
+
+
+ @Override
+ public RefactoringStatus checkFinalConditions() {
+ RefactoringStatus status = new RefactoringStatus();
+ if (fOldValueText.getText().isEmpty()) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(Messages.REPLACEREFACTORING_INITALTEXT));
+ } else if (fNewValueText.getText().isEmpty()) {
+ status.merge(RefactoringStatus.createFatalErrorStatus(Messages.REPLACEREFACTORING_NEWTEXT));
+
+ }
+ return status;
+ }
+
+
+ @Override
+ public void createContent(Composite parent) {
+
+ GridLayout layout = new GridLayout();
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 3;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.REPLACEREFACTORING_INITIALTEXT_LABEL);
+ fOldValueText = createNameField(composite);
+ fOldValueText.setFocus();
+
+ fBtnCaseSensitive = new Button(composite, SWT.CHECK);
+ fBtnCaseSensitive.setText(Messages.REPLACEREFACTORING_CASE);
+
+ label = new Label(composite, SWT.NONE);
+ label.setText(Messages.REPLACEREFACTORING_NEWTEXT_LABEL);
+
+ fNewValueText = createNameField(composite);
+
+ GridData data = new GridData();
+ data.horizontalAlignment = SWT.END;
+
+
+ fReplaceNameAttribute = new Button(parent, SWT.RADIO);
+ fReplaceNameAttribute.setText(Messages.REPLACEREFACTORING_NAMESCOPE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 3;
+ data.verticalIndent = 15;
+ fReplaceNameAttribute.setLayoutData(data);
+ fReplaceNameAttribute.setSelection(true);
+
+ fReplaceAllStringAttributes = new Button(parent, SWT.RADIO);
+ fReplaceAllStringAttributes.setText(Messages.REPLACEREFACTORING_MODELSCOPE);
+ GridData data2 = new GridData(GridData.FILL_HORIZONTAL);
+
+
+ data2.horizontalSpan = 3;
+ fReplaceAllStringAttributes.setLayoutData(data2);
+
+ }
+
+
+ @Override
+ public ITransformationOnElement getTransformationOnElement() {
+
+ Collection<ScopeEntry> scpEntry = new ArrayList<>();
+ scpEntry.add(createScopeEntry());
+ PapyrusQuery query = new PapyrusQuery(fOldValueText.getText(), fBtnCaseSensitive.getSelection(), false, scpEntry, getMetaClassesList(), fReplaceAllStringAttributes.getSelection());
+ query.run(new NullProgressMonitor());
+ return new ReplaceTransformationOnElement(query.getResults(), query, fNewValueText.getText());
+ }
+
+ /**
+ * Retrieves all the metaclasses of the UMLPackage in order to parse the model during the search query
+ *
+ * @return
+ * The list containing the metaclasses
+ */
+ private Object[] getMetaClassesList() {
+ Set<EClassifier> umlMetaClasses = new HashSet<>();
+ for (EClassifier eClassifier : UMLPackage.eINSTANCE.getEClassifiers()) {
+ if (eClassifier instanceof EClass) {
+ umlMetaClasses.add(eClassifier);
+ }
+ }
+ return umlMetaClasses.toArray();
+ }
+
+ /**
+ * Sets the entry, i.e. the scope of the query, as the selected element's model
+ *
+ * @return
+ */
+ private ScopeEntry createScopeEntry() {
+ // Resource diResource = DiModelUtils.getDiResource(fModelSet);
+ Resource diResource = ((DiModel) fModelSet.getModel(DiModel.DI_MODEL_ID)).getResource();
+ return new ScopeEntry(diResource.getURI());
+ }
+
+
+ @Override
+ public String getName() {
+ return Messages.REPLACEREFACTORING_PAGELABEL;
+ }
+
+ @Override
+ public void performHelp() {
+ // TODO Write the help
+ // http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_help_contexts.html
+ PlatformUI.getWorkbench().getHelpSystem().displayHelp("help context id");
+ }
+
+}
+
+

Back to the top