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.WSDLAutoGenerateOptionBean;
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.SelectionEvent;
027: import org.eclipse.swt.events.SelectionListener;
028: import org.eclipse.swt.layout.GridData;
029: import org.eclipse.swt.layout.GridLayout;
030: import org.eclipse.swt.widgets.Button;
031: import org.eclipse.swt.widgets.Combo;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Label;
034: import org.eclipse.swt.widgets.Table;
035: import org.eclipse.swt.widgets.TableColumn;
036: import org.eclipse.swt.widgets.TableItem;
037: import org.eclipse.swt.widgets.Text;
038:
039: import java.io.File;
040: import java.lang.reflect.Method;
041: import java.net.MalformedURLException;
042: import java.net.URL;
043: import java.net.URLClassLoader;
044:
045: public class WSDLOptionsPage extends AbstractServiceWizardPage {
046:
047: private static final String SERVICE_WSDL_DEFAULT_NAME = "service.wsdl";
048: private Text classNameTextBox;
049: private Text outputFileNameTextBox;
050: private Combo styleSelectionCombo;
051: private Button searchDeclaredMethodsCheckBox;
052: private Table table;
053:
054: private boolean dirty = false;
055:
056: public WSDLOptionsPage() {
057: super ("page6");
058: }
059:
060: /* (non-Javadoc)
061: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#initializeDefaultSettings()
062: */
063: protected void initializeDefaultSettings() {
064: settings.put(PREF_WSDL_FILE_NAME, SERVICE_WSDL_DEFAULT_NAME);
065: settings.put(PREF_WSDL_CLASS_NAME, "");
066: settings.put(PREF_WSDL_STYLE_INDEX, 0);
067:
068: }
069:
070: /* (non-Javadoc)
071: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
072: */
073: public void createControl(Composite parent) {
074: Composite container = new Composite(parent, SWT.NULL);
075: GridLayout layout = new GridLayout();
076: container.setLayout(layout);
077: layout.numColumns = 3;
078: layout.verticalSpacing = 9;
079:
080: // #########################################################
081:
082: Label label = new Label(container, SWT.NULL);
083: label.setText(ServiceArchiver
084: .getResourceString("page6.fileName.label"));
085: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
086: gd.horizontalSpan = 2;
087: outputFileNameTextBox = new Text(container, SWT.BORDER);
088: outputFileNameTextBox.setLayoutData(gd);
089: outputFileNameTextBox
090: .setText(settings.get(PREF_WSDL_FILE_NAME));
091: //###########################################################
092: outputFileNameTextBox.setEnabled(false);//this text box is disbaled for
093: // now
094: //########################################################
095: outputFileNameTextBox.addModifyListener(new ModifyListener() {
096: public void modifyText(ModifyEvent e) {
097: handlFileNameModification();
098: }
099: });
100:
101: //########################################################
102: gd = new GridData(GridData.FILL_HORIZONTAL);
103: label = new Label(container, SWT.NULL);
104: label.setText(ServiceArchiver
105: .getResourceString("page6.class.label"));
106:
107: classNameTextBox = new Text(container, SWT.BORDER);
108: classNameTextBox.setLayoutData(gd);
109: classNameTextBox.setText(settings.get(PREF_WSDL_CLASS_NAME));
110: classNameTextBox.addModifyListener(new ModifyListener() {
111: public void modifyText(ModifyEvent e) {
112: handleClassNameModification();
113: }
114: });
115:
116: gd = new GridData(GridData.FILL_HORIZONTAL);
117: Button loadButton = new Button(container, SWT.PUSH);
118: loadButton.setText("Load");
119: loadButton.setLayoutData(gd);
120: loadButton.addSelectionListener(new SelectionListener() {
121: public void widgetSelected(SelectionEvent e) {
122: updateTable();
123: }
124:
125: public void widgetDefaultSelected(SelectionEvent e) {
126: }
127: });
128:
129: gd = new GridData(GridData.FILL_HORIZONTAL);
130: gd.horizontalSpan = 3;
131:
132: searchDeclaredMethodsCheckBox = new Button(container, SWT.CHECK);
133: searchDeclaredMethodsCheckBox.setLayoutData(gd);
134: searchDeclaredMethodsCheckBox
135: .setText("List Declared Methods Only");
136: searchDeclaredMethodsCheckBox
137: .addSelectionListener(new SelectionListener() {
138: public void widgetSelected(SelectionEvent e) {
139: updateDirtyStatus(true);//dirty
140: }
141:
142: public void widgetDefaultSelected(SelectionEvent e) {
143: }
144: });
145:
146: // #####################################################
147: label = new Label(container, SWT.NULL);
148: label.setText(ServiceArchiver
149: .getResourceString("page6.style.label"));
150:
151: gd = new GridData(GridData.FILL_HORIZONTAL);
152: gd.horizontalSpan = 2;
153: styleSelectionCombo = new Combo(container, SWT.DROP_DOWN
154: | SWT.BORDER | SWT.READ_ONLY);
155: styleSelectionCombo.setLayoutData(gd);
156: populateStyleCombo();
157: styleSelectionCombo
158: .addSelectionListener(new SelectionListener() {
159: public void widgetSelected(SelectionEvent e) {
160: settings
161: .put(PREF_WSDL_STYLE_INDEX,
162: styleSelectionCombo
163: .getSelectionIndex());
164: }
165:
166: public void widgetDefaultSelected(SelectionEvent e) {
167: }
168: });
169:
170: gd = new GridData(GridData.FILL_BOTH);
171: gd.horizontalSpan = 3;
172: gd.verticalSpan = 5;
173:
174: table = new Table(container, SWT.SINGLE | SWT.FULL_SELECTION
175: | SWT.CHECK);
176: table.setLinesVisible(true);
177: table.setHeaderVisible(true);
178: table.setLayoutData(gd);
179: declareColumn(table, 20, "");
180: declareColumn(table, 100, "Method Name");
181: declareColumn(table, 100, "Return Type");
182: declareColumn(table, 100, "Parameter Count");
183:
184: table.setVisible(false);
185:
186: setControl(container);
187:
188: }
189:
190: private void declareColumn(Table table, int width, String colName) {
191: TableColumn column = new TableColumn(table, SWT.NONE);
192: column.setWidth(width);
193: column.setText(colName);
194: }
195:
196: private void populateStyleCombo() {
197: styleSelectionCombo.add("Document");
198: styleSelectionCombo.add("rpc");
199: styleSelectionCombo.add("Wrapped");
200:
201: styleSelectionCombo.select(settings
202: .getInt(PREF_WSDL_STYLE_INDEX));
203:
204: }
205:
206: private void updateTable() {
207: //get a URL from the class file location
208: try {
209: String classFileLocation = getClassFileLocation();
210: URL classFileURL = new File(classFileLocation).toURL();
211: ClassLoader loader = new URLClassLoader(
212: new URL[] { classFileURL });
213:
214: Class clazz = loader.loadClass(classNameTextBox.getText());
215: Method[] methods = null;
216:
217: if (searchDeclaredMethodsCheckBox.getSelection()) {
218: methods = clazz.getDeclaredMethods();
219: } else {
220: methods = clazz.getMethods();
221: }
222:
223: int methodCount = methods.length;
224: if (methodCount > 0) {
225: table.removeAll();
226: TableItem[] items = new TableItem[methodCount]; // An item for each field
227: for (int i = 0; i < methodCount; i++) {
228: items[i] = new TableItem(table, SWT.NONE);
229: items[i].setText(1, methods[i].getName());
230: items[i].setText(2, methods[i].getReturnType()
231: .getName());
232: items[i].setText(3,
233: methods[i].getParameterTypes().length + "");
234: items[i].setChecked(true);//check them all by default
235: }
236: table.setVisible(true);
237:
238: //update the dirty variable
239: updateDirtyStatus(false);
240: updateStatus(null);
241: }
242:
243: } catch (MalformedURLException e) {
244: updateStatus("Error : invalid location " + e.getMessage());
245: } catch (ClassNotFoundException e) {
246: updateStatus("Error : Class not found " + e.getMessage());
247: }
248: }
249:
250: private void handleClassNameModification() {
251: String className = classNameTextBox.getText();
252: settings.put(PREF_WSDL_CLASS_NAME, className);
253:
254: if (className == null || "".equals(className.trim())) {
255: updateStatus(ServiceArchiver
256: .getResourceString("page6.error.classname1"));
257: } else if (className.endsWith(".")) {
258: updateStatus(ServiceArchiver
259: .getResourceString("page6.error.classname2"));
260: } else {
261: updateStatus(null);
262: }
263:
264: }
265:
266: private void handlFileNameModification() {
267: String wsdlFileName = outputFileNameTextBox.getText();
268: settings.put(PREF_WSDL_FILE_NAME, wsdlFileName);
269:
270: if (wsdlFileName == null || "".equals(wsdlFileName.trim())) {
271: updateStatus(ServiceArchiver
272: .getResourceString("page6.error.fileName1"));
273: } else if (wsdlFileName.endsWith(".wsdl")) {
274: updateStatus(ServiceArchiver
275: .getResourceString("page6.error.fileName2"));
276: } else {
277: updateStatus(null);
278: }
279:
280: }
281:
282: private String getClassFileLocation() {
283: ServiceArchiveWizard wizard = (ServiceArchiveWizard) getWizard();
284: return wizard.getClassFileLocation();
285: }
286:
287: public WSDLAutoGenerateOptionBean getBean() {
288: WSDLAutoGenerateOptionBean optionBean = new WSDLAutoGenerateOptionBean();
289: optionBean.setClassFileName(classNameTextBox.getText());
290: optionBean.setOutputFileName(outputFileNameTextBox.getText());
291: optionBean.setStyle(styleSelectionCombo
292: .getItem(styleSelectionCombo.getSelectionIndex()));
293: return optionBean;
294: }
295:
296: private void updateDirtyStatus(boolean status) {
297: dirty = status;
298: if (table.isVisible()) {
299: table.setEnabled(!status);
300: }
301: setPageComplete(!status);
302: }
303:
304: protected boolean getWizardComplete() {
305: return false;
306: }
307: }
|