001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package com.bostechcorp.cbesb.ui.ide.wizards;
023:
024: import java.lang.reflect.InvocationTargetException;
025:
026: import org.eclipse.core.resources.IFile;
027: import org.eclipse.core.resources.IResource;
028: import org.eclipse.core.resources.IWorkspaceRunnable;
029: import org.eclipse.core.runtime.CoreException;
030: import org.eclipse.core.runtime.IProgressMonitor;
031: import org.eclipse.core.runtime.OperationCanceledException;
032: import org.eclipse.jdt.internal.ui.JavaPlugin;
033: import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
034: import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
035: import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
036: import org.eclipse.jface.viewers.IStructuredSelection;
037: import org.eclipse.jface.wizard.Wizard;
038: import org.eclipse.swt.widgets.Shell;
039: import org.eclipse.ui.INewWizard;
040: import org.eclipse.ui.IWorkbench;
041: import org.eclipse.ui.IWorkbenchPage;
042: import org.eclipse.ui.PartInitException;
043: import org.eclipse.ui.ide.IDE;
044: import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
045:
046: public abstract class BaseWizard extends Wizard implements INewWizard {
047: private IStructuredSelection selection;
048:
049: private IWorkbench workbench;
050:
051: /** Constructor for the BaseWizard object */
052: public BaseWizard() {
053: this .setNeedsProgressMonitor(true);
054: }
055:
056: /**
057: * Gets the selection attribute of the BaseWizard object
058: *
059: * @return The selection value
060: */
061: public IStructuredSelection getSelection() {
062: return this .selection;
063: }
064:
065: /**
066: * Gets the workbench attribute of the BaseWizard object
067: *
068: * @return The workbench value
069: */
070: public IWorkbench getWorkbench() {
071: return this .workbench;
072: }
073:
074: /**
075: * Description of the Method
076: *
077: * @param workbench
078: * Description of the Parameter
079: * @param currentSelection
080: * Description of the Parameter
081: */
082: public void init(IWorkbench workbench,
083: IStructuredSelection currentSelection) {
084: this .workbench = workbench;
085: this .selection = currentSelection;
086: }
087:
088: /**
089: * Description of the Method
090: *
091: * @return Description of the Return Value
092: */
093: public boolean performFinish() {
094: IWorkspaceRunnable op = new IWorkspaceRunnable() {
095: public void run(IProgressMonitor monitor)
096: throws CoreException, OperationCanceledException {
097: try {
098: finishPage(monitor);
099: } catch (InterruptedException e) {
100: throw new OperationCanceledException(e.getMessage());
101: }
102: }
103: };
104: try {
105: this .getContainer().run(false, true,
106: new WorkbenchRunnableAdapter(op));
107: } catch (InvocationTargetException e) {
108: this .handleFinishException(getShell(), e);
109: return false;
110: } catch (InterruptedException e) {
111: return false;
112: }
113: return true;
114: }
115:
116: /**
117: * Subclasses should override to perform the actions of the wizard. This
118: * method is run in the wizard container's context as a workspace runnable.
119: *
120: * @param monitor
121: * Description of the Parameter
122: * @exception InterruptedException
123: * Description of the Exception
124: * @exception CoreException
125: * Description of the Exception
126: */
127: protected void finishPage(IProgressMonitor monitor)
128: throws InterruptedException, CoreException {
129: }
130:
131: /**
132: * Description of the Method
133: *
134: * @param shell
135: * Description of the Parameter
136: * @param e
137: * Description of the Parameter
138: */
139: protected void handleFinishException(Shell shell,
140: InvocationTargetException e) {
141: String title = NewWizardMessages.NewElementWizard_op_error_title;//$NON-NLS-1$
142: String message = NewWizardMessages.NewElementWizard_op_error_message;//$NON-NLS-1$
143: ExceptionHandler.handle(e, shell, title, message);
144: }
145:
146: /**
147: * Description of the Method
148: *
149: * @param resource
150: * Description of the Parameter
151: */
152: protected void openResource(final IFile resource) {
153: IWorkbenchPage activePage = JavaPlugin.getActivePage();
154: if (activePage != null) {
155: try {
156: IDE.openEditor(activePage, resource);
157: } catch (PartInitException pie) {
158: //TODO
159: // Activator.logError("Unable to open resource " + resource,
160: // pie);//$NON-NLS-1$
161: }
162: }
163: }
164:
165: /**
166: * Description of the Method
167: *
168: * @param newResource
169: * Description of the Parameter
170: */
171: protected void selectAndReveal(IResource newResource) {
172: BasicNewResourceWizard.selectAndReveal(newResource, workbench
173: .getActiveWorkbenchWindow());
174: }
175: }
|