KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 package com.bull.eclipse.jonas.wizard;
3
4 import java.io.File JavaDoc;
5 import java.io.IOException JavaDoc;
6
7 import org.eclipse.ant.core.AntRunner;
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.IResource;
10 import org.eclipse.core.resources.ResourcesPlugin;
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.jdt.internal.ui.JavaPlugin;
13 import org.eclipse.jface.dialogs.MessageDialog;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.jface.wizard.Wizard;
16 import org.eclipse.ui.IWorkbench;
17 import org.eclipse.ui.IWorkbenchWizard;
18
19 import com.bull.eclipse.jonas.JonasLauncherPlugin;
20 import com.bull.eclipse.jonas.JonasProject;
21 import com.bull.eclipse.jonas.utils.FileUtil;
22
23
24 public class CreateEARWizard extends Wizard implements IWorkbenchWizard
25 {
26     private CreateEARWizardPage EarPage;
27     private IStructuredSelection selection;
28     private IProject proj;
29
30
31     public CreateEARWizard()
32     {
33         super();
34         setDialogSettings( JavaPlugin.getDefault().getDialogSettings() );
35         setWindowTitle(JonasLauncherPlugin.getResourceString("Create EAR"));
36     }
37
38     public void addPages()
39     {
40         EarPage = new CreateEARWizardPage("EARWizardPage1");
41         EarPage.setTitle("Create EAR");
42         EarPage.setDescription("create an EAR file in a Jonas project");
43         EarPage.setProj(proj);
44         addPage(EarPage);
45     }
46
47     public void init( IWorkbench workbench, IStructuredSelection selection )
48     {
49         this.selection = selection;
50         Object JavaDoc o = selection.getFirstElement();
51         if( o instanceof JonasProject ) {
52             proj = ((JonasProject)o).getProject();
53         } else
54         if( o instanceof IProject ) {
55             proj = (IProject)o;
56         } else
57         if( o instanceof String JavaDoc ) {
58             proj = ResourcesPlugin.getWorkspace().getRoot().getProject((String JavaDoc)selection.getFirstElement());
59         }
60     }
61
62     public boolean performFinish()
63     {
64         File JavaDoc tempfilea = null;
65         File JavaDoc tempfileb = null;
66         try {
67             String JavaDoc appxml = EarPage.getAppXml();
68             tempfilea = saveStringToTempfile( "app.xml", appxml );
69             String JavaDoc bldxml = EarPage.getBldXml(tempfilea.toString());
70             tempfileb = saveStringToTempfile( "bld.xml", bldxml );
71             AntRunner antrunner = new AntRunner();
72             antrunner.setBuildFileLocation(tempfileb.toString());
73             antrunner.run();
74             try{ proj.refreshLocal( IResource.DEPTH_INFINITE, null ); }
75             catch( CoreException e ) {}
76         }
77         catch( Exception JavaDoc e ) {
78             // two exception types are possible: IOException, CoreException
79
// no need to treat them differently
80
MessageDialog.openInformation(null,"Error","exception occurred "+e);
81             JonasLauncherPlugin.log("JOPE: exception in CreateEARWizard.performFinish "+e);
82         }
83         if( tempfilea!=null ) tempfilea.delete();
84         if( tempfileb!=null ) tempfileb.delete();
85         
86         return true;
87     }
88
89     private File JavaDoc saveStringToTempfile( String JavaDoc filename, String JavaDoc content )
90                                         throws IOException JavaDoc
91     {
92         File JavaDoc f = File.createTempFile( filename, "" );
93         FileUtil.toTextFile( f, content );
94         return f;
95     }
96
97 }
98
99
100
Popular Tags