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.codegen.eclipse.ui;
020:
021: import org.apache.axis2.tool.codegen.eclipse.plugin.CodegenWizardPlugin;
022: import org.eclipse.core.resources.IWorkspaceRoot;
023: import org.eclipse.core.resources.ResourcesPlugin;
024: import org.eclipse.core.runtime.Path;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.events.ModifyEvent;
027: import org.eclipse.swt.events.ModifyListener;
028: import org.eclipse.swt.events.SelectionAdapter;
029: import org.eclipse.swt.events.SelectionEvent;
030: import org.eclipse.swt.events.SelectionListener;
031: import org.eclipse.swt.layout.GridData;
032: import org.eclipse.swt.layout.GridLayout;
033: import org.eclipse.swt.widgets.Button;
034: import org.eclipse.swt.widgets.Composite;
035: import org.eclipse.swt.widgets.DirectoryDialog;
036: import org.eclipse.swt.widgets.Label;
037: import org.eclipse.swt.widgets.Text;
038: import org.eclipse.ui.dialogs.ContainerSelectionDialog;
039:
040: import java.io.File;
041:
042: public class JavaWSDLOutputLocationPage extends AbstractWizardPage {
043:
044: private Text outputFolderTextBox;
045:
046: private Text outputFileNameTextBox;
047:
048: private Button workspaceProjectOptionsButton;
049:
050: private Button filesyStemOptionsButton;
051:
052: private boolean workspaceSaveOption = false;
053:
054: /**
055: * @param pageName
056: */
057: public JavaWSDLOutputLocationPage() {
058: super ("page6");
059: }
060:
061: /* (non-Javadoc)
062: * @see org.apache.axis2.tool.codegen.eclipse.ui.AbstractWizardPage#initializeDefaultSettings()
063: */
064: protected void initializeDefaultSettings() {
065: settings.put(PREF_JAVA_OUTPUT_WSDL_LOCATION, "");
066: settings.put(JAVA_OUTPUT_WSDL_NAME, "services.wsdl");
067: settings.put(PREF_JAVA_OUTPUT_FILESYATEM, true);
068: settings.put(PREF_JAVA_OUTPUT_WORKSPACE, false);
069:
070: }
071:
072: /* (non-Javadoc)
073: * @see org.apache.axis2.tool.codegen.eclipse.ui.AbstractWizardPage#getPageType()
074: */
075: public int getPageType() {
076: return JAVA_2_WSDL_TYPE;
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
081: */
082: public void createControl(Composite parent) {
083: Composite container = new Composite(parent, SWT.NULL);
084: GridLayout layout = new GridLayout();
085: layout.numColumns = 3;
086: //layout.verticalSpacing = 9;
087: container.setLayout(layout);
088:
089: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
090:
091: gd = new GridData(GridData.FILL_HORIZONTAL);
092: gd.horizontalSpan = 3;
093: Label selectLabel = new Label(container, SWT.NULL);
094: selectLabel
095: .setText(CodegenWizardPlugin
096: .getResourceString("Select the location where to put the output"));
097: selectLabel.setLayoutData(gd);
098:
099: gd = new GridData(GridData.FILL_HORIZONTAL);
100: gd.horizontalSpan = 3;
101: workspaceProjectOptionsButton = new Button(container, SWT.RADIO);
102: workspaceProjectOptionsButton.setLayoutData(gd);
103: workspaceProjectOptionsButton.setText(CodegenWizardPlugin
104: .getResourceString("page6.workspace.caption"));
105: workspaceProjectOptionsButton
106: .setToolTipText(CodegenWizardPlugin
107: .getResourceString("page6.workspace.desc"));
108: workspaceProjectOptionsButton.setSelection(settings
109: .getBoolean(PREF_JAVA_OUTPUT_WORKSPACE));
110: workspaceProjectOptionsButton
111: .addSelectionListener(new SelectionAdapter() {
112: public void widgetSelected(SelectionEvent e) {
113: handleCheckboxSelection();
114: }
115: });
116:
117: gd = new GridData(GridData.FILL_HORIZONTAL);
118: gd.horizontalSpan = 3;
119: filesyStemOptionsButton = new Button(container, SWT.RADIO);
120: filesyStemOptionsButton.setLayoutData(gd);
121: filesyStemOptionsButton.setText(CodegenWizardPlugin
122: .getResourceString("page6.filesystem.caption"));
123: filesyStemOptionsButton.setToolTipText(CodegenWizardPlugin
124: .getResourceString("page6.filesystem.desc"));
125: filesyStemOptionsButton.setSelection(settings
126: .getBoolean(PREF_JAVA_OUTPUT_FILESYATEM));
127: filesyStemOptionsButton
128: .addSelectionListener(new SelectionAdapter() {
129: public void widgetSelected(SelectionEvent e) {
130: handleCheckboxSelection();
131: }
132: });
133:
134: Label label1 = new Label(container, SWT.NULL);
135: label1.setText(CodegenWizardPlugin
136: .getResourceString("page6.output.label"));
137:
138: gd = new GridData(GridData.FILL_HORIZONTAL);
139: outputFolderTextBox = new Text(container, SWT.BORDER);
140: outputFolderTextBox.setLayoutData(gd);
141: outputFolderTextBox.setText("");
142: outputFolderTextBox.addModifyListener(new ModifyListener() {
143: public void modifyText(ModifyEvent e) {
144: handleFolderTextChange();
145: }
146: });
147:
148: Button browseButton = new Button(container, SWT.PUSH);
149: browseButton.setText(CodegenWizardPlugin
150: .getResourceString("general.browse"));
151: browseButton.addSelectionListener(new SelectionListener() {
152: public void widgetSelected(SelectionEvent e) {
153: handleBrowse();
154: }
155:
156: public void widgetDefaultSelected(SelectionEvent e) {
157: }
158: });
159:
160: Label label = new Label(container, SWT.NULL);
161: label.setText(CodegenWizardPlugin
162: .getResourceString("page6.outputname.label"));
163:
164: gd = new GridData(GridData.FILL_HORIZONTAL);
165: gd.horizontalSpan = 2;
166: outputFileNameTextBox = new Text(container, SWT.BORDER);
167: outputFileNameTextBox.setLayoutData(gd);
168: outputFileNameTextBox.setText(settings
169: .get(JAVA_OUTPUT_WSDL_NAME));
170: outputFileNameTextBox.addModifyListener(new ModifyListener() {
171: public void modifyText(ModifyEvent e) {
172: handleFileNameTextChange();
173: }
174: });
175:
176: if (restoredFromPreviousSettings) {
177: handleFolderTextChange();
178: handleFolderTextChange();
179: }
180:
181: setControl(container);
182:
183: }
184:
185: private void handleCheckboxSelection() {
186: if (workspaceProjectOptionsButton.getSelection()) {
187: settings.put(PREF_JAVA_OUTPUT_WORKSPACE, true);
188: settings.put(PREF_JAVA_OUTPUT_FILESYATEM, false);
189: workspaceSaveOption = true;
190: } else if (filesyStemOptionsButton.getSelection()) {
191: settings.put(PREF_JAVA_OUTPUT_FILESYATEM, true);
192: settings.put(PREF_JAVA_OUTPUT_WORKSPACE, false);
193: workspaceSaveOption = false;
194: }
195: }
196:
197: private void handleFolderTextChange() {
198: String outputFolder = outputFolderTextBox.getText();
199: settings.put(PREF_JAVA_OUTPUT_WSDL_LOCATION, outputFolder);
200: if ("".equals(outputFolder.trim())) {
201: updateStatus("Input a proper location for the output");
202: } else {
203: updateStatus(null);
204: }
205: }
206:
207: private void handleFileNameTextChange() {
208: String outFileName = outputFileNameTextBox.getText();
209: settings.put(JAVA_OUTPUT_WSDL_NAME, outFileName);
210: if ("".equals(outFileName.trim())) {
211: updateStatus("Input a file name");
212: } else if (outFileName.matches("\\W")) {
213: updateStatus("Input a valid file name");
214: } else if (!(outFileName.endsWith(".wsdl") || outFileName
215: .endsWith(".xml"))) {
216: updateStatus("Input a valid file name , Example : services.wsdl or services.xml");
217: } else {
218: updateStatus(null);
219: }
220: }
221:
222: private void handleBrowse() {
223:
224: // boolean location = locationSelectCheckBox.getSelection();
225: boolean location = false;
226: if (settings.getBoolean(PREF_JAVA_OUTPUT_FILESYATEM)) {
227: location = false;
228: } else if (settings.getBoolean(PREF_JAVA_OUTPUT_WORKSPACE)) {
229: location = true;
230: }
231: if (workspaceSaveOption) {
232: location = true;
233: }
234: if (!location) {
235: DirectoryDialog dialog = new DirectoryDialog(this
236: .getShell());
237: String returnString = dialog.open();
238: if (returnString != null) {
239: outputFolderTextBox.setText(returnString);
240: }
241: } else {
242: IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
243: .getRoot();
244:
245: ContainerSelectionDialog dialog = new ContainerSelectionDialog(
246: getShell(),
247: root,
248: false,
249: CodegenWizardPlugin
250: .getResourceString("page3.containerbox.title"));
251: if (dialog.open() == ContainerSelectionDialog.OK) {
252: Object[] result = dialog.getResult();
253: if (result.length == 1) {
254: Path path = ((Path) result[0]);
255: // append to the workspace path
256: if (root.exists(path)) {
257: outputFolderTextBox.setText(root.getLocation()
258: .append(path).toFile()
259: .getAbsolutePath());
260: }
261: }
262: }
263: }
264:
265: }
266:
267: public String getFullFileName() {
268: String folder = this .outputFolderTextBox.getText();
269: String fileName = this .outputFileNameTextBox.getText();
270: if (!fileName.endsWith(".wsdl")) {
271: fileName = fileName + ".wsdl";
272: }
273: return folder + File.separator + fileName;
274: }
275:
276: public String getOutputWSDLName() {
277: return this .outputFileNameTextBox.getText();
278: }
279:
280: public String getOutputLocation() {
281: return this.outputFolderTextBox.getText();
282: }
283:
284: }
|