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.Page3Bean;
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.layout.GridData;
029: import org.eclipse.swt.layout.GridLayout;
030: import org.eclipse.swt.widgets.Button;
031: import org.eclipse.swt.widgets.Composite;
032: import org.eclipse.swt.widgets.DirectoryDialog;
033: import org.eclipse.swt.widgets.Label;
034: import org.eclipse.swt.widgets.Text;
035:
036: public class ServiceArchiveOutputLocationPage extends
037: AbstractServiceWizardPage {
038:
039: private static final String DEFAULT_JAR_NAME = "my_service";
040: private Text outputFileLocationTextBox;
041: private Button browseButton;
042: private Text outputFileNameTextbox;
043: private boolean isWizardComplete = false;
044:
045: public ServiceArchiveOutputLocationPage() {
046: super ("page4");
047: }
048:
049: /* (non-Javadoc)
050: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#initializeDefaultSettings()
051: */
052: protected void initializeDefaultSettings() {
053: settings.put(PREF_OUTPUT_LOCATION, System
054: .getProperty("user.dir"));
055: settings.put(PREF_OUTPUT_NAME, DEFAULT_JAR_NAME);
056:
057: }
058:
059: /* (non-Javadoc)
060: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
061: */
062: public void createControl(Composite parent) {
063: Composite container = new Composite(parent, SWT.NULL);
064: GridLayout layout = new GridLayout();
065: layout.numColumns = 3;
066: container.setLayout(layout);
067:
068: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
069: gd.grabExcessHorizontalSpace = true;
070:
071: Label lable = new Label(container, SWT.NULL);
072: lable.setText(ServiceArchiver
073: .getResourceString("page4.outputlocation.label"));
074:
075: outputFileLocationTextBox = new Text(container, SWT.BORDER);
076: outputFileLocationTextBox.setLayoutData(gd);
077: outputFileLocationTextBox.setText("");
078: outputFileLocationTextBox
079: .addModifyListener(new ModifyListener() {
080: public void modifyText(ModifyEvent e) {
081: handleLocationModification();
082: }
083: });
084:
085: gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
086:
087: browseButton = new Button(container, SWT.PUSH);
088: browseButton.setText(ServiceArchiver
089: .getResourceString("general.browse"));
090: browseButton.setLayoutData(gd);
091: browseButton.addMouseListener(new MouseAdapter() {
092: public void mouseUp(MouseEvent e) {
093: handleBrowse();
094: }
095: });
096:
097: lable = new Label(container, SWT.NULL);
098: lable.setText(ServiceArchiver
099: .getResourceString("page4.outputname.label"));
100:
101: gd = new GridData(GridData.FILL_HORIZONTAL);
102:
103: outputFileNameTextbox = new Text(container, SWT.BORDER);
104: outputFileNameTextbox.setLayoutData(gd);
105: outputFileNameTextbox.setText(settings.get(PREF_OUTPUT_NAME));
106: outputFileNameTextbox.addModifyListener(new ModifyListener() {
107: public void modifyText(ModifyEvent e) {
108: handleFileNameModification();
109: }
110: });
111:
112: //Add some fill lables
113: gd = new GridData(GridData.FILL_HORIZONTAL);
114: gd.horizontalSpan = 3;
115: Label fillLable = new Label(container, SWT.NULL);
116: fillLable.setText("");
117: fillLable.setLayoutData(gd);
118: Label fillLable1 = new Label(container, SWT.NULL);
119: fillLable1.setText("");
120: fillLable1.setLayoutData(gd);
121:
122: //Hint Lable
123: Label hintLable = new Label(container, SWT.NULL);
124: hintLable.setText(ServiceArchiver
125: .getResourceString("page4.hint.caption"));
126: hintLable.setLayoutData(gd);
127:
128: if (restoredFromPreviousSettings) {
129: handleFileNameModification();
130: handleLocationModification();
131: } else {
132: //nothing yet
133: }
134:
135: setControl(container);
136:
137: }
138:
139: private void handleBrowse() {
140: DirectoryDialog dirDialog = new DirectoryDialog(this .getShell());
141: dirDialog.setMessage(ServiceArchiver
142: .getResourceString("page4.dirdialog.caption"));
143: String returnText = dirDialog.open();
144: if (returnText != null) {
145: this .outputFileLocationTextBox.setText(returnText);
146: this .outputFileLocationTextBox.setToolTipText(returnText);
147: }
148: }
149:
150: private void handleLocationModification() {
151: String outputLocationText = outputFileLocationTextBox.getText();
152: settings.put(PREF_OUTPUT_LOCATION, outputLocationText);
153: if (outputLocationText == null
154: || "".equals(outputLocationText.trim())) {
155: this .updateStatus(ServiceArchiver
156: .getResourceString("page4.error.location"));
157: isWizardComplete = false;
158: updateStatus(null);
159: } else {
160: String outputFilenameText = outputFileNameTextbox.getText();
161: settings.put(PREF_OUTPUT_NAME, outputFilenameText);
162: if (outputFilenameText == null
163: || "".equals(outputFilenameText.trim())) {
164: this .updateStatus(ServiceArchiver
165: .getResourceString("page4.error.filename"));
166: isWizardComplete = false;
167: updateStatus(null);
168: } else {
169: isWizardComplete = true;
170: updateStatus(null);
171: }
172: }
173: }
174:
175: private void handleFileNameModification() {
176: String outputFilenameText = outputFileNameTextbox.getText();
177: settings.put(PREF_OUTPUT_NAME, outputFilenameText);
178: if (outputFilenameText == null
179: || "".equals(outputFilenameText.trim())) {
180: this .updateStatus(ServiceArchiver
181: .getResourceString("page4.error.filename"));
182: isWizardComplete = false;
183: updateStatus(null);
184: } else {
185: String outputLocationText = outputFileLocationTextBox
186: .getText();
187: settings.put(PREF_OUTPUT_LOCATION, outputLocationText);
188: if (outputLocationText == null
189: || "".equals(outputLocationText.trim())) {
190: this .updateStatus(ServiceArchiver
191: .getResourceString("page4.error.location"));
192: isWizardComplete = false;
193: updateStatus(null);
194: } else {
195: isWizardComplete = true;
196: updateStatus(null);
197: }
198: }
199: }
200:
201: public Page3Bean getBean() {
202: Page3Bean pageBean = new Page3Bean();
203: pageBean.setOutputFolderName(this .outputFileLocationTextBox
204: .getText().trim());
205: pageBean.setOutputFileName(this .outputFileNameTextbox.getText()
206: .trim());
207: return pageBean;
208: }
209:
210: protected boolean getWizardComplete() {
211: return isWizardComplete;
212: }
213: }
|