Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 53a4ffff4df1e2dbc84718e53c8ec258529bd47b (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
/*****************************************************************************
 * Copyright (c) 2011 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:
 *  Ernest Wozniak (CEA LIST) ernest.wozniak@cea.fr - Initial API and implementation
 *  Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - modification
 *****************************************************************************/
package org.eclipse.papyrus.dsml.validation.generation.wizard;

import org.eclipse.core.resources.IProject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IConstraintsManager;
import org.eclipse.pde.internal.ui.wizards.plugin.NewPluginProjectWizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Profile;

/**
 * This class represents the plugin project wizard and triggers creation of an
 * EMF Validation plugin when user clicks finish button on a plugin creation
 * wizard.
 * 
 * 
 */
public class CreateEMFValidationProject extends NewPluginProjectWizard {

	private static final String GENERATION_MESSAGE = "Generation of EMF Validation Plugin";

	private IConstraintsManager constraintsManager;

	private JavaContentGenerator generateAllJava;


	private Profile selectedProfile;

	private EPackage definition = null;

	/**
	 * 
	 * Constructor.
	 * 
	 * @param selectedProfile
	 * @param constraintsExtractor
	 */
	public CreateEMFValidationProject(Profile selectedProfile, IConstraintsManager constraintsExtractor, EPackage definition) {
		super();
		setWindowTitle(GENERATION_MESSAGE);
		this.constraintsManager = constraintsExtractor;
		this.selectedProfile = selectedProfile;
		this.definition = definition;
	}

	@Override
	public IWizardPage getNextPage(IWizardPage page) {
		if(page == fContentPage) { //Remove the template page
			return null;
		}
		return super.getNextPage(page);
	}

	@Override
	public void addPages() {
		super.addPages();
	}

	/**
	 * run the dialog
	 */
	public void openDialog() {
		Shell frame = new Shell(SWT.SHELL_TRIM);
		WizardDialog dialog = new WizardDialog(frame, this);
		dialog.open();
	}

	@Override
	public boolean performFinish() {
		boolean result = super.performFinish();
		if(result) {
			IProject project = this.fMainPage.getProjectHandle();
			try {

				//generate java code
				generateAllJava = new JavaContentGenerator(project, selectedProfile);
				generateAllJava.run();
				//generate plugin + extension point
				ValidationPluginGenerator.instance.generate(project, this, constraintsManager, definition);


				project.refreshLocal(IProject.DEPTH_INFINITE, null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return result;
	}

}

Back to the top