KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > snippeteditor > NewSnippetFileCreationWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
26  * Creates a new snippet page
27  */

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")); //$NON-NLS-1$
36
}
37
38     /* (non-Javadoc)
39      * @see org.eclipse.jface.wizard.IWizard#addPages()
40      */

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     /* (non-Javadoc)
56      * @see org.eclipse.jface.wizard.IWizard#performFinish()
57      */

58     public boolean performFinish() {
59         return fPage.finish();
60     }
61
62     /* (non-Javadoc)
63      * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
64      */

65     public void init(IWorkbench workbench, IStructuredSelection selection) {
66         fSelection= selection;
67         setDefaultPageImageDescriptor(JavaDebugImages.getImageDescriptor(JavaDebugImages.IMG_WIZBAN_NEWSCRAPPAGE));
68     }
69     
70     /**
71      * If the current active editor edits a Java element return it, else
72      * return null
73      */

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