1 11 package org.eclipse.jdt.internal.debug.ui.snippeteditor; 12 13 import org.eclipse.jdt.core.IJavaElement; 14 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 15 import org.eclipse.jdt.internal.debug.ui.JavaDebugImages; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.viewers.StructuredSelection; 18 import org.eclipse.jface.wizard.Wizard; 19 import org.eclipse.ui.IEditorInput; 20 import org.eclipse.ui.IEditorPart; 21 import org.eclipse.ui.INewWizard; 22 import org.eclipse.ui.IWorkbench; 23 import org.eclipse.ui.IWorkbenchPage; 24 25 28 public class NewSnippetFileCreationWizard extends Wizard implements INewWizard { 29 30 private NewSnippetFileWizardPage fPage; 31 private IStructuredSelection fSelection; 32 33 public NewSnippetFileCreationWizard() { 34 setNeedsProgressMonitor(true); 35 setWindowTitle(SnippetMessages.getString("NewSnippetFileCreationWizard.title")); } 37 38 41 public void addPages() { 42 super.addPages(); 43 if (fSelection == null) { 44 IJavaElement elem= getActiveEditorJavaInput(); 45 if (elem != null) { 46 fSelection= new StructuredSelection(elem); 47 } else { 48 fSelection= StructuredSelection.EMPTY; 49 } 50 } 51 fPage= new NewSnippetFileWizardPage(fSelection); 52 addPage(fPage); 53 } 54 55 58 public boolean performFinish() { 59 return fPage.finish(); 60 } 61 62 65 public void init(IWorkbench workbench, IStructuredSelection selection) { 66 fSelection= selection; 67 setDefaultPageImageDescriptor(JavaDebugImages.getImageDescriptor(JavaDebugImages.IMG_WIZBAN_NEWSCRAPPAGE)); 68 } 69 70 74 private IJavaElement getActiveEditorJavaInput() { 75 IWorkbenchPage page= JDIDebugUIPlugin.getActivePage(); 76 if (page != null) { 77 IEditorPart part= page.getActiveEditor(); 78 if (part != null) { 79 IEditorInput editorInput= part.getEditorInput(); 80 if (editorInput != null) { 81 return (IJavaElement)editorInput.getAdapter(IJavaElement.class); 82 } 83 } 84 } 85 return null; 86 } 87 } 88 | Popular Tags |