generation wizard + page added
diff --git a/org.eclipse.emf.refactor.metrics.henshin/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.metrics.henshin/META-INF/MANIFEST.MF
index 1c7752f..772d7a7 100644
--- a/org.eclipse.emf.refactor.metrics.henshin/META-INF/MANIFEST.MF
+++ b/org.eclipse.emf.refactor.metrics.henshin/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@
Bundle-Activator: org.eclipse.emf.refactor.metrics.henshin.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.8.0",
org.eclipse.emf.ecore;bundle-version="2.8.1",
org.eclipse.emf.refactor.metrics;bundle-version="0.7.0",
org.eclipse.emf.refactor.metrics.generator;bundle-version="0.7.0",
diff --git a/org.eclipse.emf.refactor.metrics.henshin/src/org/eclipse/emf/refactor/metrics/henshin/HenshinDataWizardPage.java b/org.eclipse.emf.refactor.metrics.henshin/src/org/eclipse/emf/refactor/metrics/henshin/HenshinDataWizardPage.java
new file mode 100644
index 0000000..12a55f8
--- /dev/null
+++ b/org.eclipse.emf.refactor.metrics.henshin/src/org/eclipse/emf/refactor/metrics/henshin/HenshinDataWizardPage.java
@@ -0,0 +1,182 @@
+package org.eclipse.emf.refactor.metrics.henshin;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.refactor.metrics.henshin.managers.HenshinFileManager;
+import org.eclipse.emf.refactor.metrics.managers.FileManager;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+public class HenshinDataWizardPage extends WizardPage implements Listener {
+
+ private static final String HENSHIN_EXT = ".henshin";
+ private static final String PAGE_NAME = "org.eclipse.emf.refactor.metrics.HenshinDataWizardPage";
+ private static final String TITLE = "New Metric: Henshin Data";
+ private static final String DESCRIPTION = "Please specify the corresponding Henshin transformation files.";
+ private Combo transformationCombo;
+ private String transformation;
+
+ public HenshinDataWizardPage() {
+ super(PAGE_NAME);
+ setTitle(TITLE);
+ setDescription(DESCRIPTION);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ final Shell shell = parent.getShell();
+ Composite container = new Composite(parent, SWT.NULL);
+ final GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ container.setLayout(layout);
+ setControl(container);
+ createContent(container, shell);
+ this.setPageComplete(false);
+ }
+
+ @Override
+ public boolean canFlipToNextPage() {
+ return false;
+ }
+
+ @Override
+ public void handleEvent(Event event) {
+ updatePageComplete();
+ getWizard().getContainer().updateButtons();
+ }
+
+ private void createContent(Composite container, Shell shell) {
+ Label label;
+ Button button;
+ GridData gridData;
+ Group group;
+ GridLayout layout;
+ group = new Group(container, SWT.NONE);
+ group.setText("Henshin file");
+ layout = new GridLayout();
+ layout.numColumns = 3;
+ group.setLayout(layout);
+ gridData = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(gridData);
+
+ // - Transf -
+ label = new Label(group, SWT.NONE);
+ label.setText("Metric calculation file:");
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+ transformationCombo = new Combo(group, SWT.READ_ONLY);
+ transformationCombo.addListener(SWT.Modify, this);
+ transformationCombo
+ .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ button = new Button(group, SWT.NONE);
+ button.addSelectionListener(new HenshinDataSelectionAdapter(shell,
+ transformationCombo));
+ button.setText("Import");
+ }
+
+ protected void initContents() {
+ IProject project = ((NewMetricWizardHenshin) getWizard()).getTargetProject();
+ String path = project.getLocationURI().getPath() + NewMetricWizardHenshin.TRANSFORMATIONS_DIR;
+ setCombos(HenshinFileManager.getAllHenshinFiles(path));
+ }
+
+ private void setCombos(File[] files) {
+ transformationCombo.removeAll();
+ if (files != null) {
+ for (File file : files) {
+ transformationCombo.add(file.getName());
+ }
+ }
+ }
+
+ /**
+ * Überprüft die inhalte der Textfelder und erzeugt entschprechende
+ * Meldungen im Wizardfenster.
+ */
+ private void updatePageComplete() {
+ if (!checkTransformationTextField()) {
+ setMessage("Metric-Calculation file not specified, " +
+ "or file does not exist.", ERROR);
+ this.setPageComplete(false);
+ getWizard().getContainer().updateButtons();
+ } else {
+ setMessage("");
+ saveContents();
+ this.setPageComplete(true);
+ getWizard().getContainer().updateButtons();
+ }
+ }
+
+ private boolean checkTransformationTextField() {
+ final String transf = this.transformationCombo.getText();
+ if (!transf.isEmpty())
+ return true;
+ return false;
+ }
+
+ private void saveContents() {
+ this.transformation = this.transformationCombo.getText();
+ }
+
+ public String getTransformation() {
+ return transformation;
+ }
+
+ private void addToCombo(String name){
+ transformationCombo.add(name,0);
+ }
+
+
+ // -------------------------------------------------------------------------------
+ private class HenshinDataSelectionAdapter extends SelectionAdapter {
+
+ private final Combo combo;
+ private final Shell shell;
+
+ public void widgetSelected(SelectionEvent e) {
+ String result = browseForTransformation(shell);
+ if (result != null)
+ if (!result.isEmpty()) {
+ result=result.replace('\\', '/');
+ int i = result.lastIndexOf("/");
+ String name = result.substring(i + 1);
+ String destination = ((NewMetricWizardHenshin) getWizard()).getTargetProject().getLocationURI().getPath()
+ + NewMetricWizardHenshin.TRANSFORMATIONS_DIR;
+ FileManager.copyFile(result, destination, name);
+ addToCombo(name);
+ combo.select(0);
+ }
+ }
+
+ private HenshinDataSelectionAdapter(Shell shell, Combo combo) {
+ this.shell = shell;
+ this.combo = combo;
+ }
+
+ private String browseForTransformation(Shell shell) {
+ FileDialog fd = new FileDialog(shell, SWT.OPEN);
+ fd.setText("Select Henshin file");
+ if (((NewMetricWizardHenshin) getWizard()).getTargetProject() != null) {
+ fd.setFilterPath(((NewMetricWizardHenshin) getWizard()).getTargetProject().getLocation().toString());
+ }
+ String[] filterExt = { "*" + HENSHIN_EXT };
+ fd.setFilterExtensions(filterExt);
+ String selected = fd.open();
+ return selected;
+ }
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.metrics.henshin/src/org/eclipse/emf/refactor/metrics/henshin/NewMetricWizardHenshin.java b/org.eclipse.emf.refactor.metrics.henshin/src/org/eclipse/emf/refactor/metrics/henshin/NewMetricWizardHenshin.java
new file mode 100644
index 0000000..a4fd0db
--- /dev/null
+++ b/org.eclipse.emf.refactor.metrics.henshin/src/org/eclipse/emf/refactor/metrics/henshin/NewMetricWizardHenshin.java
@@ -0,0 +1,194 @@
+package org.eclipse.emf.refactor.metrics.henshin;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.LinkedList;
+
+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.core.runtime.IProgressMonitor;
+import org.eclipse.emf.refactor.metrics.generator.interfaces.INewMetricWizard;
+import org.eclipse.emf.refactor.metrics.generator.managers.GenerationManager;
+import org.eclipse.emf.refactor.metrics.generator.ui.MetricBasicDataWizardPage;
+import org.eclipse.emf.refactor.metrics.managers.MetricManager;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class NewMetricWizardHenshin extends Wizard implements INewWizard, INewMetricWizard {
+
+ protected static final String TRANSFORMATIONS_DIR = "/transformations/";
+ private final String WINDOW_TITLE = "New Metric";
+ private MetricBasicDataWizardPage basicDataPage;
+ private HenshinDataWizardPage henshinPage;
+ private String name, id, description, metamodel, context, jar;
+ private LinkedList<IProject> projects;
+ private IProject targetProject;
+ private String importPackage;
+
+ public NewMetricWizardHenshin() { }
+
+ public NewMetricWizardHenshin(String metaModel, String contextType) {
+ metamodel = metaModel;
+ context = contextType;
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ initProjects();
+ }
+
+ @Override
+ public void addPages() {
+ setWindowTitle(WINDOW_TITLE);
+ basicDataPage = new MetricBasicDataWizardPage();
+ if (metamodel != null && ! metamodel.isEmpty()
+ && context != null && ! context.isEmpty()) {
+ setMetamodelAndContext(metamodel, context);
+ }
+ addPage(basicDataPage);
+ henshinPage = new HenshinDataWizardPage();
+ addPage(henshinPage);
+ }
+
+ @Override
+ public boolean canFinish() {
+ return (basicDataPage.isPageComplete() && henshinPage.isPageComplete());
+ }
+
+ @Override
+ public boolean performFinish() {
+ try{
+ getContainer().run(true, true, new IRunnableWithProgress(){
+ public void run(IProgressMonitor monitor)throws InvocationTargetException, InterruptedException{
+ GenerationManager.getInstance();
+ GenerationManager.createNewMetric(monitor, getMetricInfo(), targetProject);
+ }
+ });
+ }
+ catch(InvocationTargetException e){
+ e.printStackTrace();
+ return false;
+ }
+ catch(InterruptedException e){
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private void initProjects(){
+ this.projects = new LinkedList<IProject>();
+ IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject project : allProjects) {
+ if (project.isOpen()) {
+ IProjectNature nature = null;
+ try {
+ nature = project.getNature("org.eclipse.pde.PluginNature");
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ if (null != nature)
+ this.projects.add(project);
+ }
+ }
+ }
+
+ private HenshinMetricInfo getMetricInfo() {
+ MetricManager.getInstance();
+ String proj = this.targetProject.getLocation().toString();
+ String transformation = henshinPage.getTransformation();
+ HenshinMetricInfo info = new HenshinMetricInfo(name, id, description,
+ metamodel, context, proj, getJar(), importPackage, transformation);
+ return info;
+ }
+
+ private String getJar() {
+ return jar;
+ }
+
+ public MetricBasicDataWizardPage getDataPage() {
+ return basicDataPage;
+ }
+
+ public LinkedList<IProject> getProjects() {
+ return projects;
+ }
+
+ public IProject getTargetProject() {
+ return targetProject;
+ }
+
+ public String getMetamodel() {
+ return metamodel;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setMetamodel(String metamodel) {
+ this.metamodel = metamodel;
+ }
+
+ public void setContext(String context) {
+ this.context = context;
+ }
+
+ public void setTargetProject(String projectName){
+ for (IProject project : projects)
+ if (project.getName().equals(projectName))
+ this.targetProject = project;
+ }
+
+ public void setJar(String jar) {
+ this.jar = jar;
+ }
+
+ public HenshinDataWizardPage getHenshinPage() {
+ return henshinPage;
+ }
+
+ @Override
+ public int getPageNumbers() {
+ return 2;
+ }
+
+ @Override
+ public WizardPage getSecondPage() {
+ return this.henshinPage;
+ }
+
+ @Override
+ public void setImportPackage(String importPackage) {
+ this.importPackage = importPackage;
+ }
+
+ @Override
+ public void updateSecondPage() {
+ henshinPage.initContents();
+ }
+
+ @Override
+ public void setMetamodelAndContext(String metamodel, String contextType) {
+ basicDataPage.setMetamodel(metamodel);
+ basicDataPage.setContextType(contextType);
+ }
+
+}