KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package org.apache.axis.tool.service.eclipse.ui;
17
18 import org.apache.axis.tool.service.bean.Page2Bean;
19 import org.apache.axis.tool.service.eclipse.plugin.ServiceArchiver;
20 import org.eclipse.jface.wizard.WizardPage;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.ModifyEvent;
23 import org.eclipse.swt.events.ModifyListener;
24 import org.eclipse.swt.events.MouseAdapter;
25 import org.eclipse.swt.events.MouseEvent;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.events.SelectionListener;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.FileDialog;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Text;
35
36 public class WizardPane2 extends WizardPage {
37    
38     private Text serviceXMLText;
39     private Label manualSelectionLabel;
40     private Button browseButton;
41     private Button selectAutoFileGenerationCheckBox;
42     
43     private boolean skipNextPage=true;
44     private boolean pageComplete;
45     
46     public WizardPane2(){
47         super("page2");
48         this.setTitle(ServiceArchiver.getResourceString("page2.title"));
49         this.setDescription(ServiceArchiver.getResourceString("page2.welcometext"));
50         this.setImageDescriptor(ServiceArchiver.getWizardImageDescriptor());
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
55      */

56     public void createControl(Composite parent) {
57         Composite container = new Composite(parent, SWT.NULL);
58         GridLayout layout = new GridLayout();
59         layout.numColumns=3;
60         container.setLayout(layout);
61                
62         manualSelectionLabel = new Label(container,SWT.NULL);
63         manualSelectionLabel.setText(ServiceArchiver.getResourceString("page2.selectservicexml.caption"));
64         
65         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
66         serviceXMLText = new Text(container,SWT.BORDER);
67         serviceXMLText.setLayoutData(gd);
68         serviceXMLText.addModifyListener(new ModifyListener(){
69             public void modifyText(ModifyEvent e){
70             handleModify();
71             }
72         });
73         
74         browseButton = new Button(container,SWT.PUSH);
75         browseButton.setText(ServiceArchiver.getResourceString("general.browse"));
76         browseButton.addMouseListener(new MouseAdapter(){
77             public void mouseUp(MouseEvent e) {
78                 handleBrowse();
79             }
80         });
81         
82         gd = new GridData();
83         gd.horizontalSpan = 2;
84         selectAutoFileGenerationCheckBox = new Button(container,SWT.CHECK);
85         selectAutoFileGenerationCheckBox.setLayoutData(gd);
86         selectAutoFileGenerationCheckBox.setText(ServiceArchiver.getResourceString("page2.generateauto.caption"));
87         selectAutoFileGenerationCheckBox.addSelectionListener(new SelectionListener(){
88             public void widgetSelected(SelectionEvent e){
89                 handleSelection();
90             }
91             public void widgetDefaultSelected(SelectionEvent e){}
92         });
93         /////////////////////////////////////////
94
//disable the selection combo for now
95
selectAutoFileGenerationCheckBox.setEnabled(false);
96         selectAutoFileGenerationCheckBox.setToolTipText(ServiceArchiver.getResourceString("page2.autogen.tooltip"));
97         ////////////////////////////////////////////
98
setControl(container);
99         setPageComplete(false);
100     }
101     
102     private void handleBrowse(){
103         FileDialog fileDialog = new FileDialog(this.getShell());
104         fileDialog.setFilterExtensions(new String JavaDoc[]{"service.xml"});
105         String JavaDoc returnFileName = fileDialog.open() ;
106         if (returnFileName!=null){
107             this.serviceXMLText.setText(returnFileName);
108         }
109     }
110     
111     private void handleSelection(){
112         if (this.selectAutoFileGenerationCheckBox.getSelection()){
113             changeManualSelectionStatus(false);
114             this.skipNextPage = false;
115             updateMessage(null);
116         }else{
117             changeManualSelectionStatus(true);
118             this.skipNextPage = true;
119             handleModify();
120             
121         }
122     }
123     
124     private void changeManualSelectionStatus(boolean state){
125         this.serviceXMLText.setEnabled(state);
126         this.browseButton.setEnabled(state);
127         this.manualSelectionLabel.setEnabled(state);
128     }
129     
130     private void handleModify(){
131         String JavaDoc serviceXMLString =serviceXMLText.getText().trim().toLowerCase();
132         if (serviceXMLString.equals("")){
133            this.updateMessage(ServiceArchiver.getResourceString("page2.error.servicenameempty"));
134         }else if(!serviceXMLString.endsWith("service.xml")){
135             this.updateMessage(ServiceArchiver.getResourceString("page2.error.servicenamewrong"));
136         }else{
137             this.updateMessage(null);
138         }
139     }
140     
141     private void updateMessage(String JavaDoc str){
142         this.setErrorMessage(str);
143         setPageComplete(str==null);
144     }
145     
146     /**
147      * @return Returns the skipNextPage.
148      */

149     public boolean isSkipNextPage() {
150         return skipNextPage;
151     }
152     
153     public Page2Bean getBean(){
154         Page2Bean pageBean = new Page2Bean();
155         pageBean.setManual(true);
156         pageBean.setManualFileName(this.serviceXMLText.getText());
157         return pageBean;
158     }
159 }
160
Popular Tags