KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > MultiStepWizard


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.ui.internal.ide.dialogs;
12
13 import org.eclipse.jface.wizard.IWizardPage;
14 import org.eclipse.jface.wizard.Wizard;
15 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
16 import org.eclipse.ui.internal.ide.dialogs.MultiStepConfigureWizardPage.WizardStepContainer;
17
18 /**
19  * Standard workbench wizard to handle a multi-step page. The
20  * wizard is allowed any number of pages before the multi-step
21  * page is presented to the user.
22  * <p>
23  * Example:
24  * <pre>
25  * IWizard wizard = new MultiStepWizard();
26  * WizardDialog dialog = new MultiStepWizardDialog(shell, wizard);
27  * dialog.open();
28  * </pre>
29  * </p>
30  */

31 public abstract class MultiStepWizard extends Wizard {
32     private MultiStepWizardDialog wizardDialog;
33
34     private MultiStepReviewWizardPage reviewPage;
35
36     private MultiStepConfigureWizardPage configPage;
37
38     /**
39      * Creates an empty wizard
40      */

41     protected MultiStepWizard() {
42         super();
43         setNeedsProgressMonitor(true);
44     }
45
46     /**
47      * Adds any custom pages to the wizard before
48      * the multi-step review and configure pages are
49      * added.
50      */

51     protected abstract void addCustomPages();
52
53     /* (non-Javadoc)
54      * Method declared on IWizard.
55      */

56     public final void addPages() {
57         super.addPages();
58         addCustomPages();
59
60         reviewPage = new MultiStepReviewWizardPage(
61                 "multiStepReviewWizardPage", this);//$NON-NLS-1$
62
reviewPage.setTitle(getReviewPageTitle());
63         reviewPage.setDescription(getReviewPageDescription());
64         this.addPage(reviewPage);
65
66         configPage = new MultiStepConfigureWizardPage(
67                 "multiStepConfigureWizardPage");//$NON-NLS-1$
68
configPage.setTitle(getConfigurePageTitle());
69         configPage.setDescription(getConfigurePageDescription());
70         configPage.setWizardDialog(wizardDialog);
71         this.addPage(configPage);
72     }
73
74     /* (non-Javadoc)
75      * Method declared on IWizard.
76      */

77     public boolean canFinish() {
78         if (getContainer().getCurrentPage() == reviewPage) {
79             return canFinishOnReviewPage();
80         } else if (isConfigureStepMode()) {
81             return getStepContainer().canWizardFinish();
82         } else {
83             return false;
84         }
85     }
86
87     /**
88      * Returns whether the wizard wants the Finish button
89      * enabled on the review page. Should only happen if
90      * there is only one step and that step does not require
91      * further interaction with the user. The Next button will
92      * be disabled and the instructions updated.
93      */

94     protected abstract boolean canFinishOnReviewPage();
95
96     /* (non-Javadoc)
97      * Method declared on IWizard.
98      */

99     public void dispose() {
100         super.dispose();
101         wizardDialog = null;
102     }
103
104     /**
105      * Returns the title for the multi-step configure
106      * page.
107      */

108     protected abstract String JavaDoc getConfigurePageTitle();
109
110     /**
111      * Returns the description for the multi-step configure
112      * page.
113      */

114     protected abstract String JavaDoc getConfigurePageDescription();
115
116     /**
117      * Returns the title for the multi-step review
118      * page.
119      */

120     protected abstract String JavaDoc getReviewPageTitle();
121
122     /**
123      * Returns the label used on the finish button to
124      * to indicate finishing a step. Can be <code>null</code>
125      * if no special label is required.
126      * <p>
127      * The default implementation is to return the translated
128      * label "Finish Step".
129      * </p><p>
130      * On the last step, the finish button label is changed to
131      * be "Finish" and will no be changed.
132      * </p>
133      */

134     protected String JavaDoc getFinishStepLabel(WizardStep[] steps) {
135         return IDEWorkbenchMessages.MultiStepWizard_finishLabel;
136     }
137
138     /* (non-Javadoc)
139      * Method declared on IWizard.
140      */

141     public final IWizardPage getPreviousPage(IWizardPage page) {
142         if (page == configPage) {
143             return null;
144         } else {
145             return super.getPreviousPage(page);
146         }
147     }
148
149     /**
150      * Returns the description for the multi-step review
151      * page.
152      */

153     protected abstract String JavaDoc getReviewPageDescription();
154
155     /**
156      * Returns the container handler for the pages
157      * of the step's wizard.
158      */

159     /* package */WizardStepContainer getStepContainer() {
160         return configPage.getStepContainer();
161     }
162
163     /**
164      * Handles the problem of a missing step wizard.
165      *
166      * @return <code>true</code> to retry, <code>false</code> to terminate
167      * multi step wizard dialog.
168      */

169     /* package */abstract boolean handleMissingStepWizard(WizardStep step);
170
171     /**
172      * Returns whether the wizard is configuring steps
173      */

174     /* package */boolean isConfigureStepMode() {
175         return getContainer().getCurrentPage() == configPage;
176     }
177
178     /* (non-Javadoc)
179      * Method declared on IWizard.
180      */

181     public final boolean performCancel() {
182         if (isConfigureStepMode()) {
183             return getStepContainer().performCancel();
184         } else {
185             return true;
186         }
187     }
188
189     /* (non-Javadoc)
190      * Method declared on IWizard.
191      */

192     public boolean performFinish() {
193         // Finish on review page is a shortcut to performing
194
// the steps.
195
if (getContainer().getCurrentPage() == reviewPage) {
196             getContainer().showPage(configPage);
197             return false;
198         }
199
200         // Does nothing as each step is responsible
201
// to complete its work when its wizard is
202
// done.
203
return true;
204     }
205
206     /**
207      * Returns the collection of steps for the wizard.
208      */

209     public final WizardStep[] getSteps() {
210         if (reviewPage != null) {
211             return reviewPage.getSteps();
212         } else {
213             return new WizardStep[0];
214         }
215     }
216
217     /**
218      * Sets the collection of steps for the wizard.
219      * Ignored if the multi-step review and configure
220      * pages are not yet created.
221      */

222     public final void setSteps(WizardStep[] steps) {
223         if (reviewPage != null) {
224             reviewPage.setSteps(steps);
225         }
226         if (configPage != null) {
227             configPage.setSteps(steps);
228         }
229     }
230
231     /**
232      * Sets the multi-step wizard dialog processing this
233      * wizard.
234      */

235     /* package */void setWizardDialog(MultiStepWizardDialog dialog) {
236         wizardDialog = dialog;
237         if (configPage != null) {
238             configPage.setWizardDialog(wizardDialog);
239         }
240     }
241 }
242
Popular Tags