KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on Sep 18, 2003
3  *
4  */

5 package com.bull.eclipse.jonas.wizard;
6
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.resources.ResourcesPlugin;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.jface.wizard.WizardPage;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.events.ModifyEvent;
13 import org.eclipse.swt.events.ModifyListener;
14 import org.eclipse.swt.events.SelectionAdapter;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
23
24 import com.bull.eclipse.jonas.JonasLauncherPlugin;
25
26 /**
27  * @author steve krupanszky
28  *
29  */

30
31 public class CreateEJBWizardPage extends WizardPage implements ModifyListener
32 {
33
34     private Button createEJB;
35     private Button entButton1;
36     private Button entButton2;
37     private Button entButton3;
38     private Button mdbButton;
39     private Button deployUnit;
40     public static final String JavaDoc ENTITYb = "Entity, BMP";
41     public static final String JavaDoc ENTITYc1 = "Entity, CMP 1.x";
42     public static final String JavaDoc ENTITYc2 = "Entity, CMP 2.x";
43     private Text ejbnameText;
44     private Composite ejbtypeGroup;
45     private Composite ifcGroup;
46     public static final String JavaDoc INTEGER = "Integer";
47     private Text jarText;
48     //private Text jndiText;
49
private String JavaDoc jonasprojName;
50     private Composite keyGroup;
51     private Label keyLabel;
52     private static Label ejbnameLabel;
53     public static final String JavaDoc LOCAL = "Local";
54     public static final String JavaDoc MDB = "MDB";
55     protected static final String JavaDoc DEPLOYUNIT = "Deploy Unit";
56     public static final String JavaDoc OBJECT = "Object";
57     private String JavaDoc pkg;
58     private Text pkgText;
59     private Text projText;
60     public static final String JavaDoc REMOTE = "Remote";
61     private String JavaDoc srcDir;
62     private Text srcfolderText;
63     public static final String JavaDoc STATEFUL = "Session, Stateful";
64     public static final String JavaDoc STATELESS = "Session, Stateless";
65     public static final String JavaDoc STRING = "String";
66
67     public CreateEJBWizardPage(String JavaDoc pageName)
68     {
69         super(pageName);
70         setErrorMessage(null);
71     }
72
73     public void createControl( Composite parent )
74     {
75         Composite composite = new Composite(parent, SWT.NULL);
76
77         composite.setLayout(new GridLayout());
78         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
79
80         createEJBGroup(composite);
81
82         setMessage(null);
83         setControl(composite);
84         setPageComplete( validatePage() );
85
86     }
87
88     public void createEJBGroup( Composite parent )
89     {
90         GridData data;
91         
92         Composite ejbGroup = new Composite(parent,SWT.LEFT);
93         GridLayout layout = new GridLayout();
94         layout.numColumns = 2;
95         ejbGroup.setLayout(layout);
96         ejbGroup.setLayoutData( new GridData(GridData.FILL_HORIZONTAL) );
97
98     // Project Name
99
Label projLbl = new Label( ejbGroup, SWT.LEFT );
100         projLbl.setText("Jonas Project");
101
102         projText = new Text(ejbGroup, SWT.BORDER);
103         // preset this with the current selection's project name,
104
// if it is a Jonas project
105
data = new GridData(GridData.FILL_HORIZONTAL);
106         projText.setLayoutData(data);
107         if( jonasprojName!=null ) { projText.setText(jonasprojName); }
108         projText.addModifyListener(this);
109
110     // Source Folder (is not mandatory)
111
/* Label srcfolderLabel = new Label( ejbGroup, SWT.LEFT );
112         srcfolderLabel.setText("Source Folder");
113         
114         srcfolderText = new Text(ejbGroup,SWT.BORDER);
115         data = new GridData(GridData.FILL_HORIZONTAL);
116         srcfolderText.setLayoutData(data);
117         srcDir = "components";
118         srcfolderText.setEnabled(false);
119         if( srcDir!=null ) { srcfolderText.setText(srcDir); }
120 */

121     // Package Name
122
Label pkgLabel = new Label( ejbGroup, SWT.LEFT );
123         pkgLabel.setText("Package");
124
125         pkgText = new Text(ejbGroup,SWT.BORDER);
126         data = new GridData(GridData.FILL_HORIZONTAL);
127         pkgText.setLayoutData(data);
128         if( pkg!=null ) { pkgText.setText(pkg); }
129
130         pkgText.addModifyListener( new ModifyListener(){
131             public void modifyText( ModifyEvent ev )
132             {
133                 setPageComplete( validatePage() );
134             }} );
135
136     // EJB Name
137
ejbnameLabel = new Label(ejbGroup,SWT.LEFT);
138         ejbnameLabel.setText( "EJB name" );
139
140         ejbnameText = new Text(ejbGroup,SWT.BORDER);
141         data = new GridData(GridData.FILL_HORIZONTAL);
142         data.widthHint = 12;
143         ejbnameText.setLayoutData(data);
144         ejbnameText.setText("");
145
146         ejbnameText.addModifyListener( new ModifyListener(){
147             public void modifyText( ModifyEvent ev )
148             {
149                 setPageComplete( validatePage() );
150             }} );
151             
152         // set the focus to the first empty text input box
153
// FOCUS NOT WORKING TODAY (Eclipse 2.1)
154
if( projText.getText().equals("") ) {
155             projText.setFocus();
156         } else if( pkgText.getText().equals("") ) {
157             pkgText.setFocus();
158         } else {
159             ejbnameText.setFocus();
160         }
161
162     // JNDI Name (newbean has no provision to deal with this)
163
//Label jndiLabel = new Label( ejbGroup, SWT.LEFT );
164
//jndiLabel.setText("JNDI name");
165
//jndiText = new Text(ejbGroup, SWT.BORDER);
166
//data = new GridData(GridData.FILL_HORIZONTAL);
167
//jndiText.setLayoutData(data);
168

169     // Jar name
170
new Label( ejbGroup, SWT.LEFT ).setText("Jar name");
171
172         jarText = new Text(ejbGroup,SWT.BORDER);
173         jarText.setLayoutData( new GridData(GridData.FILL_HORIZONTAL) );
174
175         jarText.addModifyListener( new ModifyListener(){
176             public void modifyText( ModifyEvent ev )
177             {
178                 setPageComplete( validatePage() );
179             }} );
180
181     // EJB Type
182
Label ejbtypeLabel = new Label( ejbGroup, SWT.LEFT );
183         ejbtypeLabel.setText("EJB type");
184
185         ejbtypeGroup = new Composite( ejbGroup, SWT.NONE );
186         layout = new GridLayout();
187         layout.numColumns = 1;
188         ejbtypeGroup.setLayout( layout );
189         Button stateButton = new Button(ejbtypeGroup, SWT.RADIO);
190         stateButton.setText(STATELESS);
191         stateButton.setSelection(true); // choose a default selection
192
new Button(ejbtypeGroup, SWT.RADIO).setText(STATEFUL);
193         entButton1 = new Button(ejbtypeGroup, SWT.RADIO);
194         entButton1.setText(ENTITYb);
195         entButton2 = new Button(ejbtypeGroup, SWT.RADIO);
196         entButton2.setText(ENTITYc1);
197         entButton3 = new Button(ejbtypeGroup, SWT.RADIO);
198         entButton3.setText(ENTITYc2);
199         mdbButton = new Button(ejbtypeGroup, SWT.RADIO);
200         mdbButton.setText(MDB);
201         deployUnit = new Button(ejbtypeGroup, SWT.RADIO);
202         deployUnit.setText(DEPLOYUNIT);
203
204         
205     // Interface Type
206
final Label interfaceLabel = new Label( ejbGroup, SWT.LEFT );
207         interfaceLabel.setText("Location");
208
209         ifcGroup = new Composite( ejbGroup, SWT.NONE );
210         layout = new GridLayout();
211         layout.numColumns = 2;
212         ifcGroup.setLayout( layout );
213         Button localButton = new Button( ifcGroup, SWT.RADIO );
214         localButton.setText(LOCAL);
215         localButton.setSelection(true);
216         new Button( ifcGroup, SWT.RADIO ).setText(REMOTE);
217         SelectionAdapter sa1 = new SelectionAdapter() {
218                     public void widgetSelected(SelectionEvent ev) {
219                         if(!mdbButton.getSelection()) {
220                             ifcGroup.setVisible(true);
221                             interfaceLabel.setVisible(true);
222                         } else {
223                             ifcGroup.setVisible(false);
224                             interfaceLabel.setVisible(false);
225                         }
226                     }};
227
228         SelectionAdapter deploySA1 = new SelectionAdapter() {
229             public void widgetSelected(SelectionEvent ev) {
230                 if (!deployUnit.getSelection()) {
231                     ifcGroup.setVisible(true);
232                     interfaceLabel.setVisible(true);
233                     ejbnameText.setVisible(true);
234                     ejbnameLabel.setVisible(true);
235                 } else {
236                     ifcGroup.setVisible(false);
237                     interfaceLabel.setVisible(false);
238                     ejbnameText.setVisible(false);
239                     ejbnameLabel.setVisible(false);
240                 }
241             }
242         };
243         mdbButton.addSelectionListener(sa1);
244         deployUnit.addSelectionListener(deploySA1);
245
246     // Primary Key (for entity beans)
247
keyLabel = new Label( ejbGroup, SWT.LEFT );
248         keyLabel.setText("Primary key class");
249         keyLabel.setVisible(entityButtonSelected());
250
251         keyGroup = new Composite( ejbGroup, SWT.NONE );
252         layout = new GridLayout();
253         layout.numColumns = 3;
254         keyGroup.setLayout( layout );
255         keyGroup.setVisible(entityButtonSelected());
256         Button strButton = new Button(keyGroup, SWT.RADIO);
257         strButton.setText(STRING);
258         strButton.setSelection(true); // choose a default selection
259
new Button(keyGroup, SWT.RADIO).setText(INTEGER);
260         new Button(keyGroup, SWT.RADIO).setText(OBJECT);
261         // add listener to EJBType to enable Primary Key selection
262
SelectionAdapter sa2 = new SelectionAdapter() {
263                     public void widgetSelected(SelectionEvent ev) {
264                         if(entityButtonSelected()) {
265                             keyGroup.setVisible(true);
266                             keyLabel.setVisible(true);
267                         } else {
268                             keyGroup.setVisible(false);
269                             keyLabel.setVisible(false);
270                         }
271                     }};
272         entButton1.addSelectionListener(sa2);
273         entButton2.addSelectionListener(sa2);
274         entButton3.addSelectionListener(sa2);
275
276     }
277
278     private boolean entityButtonSelected()
279     {
280         return entButton1.getSelection()
281             || entButton2.getSelection()
282             || entButton3.getSelection();
283     }
284
285     public String JavaDoc getEJBName()
286     {
287         return ejbnameText.getText().trim();
288     }
289
290     public String JavaDoc getEJBType()
291     {
292         return getNameOfSelectedButton( ejbtypeGroup );
293     }
294
295     public String JavaDoc getInterfaceName()
296     {
297         return getNameOfSelectedButton( ifcGroup );
298     }
299
300     public String JavaDoc getJarName()
301     {
302         return jarText.getText().trim();
303     }
304
305 /* public String getJNDIName()
306     {
307         return jndiText.getText();
308     }
309 */

310
311     private String JavaDoc getNameOfSelectedButton( Composite comp )
312     {
313         // return the text associated with the selected Button
314
// of the specified Composite
315
Control[] buttons = comp.getChildren();
316         if( comp.isVisible() ) {
317             for( int i=0; i<buttons.length; i++ )
318             {
319                 if( buttons[i] instanceof Button
320                 && ((Button)buttons[i]).getSelection() ) {
321                     return ((Button)buttons[i]).getText();
322                 }
323             }
324         }
325         return "NoButtonSelected";
326     }
327
328     public String JavaDoc getPkgName()
329     {
330         return pkgText.getText().trim();
331     }
332
333     public String JavaDoc getPrimaryKey()
334     {
335         return getNameOfSelectedButton( keyGroup );
336     }
337
338     public String JavaDoc getProjName()
339     {
340         return projText.getText().trim();
341     }
342
343     public String JavaDoc getSrcDir()
344     {
345         return srcfolderText.getText().trim();
346     }
347
348     private boolean isJonasProject( String JavaDoc proj )
349     {
350         IProject p;
351         p = ResourcesPlugin.getWorkspace().getRoot().getProject(proj);
352         try {
353             return p.hasNature(JonasLauncherPlugin.NATURE_ID);
354         }
355         catch( CoreException e ) {}
356         return false;
357     }
358
359     /** @see ModifyListener
360     */

361     public void modifyText( ModifyEvent ev )
362     {
363         setPageComplete( validatePage() );
364     }
365
366     public void setProjName( String JavaDoc s )
367     {
368         jonasprojName = s;
369     }
370
371     public void setPkg( String JavaDoc s )
372     {
373         pkg = s;
374     }
375
376     public void setSrcDir( String JavaDoc s )
377     {
378         srcDir = s;
379     }
380
381     private boolean validatePage()
382     {
383         return( ( ejbnameText != null
384                 && getEJBName().length() > 0
385                 && getPkgName().length() > 0
386                 && getJarName().length() > 0
387                 && getProjName().length() > 0
388                 && isJonasProject( getProjName() )) ||
389                 (
390                 getEJBType().equals("Deploy Unit")
391                 && getPkgName().length() > 0
392                 && getJarName().length() > 0
393                 && getProjName().length() > 0
394                 && isJonasProject( getProjName()
395                 ))
396                 
397             );
398     }
399
400 }
401
Popular Tags