1 package com.bull.eclipse.jonas.wizard; 2 3 7 8 import java.io.File ; 9 import java.io.IOException ; 10 import java.lang.reflect.InvocationTargetException ; 11 import java.net.MalformedURLException ; 12 import java.net.URL ; 13 14 import org.eclipse.core.resources.IWorkspaceRoot; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExecutableExtension; 18 import org.eclipse.jdt.internal.ui.JavaPlugin; 19 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 20 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 21 import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPage; 22 import org.eclipse.jface.operation.IRunnableWithProgress; 23 import org.eclipse.jface.resource.ImageDescriptor; 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.jface.wizard.IWizardPage; 27 import org.eclipse.jface.wizard.Wizard; 28 import org.eclipse.ui.INewWizard; 29 import org.eclipse.ui.IWorkbench; 30 import org.eclipse.ui.IWorkbenchWizard; 31 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; 32 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; 33 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; 34 35 import com.bull.eclipse.jonas.JonasLauncherPlugin; 36 import com.bull.eclipse.jonas.JonasPluginResources; 37 import com.bull.eclipse.jonas.JonasProject; 38 import com.bull.eclipse.jonas.utils.FileUtil; 39 import com.bull.eclipse.jonas.utils.TemplateDirUtil; 40 import com.bull.eclipse.newwebapp.NewWebappsRunner; 41 44 public class JonasProjectCreationWizard extends Wizard implements IExecutableExtension,INewWizard, JonasPluginResources { 45 46 public static final String NEW_PROJECT_WIZARD_ID= "org.eclipse.jdt.ui.wizards.NewProjectCreationWizard"; 48 private NewJonasProjectWizardPage fJonasPage; 49 private NewJavaProjectWizardPage fJavaPage; 50 private WizardNewProjectCreationPage fMainPage; 51 private IConfigurationElement fConfigElement; 52 private ISelection selection; 53 54 public JonasProjectCreationWizard() { 55 super(); 56 setNeedsProgressMonitor(true); 57 ImageDescriptor banner = this.getBannerImg(); 58 if(banner != null) 59 setDefaultPageImageDescriptor(banner); 60 setDialogSettings(JavaPlugin.getDefault().getDialogSettings()); 61 setWindowTitle(WIZARD_PROJECT_TITLE); 62 } 63 64 private ImageDescriptor getBannerImg() { 65 try { 66 URL prefix = new URL (JonasLauncherPlugin.getDefault().getDescriptor().getInstallURL(), "icons/"); 67 return ImageDescriptor.createFromURL(new URL (prefix, "newjprj_wiz.gif")); 68 } catch (MalformedURLException e) { 69 return null; 70 } 71 } 72 73 76 public void addPages() { 77 fMainPage= new WizardNewProjectCreationPage("JOnASNewProjectPage"); 78 fMainPage.setTitle(WIZARD_PROJECT_MAINPAGE_TITLE); 79 fMainPage.setDescription(WIZARD_PROJECT_MAINPAGE_DESCRIPTION); 80 addPage(fMainPage); 81 82 fJonasPage = new NewJonasProjectWizardPage(selection,"NewJonasProjectPage"); 83 fJonasPage.setTitle(WIZARD_PROJECT_JONASPAGE_TITLE); 84 fJonasPage.setDescription(WIZARD_PROJECT_JONASPAGE_DESCRIPTION); 85 addPage(fJonasPage); 86 87 IWorkspaceRoot root= JavaPlugin.getWorkspace().getRoot(); 88 fJavaPage= new NewJavaProjectWizardPage(root, fMainPage); 89 } 91 92 93 96 public boolean performFinish() { 97 IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(fJavaPage.getRunnable());; 98 try { 99 getContainer().run(false, true, op); 100 JonasProject.addJonasNature(fJavaPage.getNewJavaProject()); 101 JonasProject jonasPrj = JonasProject.create(fJavaPage.getNewJavaProject()); 102 FileUtil.copyFile(new File (TemplateDirUtil.getTemplateDir().concat("/build.properties")),new File (jonasPrj.getProject().getLocation().append("/build.properties").toOSString())); 103 if (fJonasPage.isCreateWebApp()) { 104 jonasPrj.setWebContext(fJonasPage.getWebcontext()); 105 jonasPrj.setSrcDir(fJonasPage.getSrcpath()); 106 jonasPrj.setWebdirName(fJonasPage.getWebname()); 107 jonasPrj.setWarLocation(fJonasPage.getWarlocation()); 108 jonasPrj.saveProperties(); 109 jonasPrj.setCreateSamples( fJonasPage.isSample() ); 110 jonasPrj.fullConfiguration(); 111 NewWebappsRunner runner = new NewWebappsRunner(jonasPrj); 112 runner.RunNewwebapps(); 113 } else { 114 jonasPrj.addJonasJarToProjectClasspath(); 115 jonasPrj.clearDefaultSourceEntries(); 116 jonasPrj.setClassesAsOutputFolder(); 117 } 118 if (fJonasPage.isEJBPrj()) { 119 jonasPrj.setSrcEJBDir(fJonasPage.getSrcEJBpath()); 120 jonasPrj.saveProperties(); 121 jonasPrj.createSrcEJBFolder(); 122 } 123 } catch (InvocationTargetException e) { 124 String title= NewWizardMessages.getString("NewProjectCreationWizard.op_error.title"); String message= NewWizardMessages.getString("NewProjectCreationWizard.op_error.message"); ExceptionHandler.handle(e, getShell(), title, message); 127 return false; 128 } catch (InterruptedException e) { 129 return false; 130 } catch (CoreException e) { 131 return false; 132 } catch (IOException e) { 133 return false; 134 } 135 136 BasicNewProjectResourceWizard.updatePerspective(fConfigElement); 137 return true; 139 } 140 141 142 146 public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) { 147 fConfigElement= cfig; 148 } 149 150 151 152 155 public IWizardPage getNextPage(IWizardPage page) { 156 159 if (page instanceof WizardNewProjectCreationPage) { 160 if(!fJonasPage.wasDisplayedOnce()) { 161 fJonasPage.setWebcontext(fMainPage.getProjectName()); 162 fJonasPage.setWebname("webApplication"); 163 fJonasPage.setSrcpath("source"); 164 } 165 } 166 return super.getNextPage(page); 167 } 168 169 174 public void init(IWorkbench workbench, IStructuredSelection selection) { 175 this.selection = selection; 176 } 177 178 } | Popular Tags |