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.ide.IDE;
34 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
36 public abstract class NewElementWizard extends Wizard implements INewWizard {
38 private IWorkbench fWorkbench;
40 private IStructuredSelection fSelection;
42 public NewElementWizard() {
43 setNeedsProgressMonitor(true);
46 protected void openResource(final IFile resource) {
47 final IWorkbenchPage activePage = PHPeclipsePlugin.getActivePage();
48 if (activePage != null) {
49 final Display display = getShell().getDisplay();
50 if (display != null) {
51 display.asyncExec(new Runnable() {
54 IDE.openEditor(activePage, resource, true);
55 } catch (PartInitException e) {
56 PHPeclipsePlugin.log(e);
65 * Subclasses should override to perform the actions of the wizard. This
66 * method is run in the wizard container's context as a workspace runnable.
68 protected void finishPage(IProgressMonitor monitor)
69 throws InterruptedException, CoreException {
72 protected void handleFinishException(Shell shell,
73 InvocationTargetException e) {
74 String title = NewWizardMessages
75 .getString("NewElementWizard.op_error.title"); //$NON-NLS-1$
76 String message = NewWizardMessages
77 .getString("NewElementWizard.op_error.message"); //$NON-NLS-1$
78 ExceptionHandler.handle(e, shell, title, message);
82 * @see Wizard#performFinish
84 public boolean performFinish() {
85 IWorkspaceRunnable op = new IWorkspaceRunnable() {
86 public void run(IProgressMonitor monitor) throws CoreException,
87 OperationCanceledException {
90 } catch (InterruptedException e) {
91 throw new OperationCanceledException(e.getMessage());
96 getContainer().run(false, true, new WorkbenchRunnableAdapter(op));
97 } catch (InvocationTargetException e) {
98 handleFinishException(getShell(), e);
100 } catch (InterruptedException e) {
106 // protected void warnAboutTypeCommentDeprecation() {
107 // String key= IUIConstants.DIALOGSTORE_TYPECOMMENT_DEPRECATED;
108 // if (OptionalMessageDialog.isDialogEnabled(key)) {
109 // Templates templates= Templates.getInstance();
110 // boolean isOldWorkspace= templates.getTemplates("filecomment").length > 0
111 // && templates.getTemplates("typecomment").length > 0;
112 // //$NON-NLS-1$ //$NON-NLS-2$
113 // if (!isOldWorkspace) {
114 // OptionalMessageDialog.setDialogEnabled(key, false);
117 // NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.title");
120 // NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.message");
122 // OptionalMessageDialog.open(key, getShell(), title,
123 // OptionalMessageDialog.getDefaultImage(), message,
124 // OptionalMessageDialog.INFORMATION, new String[] {
125 // IDialogConstants.OK_LABEL }, 0);
132 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
133 * org.eclipse.jface.viewers.IStructuredSelection)
135 public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
136 fWorkbench = workbench;
137 fSelection = currentSelection;
140 public IStructuredSelection getSelection() {
144 public IWorkbench getWorkbench() {
148 protected void selectAndReveal(IResource newResource) {
149 BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench
150 .getActiveWorkbenchWindow());