KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > ui > refactoring > RefactoringWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ltk.ui.refactoring;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jface.dialogs.DialogSettings;
16 import org.eclipse.jface.dialogs.IDialogSettings;
17 import org.eclipse.jface.wizard.IWizard;
18 import org.eclipse.jface.wizard.WizardPage;
19
20 import org.eclipse.ltk.core.refactoring.Refactoring;
21
22 /**
23  * An abstract base implementation of a refactoring wizard page. The class
24  * provides access to the refactoring wizard and to the refactoring itself.
25  * Refactoring wizard pages can only be added to a
26  * {@link org.eclipse.ltk.ui.refactoring.RefactoringWizard RefactoringWizard}.
27  * Adding them to a normal {@linkplain org.eclipse.jface.wizard.Wizard wizard}
28  * result in an exception.
29  * <p>
30  * Note: this class is not intended to be subclassed by clients. Clients should
31  * extend {@link org.eclipse.ltk.ui.refactoring.UserInputWizardPage}.
32  * </p>
33  *
34  * @see RefactoringWizard
35  * @see org.eclipse.ltk.core.refactoring.Refactoring
36  */

37 public abstract class RefactoringWizardPage extends WizardPage {
38
39     public static final String JavaDoc REFACTORING_SETTINGS= "org.eclipse.ltk.ui.refactoring.settings"; //$NON-NLS-1$
40

41     /** Does the page belong to a conventional wizard? */
42     private final boolean fConventionalWizard;
43     
44     /**
45      * Creates a new refactoring wizard page.
46      * <p>
47      * Note: this constructor is not intended to be used outside the refactoring
48      * framework.
49      * </p>
50      *
51      * @param name
52      * the page's name.
53      * @param wizard
54      * <code>true</code> if the page belongs to a conventional wizard, <code>false</code> otherwise
55      * @see org.eclipse.jface.wizard.IWizardPage#getName()
56      *
57      * @since 3.2
58      */

59     protected RefactoringWizardPage(String JavaDoc name, boolean wizard) {
60         super(name);
61         fConventionalWizard= wizard;
62     }
63     
64     /**
65      * Creates a new refactoring wizard page.
66      *
67      * @param name the page's name.
68      * @see org.eclipse.jface.wizard.IWizardPage#getName()
69      */

70     protected RefactoringWizardPage(String JavaDoc name) {
71         super(name);
72         fConventionalWizard= false;
73     }
74     
75     /**
76      * {@inheritDoc}
77      *
78      * This method asserts that the wizard passed as a parameter is of
79      * type <code>RefactoringWizard</code>.
80      */

81     public void setWizard(IWizard newWizard) {
82         Assert.isTrue(fConventionalWizard || newWizard instanceof RefactoringWizard);
83         super.setWizard(newWizard);
84     }
85
86     /**
87      * Returns the refactoring associated with this wizard page. Returns
88      * <code>null</code> if the page isn't been added to any refactoring
89      * wizard yet.
90      *
91      * @return the refactoring associated with this refactoring wizard page
92      * or <code>null</code>
93      */

94     protected Refactoring getRefactoring() {
95         RefactoringWizard wizard= getRefactoringWizard();
96         if (wizard == null)
97             return null;
98         return wizard.getRefactoring();
99     }
100     
101     /**
102      * Returns the page's refactoring wizard.
103      *
104      * @return the page's refactoring wizard or <code>null</code> if the
105      * wizard hasn't been set yet
106      */

107     protected RefactoringWizard getRefactoringWizard() {
108         IWizard wizard= getWizard();
109         if (wizard instanceof RefactoringWizard)
110             return (RefactoringWizard) wizard;
111         return null;
112     }
113     
114     /**
115      * Performs any actions appropriate in response to the user having pressed
116      * the Finish button, or refuse if finishing now is not permitted. This
117      * method is called by the refactoring wizard on the currently active
118      * refactoring wizard page.
119      *
120      * @return <code>true</code> to indicate the finish request was accepted,
121      * and <code>false</code> to indicate that the finish request was
122      * refused
123      */

124     protected boolean performFinish() {
125         return true;
126     }
127     
128     /**
129      * Returns the refactoring wizard's dialog settings.
130      *
131      * @return the refactoring wizard's dialog settings or <code>null</code>
132      * if no settings are associated with the refactoring wizard dialog
133      */

134     protected IDialogSettings getRefactoringSettings() {
135         IDialogSettings settings= getDialogSettings();
136         if (settings == null)
137             return null;
138         IDialogSettings result= settings.getSection(REFACTORING_SETTINGS);
139         if (result == null) {
140             result= new DialogSettings(REFACTORING_SETTINGS);
141             settings.addSection(result);
142         }
143         return result;
144     }
145 }
146
Popular Tags