1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.wizards;
13 import java.lang.reflect.InvocationTargetException;
15 import net.sourceforge.phpdt.internal.ui.actions.WorkbenchRunnableAdapter;
16 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.ui.WebUI;
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IWorkspaceRunnable;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.IProgressMonitor;
25 import org.eclipse.core.runtime.OperationCanceledException;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.wizard.Wizard;
28 import org.eclipse.swt.widgets.Display;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.ui.INewWizard;
31 import org.eclipse.ui.IWorkbench;
32 import org.eclipse.ui.IWorkbenchPage;
33 import org.eclipse.ui.PartInitException;
34 import org.eclipse.ui.ide.IDE;
35 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
37 public abstract class NewElementWizard extends Wizard implements INewWizard {
39 private IWorkbench fWorkbench;
41 private IStructuredSelection fSelection;
43 public NewElementWizard() {
44 setNeedsProgressMonitor(true);
47 protected void openResource(final IFile resource) {
48 final IWorkbenchPage activePage = WebUI.getActivePage();
49 if (activePage != null) {
50 final Display display = getShell().getDisplay();
51 if (display != null) {
52 display.asyncExec(new Runnable() {
55 IDE.openEditor(activePage, resource, true);
56 } catch (PartInitException e) {
57 PHPeclipsePlugin.log(e);
66 * Subclasses should override to perform the actions of the wizard. This
67 * method is run in the wizard container's context as a workspace runnable.
69 protected void finishPage(IProgressMonitor monitor)
70 throws InterruptedException, CoreException {
73 protected void handleFinishException(Shell shell,
74 InvocationTargetException e) {
75 String title = NewWizardMessages
76 .getString("NewElementWizard.op_error.title"); //$NON-NLS-1$
77 String message = NewWizardMessages
78 .getString("NewElementWizard.op_error.message"); //$NON-NLS-1$
79 ExceptionHandler.handle(e, shell, title, message);
83 * @see Wizard#performFinish
85 public boolean performFinish() {
86 IWorkspaceRunnable op = new IWorkspaceRunnable() {
87 public void run(IProgressMonitor monitor) throws CoreException,
88 OperationCanceledException {
91 } catch (InterruptedException e) {
92 throw new OperationCanceledException(e.getMessage());
97 getContainer().run(false, true, new WorkbenchRunnableAdapter(op));
98 } catch (InvocationTargetException e) {
99 handleFinishException(getShell(), e);
101 } catch (InterruptedException e) {
107 // protected void warnAboutTypeCommentDeprecation() {
108 // String key= IUIConstants.DIALOGSTORE_TYPECOMMENT_DEPRECATED;
109 // if (OptionalMessageDialog.isDialogEnabled(key)) {
110 // Templates templates= Templates.getInstance();
111 // boolean isOldWorkspace= templates.getTemplates("filecomment").length > 0
112 // && templates.getTemplates("typecomment").length > 0;
113 // //$NON-NLS-1$ //$NON-NLS-2$
114 // if (!isOldWorkspace) {
115 // OptionalMessageDialog.setDialogEnabled(key, false);
118 // NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.title");
121 // NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.message");
123 // OptionalMessageDialog.open(key, getShell(), title,
124 // OptionalMessageDialog.getDefaultImage(), message,
125 // OptionalMessageDialog.INFORMATION, new String[] {
126 // IDialogConstants.OK_LABEL }, 0);
133 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
134 * org.eclipse.jface.viewers.IStructuredSelection)
136 public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
137 fWorkbench = workbench;
138 fSelection = currentSelection;
141 public IStructuredSelection getSelection() {
145 public IWorkbench getWorkbench() {
149 protected void selectAndReveal(IResource newResource) {
150 BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench
151 .getActiveWorkbenchWindow());