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;
 
  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               IDE.openEditor(activePage, resource, true);
 
  54             } catch (PartInitException e) {
 
  55               PHPeclipsePlugin.log(e);
 
  64    * Subclasses should override to perform the actions of the wizard. This method is run in the wizard container's context as a
 
  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;
 
 105   // //$NON-NLS-1$ //$NON-NLS-2$
 
 106   //                    if (!isOldWorkspace) {
 
 107   //                            OptionalMessageDialog.setDialogEnabled(key, false);
 
 109   //                    String title= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.title"); //$NON-NLS-1$
 
 110   //                    String message= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.message"); //$NON-NLS-1$
 
 111   //                    OptionalMessageDialog.open(key, getShell(), title, OptionalMessageDialog.getDefaultImage(), message,
 
 112   // OptionalMessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
 
 119    * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
 
 121   public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
 
 122     fWorkbench = workbench;
 
 123     fSelection = currentSelection;
 
 126   public IStructuredSelection getSelection() {
 
 130   public IWorkbench getWorkbench() {
 
 134   protected void selectAndReveal(IResource newResource) {
 
 135     BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow());