KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > actions > ear > ExportEarActionDelegate


1 package com.bull.eclipse.jonas.actions.ear;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 import org.eclipse.jface.viewers.IStructuredContentProvider;
7 import org.eclipse.jface.viewers.LabelProvider;
8 import org.eclipse.jface.viewers.Viewer;
9 import org.eclipse.ui.PlatformUI;
10 import org.eclipse.ui.dialogs.ListSelectionDialog;
11
12 import com.bull.eclipse.jonas.JonasProject;
13 import com.bull.eclipse.jonas.actions.JonasProjectAbstractActionDelegate;
14 import com.bull.eclipse.jonas.utils.RarManagement;
15 import com.bull.eclipse.jonas.utils.UpdatePropsFile;
16 import com.bull.eclipse.newear.NewEarRunner;
17
18
19
20 public class ExportEarActionDelegate extends JonasProjectAbstractActionDelegate
21 {
22     static private Object JavaDoc[] oldSelection = null;
23     private JonasProject prj = null;
24     
25     
26     public boolean doActionOn(JonasProject prj) throws Exception JavaDoc {
27         this.prj = prj;
28         // Update build.properties with JONAS_ROOT
29
UpdatePropsFile.updatePropsProject(prj);
30         
31         //Build the j2ee module list
32
Vector JavaDoc ejbListe = prj.getJarEjbName();
33         Vector JavaDoc listModules = new Vector JavaDoc();
34         String JavaDoc[] rarListe = RarManagement.searchRarInProject(prj);
35         if (ejbListe != null) {
36             for (Enumeration JavaDoc e = ejbListe.elements() ; e.hasMoreElements() ;) {
37                 String JavaDoc ejbName = (String JavaDoc) e.nextElement();
38                 listModules.add("Ejb Module : " + ejbName);
39             }
40         }
41         if ((prj.getWebContext() != null) && (!prj.getWebContext().equals("")))
42             listModules.add("Web module : " + prj.getWebContext());
43
44         if (rarListe != null) {
45             for (int i=0;i<rarListe.length;i++) {
46                 String JavaDoc rarName = rarListe[i];
47                 listModules.add("Rar Module : " + rarName);
48             }
49         }
50         
51         final String JavaDoc[] listModulesJ2ee = (String JavaDoc[]) listModules.toArray(new String JavaDoc[0]);
52         ListSelectionDialog lsd =
53             new ListSelectionDialog(
54                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
55                 new Object JavaDoc(),
56                 new IStructuredContentProvider() {
57
58             public void dispose() {
59             }
60
61             public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
62                 return listModulesJ2ee;
63             }
64
65             public void inputChanged(Viewer viewer1, Object JavaDoc obj, Object JavaDoc obj1) {
66                 int i = 0;
67             }
68
69         }, new LabelProvider(), "Select modules to put in application");
70
71         lsd.setTitle("Select j2ee modules");
72         if (oldSelection == null) {
73             lsd.setInitialSelections(listModulesJ2ee);
74         } else {
75             lsd.setInitialSelections(oldSelection);
76         }
77         lsd.open();
78
79         Object JavaDoc[] results_upd = lsd.getResult();
80         
81         oldSelection = results_upd;
82         
83         int ret = lsd.getReturnCode();
84         // return null ( list of methods) , if user press cancel or nothing is selected
85
if (ret == 1)
86             throw new Exception JavaDoc("Operation is cancelled");
87         if ((results_upd == null) || (results_upd.length == 0))
88             throw new Exception JavaDoc("There is no element to build the application");
89         
90         Vector JavaDoc moduleEjbSel = new Vector JavaDoc();
91         for(int i=0;i<oldSelection.length;i++) {
92             if (oldSelection[i].toString().startsWith("Ejb")) {
93                 moduleEjbSel.add(oldSelection[i].toString().replaceAll("Ejb Module : ",""));
94             }
95         }
96
97         Vector JavaDoc moduleWebSel = new Vector JavaDoc();
98         for(int i=0;i<oldSelection.length;i++) {
99             if (oldSelection[i].toString().startsWith("Web")) {
100                 moduleWebSel.add(oldSelection[i].toString().replaceAll("Web Module : ",""));
101             }
102         }
103
104         Vector JavaDoc moduleRarSel = new Vector JavaDoc();
105         for(int i=0;i<oldSelection.length;i++) {
106             if (oldSelection[i].toString().startsWith("Rar")) {
107                 moduleRarSel.add(oldSelection[i].toString().replaceAll("Rar Module : ",""));
108             }
109         }
110                 
111         NewEarRunner runner = new NewEarRunner(prj,moduleEjbSel,moduleWebSel,moduleRarSel);
112         runner.RunNewear();
113
114         //TODO Deploy
115
//DeployEarActionDelegate.deploy(prj.getProject().getName() + ".ear");
116

117         return false;
118     }
119
120 }
121
122
Popular Tags