1 17 package org.eclipse.emf.codegen.ecore.ui; 18 19 import java.util.Collections ; 20 21 import org.eclipse.core.resources.IProject; 22 import org.eclipse.core.runtime.IPath; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.Path; 25 import org.eclipse.core.runtime.Platform; 26 import org.eclipse.jface.viewers.ISelection; 27 import org.eclipse.jface.viewers.IStructuredSelection; 28 import org.eclipse.jface.viewers.StructuredSelection; 29 import org.eclipse.jface.wizard.Wizard; 30 import org.eclipse.ui.INewWizard; 31 import org.eclipse.ui.IWorkbench; 32 import org.eclipse.ui.IWorkbenchPage; 33 import org.eclipse.ui.IWorkbenchPart; 34 import org.eclipse.ui.actions.WorkspaceModifyOperation; 35 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; 36 import org.eclipse.ui.part.ISetSelectionTarget; 37 38 import org.eclipse.emf.codegen.ecore.Generator; 39 import org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin; 40 import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; 41 42 43 46 public class EmptyProjectWizard extends Wizard implements INewWizard 47 { 48 protected IWorkbench workbench; 49 protected IPath genModelProjectLocation; 50 protected IPath genModelContainerPath; 51 protected IProject project; 52 53 public void init(IWorkbench workbench, IStructuredSelection selection) 54 { 55 this.workbench = workbench; 56 setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(GenModelEditPlugin.INSTANCE.getImage("full/wizban/NewEmptyEMFProject"))); 57 setWindowTitle(GenModelEditPlugin.INSTANCE.getString("_UI_NewEmptyProject_title")); 58 } 59 60 public void addPages() 61 { 62 WizardNewProjectCreationPage newProjectCreationPage = new WizardNewProjectCreationPage("NewProjectCreationPage") 63 { 64 protected boolean validatePage() 65 { 66 if (super.validatePage()) 67 { 68 IPath locationPath = getLocationPath(); 69 genModelProjectLocation = Platform.getLocation().equals(locationPath) ? null : locationPath; 70 IPath projectPath = getProjectHandle().getFullPath(); 71 genModelContainerPath = projectPath.append("src"); 72 return true; 73 } 74 else 75 { 76 return false; 77 } 78 } 79 }; 80 81 newProjectCreationPage.setTitle(GenModelEditPlugin.INSTANCE.getString("_UI_EmptyProject_title")); 82 newProjectCreationPage.setDescription(GenModelEditPlugin.INSTANCE.getString("_UI_EmptyProject_description")); 83 addPage(newProjectCreationPage); 84 } 85 86 public boolean performFinish() 87 { 88 WorkspaceModifyOperation operation = new WorkspaceModifyOperation() 89 { 90 protected void execute(IProgressMonitor progressMonitor) 91 { 92 try 93 { 94 project = Generator.createEMFProject( 95 new Path(genModelContainerPath.toString()), 96 genModelProjectLocation, 97 Collections.EMPTY_LIST, 98 progressMonitor, 99 Generator.EMF_MODEL_PROJECT_STYLE); 100 } 101 catch (Exception exception) 102 { 103 GenModelEditPlugin.INSTANCE.log(exception); 104 } 105 finally 106 { 107 progressMonitor.done(); 108 } 109 } 110 }; 111 112 try 113 { 114 getContainer().run(false, false, operation); 115 } 116 catch (Exception exception) 117 { 118 GenModelEditPlugin.INSTANCE.log(exception); 119 return false; 120 } 121 122 if (project != null) 123 { 124 IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); 125 final IWorkbenchPart activePart = page.getActivePart(); 126 if (activePart instanceof ISetSelectionTarget) 127 { 128 final ISelection targetSelection = new StructuredSelection(project); 129 getShell().getDisplay().asyncExec(new Runnable () 130 { 131 public void run() 132 { 133 ((ISetSelectionTarget)activePart).selectReveal(targetSelection); 134 } 135 }); 136 } 137 } 138 139 return true; 140 } 141 } 142 | Popular Tags |