KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > wizard > JonasProjectCreationWizard


1 package com.bull.eclipse.jonas.wizard;
2
3 /*
4  * (c) Copyright Bull SA 2003.
5  * All Rights Reserved.
6  */

7
8 import java.io.File JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.lang.reflect.InvocationTargetException JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12 import java.net.URL JavaDoc;
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 //import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
42
//import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
43

44 public class JonasProjectCreationWizard extends Wizard implements IExecutableExtension,INewWizard, JonasPluginResources {
45
46     public static final String JavaDoc NEW_PROJECT_WIZARD_ID= "org.eclipse.jdt.ui.wizards.NewProjectCreationWizard"; //$NON-NLS-1$
47

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 JavaDoc prefix = new URL JavaDoc(JonasLauncherPlugin.getDefault().getDescriptor().getInstallURL(), "icons/");
67             return ImageDescriptor.createFromURL(new URL JavaDoc(prefix, "newjprj_wiz.gif"));
68         } catch (MalformedURLException JavaDoc e) {
69             return null;
70         }
71     }
72     
73     /*
74      * @see Wizard#addPages
75      */

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 // addPage(fJavaPage);
90
}
91     
92
93     /*
94      * @see Wizard#performFinish
95      */

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 JavaDoc(TemplateDirUtil.getTemplateDir().concat("/build.properties")),new File JavaDoc(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 JavaDoc e) {
124             String JavaDoc title= NewWizardMessages.getString("NewProjectCreationWizard.op_error.title"); //$NON-NLS-1$
125
String JavaDoc message= NewWizardMessages.getString("NewProjectCreationWizard.op_error.message"); //$NON-NLS-1$
126
ExceptionHandler.handle(e, getShell(), title, message);
127             return false;
128         } catch (InterruptedException JavaDoc e) {
129             return false;
130         } catch (CoreException e) {
131             return false;
132         } catch (IOException JavaDoc e) {
133             return false;
134         }
135         
136         BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
137 // selectAndReveal(fJavaPage.getNewJavaProject().getProject());
138
return true;
139     }
140
141             
142     /*
143      * Stores the configuration element for the wizard. The config element will be used
144      * in <code>performFinish</code> to set the result perspective.
145      */

146     public void setInitializationData(IConfigurationElement cfig, String JavaDoc propertyName, Object JavaDoc data) {
147         fConfigElement= cfig;
148     }
149     
150     
151
152     /*
153      * @see IWizard#getNextPage(IWizardPage)
154      */

155     public IWizardPage getNextPage(IWizardPage page) {
156         // initialize Jonas Wizard page webpath field
157
// Default value is / + projectName
158

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     /**
170      * We will accept the selection in the workbench to see if
171      * we can initialize from it.
172      * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
173      */

174     public void init(IWorkbench workbench, IStructuredSelection selection) {
175         this.selection = selection;
176     }
177
178 }
Popular Tags