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