1 11 package org.eclipse.ui.wizards.newresource; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.jface.resource.ImageDescriptor; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.ui.IWorkbench; 17 import org.eclipse.ui.IWorkbenchPage; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.PartInitException; 20 import org.eclipse.ui.dialogs.WizardNewFileCreationPage; 21 import org.eclipse.ui.ide.IDE; 22 import org.eclipse.ui.internal.ide.DialogUtil; 23 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 24 import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; 25 26 46 public class BasicNewFileResourceWizard extends BasicNewResourceWizard { 47 private WizardNewFileCreationPage mainPage; 48 49 52 public BasicNewFileResourceWizard() { 53 super(); 54 } 55 56 59 public void addPages() { 60 super.addPages(); 61 mainPage = new WizardNewFileCreationPage("newFilePage1", getSelection()); mainPage.setTitle(ResourceMessages.FileResource_pageTitle); 63 mainPage.setDescription(ResourceMessages.FileResource_description); 64 addPage(mainPage); 65 } 66 67 70 public void init(IWorkbench workbench, IStructuredSelection currentSelection) { 71 super.init(workbench, currentSelection); 72 setWindowTitle(ResourceMessages.FileResource_shellTitle); 73 setNeedsProgressMonitor(true); 74 } 75 76 79 protected void initializeDefaultPageImageDescriptor() { 80 ImageDescriptor desc = IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/newfile_wiz.png"); setDefaultPageImageDescriptor(desc); 82 } 83 84 87 public boolean performFinish() { 88 IFile file = mainPage.createNewFile(); 89 if (file == null) { 90 return false; 91 } 92 93 selectAndReveal(file); 94 95 IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); 97 try { 98 if (dw != null) { 99 IWorkbenchPage page = dw.getActivePage(); 100 if (page != null) { 101 IDE.openEditor(page, file, true); 102 } 103 } 104 } catch (PartInitException e) { 105 DialogUtil.openError(dw.getShell(), ResourceMessages.FileResource_errorMessage, 106 e.getMessage(), e); 107 } 108 109 return true; 110 } 111 } 112 | Popular Tags |