001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.tool.service.eclipse.ui;
020:
021: import org.apache.axis2.tool.service.bean.WSDLFileLocationBean;
022: import org.apache.axis2.tool.service.eclipse.plugin.ServiceArchiver;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.events.ModifyEvent;
025: import org.eclipse.swt.events.ModifyListener;
026: import org.eclipse.swt.events.MouseAdapter;
027: import org.eclipse.swt.events.MouseEvent;
028: import org.eclipse.swt.events.SelectionEvent;
029: import org.eclipse.swt.events.SelectionListener;
030: import org.eclipse.swt.layout.GridData;
031: import org.eclipse.swt.layout.GridLayout;
032: import org.eclipse.swt.widgets.Button;
033: import org.eclipse.swt.widgets.Composite;
034: import org.eclipse.swt.widgets.FileDialog;
035: import org.eclipse.swt.widgets.Label;
036: import org.eclipse.swt.widgets.Text;
037:
038: public class WSDLFileSelectionPage extends AbstractServiceWizardPage {
039:
040: // set the default to false. This step cannot be skipped
041: private boolean skipNextPage = false;
042:
043: private Text wsdlTextBox;
044: private Label selectionLabel;
045: private Button browseButton;
046: //private Button autoGenerateWSDLCheckButton;
047: private Button skipWSDLCheckButton;
048: private Button selectWSDLCheckButton;
049:
050: public WSDLFileSelectionPage() {
051: super ("page5");
052: }
053:
054: /* (non-Javadoc)
055: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#initializeDefaultSettings()
056: */
057: protected void initializeDefaultSettings() {
058: settings.put(PREF_WSDL_FILE_NAME, "");
059: settings.put(PREF_CHECK_WSDL_GENERATE, true);
060: settings.put(PREF_CHECK_SKIP_WSDL, false);
061: settings.put(PREF_CHECK_SELECT_WSDL, false);
062:
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
067: */
068: public void createControl(Composite parent) {
069: Composite container = new Composite(parent, SWT.NULL);
070: GridLayout layout = new GridLayout();
071: layout.numColumns = 3;
072: container.setLayout(layout);
073:
074: GridData gd = new GridData();
075: //gd.horizontalSpan = 3;
076: //autoGenerateWSDLCheckButton = new Button(container,SWT.CHECK);
077: //autoGenerateWSDLCheckButton.setLayoutData(gd);
078: //autoGenerateWSDLCheckButton.setText(ServiceArchiver.getResourceString("page5.generateauto.caption"));
079: //autoGenerateWSDLCheckButton.setSelection(settings.getBoolean(PREF_CHECK_WSDL_GENERATE));
080: //autoGenerateWSDLCheckButton.addSelectionListener(new SelectionListener(){
081: // public void widgetSelected(SelectionEvent e){
082: // handleSelection();
083: // }
084: // public void widgetDefaultSelected(SelectionEvent e){}
085: //});
086: //autoGenerateWSDLCheckButton.setToolTipText(ServiceArchiver.getResourceString("page5.autogen.tooltip"));
087: ////////////////////////////////////////
088: // enable the automatic generation box
089: //autoGenerateWSDLCheckButton.setEnabled(true);
090: ///////////////////////////////////////
091:
092: gd = new GridData();
093: gd.horizontalSpan = 3;
094: skipWSDLCheckButton = new Button(container, SWT.CHECK);
095: skipWSDLCheckButton.setText(ServiceArchiver
096: .getResourceString("page5.skipWSDL.caption"));
097: skipWSDLCheckButton.setLayoutData(gd);
098: skipWSDLCheckButton.setSelection(settings
099: .getBoolean(PREF_CHECK_SKIP_WSDL));
100: ////////////////////////////////////////
101: // enable the skip check box
102: skipWSDLCheckButton.setEnabled(true);
103: ///////////////////////////////////////
104: skipWSDLCheckButton
105: .addSelectionListener(new SelectionListener() {
106: public void widgetSelected(SelectionEvent e) {
107: handleSkip();
108: }
109:
110: public void widgetDefaultSelected(SelectionEvent e) {
111: }
112:
113: });
114:
115: //add an empty lable
116: new Label(container, SWT.NONE);
117:
118: gd = new GridData();
119: gd.horizontalSpan = 3;
120: selectWSDLCheckButton = new Button(container, SWT.CHECK);
121: selectWSDLCheckButton.setText(ServiceArchiver
122: .getResourceString("page5.selectWSDL.caption"));
123: selectWSDLCheckButton.setLayoutData(gd);
124: selectWSDLCheckButton.setSelection(settings
125: .getBoolean(PREF_CHECK_SELECT_WSDL));
126: ////////////////////////////////////////
127: // enable the skip check box
128: selectWSDLCheckButton.setEnabled(true);
129: ///////////////////////////////////////
130: selectWSDLCheckButton
131: .addSelectionListener(new SelectionListener() {
132: public void widgetSelected(SelectionEvent e) {
133: handleSelect();
134: }
135:
136: public void widgetDefaultSelected(SelectionEvent e) {
137: }
138:
139: });
140:
141: gd = new GridData(GridData.FILL_HORIZONTAL);
142: selectionLabel = new Label(container, SWT.NULL);
143: selectionLabel.setText(ServiceArchiver
144: .getResourceString("page5.selectwsdl.caption"));
145:
146: wsdlTextBox = new Text(container, SWT.BORDER);
147: wsdlTextBox.setLayoutData(gd);
148: wsdlTextBox.setText(settings.get(PREF_WSDL_FILE_NAME));
149: wsdlTextBox.addModifyListener(new ModifyListener() {
150: public void modifyText(ModifyEvent e) {
151: handleModify();
152: }
153: });
154:
155: browseButton = new Button(container, SWT.PUSH);
156: browseButton.setText(ServiceArchiver
157: .getResourceString("general.browse"));
158: browseButton.addMouseListener(new MouseAdapter() {
159: public void mouseUp(MouseEvent e) {
160: handleBrowse();
161: }
162: });
163:
164: setControl(container);
165:
166: if (restoredFromPreviousSettings) {
167: handleSkip();
168: if (!skipWSDLCheckButton.getSelection()) {
169: handleSelect();
170: }
171: }
172: }
173:
174: //private void handleSelection(){
175: // boolean selection = this.autoGenerateWSDLCheckButton.getSelection();
176: // settings.put(PREF_CHECK_WSDL_GENERATE,selection);
177: // if (selection){
178: // this.skipNextPage = false;
179: // updateStatus(null);
180: // updateRecommendation(ServiceArchiver.getResourceString("page5.recommendation"));
181: // this.skipWSDLCheckButton.setSelection(false);
182: // this.selectWSDLCheckButton.setSelection(false);
183: // changeManualSelectionStatus(false);
184: // }else{
185: // changeManualSelectionStatus(true);
186: // this.skipNextPage = true;
187: // handleModify();
188: // updateRecommendation("");
189: // this.skipWSDLCheckButton.setSelection(true);
190: // if (skipWSDLCheckButton.getSelection() || selectWSDLCheckButton.getSelection()){
191: // //you should not come here
192: //
193: // }else {
194: // autoGenerateWSDLCheckButton.setSelection(true);
195: // this.skipNextPage = false;
196: // updateStatus(null);
197: // updateRecommendation(ServiceArchiver.getResourceString("page5.recommendation"));
198: // this.skipWSDLCheckButton.setSelection(false);
199: // this.selectWSDLCheckButton.setSelection(false);
200: // changeManualSelectionStatus(false);
201: // }
202: // }
203: //}
204:
205: private void handleSkip() {
206: if (skipWSDLCheckButton.getSelection()) {
207: //disable other widgtets
208: changeManualSelectionStatus(false);
209: //enable next
210: this .updateStatus(null);
211: settings.put(PREF_CHECK_SKIP_WSDL, true);
212: this .selectWSDLCheckButton.setSelection(false);
213: } else {
214: // //call this to update the status
215: // handleModify();
216: // settings.put(PREF_CHECK_SKIP_WSDL,false);
217: // this.autoGenerateWSDLCheckButton.setSelection(true);
218: if (selectWSDLCheckButton.getSelection()) {
219: //you should not come here
220:
221: } else {
222: skipWSDLCheckButton.setSelection(true);
223: //disable other widgtets
224: changeManualSelectionStatus(false);
225: //enable next
226: this .updateStatus(null);
227: settings.put(PREF_CHECK_SKIP_WSDL, true);
228: this .selectWSDLCheckButton.setSelection(false);
229: }
230: }
231: }
232:
233: private void handleSelect() {
234: if (selectWSDLCheckButton.getSelection()) {
235: changeManualSelectionStatus(true);
236: //enable next
237: this .updateStatus(null);
238: this .skipWSDLCheckButton.setSelection(false);
239:
240: } else {
241: // setStatus(true);
242: // //call this to update the status
243: // handleModify();
244: // settings.put(PREF_CHECK_SKIP_WSDL,false);
245: // this.autoGenerateWSDLCheckButton.setSelection(true);
246: if (skipWSDLCheckButton.getSelection()) {
247: //you should not come here
248:
249: } else {
250: selectWSDLCheckButton.setSelection(true);
251: //disable other widgtets
252: changeManualSelectionStatus(true);
253: //enable next
254: this .updateStatus(null);
255: this .skipWSDLCheckButton.setSelection(false);
256: }
257: }
258: }
259:
260: private void handleBrowse() {
261: FileDialog fileDialog = new FileDialog(this .getShell());
262: fileDialog.setFilterExtensions(new String[] { "*.wsdl" });
263: String returnFileName = fileDialog.open();
264: if (returnFileName != null) {
265: this .wsdlTextBox.setText(returnFileName);
266: }
267: }
268:
269: private void handleModify() {
270: String text = wsdlTextBox.getText();
271: settings.put(PREF_WSDL_FILE_NAME, text);
272: //validate
273: if ("".equals(text)) {
274: this .updateStatus(ServiceArchiver
275: .getResourceString("page5.error.wsdlnameempty"));
276: } else if (!text.endsWith(".wsdl")) {
277: this .updateStatus(ServiceArchiver
278: .getResourceString("page5.error.wsdlnamewrong"));
279: } else {
280: this .updateStatus(null);
281: }
282:
283: }
284:
285: private void updateRecommendation(String message) {
286: ServiceArchiveWizard wizard = (ServiceArchiveWizard) this
287: .getWizard();
288: wizard.updateWsdlFileGenerationStatus(message);
289:
290: }
291:
292: private void changeManualSelectionStatus(boolean state) {
293: this .wsdlTextBox.setEnabled(state);
294: this .browseButton.setEnabled(state);
295: this .selectionLabel.setEnabled(state);
296: }
297:
298: public boolean isAutoGenerate() {
299: return false;// autoGenerateWSDLCheckButton.getSelection();
300: }
301:
302: /* (non-Javadoc)
303: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#isSkipNext()
304: */
305: public boolean isSkipNext() {
306: return false;
307: //return this.skipNextPage;
308: }
309:
310: public WSDLFileLocationBean getBean() {
311: WSDLFileLocationBean locationBean = new WSDLFileLocationBean();
312: locationBean.setManual(!isAutoGenerate());
313: locationBean.setWSDLFileName(wsdlTextBox.getText());
314: locationBean.setSkip(skipWSDLCheckButton.getSelection());
315: return locationBean;
316: }
317:
318: protected boolean getWizardComplete() {
319: return false;
320: }
321: }
|