Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2012-10-16 11:53:05 +0000
committertarendt2012-10-16 11:53:05 +0000
commitad3c0f210ddf0c8520bf42193fabb04055a26317 (patch)
treee6db6eec3199d9f88bd04ef259752d73d225b7e1 /org.eclipse.emf.refactor.refactoring.generator
parentee91ec7a4871151713b3642b549f11fa3bc0e469 (diff)
downloadorg.eclipse.emf.refactor.refactoring-ad3c0f210ddf0c8520bf42193fabb04055a26317.tar.gz
org.eclipse.emf.refactor.refactoring-ad3c0f210ddf0c8520bf42193fabb04055a26317.tar.xz
org.eclipse.emf.refactor.refactoring-ad3c0f210ddf0c8520bf42193fabb04055a26317.zip
initial commit
Diffstat (limited to 'org.eclipse.emf.refactor.refactoring.generator')
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/.classpath7
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/.project28
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF20
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/build.properties9
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/icons/refactoring.pngbin0 -> 629 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/plugin.xml15
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/generator/action/RefactoringGeneratorAction.java77
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/Activator.java61
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/ParameterInfo.java67
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/RefactoringInfo.java358
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/interfaces/INewRefactoringWizard.java5
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/DependenciesManager.java71
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java414
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java236
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/BasicDataWizardPage.java393
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java116
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/ParameterWizardPage.java266
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/TestWizardPage.java118
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/Config.javajet12
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringController.javajet188
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringDataManagement.javajet62
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringGuiHandler.javajet77
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringTest.javajet102
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizard.javajet43
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizardPage.javajet124
26 files changed, 2877 insertions, 0 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.generator/.classpath b/org.eclipse.emf.refactor.refactoring.generator/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/.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/org.eclipse.emf.refactor.refactoring.generator/.project b/org.eclipse.emf.refactor.refactoring.generator/.project
new file mode 100644
index 0000000..cd490de
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.refactor.refactoring.generator</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/org.eclipse.emf.refactor.refactoring.generator/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.refactor.refactoring.generator/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7ad133d
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Mon Jun 28 16:21:39 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/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..13f39ce
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: RefactoringGenerator
+Bundle-SymbolicName: org.eclipse.emf.refactor.refactoring.generator;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-Activator: org.eclipse.emf.refactor.refactoring.generator.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.6.0",
+ org.eclipse.jdt.core;bundle-version="3.6.0",
+ org.eclipse.emf.ecore;bundle-version="2.6.0",
+ org.eclipse.emf.codegen;bundle-version="2.6.0",
+ org.eclipse.emf.refactor.refactoring;bundle-version="0.7.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.eclipse.emf.refactor.refactoring.generator.core,
+ org.eclipse.emf.refactor.refactoring.generator.interfaces,
+ org.eclipse.emf.refactor.refactoring.generator.managers,
+ org.eclipse.emf.refactor.refactoring.generator.ui
+Import-Package: org.eclipse.ui.actions
diff --git a/org.eclipse.emf.refactor.refactoring.generator/build.properties b/org.eclipse.emf.refactor.refactoring.generator/build.properties
new file mode 100644
index 0000000..3042165
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ templates/,\
+ bin/,\
+ icons/,\
+ src/
diff --git a/org.eclipse.emf.refactor.refactoring.generator/icons/refactoring.png b/org.eclipse.emf.refactor.refactoring.generator/icons/refactoring.png
new file mode 100644
index 0000000..011556a
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/icons/refactoring.png
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.generator/plugin.xml b/org.eclipse.emf.refactor.refactoring.generator/plugin.xml
new file mode 100644
index 0000000..aaf8e34
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/plugin.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <wizard
+ category="org.eclipse.emf.refactor.newwizards.category"
+ class="org.eclipse.emf.refactor.refactoring.generator.ui.NewRefactoringWizardJava"
+ icon="icons/refactoring.png"
+ id="org.eclipse.emf.refactor.refactoring.newwizard"
+ name="Refactoring (specified in Java)">
+ </wizard>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/generator/action/RefactoringGeneratorAction.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/generator/action/RefactoringGeneratorAction.java
new file mode 100644
index 0000000..3e2992d
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/generator/action/RefactoringGeneratorAction.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.generator.action;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.refactoring.generator.ui.NewRefactoringWizardJava;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Class for triggering the model refactoring generation process.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class RefactoringGeneratorAction implements IObjectActionDelegate {
+
+ /**
+ * Selected elements on the active part.
+ */
+ private ISelection selection;
+
+ /**
+ * Active part of the workbench.
+ */
+ private IWorkbenchPart targetPart;
+
+ /**
+ * Default constructor.
+ */
+ public RefactoringGeneratorAction() {}
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run
+ * (org.eclipse.jface.action.IAction)
+ */
+ @Override
+ public void run(IAction action) {
+ StructuredSelection ss = (StructuredSelection) selection;
+ EObject selectedEObject = (EObject) ss.getFirstElement();
+ Shell shell = targetPart.getSite().getShell();
+ WizardDialog wizard = new WizardDialog
+ (shell, new NewRefactoringWizardJava(selectedEObject));
+ wizard.open();
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged
+ * (org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.selection = selection;
+ }
+
+ /**
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart
+ * (org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+ */
+ @Override
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ this.targetPart = targetPart;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/Activator.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/Activator.java
new file mode 100644
index 0000000..f84461e
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/Activator.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Activator class of the org.eclipse.emf.refactor.generator plugin.
+ * @generated
+ */
+public class Activator extends AbstractUIPlugin {
+
+ /**
+ * @generated
+ */
+ public static final String PLUGIN_ID = "org.eclipse.emf.refactor.generator";
+
+ /**
+ * @generated
+ */
+ private static Activator plugin;
+
+ /**
+ * @generated
+ */
+ public Activator() {
+ }
+
+ /**
+ * @generated
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /**
+ * @generated
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * @generated
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/ParameterInfo.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/ParameterInfo.java
new file mode 100644
index 0000000..4559dd2
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/ParameterInfo.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.core;
+
+/**
+ * Class for a model refactoring parameter configuration including a name
+ * and a description.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class ParameterInfo {
+
+ /**
+ * Name of the model refactoring parameter.
+ */
+ private String name;
+
+ /**
+ * Description of the model refactoring parameter.
+ */
+ private String description;
+
+ /**
+ * Default constructor.
+ * @param name Name of the model refactoring parameter.
+ */
+ public ParameterInfo(String name){
+ this.name = name;
+ }
+
+ /**
+ * Gets the description of the model refactoring parameter.
+ * @return Description of the model refactoring parameter.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the model refactoring parameter.
+ * @param description Description of the model refactoring parameter.
+ */
+ public void setDescription(String description) {
+ if (null == description || description.isEmpty()){
+ this.description = "Value of parameter '" + this.name + "'";
+ } else {
+ this.description = description;
+ }
+ }
+
+ /**
+ * Gets the name of the model refactoring parameter.
+ * @return Name of the model refactoring parameter.
+ */
+ public String getName() {
+ return name;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/RefactoringInfo.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/RefactoringInfo.java
new file mode 100644
index 0000000..fa78e5e
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/core/RefactoringInfo.java
@@ -0,0 +1,358 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Class for a model refactoring configuration used to generate code from.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class RefactoringInfo {
+
+ /**
+ * Name of the project the model refactoring code has to be generated to.
+ */
+ protected String projectName;
+
+ /**
+ * Id of the model refactoring that has to be generated.
+ */
+ private String refactoringId;
+
+ /**
+ * The label that shall appear before applying the model refactoring.
+ */
+ private String menuLabel;
+
+ /**
+ * Namespace of the models the model refactoring has to be generated for.
+ */
+ private String namespaceUri;
+
+ /**
+ * Class of the model element that will be the selected EObject when
+ * applying the refactoring (context). Used in JET templates.
+ */
+ private String selectedEObjectClass;
+
+ /**
+ * Jar file owning the class specified in 'selectedEObjectClass'.
+ */
+ private String selectedEObjectJar;
+
+ /**
+ * Name of the Controller class of the model refactoring specified in
+ * the extension point (default value: "RefactoringController").
+ */
+ private String controller;
+
+ /**
+ * Name of the GuiHandler class of the model refactoring specified in
+ * the extension point (default value: "RefactoringGuiHandler").
+ */
+ private String guiHandler;
+
+ /**
+ * List of parameters of the model refactoring to be generated.
+ */
+ private List<ParameterInfo> parameters;
+
+ /**
+ * Name of the package the model refactoring code has to be
+ * generated into.
+ */
+ private String packageName;
+
+ /**
+ * Namespace prefix of the models the model refactoring has to be generated for.
+ */
+ private String namespacePrefix;
+
+ /**
+ * Name of the meta model the model refactoring has to be generated for.
+ */
+ private String metaModelName;
+
+ /**
+ * Number of tests to be generated for the model refactoring.
+ */
+ private int numberOfTests;
+
+ /**
+ * Default constructor (private).
+ */
+ public RefactoringInfo(){
+ this.controller = "RefactoringController";
+ this.guiHandler = "RefactoringGuiHandler";
+ this.parameters = new ArrayList<ParameterInfo>();
+ }
+
+ /**
+ * Constructor used for existing model refactorings.
+ * @param controller Controller class of the model refactoring
+ * specified in the extension point.
+ * @param guiHandler GuiHandler class of the model refactoring
+ * specified in the extension point.
+ * @param refactoringId Id of the model refactoring specified
+ * in the extension point.
+ * @param menuLabel Menu label of the model refactoring
+ * specified in the extension point.
+ * @param namespaceURI Namespace of the model refactoring
+ * specified in the extension point.
+ */
+ public RefactoringInfo(String controller, String guiHandler,
+ String refactoringId, String menuLabel, String namespaceURI) {
+ this();
+ this.controller = controller;
+ this.guiHandler = guiHandler;
+ this.refactoringId = refactoringId;
+ this.menuLabel = menuLabel;
+ this.namespaceUri = namespaceURI;
+ }
+
+ /**
+ * Constructor used for the new model refactoring to be generated.
+ * @param projectName Name of the project the model refactoring code
+ * has to be generated to.
+ * @param refactoringId Id of the model refactoring that has to be
+ * generated.
+ * @param menuLabel The label that shall appear before applying the
+ * model refactoring.
+ * @param namespaceURI Namespace of the models the model refactoring
+ * has to be generated for.
+ * @param namespacePrefix
+ * @param numberOfTests
+ */
+ public RefactoringInfo(String projectName, String refactoringId,
+ String menuLabel, String namespaceURI,
+ String namespacePrefix, int numberOfTests) {
+ this();
+ this.projectName = projectName;
+ this.refactoringId = refactoringId;
+ this.menuLabel = menuLabel;
+ this.namespaceUri = namespaceURI;
+ this.packageName = projectName.toLowerCase().replaceAll(" ", "_")
+ + "." + refactoringId.toLowerCase();
+ this.namespacePrefix = namespacePrefix;
+ this.numberOfTests = numberOfTests;
+ }
+
+ /**
+ * Constructor used for the new model refactoring to be generated.
+ * @param projectName Name of the project the model refactoring code
+ * has to be generated to.
+ * @param refactoringId Id of the model refactoring that has to be
+ * generated.
+ * @param menuLabel The label that shall appear before applying the
+ * model refactoring.
+ * @param namespaceURI Namespace of the models the model refactoring
+ * has to be generated for.
+ * @param namespacePrefix
+ * @param numberOfTests
+ */
+ public RefactoringInfo(String projectName, String refactoringId,
+ String menuLabel, String namespaceURI) {
+ this();
+ this.projectName = projectName;
+ this.refactoringId = refactoringId;
+ this.menuLabel = menuLabel;
+ this.namespaceUri = namespaceURI;
+ this.packageName = projectName.toLowerCase().replaceAll(" ", "_")
+ + "." + refactoringId.toLowerCase();
+ }
+
+ /**
+ * Sets the list of parameters of the model refactoring to be
+ * generated.
+ * @param params List of parameters of the model refactoring to be
+ * generated.
+ */
+ public void setParameters(List<ParameterInfo> params){
+ this.parameters = params;
+ }
+
+ /**
+ * Gets the list of parameters of the model refactoring to be
+ * generated.
+ * @return List of parameters of the model refactoring to be
+ * generated.
+ */
+ public List<ParameterInfo> getParameters() {
+ return parameters;
+ }
+
+ /**
+ * Gets the name of the project the model refactoring code
+ * has to be generated to.
+ * @return Name of the project the model refactoring code
+ * has to be generated to.
+ */
+ public String getProjectName() {
+ return projectName;
+ }
+
+ /**
+ * Gets the id of the model refactoring that has to be
+ * generated.
+ * @return Id of the model refactoring that has to be
+ * generated.
+ */
+ public String getRefactoringId() {
+ return refactoringId;
+ }
+
+ /**
+ * Gets the label that shall appear before applying the
+ * model refactoring.
+ * @return Label that shall appear before applying the
+ * model refactoring.
+ */
+ public String getMenuLabel() {
+ return menuLabel;
+ }
+
+ /**
+ * Gets the namespace of the models the model refactoring
+ * has to be generated for.
+ * @return Namespace of the models the model refactoring
+ * has to be generated for.
+ */
+ public String getNamespaceUri() {
+ return namespaceUri;
+ }
+
+ /**
+ * Sets the class of the model element that will be the
+ * selected EObject when applying the refactoring (context).
+ * @param selectedEObjectClass Class of the model element
+ * that will be the selected EObject when applying the
+ * refactoring (context).
+ */
+ public void setSelectedEObjectClass(String selectedEObjectClass) {
+ this.selectedEObjectClass = selectedEObjectClass;
+ }
+
+ /**
+ * Gets the class of the model element that will be the
+ * selected EObject when applying the refactoring (context).
+ * @return Class of the model element that will be the selected
+ * EObject when applying the refactoring (context).
+ */
+ public String getSelectedEObjectClass() {
+ return selectedEObjectClass;
+ }
+
+ /**
+ * Gets the jar file owning the class specified in
+ * 'selectedEObjectClass'.
+ * @return Jar file owning the class specified in
+ * 'selectedEObjectClass'.
+ */
+ public String getJar() {
+ return selectedEObjectJar;
+ }
+
+ /**
+ * Sets the jar file owning the class specified in
+ * 'selectedEObjectClass'.
+ * @param selectedEObjectJar Jar file owning the class specified in
+ * 'selectedEObjectClass'.
+ */
+ public void setSelectedEObjectJar(String selectedEObjectJar) {
+ this.selectedEObjectJar = selectedEObjectJar;
+ }
+
+ /**
+ * Gets the name of the GuiHandler class of the model refactoring
+ * specified in the extension point.
+ * @return Name of the GuiHandler class of the model refactoring
+ * specified in the extension point.
+ */
+ public String getGuiHandler() {
+ return guiHandler;
+ }
+
+ /**
+ * Gets the name of the Controller class of the model refactoring
+ * specified in the extension point.
+ * @return Name of the Controller class of the model refactoring
+ * specified in the extension point.
+ */
+ public String getController(){
+ return this.controller;
+ }
+
+ /**
+ * Gets the name of the package the model refactoring code
+ * has to be generated into.
+ * @return Name of the package the model refactoring code
+ * has to be generated into.
+ */
+ public String getPackageName(){
+ return packageName;
+ }
+
+ /**
+ * Gets the namespace prefix of the models the model
+ * refactoring has to be generated for.
+ * @return Namespace prefix of the models the model
+ * refactoring has to be generated for.
+ */
+ public String getNamespacePrefix() {
+ return namespacePrefix;
+ }
+
+ /**
+ * Gets the name of the meta model the model refactoring
+ * has to be generated for.
+ * @return Name of the meta model the model refactoring
+ * has to be generated for.
+ */
+ public String getMetaModelName() {
+ return metaModelName;
+ }
+
+ /**
+ * Sets the name of the meta model the model refactoring
+ * has to be generated for.
+ * @param metaModelName Name of the meta model the model refactoring
+ * has to be generated for.
+ */
+ public void setMetaModelName(String metaModelName) {
+ this.metaModelName = buildMetaModelName(metaModelName);
+ }
+
+ /**
+ * Builds the correctly capitalized meta model name from the given
+ * lower case meta model name.
+ * @param metaModelName Name of the meta model the model refactoring
+ * has to be generated for.
+ * @return Correctly capitalized name of the meta model the model
+ * refactoring has to be generated for.
+ */
+ private String buildMetaModelName(String metaModelName) {
+ String result = metaModelName
+ .substring(metaModelName.lastIndexOf('.'));
+ result = result.substring(1, result.lastIndexOf("PackageImpl"));
+ return result;
+ }
+
+ /**
+ * Gets the numbers of tests to be generated for the model refactoring.
+ * @return Number of tests to be generated for the model refactoring
+ */
+ public int getNumberOfTests(){
+ return numberOfTests;
+ }
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/interfaces/INewRefactoringWizard.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/interfaces/INewRefactoringWizard.java
new file mode 100644
index 0000000..1a22b86
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/interfaces/INewRefactoringWizard.java
@@ -0,0 +1,5 @@
+package org.eclipse.emf.refactor.refactoring.generator.interfaces;
+
+public interface INewRefactoringWizard {
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/DependenciesManager.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/DependenciesManager.java
new file mode 100644
index 0000000..32197f1
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/DependenciesManager.java
@@ -0,0 +1,71 @@
+package org.eclipse.emf.refactor.refactoring.generator.managers;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+
+public class DependenciesManager {
+
+ protected final static String MANIFEST_FILE = "/META-INF/MANIFEST.MF";
+ protected final static String REQUIREBUNDLE = "Require-Bundle";
+ protected final static String ECORE = "org.eclipse.emf.ecore";
+ protected final static String EXPRESSIONS = "org.eclipse.core.expressions";
+ protected final static String ECORECHANGE = "org.eclipse.emf.ecore.change";
+ protected final static String LTKCORE = "org.eclipse.ltk.core.refactoring";
+ protected final static String LTKUI = "org.eclipse.ltk.ui.refactoring";
+ protected final static String REFACTORCOMMON = "org.eclipse.emf.refactor.refactoring";
+ protected final static String REFACTORRUNTIME = "org.eclipse.emf.refactor.refactoring.runtime";
+ protected final static String JUNIT = "org.junit";
+
+ /**
+ * Updates the plugin-dependencies (Require-Bundle) of the
+ * target project. Adds dependencies to org.eclipse.emf.ecore,
+ * org.eclipse.emf.ecore.change, org.eclipse.ltk.core.refactoring,
+ * org.eclipse.ltk.ui.refactoring, org.eclipse.emf.refactor.common,
+ * and org.eclipse.emf.refactor.runtime
+ */
+ public static void updateDependencies(RefactoringInfo info) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(info.getProjectName());
+ try {
+ String fileName = project.getLocation().append(MANIFEST_FILE)
+ .toOSString();
+ FileInputStream is = new FileInputStream(fileName);
+ Manifest mf = new Manifest(is);
+ Attributes att = mf.getMainAttributes();
+ String value = att.getValue(REQUIREBUNDLE);
+ if (! value.contains(EXPRESSIONS))
+ value = value + "," + EXPRESSIONS;
+ if (! value.contains(ECORE))
+ value = value + "," + ECORE;
+ if (! value.contains(ECORECHANGE))
+ value = value + "," + ECORECHANGE;
+ if (! value.contains(LTKCORE))
+ value = value + "," + LTKCORE;
+ if (! value.contains(LTKUI))
+ value = value + "," + LTKUI;
+ if (! value.contains(REFACTORCOMMON))
+ value = value + "," + REFACTORCOMMON;
+ if (! value.contains(REFACTORRUNTIME))
+ value = value + "," + REFACTORRUNTIME;
+ if (! value.contains(JUNIT))
+ value = value + "," + JUNIT + ";bundle-version=\"4.8.1\"";
+ if (! value.contains(info.getJar()))
+ value = value + "," + info.getJar();
+ att.putValue(REQUIREBUNDLE, value);
+ FileOutputStream out = new FileOutputStream(fileName);
+ mf.write(out);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java
new file mode 100644
index 0000000..b3b555b
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java
@@ -0,0 +1,414 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.managers;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.emf.codegen.jet.JETEmitter;
+import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.emf.codegen.util.CodeGenUtil;
+import org.eclipse.emf.refactor.refactoring.generator.Activator;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.osgi.framework.Bundle;
+
+/**
+ * Main class for generating model refactoring code out of an object of class
+ * RefactoringConfig using JET.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+/**
+ * @author arendt
+ *
+ */
+/**
+ * @author arendt
+ *
+ */
+public class GeneratioManager {
+
+ /**
+ * Full qualified name of the template directory inside the plugin.
+ */
+ protected String templateDirectory;
+
+ /**
+ * Configuration data used for generating model refactoring code.
+ */
+ protected RefactoringInfo info;
+
+ /**
+ * Classpath entry needed for compiling JET code.
+ */
+ protected List<IClasspathEntry> classpathEntries;
+
+ /**
+ * JETEmitter instance used for code generation.
+ */
+ protected JETEmitter jetEmitter;
+
+ protected final String TEMPLATES = "templates";
+ protected final String BUNDLEVERSION = "Bundle-Version";
+ protected final String BUNDLESYMBOLICNAME = "Bundle-SymbolicName";
+ protected final String SINGLETONTRUE = "singleton:=true";
+ protected final String PLUGINSPATH =
+ Platform.getInstallLocation().getURL().getPath() + "plugins/";
+
+ private final String JETEMITTERS = ".JETEmitters";
+ protected final String JAVAJET = ".javajet";
+ private final String JAVA = ".java";
+ protected final String REFACTORINGWIZARD = "RefactoringWizard";
+ protected final String REFACTORINGWIZARDPAGE =
+ "RefactoringWizardPage";
+ protected final String REFACTORINGGUIHANDLER =
+ "RefactoringGuiHandler";
+ protected final String REFACTORINGCONTROLLER =
+ "RefactoringController";
+ protected final String REFACTORINGDATAMANAGEMENT =
+ "RefactoringDataManagement";
+ protected final String REFACTORINGTEST = "RefactoringTest";
+ protected final String XMLCONFIG = "Config";
+
+
+ /**
+ * Default constructor using configuration data.
+ * @param config Configuration data used for generating model
+ * refactoring code.
+ */
+ public GeneratioManager(RefactoringInfo info) {
+ this.info = info;
+ this.templateDirectory = setTemplateDirectory();
+ this.classpathEntries = setClassPathEntries();
+ System.out.println("GenerationManager initialized!");
+ }
+
+ private String setTemplateDirectory() {
+ String td = "";
+ final Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
+ try {
+ td = FileLocator.toFileURL(bundle.getEntry(TEMPLATES)).getFile();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ return td;
+ }
+
+ private List<IClasspathEntry> setClassPathEntries() {
+ List<IClasspathEntry> cpe = new ArrayList<IClasspathEntry>();
+ // add org.eclipse.emf.refactor.refactoring.generator to class path
+ Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
+ String version = (String) bundle.getHeaders().get(BUNDLEVERSION);
+ cpe.add(JavaCore.newLibraryEntry(new Path(PLUGINSPATH
+ + Activator.PLUGIN_ID + "_" + version + ".jar"), null, null));
+ // add org.eclipse.emf.refactor.refactoring to class path
+ bundle = Platform.getBundle(org.eclipse.emf.refactor.refactoring.Activator.PLUGIN_ID);
+ version = (String) bundle.getHeaders().get(BUNDLEVERSION);
+ cpe.add(JavaCore.newLibraryEntry(new Path(PLUGINSPATH +
+ org.eclipse.emf.refactor.refactoring.Activator.PLUGIN_ID + "_" + version + ".jar"), null, null));
+ return cpe;
+ }
+
+ /**
+ * Method for executing model refactoring code generation.
+ * @param monitor Object for monitoring the progress of the model
+ * refactoring code generation activity.
+ */
+ public void run(IProgressMonitor monitor){
+ deleteJetEmittersProject(monitor);
+ updatePluginXml();
+ DependenciesManager.updateDependencies(info);
+ setSingletonDirective();
+ createTestFolders(monitor);
+ generateCode(monitor);
+ }
+
+ /**
+ * Sets the singleton directive of the plugin to true.
+ */
+ protected void setSingletonDirective() {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(this.info.getProjectName());
+ try {
+ String fileName = project.getLocation()
+ .append("/META-INF/MANIFEST.MF")
+ .toOSString();
+ FileInputStream is = new FileInputStream(fileName);
+ Manifest mf = new Manifest(is);
+ Attributes att = mf.getMainAttributes();
+ String value = att.getValue(BUNDLESYMBOLICNAME);
+ if (! value.contains(SINGLETONTRUE))
+ value = value + ";" + SINGLETONTRUE;
+ att.putValue(BUNDLESYMBOLICNAME, value);
+ FileOutputStream out = new FileOutputStream(fileName);
+ mf.write(out);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Deletes the .JETEmitters project used for model refactoring
+ * code generation.
+ * @param monitor Object for monitoring the deleting activity.
+ */
+ protected void deleteJetEmittersProject(IProgressMonitor monitor) {
+ try {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource r = root.findMember(JETEMITTERS);
+ if (r != null){
+ r.delete(false, monitor);
+ }
+ }
+ catch (CoreException e) { }
+ catch (Exception e) { }
+ }
+
+ /**
+ * Method for generating model refactoring code. This includes
+ * "RefactoringWizard.java", "RactoringWizardPage.java",
+ * "RefactoringGuiHandler.java", "RefactoringController.java", and
+ * "RefactoringDataManagement.java".
+ * @param monitor Object for monitoring the code generation.
+ */
+ private void generateCode(IProgressMonitor monitor) {
+ String generatedCode = "";
+ try {
+ generatedCode = this.generateCode
+ (monitor, REFACTORINGWIZARD);
+ this.save(monitor, generatedCode, REFACTORINGWIZARD);
+ generatedCode = this.generateCode
+ (monitor, REFACTORINGWIZARDPAGE);
+ this.save(monitor, generatedCode, REFACTORINGWIZARDPAGE);
+ generatedCode = this.generateCode
+ (monitor, REFACTORINGGUIHANDLER);
+ this.save(monitor, generatedCode, REFACTORINGGUIHANDLER);
+ generatedCode = this.generateCode
+ (monitor, REFACTORINGCONTROLLER);
+ this.save(monitor, generatedCode, REFACTORINGCONTROLLER);
+ generatedCode = this.generateCode
+ (monitor, REFACTORINGDATAMANAGEMENT);
+ this.save(monitor, generatedCode, REFACTORINGDATAMANAGEMENT);
+ generatedCode = this.generateCode
+ (monitor, REFACTORINGTEST);
+ this.save(monitor, generatedCode, REFACTORINGTEST);
+ } catch (JETException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Saves the given content in a file with the given name.
+ * @param monitor Object for monitoring the saving activity.
+ * @param content Content to be saved in a file with the given name.
+ * @param fileName Name of the file the content has to be saved in.
+ * @throws CoreException Exception that can be thrown.
+ * @throws JETException Exception that can be thrown.
+ */
+ protected void save
+ (IProgressMonitor monitor, String content, String fileName)
+ throws CoreException, JETException {
+ IContainer container = findOrCreatePackage(monitor);
+ if (container == null) {
+ throw new JETException
+ ("Cound not find or create container for package "
+ + this.info.getPackageName() + " in "
+ + this.info.getProjectName());
+ }
+ IFile file = container.getFile(new Path(fileName + JAVA));
+ InputStream inputStream =
+ new ByteArrayInputStream(content.getBytes());
+ if (!file.exists()) {
+ file.create(inputStream, false, monitor);
+ } else {
+ container.refreshLocal(1, monitor);
+ file.setContents(inputStream, true, false, monitor);
+ }
+ }
+
+ /**
+ * Saves the given content in a XML file with the given name.
+ * @param monitor Object for monitoring the saving activity.
+ * @param content Content to be saved in a file with the given name.
+ * @param fileName Name of the file the content has to be saved in.
+ * @throws CoreException Exception that can be thrown.
+ * @throws JETException Exception that can be thrown.
+ */
+ protected void saveXml
+ (IProgressMonitor monitor, String content, String fileName)
+ throws CoreException, JETException {
+ IContainer container = findOrCreatePackage(monitor).getParent()
+ .getParent().getParent();
+ if (container == null) {
+ throw new JETException
+ ("Cound not find or create container for package "
+ + this.info.getPackageName() + " in "
+ + this.info.getProjectName());
+ }
+ File file = new File(fileName);
+ try {
+ if (!file.exists()) {
+ Writer output = new BufferedWriter(new FileWriter(file));
+ output.write(content);
+ output.close();
+ } else {
+ container.refreshLocal(1, monitor);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Finds or creates the package the code has to be located to.
+ * @param progressMonitor Object for monitoring the activity.
+ * @return Package the code has to be located to.
+ * @throws CoreException Exception that can be thrown.
+ */
+ private IContainer findOrCreatePackage(IProgressMonitor progressMonitor)
+ throws CoreException {
+ IPath outputPath = new Path
+ (this.info.getProjectName() + "/src/"
+ + this.info.getPackageName().replace('.', '/'));
+ IProgressMonitor subMonitor =
+ new SubProgressMonitor(progressMonitor, 1);
+ IPath localLocation = null;
+ IContainer container =
+ CodeGenUtil.EclipseUtil.findOrCreateContainer
+ (outputPath, true, localLocation, subMonitor);
+ return container;
+ }
+
+ /**
+ * Generates code out of the template with the given name.
+ * @param monitor Object monitoring the code generation.
+ * @param template Name of the template used by JET.
+ * @return Generated code as String.
+ */
+ private String generateCode(IProgressMonitor monitor, String template) {
+ String templatePath = this.templateDirectory + template + JAVAJET;
+ ClassLoader classLoader = getClass().getClassLoader();
+ this.jetEmitter = new JETEmitter(templatePath, classLoader);
+ this.jetEmitter.getClasspathEntries().addAll(classpathEntries);
+ String result = "";
+ IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
+ try {
+ result = jetEmitter.generate(sub, new Object[] { this.info });
+ } catch (JETException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Updates the plugin.xml file by adding the generated model refactoring
+ * to served extension points.
+ */
+ protected void updatePluginXml() {
+ List<RefactoringInfo> refactoringConfig =
+ XMLPluginFileManager.getRefactoringConfig
+ (this.info.getProjectName());
+ refactoringConfig.add(this.info);
+ XMLPluginFileManager.saveRefactoringConfig
+ (this.info.getProjectName(), refactoringConfig);
+ }
+
+ /**
+ * Creates the set of test folders for the generated model refactoring
+ * as well as the contained config.xml files.
+ * @param monitor Object monitoring the code generation.
+ */
+ protected void createTestFolders(IProgressMonitor monitor) {
+ String packageName = this.info.getPackageName();
+ packageName = packageName.substring(0, packageName.lastIndexOf('.'));
+ String path = Platform.getInstanceLocation()
+ .getURL().getPath() + packageName;
+ if (this.info.getNumberOfTests() > 0) {
+ try {
+ File testFolder = new File(path + "/tests/" +
+ this.info.getRefactoringId() + "/");
+ testFolder.mkdirs();
+ if (testFolder.exists() && testFolder.isDirectory()){
+ String testfolderprefix =
+ testFolder.getCanonicalPath() + "/test_";
+ for (int i = 1; i <= this.info.getNumberOfTests(); i++) {
+ File specifictestfolder = new File(testfolderprefix
+ + String.format("%03d", i) + "/");
+ if (!specifictestfolder.exists()
+ || !specifictestfolder.isDirectory()) {
+ specifictestfolder.mkdir();
+ createConfigXml(monitor, specifictestfolder);
+ }
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Creates the config.xml files within the test folders for the
+ * generated model refactoring.
+ * @param monitor Object monitoring the code generation.
+ * @param xmlFolder File object containing the folder in which
+ * the config should be saved.
+ */
+ private void createConfigXml(IProgressMonitor monitor, File xmlFolder) {
+ String generatedCode = this.generateCode(monitor, XMLCONFIG);
+ try {
+ File configXml = new File(xmlFolder.getCanonicalPath()
+ + "/config.xml");
+ if (!configXml.exists() || !configXml.isFile()) {
+ this.saveXml(monitor, generatedCode,
+ configXml.getCanonicalPath().toString());
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (JETException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+}
+
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java
new file mode 100644
index 0000000..62a4e94
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.managers;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.refactor.refactoring.core.ExtensionPointTags;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Abstract class for load and store operations (plugin.xml file and
+ * RefactoringConfig out of model refactoring extension point.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public abstract class XMLPluginFileManager {
+
+ private static final String PLUGINXML = "plugin.xml";
+ private static final String PLUGIN = "plugin";
+ private static final String EXTENSION = "extension";
+ private static final String POINT = "point";
+
+ /**
+ * Static method for checking whether the project with the given name
+ * owns a plugin.xml file.
+ * @param projectName Name of the project to be checked.
+ * @return true if the project with the given name owns a plugin.xml
+ * file; false otherwise.
+ */
+ public static boolean pluginXmlExists(String projectName) {
+ IProject project = ResourcesPlugin.getWorkspace()
+ .getRoot().getProject(projectName);
+ java.net.URI uri = project.getLocationURI();
+ String path = uri.getPath() + "/" + XMLPluginFileManager.PLUGINXML;
+ File file = new File(path);
+ return file.exists();
+ }
+
+ /**
+ * Static method for creating a plugin.xml file within the project
+ * with the given name.
+ * @param projectName Name of the project the plugin.xml file has
+ * to be generated into.
+ */
+ public static void createPluginXml(String projectName) {
+ final DocumentBuilder builder =
+ XMLPluginFileManager.newDocumentBuilder();
+ if (null != builder){
+ final Document doc = builder.newDocument();
+ final Element root = doc.createElement
+ (XMLPluginFileManager.PLUGIN);
+ doc.appendChild(root);
+ final TransformerFactory transformerFactory =
+ TransformerFactory.newInstance();
+ Transformer transformer = null;
+ try {
+ transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT,"yes");
+ } catch (final TransformerConfigurationException e) {
+ e.printStackTrace();
+ }
+ final DOMSource source = new DOMSource(doc);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ java.net.URI uri = project.getLocationURI();
+ StreamResult result = new StreamResult
+ (uri + "/" + XMLPluginFileManager.PLUGINXML);
+ try {
+ transformer.transform(source, result);
+ } catch (final TransformerException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static DocumentBuilder newDocumentBuilder() {
+ try {
+ return DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder();
+ } catch (final ParserConfigurationException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Abstract method for getting a list of RefactoringConfig out from
+ * the model refactoring extension point served in the plugin.xml
+ * file of the project with the given name.
+ * @param projectName Name of the project the plugin.xml file has to
+ * be analyzed for serving the model refactoring extension point.
+ * @return List of RefactoringConfig out from the model refactoring
+ * extension point served in the plugin.xml file of the project with
+ * the given name.
+ */
+ public static List<RefactoringInfo> getRefactoringConfig
+ (String projectName) {
+ final DocumentBuilder builder = XMLPluginFileManager
+ .newDocumentBuilder();
+ List<RefactoringInfo> refactoringConfigs =
+ new ArrayList<RefactoringInfo>();
+ if (null != builder){
+ Document doc = null;
+ try {
+ IProject project = ResourcesPlugin.getWorkspace()
+ .getRoot().getProject(projectName);
+ java.net.URI uri = project.getLocationURI();
+ doc = builder.parse
+ (uri + "/" + XMLPluginFileManager.PLUGINXML);
+ } catch (final SAXException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ if (doc != null) {
+ Element root = doc.getDocumentElement();
+ NodeList refactorings = root.getElementsByTagName
+ (ExtensionPointTags.REFACTORING_TAG);
+ for (int i=0; i < refactorings.getLength(); i++){
+ Element refactoring = (Element) refactorings.item(i);
+ String controller = refactoring.getAttribute
+ (ExtensionPointTags.REFACTORING_CONTROLLER_TAG);
+ String gui = refactoring.getAttribute
+ (ExtensionPointTags.REFACTORING_GUI_TAG);
+ String id = refactoring.getAttribute
+ (ExtensionPointTags.REFACTORING_ID_TAG);
+ String menuLabel = refactoring.getAttribute
+ (ExtensionPointTags.REFACTORING_MENULABEL_TAG);
+ String namespaceURI = refactoring.getAttribute
+ (ExtensionPointTags.REFACTORING_NSURI_TAG);
+ RefactoringInfo refactoringConfig =
+ new RefactoringInfo
+ (controller, gui, id, menuLabel, namespaceURI);
+ refactoringConfigs.add(refactoringConfig);
+ }
+ }
+ }
+ return refactoringConfigs;
+ }
+
+ /**
+ * Abstract method for saving the given RefactoringConfig list as model
+ * refactoring extension point servings in the plugin.xml file of the
+ * project with the given name.
+ * @param projectName Name of the project the model refactoring
+ * extension point servings shall be stored in the plugin.xml file.
+ * @param refactoringConfig List of RefactoringConfig to be saved as
+ * model refactoring extension point servings.
+ */
+ public static void saveRefactoringConfig
+ (String projectName, List<RefactoringInfo> refactoringConfig) {
+ final DocumentBuilder builder =
+ XMLPluginFileManager.newDocumentBuilder();
+ if (null != builder){
+ final Document doc = builder.newDocument();
+ Element root = doc.createElement(XMLPluginFileManager.PLUGIN);
+ doc.appendChild(root);
+ final Element extension = doc.createElement
+ (XMLPluginFileManager.EXTENSION);
+ extension.setAttribute(XMLPluginFileManager.POINT,
+ ExtensionPointTags.EXTENSION_POINT_NAME);
+ for (RefactoringInfo rc : refactoringConfig){
+ Element refactoring = doc.createElement
+ (ExtensionPointTags.REFACTORING_TAG);
+ if (rc.getPackageName() == null){
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_CONTROLLER_TAG,
+ rc.getController());
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_GUI_TAG,
+ rc.getGuiHandler());
+ } else {
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_CONTROLLER_TAG,
+ rc.getPackageName() + "." + rc.getController());
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_GUI_TAG,
+ rc.getPackageName() + "." + rc.getGuiHandler());
+ }
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_ID_TAG,
+ rc.getRefactoringId());
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_MENULABEL_TAG,
+ rc.getMenuLabel());
+ refactoring.setAttribute(ExtensionPointTags.REFACTORING_NSURI_TAG,
+ rc.getNamespaceUri());
+ extension.appendChild(refactoring);
+ }
+ root.appendChild(extension);
+ final TransformerFactory transformerFactory =
+ TransformerFactory.newInstance();
+ Transformer transformer = null;
+ try {
+ transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT,"yes");
+ } catch (final TransformerConfigurationException e) {
+ e.printStackTrace();
+ }
+ final DOMSource source = new DOMSource(doc);
+ IProject project = ResourcesPlugin.getWorkspace()
+ .getRoot().getProject(projectName);
+ java.net.URI uri = project.getLocationURI();
+ StreamResult result = new StreamResult(uri + "/"
+ + XMLPluginFileManager.PLUGINXML);
+ try {
+ transformer.transform(source, result);
+ } catch (final TransformerException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/BasicDataWizardPage.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/BasicDataWizardPage.java
new file mode 100644
index 0000000..0db1f4a
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/BasicDataWizardPage.java
@@ -0,0 +1,393 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.ui;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+import org.eclipse.emf.refactor.refactoring.generator.managers.XMLPluginFileManager;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Wizard page for configurating model refactoring data (basics).
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class BasicDataWizardPage extends WizardPage implements Listener {
+
+ private Text idText;
+ private Text menuText;
+ private Text nsUriText;
+ private Text classText;
+ private Text jarText;
+ private Combo projectCombo;
+
+ /**
+ * Id of the model refactoring to be generated.
+ */
+ private String id = "";
+
+ /**
+ * Inserted id of the model refactoring to be generated.
+ */
+ private String originalId = "";
+
+ /**
+ * Menu Label of the model refactoring to be generated.
+ */
+ private String menuLabel = "";
+
+ /**
+ * Name of the project the model refactoring code has to be
+ * generated to.
+ */
+ private String projectName = "";
+
+ /**
+ * Namespace for the model refactoring to be generated.
+ */
+ private String nsUri = "";
+
+ /**
+ * Name of the class the model refactoring shall be executed on.
+ */
+ private String className = "";
+
+ /**
+ * Name of the jar file that owns the class specified in 'className'.
+ */
+ private String jar = "";
+
+ /**
+ * The selected EObject when starting the generation process of
+ * the model refactoring.
+ */
+ private EObject selectedEObject;
+
+ /**
+ * Namespace prefix for the model refactoring to be generated.
+ */
+ private String nsPrefix = "";
+
+ /**
+ * Name of the meta model for the model refactoring to be generated.
+ */
+ private String metaModelName = "";
+
+ /**
+ * Default constructor.
+ * @param pageName Name of the wizard page.
+ * @param selectedEObject Selected EObject when starting the
+ * generation process of the model refactoring.
+ */
+ protected BasicDataWizardPage(String pageName, EObject selectedEObject) {
+ super(pageName);
+ this.selectedEObject = selectedEObject;
+ }
+
+ /**
+ * Gets the id of the model refactoring to be generated.
+ * @return Id of the model refactoring to be generated.
+ */
+ public String getRefactoringId(){
+ return id;
+ }
+
+ /**
+ * Gets the menu Label of the model refactoring to be generated.
+ * @return Menu Label of the model refactoring to be generated.
+ */
+ public String getMenuLabel(){
+ if (menuLabel.isEmpty()){
+ return originalId;
+ } else {
+ return menuLabel;
+ }
+ }
+
+ /**
+ * Gets the namespace for the model refactoring to be generated.
+ * @return Namespace for the model refactoring to be generated.
+ */
+ public String getNsUri(){
+ return nsUri;
+ }
+
+ /**
+ * Gets the name of the class the model refactoring shall be
+ * executed on.
+ * @return Name of the class the model refactoring shall be
+ * executed on.
+ */
+ public String getClassName(){
+ return className;
+ }
+
+ /**
+ * Gets the name of the jar file that owns the class
+ * specified in 'className'.
+ * @return Name of the jar file that owns the class
+ * specified in 'className'.
+ */
+ public String getJar(){
+ return jar;
+ }
+
+ /**
+ * Gets the name of the project the model refactoring code
+ * has to be generated to.
+ * @return Name of the project the model refactoring code
+ * has to be generated to.
+ */
+ public String getProjectName(){
+ return projectName;
+ }
+
+ /**
+ * Gets the namespace prefix for the model refactoring to be generated.
+ * @return Namespace prefix for the model refactoring to be generated.
+ */
+ public String getNsPrefix(){
+ return nsPrefix;
+ }
+
+ /**
+ * Gets the name of the meta model for the model refactoring to be generated.
+ * @return Name of the meta model for the model refactoring to be generated.
+ */
+ public String getMetaModelName(){
+ return metaModelName;
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl
+ * (org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ FillLayout fillLayout = new FillLayout();
+ fillLayout.spacing = 5;
+ fillLayout.type = SWT.VERTICAL;
+ composite.setLayout(fillLayout);
+ createTextComposite(composite);
+ createSelectedEObjectComposite(composite);
+ createProjectComposite(composite);
+ checkIsPageComplete();
+ setControl(composite);
+ }
+
+ /**
+ * Creates a composite for editing id and menu label of the
+ * model refactoring to be generated.
+ * @param parent Parent composite.
+ */
+ private void createTextComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.BORDER);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ composite.setLayout(gl);
+ Label idLabel = new Label(composite, SWT.NONE);
+ idLabel.setText("Name of the new EMF Model Refactoring (Id): ");
+ idLabel.setEnabled(true);
+ idText = new Text(composite, SWT.BORDER);
+ idText.setToolTipText("Refactoring-Id");
+ idText.setEnabled(true);
+ idText.setLayoutData(gd);
+ idText.addListener(SWT.Modify, this);
+ Label menuLabel = new Label(composite, SWT.NONE);
+ menuLabel.setText("Text to be shown in menu (menu label): ");
+ menuLabel.setEnabled(true);
+ menuText = new Text(composite, SWT.BORDER);
+ menuText.setToolTipText("Menu Label Text");
+ menuText.setEnabled(true);
+ menuText.setLayoutData(gd);
+ menuText.addListener(SWT.Modify, this);
+ }
+
+ /**
+ * Creates a composite for displaying the namespace, the selected class,
+ * and the owning jar file of the model refactoring to be generated.
+ * @param parent Parent composite.
+ */
+ private void createSelectedEObjectComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.BORDER);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ composite.setLayout(gl);
+ Label nsUriLabel = new Label(composite, SWT.NONE);
+ nsUriLabel.setText("Namespace-Uri: ");
+ nsUriLabel.setEnabled(true);
+ nsUriText = new Text(composite, SWT.BORDER);
+ nsUri = ((EPackage)selectedEObject.eClass().eContainer())
+ .getNsURI();
+ nsUriText.setText(nsUri);
+ nsUriText.setEnabled(false);
+ nsUriText.setLayoutData(gd);
+ Label classLabel = new Label(composite, SWT.NONE);
+ classLabel.setText("Class of selected EObject (context): ");
+ classLabel.setEnabled(true);
+ classText = new Text(composite, SWT.BORDER);
+ className = selectedEObject.eClass().getInstanceClassName();
+ classText.setText(className);
+ classText.setEnabled(false);
+ classText.setLayoutData(gd);
+ Label jarLabel = new Label(composite, SWT.NONE);
+ jarLabel.setText("jar-File to be included (required bundle): ");
+ jarLabel.setEnabled(true);
+ jarText = new Text(composite, SWT.BORDER);
+ jar = selectedEObject.eClass().getInstanceClass().getPackage()
+ .getName();
+ jarText.setText(jar);
+ jarText.setEnabled(false);
+ jarText.setLayoutData(gd);
+
+ nsPrefix = ((EPackage)selectedEObject.eClass().eContainer())
+ .getNsPrefix();
+ metaModelName = selectedEObject.eClass().eContainer()
+ .getClass().getName();
+ }
+
+ /**
+ * Creates a composite for choosing the project the model refactoring
+ * code has to be generated to.
+ * @param parent Parent composite.
+ */
+ private void createProjectComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.BORDER);
+ GridLayout gl = new GridLayout();
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gl.numColumns = 2;
+ composite.setLayout(gl);
+ Label projectLabel = new Label(composite, SWT.NONE);
+ projectLabel.setText("Plugin-Project that will contain the code: ");
+ projectLabel.setEnabled(true);
+ projectCombo = new Combo (composite, SWT.READ_ONLY);
+ projectCombo.setLayoutData(gd);
+ projectCombo.addListener(SWT.Selection, this);
+ addProjectsToCombo(projectCombo);
+ }
+
+ /**
+ * Adds the plugin-projects of the workspace to the given combo.
+ * @param projectCombo Combo the projects have to be inserted to.
+ */
+ private void addProjectsToCombo(Combo projectCombo) {
+ IProject[] projects =
+ ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject project : projects){
+ if (project.isOpen()){
+ IProjectNature nature = null;
+ try {
+ nature = project.getNature("org.eclipse.pde.PluginNature");
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ if (null != nature){
+ projectCombo.add(project.getName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks whether the edited data are complete and sets
+ * the corresponding message to the top of the wizard page.
+ */
+ private void checkIsPageComplete() {
+ if (projectCombo.getItemCount() == 0){
+ setErrorMessage("EMF Refactor cannot generate code without an " +
+ "open plugin-project in the actual workspace.");
+ setPageComplete(false);
+ return;
+ }
+ if (id.isEmpty()){
+ setMessage("Please insert a name.", SWT.ERROR);
+ setPageComplete(false);
+ } else {
+ if (projectName.isEmpty()){
+ setMessage("Please select a plugin-project to generate " +
+ " your code in.", SWT.ERROR);
+ setPageComplete(false);
+ } else {
+ if (! XMLPluginFileManager.pluginXmlExists(projectName)){
+ XMLPluginFileManager.createPluginXml(projectName);
+ }
+ List<RefactoringInfo> refactoringConfig =
+ XMLPluginFileManager.getRefactoringConfig(projectName);
+ boolean exists = false;
+ for (RefactoringInfo refCon : refactoringConfig){
+ if (refCon.getRefactoringId().equals(id)){
+ exists = true;
+ break;
+ }
+ }
+ if (exists){
+ setMessage("There is already a refactoring with id '" +
+ id + "' in project '" + projectName + "'!");
+ setPageComplete(false);
+ } else {
+ if (menuLabel.isEmpty()){
+ setMessage("Please insert a text to be shown in " +
+ "menu (menu label). Otherwise, EMF Refactor " +
+ "will show the refactoring name.", SWT.ERROR);
+ } else {
+ setMessage("", SWT.NONE);
+ }
+ setPageComplete(true);
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.swt.widgets.Listener#handleEvent
+ * (org.eclipse.swt.widgets.Event)
+ */
+ @Override
+ public void handleEvent(Event event) {
+ if (event.widget == idText){
+ id = idText.getText().trim().replaceAll(" ", "");
+ originalId = idText.getText().trim();
+ }
+ if (event.widget == menuText){
+ menuLabel = menuText.getText().trim();
+ }
+ if (event.widget == projectCombo){
+ int index = projectCombo.getSelectionIndex();
+ if (index == -1){
+ projectName = "";
+ } else {
+ projectName = projectCombo.getItem(index);
+ }
+ }
+ checkIsPageComplete();
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java
new file mode 100644
index 0000000..222b2cb
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.ui;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+import org.eclipse.emf.refactor.refactoring.generator.interfaces.INewRefactoringWizard;
+import org.eclipse.emf.refactor.refactoring.generator.managers.GeneratioManager;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+
+/**
+ * Wizard for editing data needed for model refactoring code generation.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class NewRefactoringWizardJava extends Wizard implements INewRefactoringWizard {
+
+ /**
+ * Wizard page for configurating model refactoring data (basics).
+ */
+ private BasicDataWizardPage basicWizardPage;
+
+ /**
+ * Wizard page for configurating model refactoring parameters.
+ */
+ private ParameterWizardPage parameterWizardPage;
+
+ /**
+ * Wizard page for configurating model test parameters.
+ */
+ private TestWizardPage testWizardPage;
+
+ /**
+ * Default constructor that initializes its wizard pages.
+ * @param selectedEObject The selected EObject when starting the
+ * generation process of the model refactoring.
+ */
+ public NewRefactoringWizardJava(EObject selectedEObject){
+ super();
+ setWindowTitle("EMF Refactor - Specify EMF Model Refactoring");
+ this.basicWizardPage = new BasicDataWizardPage("EMF Refactor", selectedEObject);
+ this.parameterWizardPage = new ParameterWizardPage("EMF Refactor");
+ this.testWizardPage = new TestWizardPage("EMF Refactor");
+ this.addPage(basicWizardPage);
+ this.addPage(parameterWizardPage);
+ this.addPage(testWizardPage);
+ }
+
+ /**
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ @Override
+ public void execute(IProgressMonitor monitor)
+ throws InvocationTargetException {
+ try {
+ createRefactoring(monitor);
+ } catch (Exception e){
+ e.printStackTrace();
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(false, false, op);
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ /**
+ * Triggers the model refactoring generation activity. Collects data
+ * from its wizard pages and starts the refactoring generator.
+ * @param monitor Object monitoring the model refactoring
+ * generation activity.
+ */
+ protected void createRefactoring(IProgressMonitor monitor) {
+ String projectName = basicWizardPage.getProjectName();
+ String id = basicWizardPage.getRefactoringId();
+ String menuLabel = basicWizardPage.getMenuLabel();
+ String namespaceUri = basicWizardPage.getNsUri();
+ String namespacePrefix = basicWizardPage.getNsPrefix();
+ String metaModelName = basicWizardPage.getMetaModelName();
+ String className = basicWizardPage.getClassName();
+ String jar = basicWizardPage.getJar();
+ int numberOfTests = testWizardPage.getNumberOfTests();
+ RefactoringInfo refactoringConfig =
+ new RefactoringInfo(projectName, id, menuLabel, namespaceUri,
+ namespacePrefix, numberOfTests);
+ refactoringConfig.setSelectedEObjectJar(jar);
+ refactoringConfig.setSelectedEObjectClass(className);
+ refactoringConfig.setMetaModelName(metaModelName);
+ refactoringConfig.setParameters(parameterWizardPage.getParameters());
+ GeneratioManager rg = new GeneratioManager(refactoringConfig);
+ rg.run(monitor);
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/ParameterWizardPage.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/ParameterWizardPage.java
new file mode 100644
index 0000000..941d0fb
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/ParameterWizardPage.java
@@ -0,0 +1,266 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.ui;
+
+import java.util.ArrayList;
+
+import org.eclipse.emf.refactor.refactoring.generator.core.ParameterInfo;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Wizard page for configurating model refactoring parameters.
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class ParameterWizardPage extends WizardPage implements Listener {
+
+ private Button addButton;
+ private Button removeButton;
+ private List parameterList;
+ private Button cancelButton;
+ private Button saveButton;
+ private Text nameText;
+ private Text descriptionText;
+
+ /**
+ * List of model refactoring parameter configuration data.
+ */
+ private java.util.List<ParameterInfo> parameters;
+
+ /**
+ * Default constructor.
+ * @param pageName Name of the wizard page.
+ */
+ protected ParameterWizardPage(String pageName) {
+ super(pageName);
+ parameters = new ArrayList<ParameterInfo>();
+ }
+
+ /**
+ * Gets a list of model refactoring parameter configuration data.
+ * @return List of model refactoring parameter configuration data.
+ */
+ public java.util.List<ParameterInfo> getParameters(){
+ return parameters;
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl
+ * (org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ FillLayout fillLayout = new FillLayout();
+ fillLayout.spacing = 5;
+ fillLayout.type = SWT.VERTICAL;
+ composite.setLayout(fillLayout);
+ createListComposite(composite);
+ createParameterComposite(composite);
+ checkParameterList();
+ setControl(composite);
+ }
+
+ /**
+ * Creates a composite including a list of parameter configuration
+ * data objects.
+ * @param parent Parent composite.
+ */
+ private void createListComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.BORDER);
+ composite.setLayout(new RowLayout(SWT.VERTICAL));
+ Label textLabel = new Label(composite, SWT.CENTER);
+ textLabel.setText("Refactoring parameters: ");
+ Composite parameterComposite = new Composite(composite, SWT.NULL);
+ parameterComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
+ parameterList = new List(parameterComposite,
+ SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
+ parameterList.setLayoutData(new RowData(350, 80));
+ Composite buttonComposite =
+ new Composite(parameterComposite, SWT.NULL);
+ buttonComposite.setLayout(new RowLayout(SWT.VERTICAL));
+ addButton = new Button(buttonComposite, SWT.PUSH);
+ addButton.setText("Add");
+ addButton.setLayoutData(new RowData(100, 25));
+ addButton.addListener(SWT.Selection, this);
+ removeButton = new Button(buttonComposite, SWT.PUSH);
+ removeButton.setText("Remove");
+ removeButton.setLayoutData(new RowData(100, 25));
+ removeButton.addListener(SWT.Selection, this);
+ removeButton.setEnabled(false);
+ }
+
+ /**
+ * Creates a composite for editing parameter configuration data.
+ * @param parent Parent composite.
+ */
+ private void createParameterComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.BORDER);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ composite.setLayout(gl);
+ Label idLabel = new Label(composite, SWT.NONE);
+ idLabel.setText("Parameter name: ");
+ idLabel.setEnabled(true);
+ nameText = new Text(composite, SWT.BORDER);
+ nameText.setToolTipText("Parameter name");
+ nameText.setEnabled(false);
+ nameText.setLayoutData(gd);
+ Label menuLabel = new Label(composite, SWT.NONE);
+ menuLabel.setText("Parameter description: ");
+ menuLabel.setEnabled(true);
+ descriptionText = new Text(composite, SWT.BORDER);
+ descriptionText.setToolTipText("Parameter description");
+ descriptionText.setEnabled(false);
+ descriptionText.setLayoutData(gd);
+ cancelButton = new Button(composite, SWT.PUSH);
+ cancelButton.setText("Cancel");
+ cancelButton.setLayoutData(new GridData(100, 25));
+ cancelButton.setEnabled(false);
+ cancelButton.addListener(SWT.Selection, this);
+ saveButton = new Button(composite, SWT.PUSH);
+ saveButton.setText("Save");
+ saveButton.setLayoutData(new GridData(100, 25));
+ saveButton.setEnabled(false);
+ saveButton.addListener(SWT.Selection, this);
+ }
+
+ /**
+ * Checks whether the parameter list is empty and sets
+ * the corresponding message to the top of the wizard page.
+ */
+ private void checkParameterList() {
+ if (parameters.isEmpty()){
+ setMessage("There is no parameter specified. " +
+ "Please insert a parameter.", SWT.ERROR);
+ removeButton.setEnabled(false);
+ } else {
+ setMessage("", SWT.NONE);
+ removeButton.setEnabled(true);
+ }
+ }
+
+ /**
+ * @see org.eclipse.swt.widgets.Listener#handleEvent
+ * (org.eclipse.swt.widgets.Event)
+ */
+ @Override
+ public void handleEvent(Event event) {
+ if (event.widget == addButton){
+ enableListElements(false);
+ enableParameterElements(true);
+ }
+ if (event.widget == removeButton){
+ int index = parameterList.getSelectionIndex();
+ if (index == -1){
+ MessageDialog.openError(getShell(), "EMF Refactor",
+ "Please select a parameter from the list.");
+ return;
+ }
+ if (MessageDialog.openConfirm(getShell(), "EMF Refactor",
+ "Remove parameter '"
+ + parameters.get(index).getName() + "'?")){
+ parameters.remove(index);
+ updateList();
+ checkParameterList();
+ }
+ }
+ if (event.widget == cancelButton){
+ clearTextElements();
+ enableParameterElements(false);
+ enableListElements(true);
+ checkParameterList();
+ }
+ if (event.widget == saveButton){
+ String name = nameText.getText().trim().replaceAll(" ", "");
+ if (name.isEmpty()){
+ MessageDialog.openError(getShell(), "EMF Refactor",
+ "Please insert a parameter name.");
+ return;
+ }
+ name = name.substring(0,1).toLowerCase() + name.substring(1);
+ for (ParameterInfo param : parameters){
+ if (param.getName().equals(name)){
+ MessageDialog.openError(getShell(), "EMF Refactor",
+ "There is already a parameter named '"
+ + name + "'.");
+ return;
+ }
+ }
+ ParameterInfo newParameter = new ParameterInfo(name);
+ newParameter.setDescription(descriptionText.getText().trim());
+ parameters.add(newParameter);
+ updateList();
+ clearTextElements();
+ enableParameterElements(false);
+ enableListElements(true);
+ checkParameterList();
+ }
+ }
+
+ /**
+ * Updates the list of model refactoring parameter configuration data.
+ */
+ private void updateList(){
+ parameterList.removeAll();
+ for (ParameterInfo param : parameters){
+ parameterList.add(param.getName());
+ }
+ }
+
+ /**
+ * Removes the contents of the text components.
+ */
+ private void clearTextElements(){
+ nameText.setText("");
+ descriptionText.setText("");
+ }
+
+ /**
+ * Enables the composites of the parameter section of the wizard page.
+ * @param b true if the composites shall be enabled, false otherwise.
+ */
+ private void enableParameterElements(boolean b){
+ nameText.setEnabled(b);
+ descriptionText.setEnabled(b);
+ cancelButton.setEnabled(b);
+ saveButton.setEnabled(b);
+ if (b){
+ nameText.setFocus();
+ }
+ }
+
+ /**
+ * Enables the composites of the list section of the wizard page.
+ * @param b true if the composites shall be enabled, false otherwise.
+ */
+ private void enableListElements(boolean b){
+ parameterList.setEnabled(b);
+ addButton.setEnabled(b);
+ removeButton.setEnabled(b);
+ setPageComplete(b);
+ }
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/TestWizardPage.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/TestWizardPage.java
new file mode 100644
index 0000000..a3dbf2f
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/TestWizardPage.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) Philipps University of Marburg. 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:
+ * Philipps University of Marburg - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.refactor.refactoring.generator.ui;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Wizard page for configurating model refactoring data (basics).
+ * @generated NOT
+ * @author Thorsten Arendt
+ */
+public class TestWizardPage extends WizardPage implements Listener {
+
+ private Text numberText;
+ private Combo numberCombo;
+
+ /**
+ * Default constructor.
+ * @param pageName Name of the wizard page.
+ */
+ protected TestWizardPage(String pageName) {
+ super(pageName);
+ }
+
+ /**
+ * The number of tests to be generated for this model refactoring.
+ */
+ private int numberOfTests;
+
+ /**
+ * Returns the number of tests to be generated for this
+ * model refactoring.
+ * @return Number of tests to be generated for this model
+ * refactoring
+ */
+ public int getNumberOfTests() {
+ return numberOfTests;
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl
+ * (org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ FillLayout fillLayout = new FillLayout();
+ fillLayout.spacing = 5;
+ fillLayout.type = SWT.VERTICAL;
+ composite.setLayout(fillLayout);
+ createTextComposite(composite);
+ setControl(composite);
+ }
+
+ /**
+ * Creates a composite for changing the number of tests to be
+ * generated for this model refactoring.
+ * @param parent Parent composite.
+ */
+ private void createTextComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.BORDER);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ composite.setLayout(gl);
+ Label numberLabel = new Label(composite, SWT.NONE);
+ numberLabel.setText
+ ("Number of (empty) test cases to be generated: ");
+ numberLabel.setEnabled(true);
+ numberCombo = new Combo (composite, SWT.READ_ONLY);
+ numberCombo.setLayoutData(gd);
+ numberCombo.addListener(SWT.Selection, this);
+ for (int i = 0 ; i <= 100; i++) {
+ numberCombo.add(Integer.toString(i));
+ }
+ numberCombo.select(0);
+ }
+
+ /**
+ * @see org.eclipse.swt.widgets.Listener#handleEvent
+ * (org.eclipse.swt.widgets.Event)
+ */
+ @Override
+ public void handleEvent(Event event) {
+ if (event.widget == numberText){
+ numberOfTests = Integer.parseInt
+ (numberText.getText().trim().replaceAll(" ", ""));
+ }
+ if (event.widget == numberCombo){
+ int index = numberCombo.getSelectionIndex();
+ if (index == -1){
+ numberOfTests = 0;
+ } else {
+ numberOfTests = Integer.parseInt
+ (numberCombo.getItem(index));
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/Config.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/Config.javajet
new file mode 100644
index 0000000..6a09a44
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/Config.javajet
@@ -0,0 +1,12 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringController"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+ <% for (ParameterInfo pi : info.getParameters()) { %>
+ <param>
+ <name><%=pi.getName()%></name>
+ <value>enter value here</value>
+ </param>
+ <% } %>
+</config> \ No newline at end of file
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringController.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringController.javajet
new file mode 100644
index 0000000..d8d93b6
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringController.javajet
@@ -0,0 +1,188 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringController"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * $Id: RefactoringController.javajet,v 1.1 2012/10/16 11:53:05 tarendt Exp $
+ */
+package <%=info.getPackageName()%>;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.interfaces.IController;
+import org.eclipse.emf.refactor.refactoring.interfaces.IDataManagement;
+import org.eclipse.emf.refactor.refactoring.runtime.ltk.LtkEmfRefactoringProcessorAdapter;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
+
+public final class RefactoringController implements IController{
+
+ /**
+ * Refactoring supported by the controller.
+ * @generated
+ */
+ private Refactoring parent;
+
+ /**
+ * DataManagement object of the model refactoring.
+ * @generated
+ */
+ private RefactoringDataManagement dataManagement =
+ new RefactoringDataManagement();
+
+ /**
+ * Invocation context of the model refactoring.
+ * @generated
+ */
+ private List<EObject> selection = new ArrayList<EObject>();
+
+ /**
+ * Ltk RefactoringProcessor of the model refactoring.
+ * @generated
+ */
+ private InternalRefactoringProcessor refactoringProcessor = null;
+
+ /**
+ * Gets the Refactoring supported by the controller.
+ * @return Refactoring supported by the controller.
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IController#getParent()
+ * @generated
+ */
+ @Override
+ public Refactoring getParent() {
+ return this.parent;
+ }
+
+ /**
+ * Sets the Refactoring supported by the controller.
+ * @param emfRefactoring Refactoring supported by the controller.
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IController#
+ * setParent(org.eclipse.emf.refactor.refactoring.core.Refactoring)
+ * @generated
+ */
+ @Override
+ public void setParent(Refactoring emfRefactoring) {
+ this.parent = emfRefactoring;
+ }
+
+ /**
+ * Returns the DataManagement object of the model refactoring.
+ * @return DataManagement object of the model refactoring.
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IController#
+ * getDataManagementObject()
+ * @generated
+ */
+ @Override
+ public IDataManagement getDataManagementObject() {
+ return this.dataManagement;
+ }
+
+ /**
+ * Returns the ltk RefactoringProcessor of the model refactoring.
+ * @return Ltk RefactoringProcessor of the model refactoring.
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IController#
+ * getLtkRefactoringProcessor()
+ * @generated
+ */
+ @Override
+ public RefactoringProcessor getLtkRefactoringProcessor() {
+ return this.refactoringProcessor;
+ }
+
+ /**
+ * Sets the selected EObject (invocation context of the model refactoring).
+ * @param selection Invocation context of the model refactoring.
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IController#
+ * setSelection(java.util.List)
+ * @generated
+ */
+ @Override
+ public void setSelection(List<EObject> selection) {
+ this.selection = selection;
+ this.refactoringProcessor =
+ new InternalRefactoringProcessor(this.selection);
+ }
+
+ /**
+ * Returns a Runnable object that executes the model refactoring.
+ * @return Runnable object that executes the model refactoring.
+ * @generated
+ */
+ private Runnable applyRefactoring() {
+ return new Runnable() {
+ /**
+ * @see java.lang.Runnable#run()
+ * @generated
+ */
+ @Override
+ public void run() {
+ <%=info.getSelectedEObjectClass()%> selectedEObject =
+ (<%=info.getSelectedEObjectClass()%>) dataManagement.
+ getInPortByName(dataManagement.SELECTEDEOBJECT).getValue();<%/*
+ */%><%for (ParameterConfig pC : info.getParameters()) { %>
+ String <%=pC.getName()%> =
+ (String) dataManagement.getInPortByName("<%=pC.getName()%>").getValue();<%}%>
+ // TODO: implement model transformation
+ }
+ };
+ }
+
+ /**
+ * Internal class for providing an instance of a LTK RefactoringProcessor
+ * used for EMF model refactorings.
+ * @generated
+ */
+ public final class InternalRefactoringProcessor extends
+ LtkEmfRefactoringProcessorAdapter {
+
+ /**
+ * Constructor using the invocation context of the model refactoring.
+ * @param selection Invocation context of the model refactoring.
+ * @generated
+ */
+ private InternalRefactoringProcessor(List<EObject> selection){
+ super(getParent(), selection, applyRefactoring());
+ }
+
+ /**
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#
+ * checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
+ * @generated
+ */
+ @Override
+ public RefactoringStatus checkInitialConditions(){
+ RefactoringStatus result = new RefactoringStatus();
+ <%=info.getSelectedEObjectClass()%> selectedEObject =
+ (<%=info.getSelectedEObjectClass()%>) dataManagement.
+ getInPortByName(dataManagement.SELECTEDEOBJECT).getValue();
+ // TODO: implement initial check
+ return result;
+ }
+
+ /**
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#
+ * checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+ * @generated
+ */
+ @Override
+ public RefactoringStatus checkFinalConditions(){
+ RefactoringStatus result = new RefactoringStatus();
+ <%=info.getSelectedEObjectClass()%> selectedEObject =
+ (<%=info.getSelectedEObjectClass()%>) dataManagement.
+ getInPortByName(dataManagement.SELECTEDEOBJECT).getValue();<%/*
+ */%><%for (ParameterConfig pC : info.getParameters()) {%>
+ String <%=pC.getName()%> =
+ (String) dataManagement.getInPortByName("<%=pC.getName()%>").getValue();<%}%>
+ // TODO: implement final check
+ return result;
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringDataManagement.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringDataManagement.javajet
new file mode 100644
index 0000000..1bf372b
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringDataManagement.javajet
@@ -0,0 +1,62 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringDataManagement"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * $Id: RefactoringDataManagement.javajet,v 1.1 2012/10/16 11:53:05 tarendt Exp $
+ */
+ package <%=info.getPackageName()%>;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.refactoring.runtime.DataManagementAdapter;
+import org.eclipse.emf.refactor.refactoring.core.Port;
+
+/**
+ * Class for specific data concerning a model refactoring.
+ * @generated
+ */
+public class RefactoringDataManagement extends DataManagementAdapter {
+
+ protected final String SELECTEDEOBJECT = "selectedEObject";
+
+ /**
+ * Default constructor.
+ * @generated
+ */
+ public RefactoringDataManagement() {
+ this.addPorts();
+ }
+
+ /**
+ * Adds the ports to the data management used for parameter passing.
+ * @generated
+ */
+ private void addPorts(){
+ this.inPorts.add
+ (new Port<<%=info.getSelectedEObjectClass()%>>
+ (SELECTEDEOBJECT, <%=info.getSelectedEObjectClass()%>.class));
+<% for (ParameterInfo pi : info.getParameters()) { %>
+ this.inPorts.add
+ (new Port<String>
+ ("<%=pi.getName()%>", String.class, "unspecified"));
+<% } %>
+ }
+
+ /**
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IDataManagement#
+ * preselect(java.util.List)
+ * @generated
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void preselect(List<EObject> selection) {
+ getInPortByName(SELECTEDEOBJECT).
+ setValue((<%=info.getSelectedEObjectClass()%>) selection.get(0));
+ }
+
+}
+ \ No newline at end of file
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringGuiHandler.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringGuiHandler.javajet
new file mode 100644
index 0000000..2a3a5fd
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringGuiHandler.javajet
@@ -0,0 +1,77 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringGuiHandler"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * $Id: RefactoringGuiHandler.javajet,v 1.1 2012/10/16 11:53:04 tarendt Exp $
+ */
+ package <%=info.getPackageName()%>;
+
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.interfaces.IGuiHandler;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+
+/**
+ * Class used for specifying gui topics of a specific model refactoring.
+ * @generated
+ */
+public class RefactoringGuiHandler implements IGuiHandler {
+
+ /**
+ * Refactoring supported by the GuiHandler.
+ * @generated
+ */
+ private Refactoring parent;
+
+ /**
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IGuiHandler#getParent()
+ * @generated
+ */
+ @Override
+ public Refactoring getParent() {
+ return parent;
+ }
+
+ /**
+ * @see oorg.eclipse.emf.refactor.refactoring.interfaces.IGuiHandler#
+ * setParent(Refactoring)
+ * @generated
+ */
+ @Override
+ public void setParent(Refactoring refactoring) {
+ this.parent = refactoring;
+ }
+
+ /**
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IGuiHandler#show()
+ * @generated
+ */
+ @Override
+ public RefactoringWizard show() {
+ return new <%=info.getPackageName()%>.RefactoringWizard
+ ((RefactoringController)this.parent.getController());
+ }
+
+ /**
+ * @see org.eclipse.emf.refactor.refactoring.interfaces.IGuiHandler#
+ * showInMenu(java.util.List)
+ * @generated
+ */
+ @Override
+ public boolean showInMenu(List<EObject> selection) {
+ for(EObject o:selection){
+ if(null != o){
+ if (o instanceof <%=info.getSelectedEObjectClass()%>) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
+ \ No newline at end of file
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringTest.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringTest.javajet
new file mode 100644
index 0000000..601cf1a
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringTest.javajet
@@ -0,0 +1,102 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringTest"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * $Id: RefactoringTest.javajet,v 1.1 2012/10/16 11:53:05 tarendt Exp $
+ */
+
+package <%=info.getPackageName()%>;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import <%=info.getPackageName()%>.RefactoringController;
+import <%=info.getPackageName()%>.RefactoringGuiHandler;
+import org.eclipse.emf.refactor.refactoring.runtime.test.JUnitTestCaseAdapter;
+import <%=info.getJar()%>.<%=info.getMetaModelName()%>Package;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Class used for running individual JUnit test cases
+ * of the specific model refactoring.
+ * @generated
+ */
+@RunWith(value = Parameterized.class)
+public class RefactoringTest extends JUnitTestCaseAdapter {
+
+ /**
+ * Number of test cases.
+ * @generated
+ */
+ private String number;
+
+ /**
+ * Constructor implementation.
+ * @param number Number of test cases.
+ * @generated
+ */
+ public RefactoringTest(String number) throws IOException {
+ super("<%=info.getRefactoringId()%>",
+ "<%=info.getNamespacePrefix()%>",
+ new File(".").getCanonicalPath(),
+ new Refactoring(null, "", "<%=info.getNamespaceUri()%>", new RefactoringGuiHandler(), new RefactoringController()));
+ register(<%=info.getMetaModelName()%>Package.eINSTANCE);
+ this.number = number;
+ }
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ List<String> testNumbers = getTestNumbers();
+ Object[][] data = new Object[testNumbers.size()][1];
+ for (int i = 0; i < testNumbers.size(); i++) {
+ data[i][0] = testNumbers.get(i);
+ }
+ return Arrays.asList(data);
+ }
+
+ private static List<String> getTestNumbers() {
+ List<String> numbers = new ArrayList<String>();
+ try {
+ String pathPrefix = new File(".").getCanonicalPath() + "/tests/" + "<%=info.getRefactoringId()%>";
+ File testCaseDir = new File(pathPrefix,"/");
+ FilenameFilter filter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.startsWith("test_");
+ }
+ };
+ String[] children = testCaseDir.list(filter);
+ if (children != null) {
+ for (String child : children) {
+ numbers.add(
+ child.substring(
+ child.indexOf('_') + 1));
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return numbers;
+ }
+
+ /**
+ * Runs the test.
+ */
+ @Test
+ public void test() {
+ System.out.println("running test test_" + number);
+ executeTestCase(number);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizard.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizard.javajet
new file mode 100644
index 0000000..5aa2229
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizard.javajet
@@ -0,0 +1,43 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringWizard"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * $Id: RefactoringWizard.javajet,v 1.1 2012/10/16 11:53:05 tarendt Exp $
+ */
+ package <%=info.getPackageName()%>;
+
+import org.eclipse.emf.refactor.refactoring.interfaces.IController;
+import org.eclipse.emf.refactor.refactoring.runtime.ltk.ui.AbstractRefactoringWizard;
+
+/**
+ * Class used for providing an implementation of an LTK
+ * RefactoringWizard in EMF Refactor.
+ * @generated
+ */
+public class RefactoringWizard
+ extends AbstractRefactoringWizard {
+
+ /**
+ * Default constructor implementation.
+ * @param controller Controller of the EMF model refactoring.
+ * @generated
+ */
+ public RefactoringWizard(IController controller) {
+ super(controller);
+ }
+
+ /**
+ * @see org.eclipse.ltk.ui.refactoring.RefactoringWizard#
+ * addUserInputPages()
+ * @generated
+ */
+ @Override
+ protected void addUserInputPages() {
+ addPage(new RefactoringWizardPage
+ (controller.getParent().getName(), (RefactoringController)controller));
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizardPage.javajet b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizardPage.javajet
new file mode 100644
index 0000000..57e9b86
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.generator/templates/RefactoringWizardPage.javajet
@@ -0,0 +1,124 @@
+<%@ jet package="org.eclipse.emf.refactor.refactoring" class="RefactoringWizardPage"
+imports="org.eclipse.emf.refactor.refactoring.generator.core"%>
+<%RefactoringInfo info = (RefactoringInfo) argument; %>
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * $Id: RefactoringWizardPage.javajet,v 1.1 2012/10/16 11:53:05 tarendt Exp $
+ */
+ package <%=info.getPackageName()%>;
+
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Class for setting model refactoring specific parameters
+ * by the user.
+ * @generated
+ */
+public class RefactoringWizardPage extends
+ UserInputWizardPage implements Listener {
+
+ /**
+ * Controller of the EMF model refactoring.
+ * @generated
+ */
+ private final RefactoringController controller;
+
+<% for (ParameterInfo pi : info.getParameters()) { %>
+ /**
+ * Label for each parameter.
+ * @generated
+ */
+ private Label <%=pi.getName()%>Label;
+
+ /**
+ * TextField for each parameter.
+ * @generated
+ */
+ private Text <%=pi.getName()%>Widget;
+<% } %>
+
+ /**
+ * Default constructor using a name and the controller of the
+ * EMF model refactoring.
+ * @param name Name of the WizardPage.
+ * @param controller Controller of the EMF model refactoring.
+ * @generated
+ */
+ public RefactoringWizardPage
+ (String name, RefactoringController controller) {
+ super(name);
+ this.controller = controller;
+ }
+
+ /**
+ * @see org.eclipse.swt.widgets.Listener#
+ * handleEvent(org.eclipse.swt.widgets.Event)
+ * @generated
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void handleEvent(Event event) {
+ getWizard().getContainer().updateButtons();
+
+<% for (ParameterInfo pi : info.getParameters()) { %>
+ if (<%=pi.getName()%>Widget != null) {
+ String <%=pi.getName()%> = <%=pi.getName()%>Widget.getText();
+ if (!<%=pi.getName()%>.isEmpty()){
+ ((RefactoringDataManagement)
+ this.controller.getDataManagementObject()).
+ getInPortByName("<%=pi.getName()%>").
+ setValue(<%=pi.getName()%>);
+ } else {
+ ((RefactoringDataManagement)
+ this.controller.getDataManagementObject()).
+ getInPortByName("<%=pi.getName()%>").
+ setValue("unspecified");
+ }
+ }
+<% } %>
+
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.IDialogPage#
+ * createControl(org.eclipse.swt.widgets.Composite)
+ * @generated
+ */
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ composite.setLayout(gl);
+
+<% for (ParameterInfo pi : info.getParameters()) { %>
+
+ <%=pi.getName()%>Label = new Label(composite, SWT.NONE);
+ <%=pi.getName()%>Label.setText("<%=pi.getDescription()%>: ");
+ <%=pi.getName()%>Label.setEnabled(true);
+
+ <%=pi.getName()%>Widget = new Text(composite, SWT.BORDER);
+ <%=pi.getName()%>Widget.setToolTipText
+ ("value of variable '<%=pi.getName()%>'");
+ <%=pi.getName()%>Widget.setEnabled(true);
+ <%=pi.getName()%>Widget.setLayoutData(gd);
+ <%=pi.getName()%>Widget.addListener(SWT.Modify, this);
+
+<% } %>
+
+ setControl(composite);
+ }
+
+}
+ \ No newline at end of file

Back to the top