KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > service > swing > ui > WizardPane2


1 package org.apache.axis.tool.service.swing.ui;
2
3 import java.awt.HeadlessException JavaDoc;
4 import java.awt.event.ActionEvent JavaDoc;
5 import java.awt.event.ActionListener JavaDoc;
6 import java.awt.event.KeyEvent JavaDoc;
7 import java.awt.event.KeyListener JavaDoc;
8 import java.util.ArrayList JavaDoc;
9
10 import javax.swing.ButtonGroup JavaDoc;
11 import javax.swing.JButton JavaDoc;
12 import javax.swing.JCheckBox JavaDoc;
13 import javax.swing.JDialog JavaDoc;
14 import javax.swing.JFrame JavaDoc;
15 import javax.swing.JLabel JavaDoc;
16 import javax.swing.JPanel JavaDoc;
17 import javax.swing.JRadioButton JavaDoc;
18 import javax.swing.JTextField JavaDoc;
19
20 import org.apache.axis.tool.service.bean.Page2Bean;
21 import org.apache.axis.tool.service.bean.WizardBean;
22 import org.apache.axis.tool.service.control.Controller;
23 import org.apache.axis.tool.service.control.ProcessException;
24 import org.apache.axis.tool.util.Constants;
25
26 /*
27  * Copyright 2004,2005 The Apache Software Foundation.
28  *
29  * Licensed under the Apache License, Version 2.0 (the "License");
30  * you may not use this file except in compliance with the License.
31  * You may obtain a copy of the License at
32  *
33  * http://www.apache.org/licenses/LICENSE-2.0
34  *
35  * Unless required by applicable law or agreed to in writing, software
36  * distributed under the License is distributed on an "AS IS" BASIS,
37  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38  * See the License for the specific language governing permissions and
39  * limitations under the License.
40  */

