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.WizardBean;
022: import org.apache.axis2.tool.service.control.Controller;
023: import org.apache.axis2.tool.service.eclipse.plugin.ServiceArchiver;
024: import org.eclipse.core.runtime.CoreException;
025: import org.eclipse.core.runtime.IProgressMonitor;
026: import org.eclipse.core.runtime.NullProgressMonitor;
027: import org.eclipse.jface.dialogs.MessageDialog;
028: import org.eclipse.jface.viewers.IStructuredSelection;
029: import org.eclipse.jface.wizard.IWizardPage;
030: import org.eclipse.jface.wizard.Wizard;
031: import org.eclipse.ui.INewWizard;
032: import org.eclipse.ui.IWorkbench;
033: import org.eclipse.ui.actions.WorkspaceModifyOperation;
034:
035: import java.lang.reflect.InvocationTargetException;
036: import java.util.List;
037:
038: public class ServiceArchiveWizard extends Wizard implements INewWizard {
039:
040: private ClassFileLocationPage classFileLocationPage;
041: private WSDLFileSelectionPage wsdlFileSelectionPage;
042: private ServiceXMLFileSelectionPage serviceXMLFileSelectionPage;
043: private ServiceXMLGenerationPage serviceXMLGenerationPage;
044: private ServiceArchiveOutputLocationPage serviceArchiveOutputLocationPage;
045: private LibraryAddingPage libPage;
046:
047: private boolean updateServiceGenerationStatus;
048: private String classFileLocation;
049: private String wsdlFileGenerationStatus;
050:
051: /**
052: * @return Returns the wsdlFileGenerationStatus.
053: */
054: public String getWsdlFileGenerationStatus() {
055: return wsdlFileGenerationStatus;
056: }
057:
058: /**
059: * @param message The wsdlFileGenerationStatus to set.
060: */
061: public void updateWsdlFileGenerationStatus(String message) {
062: this .wsdlFileGenerationStatus = message;
063: }
064:
065: public String getClassFileLocation() {
066: return classFileLocation;
067: }
068:
069: //get the lib file list
070: public String[] getLibFileList() {
071: return libPage.getBean().getFileList();
072: }
073:
074: public void setClassFileLocation(String location) {
075: this .classFileLocation = location;
076: }
077:
078: public void updateServiceXMLGeneration(boolean status) {
079: serviceXMLGenerationPage.setPageComplete(status);
080: }
081:
082: /**
083: *
084: */
085: public ServiceArchiveWizard() {
086: super ();
087: setNeedsProgressMonitor(true);
088: setWindowTitle(ServiceArchiver.getResourceString("main.title"));
089: }
090:
091: public boolean canFinish() {
092: IWizardPage[] pages = getPages();
093: AbstractServiceWizardPage wizardPage = null;
094: for (int i = 0; i < pages.length; i++) {
095: wizardPage = (AbstractServiceWizardPage) pages[i];
096: if (wizardPage.getName().equals("page4.name")) {
097: if (!wizardPage.getWizardComplete()) {
098: return false;
099: }
100: }
101: }
102: return true;
103: }
104:
105: /* (non-Javadoc)
106: * @see org.eclipse.jface.wizard.IWizard#getNextPage(org.eclipse.jface.wizard.IWizardPage)
107: */
108: public IWizardPage getNextPage(IWizardPage page) {
109: AbstractServiceWizardPage this Page = (AbstractServiceWizardPage) page;
110: AbstractServiceWizardPage nextPage = (AbstractServiceWizardPage) super
111: .getNextPage(page);
112: while (this Page != null && this Page.isSkipNext()) {
113: if (nextPage != null) {
114: this Page = nextPage;
115: nextPage = (AbstractServiceWizardPage) super
116: .getNextPage(nextPage);
117: } else {
118: break;
119: }
120: }
121: return nextPage;
122: }
123:
124: /* (non-Javadoc)
125: * @see org.eclipse.jface.wizard.IWizard#addPages()
126: */
127: public void addPages() {
128: classFileLocationPage = new ClassFileLocationPage();
129: this .addPage(classFileLocationPage);
130: wsdlFileSelectionPage = new WSDLFileSelectionPage();
131: this .addPage(wsdlFileSelectionPage);
132: libPage = new LibraryAddingPage();
133: this .addPage(libPage);
134: serviceXMLFileSelectionPage = new ServiceXMLFileSelectionPage();
135: this .addPage(serviceXMLFileSelectionPage);
136: serviceXMLGenerationPage = new ServiceXMLGenerationPage();
137: this .addPage(serviceXMLGenerationPage);
138: serviceArchiveOutputLocationPage = new ServiceArchiveOutputLocationPage();
139: this .addPage(serviceArchiveOutputLocationPage);
140: }
141:
142: /* (non-Javadobc)
143: * @see org.eclipse.jface.wizard.IWizard#performFinish()
144: */
145: public boolean performFinish() {
146:
147: WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
148: protected void execute(IProgressMonitor monitor)
149: throws CoreException, InvocationTargetException,
150: InterruptedException {
151: if (monitor == null)
152: monitor = new NullProgressMonitor();
153:
154: /*
155: * "7" is the total amount of steps, see below monitor.worked(amount)
156: */
157: monitor.beginTask(ServiceArchiver
158: .getResourceString("wizard.codegen.startmsg"),
159: 8);
160:
161: try {
162: monitor.worked(1);
163: // create a wizard bean
164: WizardBean wizBean = new WizardBean();
165: monitor.worked(1);
166: wizBean.setPage1bean(classFileLocationPage
167: .getBean());
168: monitor.worked(1);
169: wizBean
170: .setWsdlBean(wsdlFileSelectionPage
171: .getBean());
172: monitor.worked(1);
173: wizBean.setPage2bean(serviceXMLGenerationPage
174: .getBean(serviceXMLFileSelectionPage
175: .getBean()));
176: monitor.worked(1);
177: wizBean.setLibraryBean(libPage.getBean());
178: monitor.worked(1);
179: wizBean
180: .setPage3bean(serviceArchiveOutputLocationPage
181: .getBean());
182: monitor.worked(1);
183: new Controller().process(wizBean);
184: monitor.worked(1);
185: } catch (Throwable e) {
186: throw new InterruptedException(e.getMessage());
187: }
188:
189: monitor.done();
190: }
191: };
192:
193: /*
194: * Start the generation as new Workbench Operation, so the user
195: * can see the progress and, if needed, can stop the operation.
196: */
197: try {
198: getContainer().run(false, true, op);
199: showSuccessMessage(ServiceArchiver
200: .getResourceString("wizard.codegen.success"));
201: return true;
202: } catch (InvocationTargetException e1) {
203: showErrorMessage(e1.getTargetException().getMessage());
204: return false;
205: } catch (InterruptedException e1) {
206: showErrorMessage(e1.getMessage());
207: return false;
208: } catch (Exception e) {
209: showErrorMessage(ServiceArchiver
210: .getResourceString("wizard.codegen.unknown.error")
211: + " " + e.getMessage());
212: return false;
213: }
214:
215: }
216:
217: /* (non-Javadoc)
218: * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
219: */
220: public void init(IWorkbench workbench,
221: IStructuredSelection selection) {
222: // TODO Auto-generated method stub
223:
224: }
225:
226: private void showErrorMessage(String message) {
227: MessageDialog.openError(this .getShell(), ServiceArchiver
228: .getResourceString("wizard.codegen.error.msg.heading"),
229: message);
230: }
231:
232: private void showSuccessMessage(String message) {
233: MessageDialog
234: .openInformation(
235: this .getShell(),
236: ServiceArchiver
237: .getResourceString("wizard.codegen.success.msg.heading"),
238: message);
239: }
240: }
|