Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2012-10-15 21:10:41 +0000
committertarendt2012-10-15 21:10:41 +0000
commit9e6454ec1e1d9db626d3564dbdb026eb345082ec (patch)
tree4d8bab7a961adc662b6a3df7a939ade15f82f658 /org.eclipse.emf.refactor.refactoring.configuration
parent8412153ff6eb9c6b34a12214cd128674198d965a (diff)
downloadorg.eclipse.emf.refactor.refactoring-9e6454ec1e1d9db626d3564dbdb026eb345082ec.tar.gz
org.eclipse.emf.refactor.refactoring-9e6454ec1e1d9db626d3564dbdb026eb345082ec.tar.xz
org.eclipse.emf.refactor.refactoring-9e6454ec1e1d9db626d3564dbdb026eb345082ec.zip
initial commit
Diffstat (limited to 'org.eclipse.emf.refactor.refactoring.configuration')
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/.classpath7
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/.project28
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/META-INF/MANIFEST.MF14
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/build.properties7
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/plugin.xml14
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/Activator.java52
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/Configuration.java98
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/SortedRefactoringList.java54
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/ConfigurationManager.java104
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/XMLProjectFileManager.java92
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/RefactoringsConfigurationPage.java170
-rw-r--r--org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/TableItemsMapping.java77
13 files changed, 724 insertions, 0 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/.classpath b/org.eclipse.emf.refactor.refactoring.configuration/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/.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.configuration/.project b/org.eclipse.emf.refactor.refactoring.configuration/.project
new file mode 100644
index 0000000..b9138d9
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.refactor.refactoring.configuration</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.configuration/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.refactor.refactoring.configuration/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..c537b63
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.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.configuration/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.refactoring.configuration/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..75f3618
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: RefactoringConfiguration
+Bundle-SymbolicName: org.eclipse.emf.refactor.refactoring.configuration;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-Activator: org.eclipse.emf.refactor.refactoring.configuration.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.8.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.configuration.core,
+ org.eclipse.emf.refactor.refactoring.configuration.managers
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/build.properties b/org.eclipse.emf.refactor.refactoring.configuration/build.properties
new file mode 100644
index 0000000..316d0b2
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ bin/,\
+ src/
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/plugin.xml b/org.eclipse.emf.refactor.refactoring.configuration/plugin.xml
new file mode 100644
index 0000000..25d585f
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/plugin.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ category="org.eclipse.emf.refactor.propertypage"
+ class="org.eclipse.emf.refactor.refactoring.configuration.ui.RefactoringsConfigurationPage"
+ id="org.eclipse.emf.refactor.refactoring.configuration"
+ name="Refactorings configuration">
+ </page>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/Activator.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/Activator.java
new file mode 100644
index 0000000..1edf33f
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/Activator.java
@@ -0,0 +1,52 @@
+package org.eclipse.emf.refactor.refactoring.configuration;
+
+import org.eclipse.emf.refactor.refactoring.configuration.managers.ConfigurationManager;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.emf.refactor.refactoring.configuration"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ ConfigurationManager.getInstance();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/Configuration.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/Configuration.java
new file mode 100644
index 0000000..6261ff8
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/Configuration.java
@@ -0,0 +1,98 @@
+package org.eclipse.emf.refactor.refactoring.configuration.core;
+
+import java.util.LinkedList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.managers.RefactoringManager;
+
+/**
+ * This class provides a container for the project-specific metric configurations.
+ *
+ * @author Pawel Stepien
+ */
+public class Configuration {
+
+ private IProject project;
+ private boolean[] selection = null;
+
+ /**
+ * Constructor which creates a new configuration for a given project.
+ *
+ * @param project
+ */
+ public Configuration(IProject project) {
+ this.project = project;
+ }
+
+ /**
+ * Sets the metric selection for this project.
+ * This method awaits a boolean array as parameter.
+ *
+ * @param selection
+ */
+ public void setSelection(boolean[] selection) {
+ this.selection = selection;
+ }
+
+ /**
+ * Returns the the exact date of the calculation.
+ * This method awaits a <i>LinkedList</i> containing the ID's of the selected metrics
+ * as parameter.
+ *
+ * @param idList
+ */
+ public void setSelection(LinkedList<String> idList) {
+ this.selection = getSelection(idList);
+ }
+
+ /**
+ * Returns the the project for that this configuration has been made.
+ *
+ * @return project
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * Returns a <i>LinkedList</i> containing all refactoring selected for this project..
+ *
+ * @return selectedMetrics
+ */
+ public LinkedList<Refactoring> getSelectedRefactorings() {
+ if(selection==null)
+ return new LinkedList<Refactoring>();
+ final int nuberOfRefactorings = RefactoringManager.getAllRefactorings().size();
+ LinkedList<Refactoring> selectedRefactorings = new LinkedList<Refactoring>();
+ for (int index = 0; index < nuberOfRefactorings; index++) {
+ if (selection[index] == true)
+ selectedRefactorings.add(RefactoringManager.getAllRefactorings().get(index));
+ }
+ return selectedRefactorings;
+ }
+
+ private boolean[] getSelection(LinkedList<String> idList){
+ final LinkedList<Refactoring> allRefactorings = RefactoringManager.getAllRefactorings();
+ boolean[] selection = new boolean[allRefactorings.size()];
+ for(int index=0; index<selection.length; index++)
+ selection[index]=false;
+ int index;
+ for(String id : idList){
+ index = isInList(id, allRefactorings);
+ if (index>=0){
+ selection[index]=true;
+ }
+ }
+ return selection;
+ }
+
+ private int isInList(String id, LinkedList<Refactoring> refactorings){
+ for(int index=0; index < refactorings.size(); index++){
+ if(refactorings.get(index).getId().equals(id))
+ return index;
+ }
+ return -1;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/SortedRefactoringList.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/SortedRefactoringList.java
new file mode 100644
index 0000000..28b5c5f
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/core/SortedRefactoringList.java
@@ -0,0 +1,54 @@
+package org.eclipse.emf.refactor.refactoring.configuration.core;
+
+import java.util.LinkedList;
+
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+
+/**
+ * Helper class for the property page providing a sorted list of the installed smells to be used
+ * <br>- by the pages table.
+ *
+ * @author Matthias Burhenne
+ *
+ */
+
+public class SortedRefactoringList {
+ private LinkedList<LinkedList<Refactoring>> refactoringList;
+
+ public SortedRefactoringList(LinkedList<Refactoring> rawRefactoringList) {
+ refactoringList = new LinkedList<LinkedList<Refactoring>>();
+ for (int position = 0; position < rawRefactoringList.size(); position++) {
+ addRefactoringToList(rawRefactoringList.get(position));
+ }
+ }
+
+ public int getSize() {
+ return refactoringList.size();
+ }
+
+ public LinkedList<Refactoring> get(int index){
+ return refactoringList.get(index);
+ }
+
+ public LinkedList<LinkedList<Refactoring>> getRefactoringList() {
+ return refactoringList;
+ }
+
+ private void addRefactoringToList(Refactoring refactoring) {
+ final String metamodel = refactoring.getNamespaceUri();
+ LinkedList<Refactoring> list = getMetamodelList(metamodel);
+ if (list == null) {
+ list = new LinkedList<Refactoring>();
+ refactoringList.add(list);
+ }
+ list.add(refactoring);
+ }
+
+ public LinkedList<Refactoring> getMetamodelList(String metamodel) {
+ for (LinkedList<Refactoring> list : refactoringList) {
+ if (list.get(0).getNamespaceUri().equals(metamodel))
+ return list;
+ }
+ return null;
+ }
+}
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/ConfigurationManager.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/ConfigurationManager.java
new file mode 100644
index 0000000..f8de709
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/ConfigurationManager.java
@@ -0,0 +1,104 @@
+package org.eclipse.emf.refactor.refactoring.configuration.managers;
+
+import java.util.LinkedList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.refactor.refactoring.configuration.core.Configuration;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.managers.RefactoringManager;
+
+
+/**
+ * This class is the main controller. It provides Methods needed to coordinate all
+ * EMFMetrics system tasks.
+ *
+ * @author Pawel Stepien
+ */
+public class ConfigurationManager {
+
+ private static LinkedList<Configuration> configurations;
+ private static LinkedList<Refactoring> allRefactorings = null;
+
+ private static ConfigurationManager instance;
+
+ private ConfigurationManager() {
+ configurations = new LinkedList<Configuration>();
+ allRefactorings = RefactoringManager.getAllRefactorings();
+ System.out.println("ConfigurationManager initialized!");
+ }
+
+ public static ConfigurationManager getInstance() {
+ if (instance == null) {
+ instance = new ConfigurationManager();
+ }
+ return instance;
+ }
+
+ private static LinkedList<Refactoring> getAllRefactorings() {
+ if (allRefactorings == null)
+ allRefactorings = RefactoringManager.getAllRefactorings();
+ return allRefactorings;
+ }
+
+ /**
+ * Saves the actual Refactoring configuration for a given project into a File.
+ *
+ * @param project
+ */
+ public static void saveConfiguration(IProject project) {
+ XMLProjectFileManager.saveConfiguration(getConfiguration(project));
+ }
+
+ private static Configuration loadConfiguration(IProject project) {
+ return XMLProjectFileManager.loadConfiguration(project);
+ }
+
+ /**
+ * Returns a LinkedList containing all selected Refactorings for a given project.
+ *
+ * @param project
+ *
+ * @return selectedRefactorings
+ */
+ public static LinkedList<Refactoring> getSelectedRefactorings(IProject project){
+ Configuration configuration = getConfiguration(project);
+ return configuration.getSelectedRefactorings();
+ }
+
+ /**
+ * Saves a Refactoring selection for a given project.
+ *
+ * @param project
+ * @param Refactorings selection
+ */
+ public static void setConfiguration(IProject project, boolean[] selection){
+ Configuration configuration = getConfiguration(project);
+ configuration.setSelection(selection);
+ }
+
+ public static Configuration getConfiguration(IProject project) {
+ Configuration configuration = null;
+ if(! configurations.isEmpty()) {
+ for (Configuration tempConfiguration : configurations) {
+ if (tempConfiguration.getProject().equals(project))
+ configuration = tempConfiguration;
+ }
+ }
+ if(configuration == null) {
+ configuration = loadConfiguration(project);
+ }
+ if(configuration == null) {
+ configuration = new Configuration(project);
+ LinkedList<String> refactoringIdList = new LinkedList<String>();
+ if (allRefactorings == null) getAllRefactorings();
+ for (Refactoring refactoring : allRefactorings) {
+ refactoringIdList.add(refactoring.getId());
+ System.out.println("add: " + refactoring.getId());
+ }
+ configuration.setSelection(refactoringIdList);
+ }
+ configurations.add(configuration);
+ return configuration;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/XMLProjectFileManager.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/XMLProjectFileManager.java
new file mode 100644
index 0000000..6bcb92d
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/managers/XMLProjectFileManager.java
@@ -0,0 +1,92 @@
+package org.eclipse.emf.refactor.refactoring.configuration.managers;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.refactor.refactoring.configuration.core.Configuration;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.managers.XMLManager;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class XMLProjectFileManager extends XMLManager{
+
+ private static final String REF_CONFIG = ".emfrefactorings.xml";
+ private static final String CONFIGURATOR_TAG = "refactoringConfiguration";
+
+ public static void saveConfiguration(Configuration configurator) {
+ final DocumentBuilder builder = createDocumentBuilder();
+ if (builder != null){
+ final Document doc = builder.newDocument();
+ final Element root = doc.createElement(CONFIGURATOR_TAG);
+ doc.appendChild(root);
+ for (Refactoring refactoring : configurator.getSelectedRefactorings()){
+ Element metricEntry = doc.createElement(REFACTORING_TAG);
+ Element metricId = doc.createElement(REFACTORING_ID_TAG);
+ metricId.setTextContent(refactoring.getId());
+ metricEntry.appendChild(metricId);
+ root.appendChild(metricEntry);
+ }
+ final Transformer transformer = createTransformer();
+ final DOMSource source = new DOMSource(doc);
+ final java.net.URI uri = configurator.getProject().getLocationURI();
+ StreamResult result = new StreamResult(uri + "/" + REF_CONFIG);
+ try {
+ transformer.transform(source, result);
+ } catch (final TransformerException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static Configuration loadConfiguration(IProject project){
+ if(! configurationFileExists(project)) {
+ return null;
+ }
+ Configuration configurator = new Configuration(project);
+ final DocumentBuilder builder = createDocumentBuilder();
+ if (builder != null){
+ Document doc = null;
+ try {
+ java.net.URI uri = project.getLocationURI();
+ doc = builder.parse(uri + "/" + REF_CONFIG);
+ } catch (final SAXException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ if (doc != null) {
+ Element root = doc.getDocumentElement();
+ NodeList entryList = root.getElementsByTagName(REFACTORING_TAG);
+ LinkedList<String> metricIdList = new LinkedList<String>();
+ for (int i=0; i < entryList.getLength(); i++){
+ Element entry = (Element) entryList.item(i);
+ NodeList nodeList = entry.getElementsByTagName(REFACTORING_ID_TAG);
+ Element metricId = (Element) nodeList.item(0);
+ metricIdList.add(metricId.getTextContent());
+ }
+ configurator.setSelection(metricIdList);
+ }
+ }
+ return configurator;
+ }
+
+ private static boolean configurationFileExists(IProject project) {
+ java.net.URI uri = project.getLocationURI();
+ String path = uri.getPath() + "/" + REF_CONFIG;
+ File file = new File(path);
+ return file.exists();
+ }
+
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/RefactoringsConfigurationPage.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/RefactoringsConfigurationPage.java
new file mode 100644
index 0000000..529a6aa
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/RefactoringsConfigurationPage.java
@@ -0,0 +1,170 @@
+package org.eclipse.emf.refactor.refactoring.configuration.ui;
+
+import java.util.LinkedList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.refactor.refactoring.configuration.core.SortedRefactoringList;
+import org.eclipse.emf.refactor.refactoring.configuration.managers.ConfigurationManager;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.managers.ProjectManager;
+import org.eclipse.emf.refactor.refactoring.managers.RefactoringManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+public class RefactoringsConfigurationPage extends PropertyPage {
+
+ private IProject project;
+ private TableItemsMapping mapping;
+ private SortedRefactoringList refactoringList;
+ private Table[] refactoringsTables;
+
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ this.getDefaultsButton().setText("(De-)Select All");
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite panel = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.verticalSpacing = 20;
+ layout.horizontalSpacing = 10;
+ layout.marginHeight = 20;
+ layout.marginWidth = 10;
+ layout.numColumns = 1;
+ panel.setLayout(layout);
+ refactoringList = new SortedRefactoringList(RefactoringManager.getAllRefactorings());
+ mapping = new TableItemsMapping(RefactoringManager.getAllRefactorings());
+ createHeader(panel);
+ createRefactoringTables(panel);
+ project = ProjectManager.getActualProjectForPropertyPage(this);
+ fillTables();
+ loadSelection();
+ return panel;
+ }
+
+ @Override
+ public boolean performOk() {
+ saveSelection();
+ ConfigurationManager.getInstance();
+ ConfigurationManager.saveConfiguration(project);
+ return true;
+ }
+
+ @Override
+ protected void performApply() {
+ performOk();
+ }
+
+ @Override
+ protected void performDefaults() {
+ boolean allSelected = true;
+ for (int index = 0; index < mapping.getSize(); index++) {
+ if(! mapping.getTableItem(index).getChecked()){
+ allSelected = false;
+ break;
+ }
+ }
+ for (int index = 0; index < mapping.getSize(); index++) {
+ mapping.getTableItem(index).setChecked(!allSelected);
+ }
+ }
+
+ private void createHeader(Composite panel) {
+ Text text = new Text(panel, SWT.LEFT);
+ text.setBackground(panel.getBackground());
+ text.setText("Please select EMF refactorings from the list below to be supported by the project.");
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ text.setLayoutData(gridData);
+ }
+
+ private void createRefactoringTables(Composite panel) {
+ TabFolder tabs = new TabFolder(panel, SWT.NULL);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalAlignment = GridData.FILL;
+ tabs.setLayoutData(gridData);
+ refactoringsTables = new Table[refactoringList.getRefactoringList().size()];
+ for (int index = 0; index < refactoringList.getRefactoringList().size(); index++) {
+ TabItem tabItem = new TabItem(tabs, SWT.LEFT);
+ tabItem.setText(""+ refactoringList.getRefactoringList().get(index).get(0)
+ .getNamespaceUri());
+ Composite composite = new Composite(tabs, SWT.NULL);
+ tabItem.setControl(composite);
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+ refactoringsTables[index] = new Table(composite, SWT.CHECK | SWT.SINGLE
+ | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
+ refactoringsTables[index].setHeaderVisible(true);
+ gridData = new GridData(GridData.FILL_BOTH);
+ refactoringsTables[index].setLayoutData(gridData);
+ TableColumn col;
+ col = new TableColumn(refactoringsTables[index], SWT.CENTER
+ | SWT.READ_ONLY);
+ col.setText("Selected");
+ col.setWidth(60);
+ col = new TableColumn(refactoringsTables[index], SWT.LEFT
+ | SWT.READ_ONLY);
+ col.setText("Name");
+ col.setWidth(300);
+ col = new TableColumn(refactoringsTables[index], SWT.LEFT
+ | SWT.READ_ONLY);
+ col.setText("Description");
+ col.setWidth(100);
+
+ final Table currentTable = refactoringsTables[index];
+
+ final TableEditor tableEditor = new TableEditor(currentTable);
+ // The editor must have the same size as the cell and must
+ // not be any smaller than 50 pixels.
+ tableEditor.horizontalAlignment = SWT.LEFT;
+ tableEditor.grabHorizontal = true;
+ tableEditor.minimumWidth = 100;
+ }
+ }
+
+ private void fillTables() {
+ for (int index = 0; index < refactoringList.getSize(); index++) {
+ LinkedList<Refactoring> metamodelList = refactoringList.get(index);
+ for(Refactoring refactoring : metamodelList) {
+ TableItem item = new TableItem(refactoringsTables[index], SWT.NONE);
+ item.setText(1, refactoring.getName());
+ // TODO insert field description to refactorings
+// item.setText(2, refactoring.getDescription());
+ item.setText(2, "");
+ mapping.setItemForRefactoring(refactoring, item);
+ }
+ }
+ }
+
+ private void loadSelection() {
+ ConfigurationManager.getInstance();
+ LinkedList<Refactoring> selectedRefactorings = ConfigurationManager.getSelectedRefactorings(project);
+ if(selectedRefactorings==null || selectedRefactorings.isEmpty())
+ for(int i=0; i < mapping.getSize(); i++)
+ mapping.getTableItem(i).setChecked(true);
+ for (Refactoring refactoring : selectedRefactorings)
+ mapping.getTableItem(refactoring).setChecked(true);
+ }
+
+ private void saveSelection() {
+ boolean[] selection = new boolean[mapping.getSize()];
+ for (int index = 0; index < mapping.getSize(); index++) {
+ selection[index] = mapping.getTableItem(index).getChecked();
+ }
+ ConfigurationManager.getInstance();
+ ConfigurationManager.setConfiguration(project, selection);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/TableItemsMapping.java b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/TableItemsMapping.java
new file mode 100644
index 0000000..c09bb64
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.configuration/src/org/eclipse/emf/refactor/refactoring/configuration/ui/TableItemsMapping.java
@@ -0,0 +1,77 @@
+package org.eclipse.emf.refactor.refactoring.configuration.ui;
+
+import java.util.LinkedList;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.swt.widgets.TableItem;
+
+public class TableItemsMapping {
+
+ private TableItemMapping[] tableItems;
+
+ public TableItemsMapping(LinkedList<Refactoring> inputList) {
+ LinkedList<TableItemMapping> tableItemsList = new LinkedList<TableItemMapping>();
+ for (Refactoring Refactoring : inputList) {
+ tableItemsList.add(new TableItemMapping(Refactoring));
+ }
+ tableItems = new TableItemMapping[tableItemsList.size()];
+ for (int i = 0; i < tableItemsList.size(); i++) {
+ tableItems[i] = tableItemsList.get(i);
+ }
+ }
+
+ public int getSize() {
+ return tableItems.length;
+ }
+
+ public void setItemForRefactoring(Refactoring Refactoring, TableItem item) {
+ int index = getTableItemIndex(Refactoring);
+ setItem(index, item);
+ }
+
+ public Refactoring getRefactoring(int index){
+ return tableItems[index].getRefactoring();
+ }
+
+ public TableItem getTableItem(int index) {
+ return tableItems[index].getItem();
+ }
+
+ public TableItem getTableItem(Refactoring refactoring) {
+ return tableItems[getTableItemIndex(refactoring)].getItem();
+ }
+
+ private void setItem(int index, TableItem item) {
+ tableItems[index].setItem(item);
+ }
+
+ private int getTableItemIndex(Refactoring refactoring) {
+ for (int i = 0; i < tableItems.length; i++) {
+ if (tableItems[i].getRefactoring().equals(refactoring))
+ return i;
+ }
+ return -1;
+ }
+
+ private class TableItemMapping {
+ private TableItem item;
+ private Refactoring refactoring;
+
+ private TableItemMapping(Refactoring refactoring) {
+ this.refactoring = refactoring;
+ this.item = null;
+ }
+
+ private void setItem(TableItem item) {
+ this.item = item;
+ }
+
+ private TableItem getItem() {
+ return item;
+ }
+
+ private Refactoring getRefactoring() {
+ return refactoring;
+ }
+
+ }
+}

Back to the top