]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / wizards / NewAnnotationCreationWizard.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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.ui.wizards;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.jdt.core.IJavaElement;
20
21 import org.eclipse.jdt.ui.wizards.NewAnnotationWizardPage;
22
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
24 import org.eclipse.jdt.internal.ui.JavaPluginImages;
25
26 public class NewAnnotationCreationWizard extends NewElementWizard {
27
28     private NewAnnotationWizardPage fPage;
29     private boolean fOpenEditorOnFinish;
30
31         public NewAnnotationCreationWizard(NewAnnotationWizardPage page, boolean openEditorOnFinish) {
32                 setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWANNOT);
33                 setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
34                 setWindowTitle(NewWizardMessages.NewAnnotationCreationWizard_title);
35
36                 fPage= page;
37                 fOpenEditorOnFinish= openEditorOnFinish;
38         }
39
40         public NewAnnotationCreationWizard() {
41                 this(null, true);
42         }
43
44         /*
45          * @see Wizard#addPages
46          */
47         @Override
48         public void addPages() {
49                 super.addPages();
50                 if (fPage == null) {
51                         fPage= new NewAnnotationWizardPage();
52                         fPage.init(getSelection());
53                 }
54                 addPage(fPage);
55
56         }
57
58         /* (non-Javadoc)
59          * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#canRunForked()
60          */
61         @Override
62         protected boolean canRunForked() {
63                 return !fPage.isEnclosingTypeSelected();
64         }
65
66         /* (non-Javadoc)
67          * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
68          */
69         @Override
70         protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
71                 fPage.createType(monitor); // use the full progress monitor
72         }
73
74         /* (non-Javadoc)
75          * @see org.eclipse.jface.wizard.IWizard#performFinish()
76          */
77         @Override
78         public boolean performFinish() {
79                 warnAboutTypeCommentDeprecation();
80                 boolean res= super.performFinish();
81                 if (res) {
82                         IResource resource= fPage.getModifiedResource();
83                         if (resource != null) {
84                                 selectAndReveal(resource);
85                                 if (fOpenEditorOnFinish) {
86                                         openResource((IFile) resource);
87                                 }
88                         }
89                 }
90                 return res;
91         }
92
93         /* (non-Javadoc)
94          * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
95          */
96         @Override
97         public IJavaElement getCreatedElement() {
98                 return fPage.getCreatedType();
99         }
100 }