]> git.uio.no Git - ifi-stolz-refaktor.git/blobdiff - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / wizards / NewAnnotationCreationWizard.java
diff --git a/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java b/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/wizards/NewAnnotationCreationWizard.java
new file mode 100644 (file)
index 0000000..fada22a
--- /dev/null
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.wizards;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+
+import org.eclipse.jdt.core.IJavaElement;
+
+import org.eclipse.jdt.ui.wizards.NewAnnotationWizardPage;
+
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+
+public class NewAnnotationCreationWizard extends NewElementWizard {
+
+    private NewAnnotationWizardPage fPage;
+    private boolean fOpenEditorOnFinish;
+
+       public NewAnnotationCreationWizard(NewAnnotationWizardPage page, boolean openEditorOnFinish) {
+               setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWANNOT);
+               setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
+               setWindowTitle(NewWizardMessages.NewAnnotationCreationWizard_title);
+
+               fPage= page;
+               fOpenEditorOnFinish= openEditorOnFinish;
+       }
+
+       public NewAnnotationCreationWizard() {
+               this(null, true);
+       }
+
+       /*
+        * @see Wizard#addPages
+        */
+       @Override
+       public void addPages() {
+               super.addPages();
+               if (fPage == null) {
+                       fPage= new NewAnnotationWizardPage();
+                       fPage.init(getSelection());
+               }
+               addPage(fPage);
+
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#canRunForked()
+        */
+       @Override
+       protected boolean canRunForked() {
+               return !fPage.isEnclosingTypeSelected();
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
+        */
+       @Override
+       protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+               fPage.createType(monitor); // use the full progress monitor
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.wizard.IWizard#performFinish()
+        */
+       @Override
+       public boolean performFinish() {
+               warnAboutTypeCommentDeprecation();
+               boolean res= super.performFinish();
+               if (res) {
+                       IResource resource= fPage.getModifiedResource();
+                       if (resource != null) {
+                               selectAndReveal(resource);
+                               if (fOpenEditorOnFinish) {
+                                       openResource((IFile) resource);
+                               }
+                       }
+               }
+               return res;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#getCreatedElement()
+        */
+       @Override
+       public IJavaElement getCreatedElement() {
+               return fPage.getCreatedType();
+       }
+}