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;
19 import org.eclipse.core.resources.IFile;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.resources.IWorkspaceRunnable;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.core.runtime.OperationCanceledException;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.jface.wizard.Wizard;
27 import org.eclipse.swt.widgets.Display;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.ui.INewWizard;
30 import org.eclipse.ui.IWorkbench;
31 import org.eclipse.ui.IWorkbenchPage;
32 import org.eclipse.ui.PartInitException;
33 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
36 public abstract class NewElementWizard extends Wizard implements INewWizard {
38 private IWorkbench fWorkbench;
39 private IStructuredSelection fSelection;
41 public NewElementWizard() {
42 setNeedsProgressMonitor(true);
45 protected void openResource(final IFile resource) {
46 final IWorkbenchPage activePage= PHPeclipsePlugin.getActivePage();
47 if (activePage != null) {
48 final Display display= getShell().getDisplay();
49 if (display != null) {
50 display.asyncExec(new Runnable() {
53 activePage.openEditor(resource);
54 } catch (PartInitException e) {
55 PHPeclipsePlugin.log(e);
64 * Subclasses should override to perform the actions of the wizard.
65 * This method is run in the wizard container's context as a workspace runnable.
67 protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
70 protected void handleFinishException(Shell shell, InvocationTargetException e) {
71 String title= NewWizardMessages.getString("NewElementWizard.op_error.title"); //$NON-NLS-1$
72 String message= NewWizardMessages.getString("NewElementWizard.op_error.message"); //$NON-NLS-1$
73 ExceptionHandler.handle(e, shell, title, message);
77 * @see Wizard#performFinish
79 public boolean performFinish() {
80 IWorkspaceRunnable op= new IWorkspaceRunnable() {
81 public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
84 } catch (InterruptedException e) {
85 throw new OperationCanceledException(e.getMessage());
90 getContainer().run(false, true, new WorkbenchRunnableAdapter(op));
91 } catch (InvocationTargetException e) {
92 handleFinishException(getShell(), e);
94 } catch (InterruptedException e) {
100 // protected void warnAboutTypeCommentDeprecation() {
101 // String key= IUIConstants.DIALOGSTORE_TYPECOMMENT_DEPRECATED;
102 // if (OptionalMessageDialog.isDialogEnabled(key)) {
103 // Templates templates= Templates.getInstance();
104 // boolean isOldWorkspace= templates.getTemplates("filecomment").length > 0 && templates.getTemplates("typecomment").length > 0; //$NON-NLS-1$ //$NON-NLS-2$
105 // if (!isOldWorkspace) {
106 // OptionalMessageDialog.setDialogEnabled(key, false);
108 // String title= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.title"); //$NON-NLS-1$
109 // String message= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.message"); //$NON-NLS-1$
110 // OptionalMessageDialog.open(key, getShell(), title, OptionalMessageDialog.getDefaultImage(), message, OptionalMessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
115 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
117 public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
118 fWorkbench= workbench;
119 fSelection= currentSelection;
122 public IStructuredSelection getSelection() {
126 public IWorkbench getWorkbench() {
130 protected void selectAndReveal(IResource newResource) {
131 BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow());