Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3b2b3e43706ef43d7db52ab86c0aa53a33d8b050 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.migration.rsa.wizard;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.Config;
import org.eclipse.papyrus.migration.rsa.messages.Messages;
import org.eclipse.papyrus.migration.rsa.transformation.ImportTransformationLauncher;
import org.eclipse.papyrus.migration.rsa.wizard.pages.TransformationConfigPage;
import org.eclipse.papyrus.migration.rsa.wizard.pages.TransformationSelectionPage;
import org.eclipse.papyrus.migration.rsa.wizard.pages.DialogData;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;

/**
 * 
 * Wizard handling the selection and transformation of .emx/.epx files
 * 
 * @author Quentin Le Menez
 *
 */
public class TransformationWizard extends Wizard implements IImportWizard {

	protected IWizardPage currentPage;

	protected DialogData dialogData = new DialogData();

	protected TransformationSelectionPage selectionPage = new TransformationSelectionPage(dialogData);

	protected TransformationConfigPage configPage = new TransformationConfigPage(dialogData);


	public TransformationWizard() {
		setWindowTitle(Messages.TransformationWizard_Title);
	}

	@Override
	public void addPages() {
		this.addPage(selectionPage);
		this.addPage(configPage);

	}

	@Override
	public IWizardPage getNextPage(IWizardPage currentPage) {
		if (currentPage == selectionPage) {
			this.currentPage = configPage;
			// Reset the viewer input in order to show the newly selected elements from the selectionPage
			configPage.resetViewerInput();
			return configPage;
		}
		if (this.currentPage == configPage) {
			this.currentPage = selectionPage;
		}
		return null;
	}

	@Override
	public boolean canFinish() {
		if (currentPage == configPage) {
			return super.canFinish();
		}
		return false;
	}


	@Override
	public boolean performFinish() {
		// Set or update the unchecked elements for future executions of the plugin
		dialogData.setSelectionMap();
		importFiles();

		return true;
	}


	/**
	 *
	 * Launch the transformation with the previously selected files and configuration parameters
	 *
	 */
	protected void importFiles() {
		Config config = dialogData.getConfig();
		if (config == null) {
			return;
		}

		Set<IFile> selectedFiles = new HashSet<IFile>();
		for (Object file : dialogData.getTransformationFiles()) {
			if (file instanceof IFile) {
				selectedFiles.add((IFile) file);
			}
		}

		List<URI> urisToImport = new LinkedList<URI>();

		for (IFile selectedFile : selectedFiles) {
			URI uri = URI.createPlatformResourceURI(selectedFile.getFullPath().toString(), true);

			urisToImport.add(uri);
		}

		// The wizard's Shell will be disposed because the transformation is asynchronous. Use the Shell's parent instead
		ImportTransformationLauncher launcher = new ImportTransformationLauncher(config, this.getShell().getParent());
		launcher.run(urisToImport);
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		// TODO Auto-generated method stub

	}


}

Back to the top