Skip to main content
summaryrefslogtreecommitdiffstats
blob: ecd0362c3f0809f2b4addcf7f090375c36b3c485 (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
/*******************************************************************************
 *  Copyright (c) 2008  Oracle. 
 *  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: 
 *  	Oracle - initial API and implementation
 *******************************************************************************/
package org.eclipse.jpt.ui.internal.actions;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jpt.core.JpaFacet;
import org.eclipse.jpt.ui.JptUiPlugin;
import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationOperation;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard;

public class MigrateJavaProjectAction implements IObjectActionDelegate
{
	private ISelection currentSelection;
	
	
	public MigrateJavaProjectAction() {
		super();
	}
	
	
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// do nothing
	}
	
	public void selectionChanged(IAction action, ISelection selection) {
		this.currentSelection = selection;
	}
	
	public void run(IAction action) {
		// This action is currently enabled only for a singly selected, java,
		// non-faceted IProject
		IProject project = (IProject) ((IStructuredSelection) currentSelection).getFirstElement();
		execute(project);
	}
	
	private void execute(IProject project) {
		// add facets nature, java facet, and utility facet to project
		JavaProjectMigrationOperation operation = 
			J2EEProjectUtilities.createFlexJavaProjectForProjectOperation(project, false);
		operation.execute(null, null);
		
		IFacetedProject facetedProject;
		try {
			// get the faceted project
			facetedProject = ProjectFacetsManager.create(project);
		}
		catch (CoreException ce) {
			JptUiPlugin.log(ce);
			return;
		}
		
		// launch the UI with JPA facet preselected
		final ModifyFacetedProjectWizard wizard = new ModifyFacetedProjectWizard(facetedProject);
		IFacetedProjectWorkingCopy facetedProjectWorkingCopy = wizard.getFacetedProjectWorkingCopy();
		IProjectFacetVersion fv = JpaFacet.FACET.getDefaultVersion();
		facetedProjectWorkingCopy.addProjectFacet(fv);
		
		final WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
		dialog.open();
	}
}

Back to the top