41 public class WizardPane2 extends WizardPane {
42
43     private WizardBean parentBean;
44     private Page2Bean myBean;
45
46     private JRadioButton JavaDoc selectManualFileRadioButton;
47     private JRadioButton JavaDoc createAutomaticFileRadioButton;
48     private JPanel JavaDoc selectionPanel;
49
50
51     public WizardPane2(WizardBean wizardBean, JFrame JavaDoc ownerFrame) {
52         super(ownerFrame);
53
54         init();
55
56         parentBean = wizardBean;
57
58         if (wizardBean.getPage2bean()!=null){
59             myBean = wizardBean.getPage2bean();
60             //set the initial settings from the bean
61
setBeanValues();
62
63         }else{
64             myBean = new Page2Bean();
65             wizardBean.setPage2bean(myBean);
66             setDefaultValues();
67         }
68
69     }
70
71     public void setBeanValues(){
72         if (myBean.isManual()){
73             this.selectManualFileRadioButton.setSelected(true);
74             loadScreen(new ManualSelectionPanel(true));
75         }else{
76             this.createAutomaticFileRadioButton.setSelected(true);
77             loadScreen(new AutomaticSelectionPanel(true));
78         }
79     }
80
81
82     public boolean validateValues() {
83         String JavaDoc text = "";
84         String JavaDoc text2="";
85         boolean returnValue = false;
86         if (myBean.isManual()){
87             text = myBean.getManualFileName();
88             returnValue = (text!=null && text.trim().length()>0);
89         }else{
90             text = myBean.getAutomaticClassName();
91             text2 = myBean.getProviderClassName();
92             returnValue = (text!=null && text.trim().length()>0) &&
93                     (text2!=null && text2.trim().length()>0) ;
94         }
95
96         return returnValue;
97     }
98
99     private void init(){
100         this.setLayout(null);
101         this.setSize(width,height);
102
103         initDescription("\n Select either the service xml file or the class that you want to \n " +
104                 " expose as the service to auto generate a service.xml. \n " +
105                 " Only the class files that are in the previously selected location can\n" +
106                 " be laded from here");
107
108         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
109
110         this.selectManualFileRadioButton = new JRadioButton JavaDoc("Select a file manually");
111         this.selectManualFileRadioButton.setBounds(hgap,descHeight,Constants.UIConstants.RADIO_BUTTON_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
112         this.add(this.selectManualFileRadioButton);
113         group.add(selectManualFileRadioButton);
114         this.selectManualFileRadioButton.addActionListener(new ActionListener JavaDoc(){
115             public void actionPerformed(ActionEvent JavaDoc e) {
116                 changeSelectionScreen();
117             }
118         });
119         this.createAutomaticFileRadioButton = new JRadioButton JavaDoc("Create a file automatically");
120         this.createAutomaticFileRadioButton.setBounds(hgap,descHeight+vgap +Constants.UIConstants.GENERAL_COMP_HEIGHT ,Constants.UIConstants.RADIO_BUTTON_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
121         this.add(this.createAutomaticFileRadioButton);
122         group.add(createAutomaticFileRadioButton);
123         this.createAutomaticFileRadioButton.addActionListener(new ActionListener JavaDoc(){
124             public void actionPerformed(ActionEvent JavaDoc e) {
125                 changeSelectionScreen();
126             }
127         });
128
129         this.selectionPanel = new JPanel JavaDoc();
130         this.selectionPanel.setLayout(null);
131         this.selectionPanel.setBounds(0,descHeight + 2*Constants.UIConstants.GENERAL_COMP_HEIGHT +2*vgap,width,100);
132         this.add(this.selectionPanel);
133
134         //select manual option by default
135

136
137
138     }
139     private void setDefaultValues(){
140         this.selectManualFileRadioButton.setSelected(true);
141         loadScreen(new ManualSelectionPanel());
142         updateBeanFlags(true);
143     }
144     private void changeSelectionScreen(){
145         if (selectManualFileRadioButton.isSelected()){
146             loadScreen(new ManualSelectionPanel(true));
147             updateBeanFlags(true);
148         } else{
149             loadScreen(new AutomaticSelectionPanel(true));
150             updateBeanFlags(false);
151         }
152     }
153     private void updateBeanFlags(boolean flag){
154         myBean.setManual(flag);myBean.setAutomatic(!flag);
155     }
156
157     private void loadScreen(JPanel JavaDoc panel){
158         this.selectionPanel.removeAll();
159         this.selectionPanel.add(panel);
160         this.repaint();
161     }
162
163
164
165     private class ManualSelectionPanel extends JPanel JavaDoc{
166
167         private JLabel JavaDoc serverXMLFileLocationLabel;
168         private JTextField JavaDoc serverXMLFileLocationTextBox;
169         private JButton JavaDoc browseButton;
170
171         public ManualSelectionPanel() {
172             init();
173         }
174
175         public ManualSelectionPanel(boolean loadVals) {
176             init();
177             if (loadVals){
178                 this.serverXMLFileLocationTextBox.setText(myBean.getManualFileName());
179             }
180         }
181
182         private void init(){
183             this.setLayout(null);
184             this.setSize(width,100);
185
186             this.serverXMLFileLocationLabel = new JLabel JavaDoc("Service File");
187             this.add(this.serverXMLFileLocationLabel);
188             this.serverXMLFileLocationLabel.setBounds(hgap,vgap,Constants.UIConstants.LABEL_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
189
190             this.serverXMLFileLocationTextBox = new JTextField JavaDoc();
191             this.add(this.serverXMLFileLocationTextBox);
192             this.serverXMLFileLocationTextBox.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap ,vgap,Constants.UIConstants.TEXT_BOX_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
193             this.serverXMLFileLocationTextBox.addActionListener(new ActionListener JavaDoc(){
194                 public void actionPerformed(ActionEvent JavaDoc e) {
195                     setOutFileName();
196                 }
197             });
198             this.serverXMLFileLocationTextBox.addKeyListener(new KeyListener JavaDoc(){
199                 public void keyTyped(KeyEvent JavaDoc e) { }
200                 public void keyPressed(KeyEvent JavaDoc e) {}
201                 public void keyReleased(KeyEvent JavaDoc e) { setOutFileName();}
202             });
203
204             this.browseButton = new JButton JavaDoc(".");
205             this.add(this.browseButton);
206             this.browseButton.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap +Constants.UIConstants.TEXT_BOX_WIDTH,vgap,Constants.UIConstants.BROWSE_BUTTON_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
207             this.browseButton.addActionListener(new ActionListener JavaDoc(){
208                 public void actionPerformed(ActionEvent JavaDoc e) {
209                     serverXMLFileLocationTextBox.setText(browseForAFile("xml"));
210                     setOutFileName();
211                 }
212             });
213
214         }
215
216         private void setOutFileName(){
217             myBean.setManualFileName(serverXMLFileLocationTextBox.getText());
218         }
219     }
220
221     private class AutomaticSelectionPanel extends JPanel JavaDoc{
222
223         private JLabel JavaDoc classFileListLable;
224         private JLabel JavaDoc providerClassLable;
225         private JTextField JavaDoc classFileNameTextBox;
226         private JTextField JavaDoc providerClassNameTextBox;
227         private JButton JavaDoc loadButton;
228         private JButton JavaDoc advancedButton;
229
230         public AutomaticSelectionPanel() {
231             init();
232         }
233
234         public AutomaticSelectionPanel(boolean loadVals) {
235             init();
236             if (loadVals){
237                 this.classFileNameTextBox.setText(myBean.getAutomaticClassName());
238                 this.providerClassNameTextBox.setText(myBean.getProviderClassName());
239             }
240         }
241         private void init(){
242             this.setLayout(null);
243             this.setSize(width,100);
244
245             this.classFileListLable = new JLabel JavaDoc("Class Name");
246             this.add(this.classFileListLable);
247             this.classFileListLable.setBounds(hgap,vgap,Constants.UIConstants.LABEL_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
248
249             this.classFileNameTextBox = new JTextField JavaDoc();
250             this.add(this.classFileNameTextBox);
251             this.classFileNameTextBox.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap ,vgap,Constants.UIConstants.TEXT_BOX_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
252             this.classFileNameTextBox.addActionListener(new ActionListener JavaDoc(){
253                 public void actionPerformed(ActionEvent JavaDoc e) {
254                     setClassName();
255                 }
256             });
257             this.classFileNameTextBox.addKeyListener(new KeyListener JavaDoc(){
258                 public void keyTyped(KeyEvent JavaDoc e) {}
259                 public void keyPressed(KeyEvent JavaDoc e) {}
260                 public void keyReleased(KeyEvent JavaDoc e) {setClassName();}
261             });
262
263             this.providerClassLable = new JLabel JavaDoc("Provider Class Name");
264             this.add(this.providerClassLable);
265             this.providerClassLable.setBounds(hgap,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap),Constants.UIConstants.LABEL_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
266
267             this.providerClassNameTextBox = new JTextField JavaDoc();
268             this.add(this.providerClassNameTextBox);
269             this.providerClassNameTextBox.setBounds(Constants.UIConstants.LABEL_WIDTH + 2*hgap ,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap*2),Constants.UIConstants.TEXT_BOX_WIDTH,Constants.UIConstants.GENERAL_COMP_HEIGHT);
270             this.providerClassNameTextBox.addActionListener(new ActionListener JavaDoc(){
271                 public void actionPerformed(ActionEvent JavaDoc e) {
272                     setProviderClassName();
273                 }
274             });
275             this.providerClassNameTextBox.addKeyListener(new KeyListener JavaDoc(){
276                 public void keyTyped(KeyEvent JavaDoc e) {}
277                 public void keyPressed(KeyEvent JavaDoc e) {}
278                 public void keyReleased(KeyEvent JavaDoc e) {setProviderClassName();}
279             });
280
281             this.loadButton = new JButton JavaDoc("Load");
282             this.add(this.loadButton);
283             this.loadButton.setBounds(hgap,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap)*2 + vgap,
284                     Constants.UIConstants.GENERAL_BUTTON_WIDTH,
285                     Constants.UIConstants.GENERAL_COMP_HEIGHT);
286             this.loadButton.addActionListener(new ActionListener JavaDoc(){
287                 public void actionPerformed(ActionEvent JavaDoc e) {
288                     loadAllMethods();
289                 }
290             });
291             loadButton.setEnabled(false);
292
293             this.advancedButton = new JButton JavaDoc("Advanced");
294             this.add(this.advancedButton);
295             this.advancedButton.setBounds(2*hgap +Constants.UIConstants.GENERAL_BUTTON_WIDTH
296                     ,(Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap)*2 + vgap,
297                     Constants.UIConstants.GENERAL_BUTTON_WIDTH,
298                     Constants.UIConstants.GENERAL_COMP_HEIGHT);
299             this.advancedButton.addActionListener(new ActionListener JavaDoc(){
300                 public void actionPerformed(ActionEvent JavaDoc e) {
301                     openDialog();
302                 }
303             });
304             this.advancedButton.setEnabled(false);
305         }
306
307         private void loadAllMethods(){
308             try {
309                 ArrayList JavaDoc methodList = new Controller().getMethodList(parentBean);
310                 myBean.setSelectedMethodNames(methodList);
311                 loadButton.setEnabled(false);
312                 advancedButton.setEnabled(true);
313             } catch (ProcessException e) {
314                 showErrorMessage(e.getMessage());
315             }
316         }
317
318         private void openDialog(){
319             try {
320                 new AdvancedSelectionDialog().show();
321             } catch (ProcessException e) {
322                 showErrorMessage(e.getMessage());
323             }
324         }
325         private void setClassName(){
326             loadButton.setEnabled(true);
327             advancedButton.setEnabled(false);
328             myBean.setAutomaticClassName(classFileNameTextBox.getText());
329         }
330
331         private void setProviderClassName(){
332             //loadButton.setEnabled(true);
333
//advancedButton.setEnabled(false);
334
myBean.setProviderClassName(providerClassNameTextBox.getText());
335         }
336
337
338
339     }
340
341
342     private class AdvancedSelectionDialog extends JDialog JavaDoc{
343
344         private JPanel JavaDoc lablePanel;
345         private JButton JavaDoc okButton;
346         private JButton JavaDoc cancelButton;
347         private boolean[] selectedValues;
348         private ArrayList JavaDoc completeMethodList;
349
350
351         public AdvancedSelectionDialog() throws HeadlessException JavaDoc,ProcessException {
352             super();
353             super.setModal(true);
354             super.setTitle("Select Methods");
355             this.getContentPane().setLayout(null);
356             init();
357         }
358
359         private void init() throws ProcessException{
360             //load the class file list
361
this.completeMethodList = new Controller().getMethodList(parentBean);
362             int methodCount = this.completeMethodList.size();
363             int panelHeight = methodCount*(Constants.UIConstants.GENERAL_COMP_HEIGHT + vgap);
364
365             this.lablePanel = new JPanel JavaDoc();
366             this.lablePanel.setLayout(null);
367             this.lablePanel.setBounds(0,0,width,panelHeight);
368             this.getContentPane().add(this.lablePanel);
369
370             ArrayList JavaDoc currentSelectedList = myBean.getSelectedMethodNames();
371             //create check boxes for all the methods and add them to the panel
372
JCheckBox JavaDoc tempCheckBox;
373             boolean currentSelection;
374             this.selectedValues = new boolean[methodCount];
375
376             for (int i = 0; i < methodCount; i++) {
377                 tempCheckBox = new JCheckBox JavaDoc(this.completeMethodList.get(i).toString());
378                 currentSelection = currentSelectedList.contains(this.completeMethodList.get(i));
379                 tempCheckBox.setSelected(currentSelection);
380                 selectedValues[i] = currentSelection;
381                 tempCheckBox.setBounds(hgap,vgap + (Constants.UIConstants.GENERAL_COMP_HEIGHT+vgap)*i,
382                         Constants.UIConstants.LABEL_WIDTH*3,
383                         Constants.UIConstants.GENERAL_COMP_HEIGHT);
384                 tempCheckBox.addActionListener(new CheckBoxActionListner(tempCheckBox,i));
385                 this.lablePanel.add(tempCheckBox);
386
387             }
388
389             okButton = new JButton JavaDoc("OK");
390             this.getContentPane().add (this.okButton);
391             this.okButton.setBounds(hgap,panelHeight+vgap,
392                     Constants.UIConstants.GENERAL_BUTTON_WIDTH,
393                     Constants.UIConstants.GENERAL_COMP_HEIGHT);
394             this.okButton.addActionListener(new ActionListener JavaDoc(){
395                 public void actionPerformed(ActionEvent JavaDoc e) {
396                     loadValuesToBean();
397                     closeMe();
398                 }
399             });
400
401             cancelButton = new JButton JavaDoc("Cancel");
402             this.getContentPane().add (this.cancelButton);
403             this.cancelButton.setBounds(hgap*2 +Constants.UIConstants.GENERAL_BUTTON_WIDTH ,panelHeight+vgap,
404                     Constants.UIConstants.GENERAL_BUTTON_WIDTH,
405                     Constants.UIConstants.GENERAL_COMP_HEIGHT);
406             this.cancelButton.addActionListener(new ActionListener JavaDoc(){
407                 public void actionPerformed(ActionEvent JavaDoc e) {
408                     closeMe();
409                 }
410             });
411
412             this.setSize(width,panelHeight+2*Constants.UIConstants.GENERAL_COMP_HEIGHT + 30);
413             this.setResizable(false);
414         }
415
416         private void updateSelection(JCheckBox JavaDoc checkBox,int index){
417             if (checkBox.isSelected()){
418                 selectedValues[index] = true;
419             }else{
420                 selectedValues[index] = false;
421             }
422
423         }
424
425         private void loadValuesToBean(){
426             ArrayList JavaDoc modifiedMethodList = new ArrayList JavaDoc();
427             for (int i = 0; i < selectedValues.length; i++) {
428                 if( selectedValues[i])
429                     modifiedMethodList.add(completeMethodList.get(i));
430             }
431
432             myBean.setSelectedMethodNames(modifiedMethodList);
433         }
434         private void closeMe(){
435             this.dispose();
436         }
437
438         private class CheckBoxActionListner implements ActionListener JavaDoc{
439             private JCheckBox JavaDoc checkBox;
440             private int index;
441
442             public CheckBoxActionListner(JCheckBox JavaDoc checkBox,int index) {
443                 this.index = index;
444                 this.checkBox = checkBox;
445             }
446
447             public void actionPerformed(ActionEvent JavaDoc e) {
448                 updateSelection(checkBox,index);
449             }
450
451         }
452     }
453
454
455 }
456
Popular Tags