KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > codegen > eclipse > ui > WSDLFileSelectionPage


1 package org.apache.axis.tool.codegen.eclipse.ui;
2
3 import org.apache.axis.tool.codegen.eclipse.plugin.CodegenWizardPlugin;
4 import org.eclipse.jface.dialogs.IDialogPage;
5 import org.eclipse.jface.viewers.ISelection;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.events.ModifyEvent;
8 import org.eclipse.swt.events.ModifyListener;
9 import org.eclipse.swt.events.SelectionAdapter;
10 import org.eclipse.swt.events.SelectionEvent;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Button;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.FileDialog;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
18
19 /**
20  * The first page of the code generator wizrad. Asks for the WSDL file Name
21  */

22
23 public class WSDLFileSelectionPage extends AbstractWizardPage {
24
25     private Text fileText;
26
27     private ISelection selection;
28
29    
30     /**
31      *
32      * @param pageName
33      */

34     public WSDLFileSelectionPage() {
35         super("page1");
36        
37
38     }
39
40     /**
41      * Creates a default value for the settings on this page. For
42      * WSDLFileSelection, this is not very much.
43      */

44     protected void initializeDefaultSettings() {
45         settings.put(PREF_WSDL_LOCATION, "");
46     }
47
48     /**
49      * @see IDialogPage#createControl(Composite)
50      */

51     public void createControl(Composite parent) {
52
53         Composite container = new Composite(parent, SWT.NULL);
54         GridLayout layout = new GridLayout();
55         container.setLayout(layout);
56         layout.numColumns = 3;
57         layout.verticalSpacing = 9;
58
59         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
60         Label label = new Label(container, SWT.NULL);
61         label.setText(CodegenWizardPlugin
62                 .getResourceString("page1.fileselection.label"));
63
64         fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
65         fileText.setLayoutData(gd);
66         fileText.setText(settings.get(PREF_WSDL_LOCATION));
67         fileText.addModifyListener(new ModifyListener() {
68             public void modifyText(ModifyEvent e) {
69                 settings.put(PREF_WSDL_LOCATION, fileText.getText());
70                 dialogChanged();
71             }
72         });
73
74         Button button = new Button(container, SWT.PUSH);
75         button.setText(CodegenWizardPlugin
76                 .getResourceString("page1.fileselection.browse"));
77         button.addSelectionListener(new SelectionAdapter() {
78             public void widgetSelected(SelectionEvent e) {
79                 handleBrowse();
80             }
81         });
82         
83         setPageComplete(false);
84         setControl(container);
85
86         /*
87          * Validate this dialog, because we could have got valid values from the
88          * settings already.
89          */

90         if (restoredFromPreviousSettings){
91             dialogChanged();
92         }
93     }
94
95     /**
96      * Handle the dialog change event. Basically evaluates the file name and
97      * sets the error message accordingly
98      */

99     private void dialogChanged() {
100         String JavaDoc fileName = getFileName();
101
102         if (fileName.length() == 0) {
103             updateStatus(CodegenWizardPlugin
104                     .getResourceString("page1.error.filemissingerror"));
105             return;
106         }
107
108         if (!fileName.matches(".*\\.wsdl")) {
109             updateStatus(org.apache.axis.tool.codegen.eclipse.plugin.CodegenWizardPlugin
110                     .getResourceString("page1.error.wrongextension"));
111             return;
112         }
113
114         updateStatus(null);
115
116     }
117
118     /**
119      * Pops up the file browse dialog box
120      *
121      */

122     private void handleBrowse() {
123         FileDialog fileDialog = new FileDialog(this.getShell());
124         fileDialog.setFilterExtensions(new String JavaDoc[] { "*.wsdl" });
125         String JavaDoc fileName = fileDialog.open();
126         if (fileName != null) {
127             fileText.setText(fileName);
128         }
129
130     }
131
132     
133     /**
134      * Get the file name
135      *
136      * @return
137      */

138     public String JavaDoc getFileName() {
139         return fileText.getText();
140     }
141
142     /*
143      * (non-Javadoc)
144      *
145      * @see org.apache.axis.tool.codegen.eclipse.ui.CodegenPage#getPageType()
146      */

147     public int getPageType() {
148         return WSDL_2_JAVA_TYPE;
149     }
150 }
Popular Tags