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:
020: package org.apache.axis2.tool.codegen.eclipse.ui;
021:
022: import org.apache.axis2.tool.codegen.eclipse.plugin.CodegenWizardPlugin;
023: import org.eclipse.jface.dialogs.IDialogPage;
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.events.ModifyEvent;
026: import org.eclipse.swt.events.ModifyListener;
027: import org.eclipse.swt.events.SelectionAdapter;
028: import org.eclipse.swt.events.SelectionEvent;
029: import org.eclipse.swt.layout.GridData;
030: import org.eclipse.swt.layout.GridLayout;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.FileDialog;
034: import org.eclipse.swt.widgets.Label;
035: import org.eclipse.swt.widgets.Text;
036:
037: /**
038: * The first page of the code generator wizrad. Asks for the WSDL file Name
039: */
040:
041: public class WSDLFileSelectionPage extends AbstractWizardPage {
042:
043: private Text fileText;
044:
045: /**
046: *
047: * @param pageName
048: */
049: public WSDLFileSelectionPage() {
050: super ("page1");
051:
052: }
053:
054: /**
055: * Creates a default value for the settings on this page. For
056: * WSDLFileSelection, this is not very much.
057: */
058: protected void initializeDefaultSettings() {
059: settings.put(PREF_WSDL_LOCATION, "");
060: }
061:
062: /**
063: * @see IDialogPage#createControl(Composite)
064: */
065: public void createControl(Composite parent) {
066:
067: Composite container = new Composite(parent, SWT.NULL);
068: GridLayout layout = new GridLayout();
069: container.setLayout(layout);
070: layout.numColumns = 3;
071: //layout.verticalSpacing = 9;
072:
073: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
074:
075: gd = new GridData(GridData.FILL_HORIZONTAL);
076: Label labelFile = new Label(container, SWT.NULL);
077: labelFile.setText(CodegenWizardPlugin
078: .getResourceString("page1.fileselection.label"));
079:
080: fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
081: fileText.setLayoutData(gd);
082: fileText.setText(settings.get(PREF_WSDL_LOCATION));
083: fileText.addModifyListener(new ModifyListener() {
084: public void modifyText(ModifyEvent e) {
085: settings.put(PREF_WSDL_LOCATION, fileText.getText());
086: dialogChanged();
087: }
088: });
089:
090: Button button = new Button(container, SWT.PUSH);
091: button.setText(CodegenWizardPlugin
092: .getResourceString("page1.fileselection.browse"));
093: button.addSelectionListener(new SelectionAdapter() {
094: public void widgetSelected(SelectionEvent e) {
095: handleBrowse();
096: }
097: });
098:
099: gd = new GridData(GridData.FILL_HORIZONTAL);
100: gd.horizontalSpan = 3;
101: Label fillLabel = new Label(container, SWT.NULL);
102: fillLabel.setLayoutData(gd);
103:
104: gd = new GridData(GridData.FILL_HORIZONTAL);
105: gd.horizontalSpan = 3;
106: Label hintLabel = new Label(container, SWT.NULL);
107: hintLabel.setText(CodegenWizardPlugin
108: .getResourceString("page1.hint.desc"));
109: hintLabel.setLayoutData(gd);
110: // hintLabel.setFont(new Font(new Device() {
111: // public int internal_new_GC(GCData data) {return 0;}
112: // public void internal_dispose_GC(int handle, GCData data) {}
113: // },"hintFont",6,SWT.NORMAL));
114:
115: setPageComplete(false);
116: setControl(container);
117:
118: /*
119: * Validate this dialog, because we could have got valid values from the
120: * settings already.
121: */
122: if (restoredFromPreviousSettings) {
123: dialogChanged();
124: }
125: }
126:
127: /**
128: * Handle the dialog change event. Basically evaluates the file name and
129: * sets the error message accordingly
130: *
131: * TODO - we might need to call this in a different event!!!
132: */
133: private void dialogChanged() {
134: String fileName = getFileName();
135:
136: if (fileName.length() == 0) {
137: updateStatus(CodegenWizardPlugin
138: .getResourceString("page1.error.filemissingerror"));
139: return;
140: }
141:
142: //try populate the options
143: getCodegenWizard().populateOptions();
144: // update the status
145: updateStatus(null);
146:
147: }
148:
149: /**
150: * Pops up the file browse dialog box
151: *
152: */
153: private void handleBrowse() {
154: fileText
155: .setText("enter a valid *.wsdl/*.xml service description file");
156: FileDialog fileDialog = new FileDialog(this .getShell());
157: fileDialog
158: .setFilterExtensions(new String[] { "*.wsdl", "*.xml" });
159: String fileName = fileDialog.open();
160: if (fileName != null) {
161: fileText.setText(fileName);
162: }
163: }
164:
165: /**
166: * Get the file name
167: *
168: * @return
169: */
170: public String getFileName() {
171: return fileText.getText();
172: }
173:
174: /*
175: * (non-Javadoc)
176: *
177: * @see org.apache.axis2.tool.codegen.eclipse.ui.CodegenPage#getPageType()
178: */
179: public int getPageType() {
180: return WSDL_2_JAVA_TYPE;
181: }
182:
183: }
|