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.Page2Bean;
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 ServiceXMLFileSelectionPage extends
039: AbstractServiceWizardPage {
040:
041: private static final String SERVICES_XML_NAME = "services.xml";
042: private Text serviceXMLText;
043: private Label manualSelectionLabel;
044: private Label recommendationTextLable;
045: private Button browseButton;
046: private Button selectAutoFileGenerationCheckBox;
047:
048: private boolean skipNextPage = true;
049: private boolean pageComplete;
050:
051: public ServiceXMLFileSelectionPage() {
052: super ("page2");
053: }
054:
055: /* (non-Javadoc)
056: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#initializeDefaultSettings()
057: */
058: protected void initializeDefaultSettings() {
059: settings.put(PREF_SERVICE_XML_FILE, "");
060: settings.put(PREF_CHECK_AUTO_GEN_SERVICE_XML, false);
061:
062: }
063:
064: /* (non-Javadoc)
065: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
066: */
067: public void createControl(Composite parent) {
068: Composite container = new Composite(parent, SWT.NULL);
069: GridLayout layout = new GridLayout();
070: layout.numColumns = 3;
071: container.setLayout(layout);
072:
073: manualSelectionLabel = new Label(container, SWT.NULL);
074: manualSelectionLabel.setText(ServiceArchiver
075: .getResourceString("page2.selectservicexml.caption"));
076:
077: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
078: serviceXMLText = new Text(container, SWT.BORDER);
079: serviceXMLText.setLayoutData(gd);
080: serviceXMLText.setText(settings.get(PREF_SERVICE_XML_FILE));
081: serviceXMLText.addModifyListener(new ModifyListener() {
082: public void modifyText(ModifyEvent e) {
083: handleModify();
084: }
085: });
086:
087: browseButton = new Button(container, SWT.PUSH);
088: browseButton.setText(ServiceArchiver
089: .getResourceString("general.browse"));
090: browseButton.addMouseListener(new MouseAdapter() {
091: public void mouseUp(MouseEvent e) {
092: handleBrowse();
093: }
094: });
095:
096: gd = new GridData();
097: gd.horizontalSpan = 2;
098: selectAutoFileGenerationCheckBox = new Button(container,
099: SWT.CHECK);
100: selectAutoFileGenerationCheckBox.setLayoutData(gd);
101: selectAutoFileGenerationCheckBox.setText(ServiceArchiver
102: .getResourceString("page2.generateauto.caption"));
103: selectAutoFileGenerationCheckBox.setSelection(settings
104: .getBoolean(PREF_CHECK_AUTO_GEN_SERVICE_XML));
105: selectAutoFileGenerationCheckBox
106: .addSelectionListener(new SelectionListener() {
107: public void widgetSelected(SelectionEvent e) {
108: handleSelection();
109: }
110:
111: public void widgetDefaultSelected(SelectionEvent e) {
112: }
113: });
114: /////////////////////////////////////////
115: //enable the selection combo for now
116: //selectAutoFileGenerationCheckBox.setEnabled(false);
117: selectAutoFileGenerationCheckBox.setToolTipText(ServiceArchiver
118: .getResourceString("page2.autogen.tooltip"));
119: ////////////////////////////////////////////
120:
121: gd = new GridData(GridData.FILL_BOTH);
122: gd.horizontalSpan = 2;
123: gd.verticalSpan = 2;
124: recommendationTextLable = new Label(container, SWT.NULL);
125: recommendationTextLable.setLayoutData(gd);
126: //recommendationTextLable.setForeground()));
127:
128: setControl(container);
129:
130: if (restoredFromPreviousSettings) {
131: handleModify();
132: handleSelection();
133: } else {
134: setPageComplete(false);
135: updateGenerationPage(false);
136: }
137:
138: }
139:
140: private void handleBrowse() {
141: FileDialog fileDialog = new FileDialog(this .getShell());
142: fileDialog
143: .setFilterExtensions(new String[] { SERVICES_XML_NAME });
144: String returnFileName = fileDialog.open();
145: if (returnFileName != null) {
146: this .serviceXMLText.setText(returnFileName);
147: }
148: }
149:
150: private void handleSelection() {
151: boolean selection = this .selectAutoFileGenerationCheckBox
152: .getSelection();
153: settings.put(PREF_CHECK_AUTO_GEN_SERVICE_XML, selection);
154: if (selection) {
155: changeManualSelectionStatus(false);
156: this .skipNextPage = false;
157: updateStatus(null);
158: updateGenerationPage(false);
159: } else {
160: changeManualSelectionStatus(true);
161: this .skipNextPage = true;
162: handleModify();
163: updateGenerationPage(true);
164: }
165: }
166:
167: private void updateGenerationPage(boolean status) {
168: ServiceArchiveWizard wizard = (ServiceArchiveWizard) this
169: .getWizard();
170: wizard.updateServiceXMLGeneration(status);
171:
172: }
173:
174: private void changeManualSelectionStatus(boolean state) {
175: this .serviceXMLText.setEnabled(state);
176: this .browseButton.setEnabled(state);
177: this .manualSelectionLabel.setEnabled(state);
178: }
179:
180: private void handleModify() {
181: String serviceXMLString = serviceXMLText.getText().trim()
182: .toLowerCase();
183: settings.put(PREF_SERVICE_XML_FILE, serviceXMLString);
184: if (serviceXMLString.equals("")) {
185: this .updateStatus(ServiceArchiver
186: .getResourceString("page2.error.servicenameempty"));
187: } else if (!serviceXMLString.endsWith(SERVICES_XML_NAME)) {
188: this .updateStatus(ServiceArchiver
189: .getResourceString("page2.error.servicenamewrong"));
190: } else {
191: this .updateStatus(null);
192: }
193: }
194:
195: public void updateRecommendation(String message) {
196: if (recommendationTextLable != null)
197: recommendationTextLable.setText(message);
198: }
199:
200: /* (non-Javadoc)
201: * @see org.apache.axis2.tool.service.eclipse.ui.AbstractServiceWizardPage#isSkipNext()
202: */
203: public boolean isSkipNext() {
204: return this .skipNextPage;
205: }
206:
207: public Page2Bean getBean() {
208: Page2Bean pageBean = new Page2Bean();
209: pageBean.setManual(!this .selectAutoFileGenerationCheckBox
210: .getSelection());
211: pageBean.setManualFileName(this .serviceXMLText.getText());
212: return pageBean;
213: }
214:
215: protected boolean getWizardComplete() {
216: return false;
217: }
218: }
|