35
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.wizard.WizardPage;
|
|
14
|
|
15 import dwtx.jface.wizard.IWizardPage;
|
|
16 import dwtx.jface.wizard.IWizard;
|
|
17 import dwtx.jface.wizard.IWizardContainer;
|
|
18
|
|
19 import dwt.graphics.Image;
|
|
20 import dwt.widgets.Shell;
|
|
21 import dwtx.core.runtime.Assert;
|
|
22 import dwtx.jface.dialogs.DialogPage;
|
|
23 import dwtx.jface.dialogs.IDialogSettings;
|
|
24 import dwtx.jface.resource.ImageDescriptor;
|
|
25
|
|
26 import dwt.dwthelper.utils;
|
|
27
|
|
28 /**
|
|
29 * An abstract base implementation of a wizard page.
|
|
30 * <p>
|
|
31 * Subclasses must implement the <code>createControl</code> method
|
|
32 * to create the specific controls for the wizard page.
|
|
33 * </p>
|
|
34 * <p>
|
|
35 * Subclasses may call the following methods to configure the wizard page:
|
|
36 * <ul>
|
|
37 * <li><code>setDescription</code></li>
|
|
38 * <li><code>setErrorMessage</code></li>
|
|
39 * <li><code>setImageDescriptor</code></li>
|
|
40 * <li><code>setMessage</code></li>
|
|
41 * <li><code>setPageComplete</code></li>
|
|
42 * <li><code>setPreviousPage</code></li>
|
|
43 * <li><code>setTitle</code></li>
|
|
44 * </ul>
|
|
45 * </p>
|
|
46 * <p>
|
|
47 * Subclasses may override these methods if required:
|
|
48 * <ul>
|
|
49 * <li><code>performHelp</code> - may be reimplemented to display help for the page</li>
|
|
50 * <li><code>canFlipToNextPage</code> - may be extended or reimplemented</li>
|
|
51 * <li><code>isPageComplete</code> - may be extended </li>
|
|
52 * <li><code>setDescription</code> - may be extended </li>
|
|
53 * <li><code>setTitle</code> - may be extended </li>
|
|
54 * <li><code>dispose</code> - may be extended to dispose additional allocated DWT resources</li>
|
|
55 * </ul>
|
|
56 * </p>
|
|
57 * <p>
|
|
58 * Note that clients are free to implement <code>IWizardPage</code> from scratch
|
|
59 * instead of subclassing <code>WizardPage</code>. Correct implementations of
|
|
60 * <code>IWizardPage</code> will work with any correct implementation of
|
|
61 * <code>IWizard</code>.
|
|
62 * </p>
|
|
63 */
|
|
64 public abstract class WizardPage : DialogPage, IWizardPage {
|
|
65
|
|
66 /**
|
|
67 * This page's name.
|
|
68 */
|
|
69 private String name;
|
|
70
|
|
71 /**
|
|
72 * The wizard to which this page belongs; <code>null</code>
|
|
73 * if this page has yet to be added to a wizard.
|
|
74 */
|
|
75 private IWizard wizard = null;
|
|
76
|
|
77 /**
|
|
78 * Indicates whether this page is complete.
|
|
79 */
|
|
80 private bool isPageComplete_ = true;
|
|
81
|
|
82 /**
|
|
83 * The page that was shown right before this page became visible;
|
|
84 * <code>null</code> if none.
|
|
85 */
|
|
86 private IWizardPage previousPage = null;
|
|
87
|
|
88 /**
|
|
89 * Creates a new wizard page with the given name, and
|
|
90 * with no title or image.
|
|
91 *
|
|
92 * @param pageName the name of the page
|
|
93 */
|
|
94 protected this(String pageName) {
|
|
95 this(pageName, null, cast(ImageDescriptor) null);
|
|
96 }
|
|
97
|
|
98 /**
|
|
99 * Creates a new wizard page with the given name, title, and image.
|
|
100 *
|
|
101 * @param pageName the name of the page
|
|
102 * @param title the title for this wizard page,
|
|
103 * or <code>null</code> if none
|
|
104 * @param titleImage the image descriptor for the title of this wizard page,
|
|
105 * or <code>null</code> if none
|
|
106 */
|
|
107 protected this(String pageName, String title,
|
|
108 ImageDescriptor titleImage) {
|
|
109 super(title, titleImage);
|
|
110 Assert.isNotNull(pageName); // page name must not be null
|
|
111 name = pageName;
|
|
112 }
|
|
113
|
|
114 /**
|
|
115 * The <code>WizardPage</code> implementation of this <code>IWizardPage</code>
|
|
116 * method returns <code>true</code> if this page is complete (<code>isPageComplete</code>)
|
|
117 * and there is a next page to flip to. Subclasses may override (extend or reimplement).
|
|
118 *
|
|
119 * @see #getNextPage
|
|
120 * @see #isPageComplete()
|
|
121 */
|
|
122 public bool canFlipToNextPage() {
|
|
123 return isPageComplete() && getNextPage() !is null;
|
|
124 }
|
|
125
|
|
126 /**
|
|
127 * Returns the wizard container for this wizard page.
|
|
128 *
|
|
129 * @return the wizard container, or <code>null</code> if this
|
|
130 * wizard page has yet to be added to a wizard, or the
|
|
131 * wizard has yet to be added to a container
|
|
132 */
|
|
133 protected IWizardContainer getContainer() {
|
|
134 if (wizard is null) {
|
|
135 return null;
|
|
136 }
|
|
137 return wizard.getContainer();
|
|
138 }
|
|
139
|
|
140 /**
|
|
141 * Returns the dialog settings for this wizard page.
|
|
142 *
|
|
143 * @return the dialog settings, or <code>null</code> if none
|
|
144 */
|
|
145 protected IDialogSettings getDialogSettings() {
|
|
146 if (wizard is null) {
|
|
147 return null;
|
|
148 }
|
|
149 return wizard.getDialogSettings();
|
|
150 }
|
|
151
|
|
152 /* (non-Javadoc)
|
|
153 * Method declared on IDialogPage.
|
|
154 */
|
|
155 public Image getImage() {
|
|
156 Image result = super.getImage();
|
|
157
|
|
158 if (result is null && wizard !is null) {
|
|
159 return wizard.getDefaultPageImage();
|
|
160 }
|
|
161
|
|
162 return result;
|
|
163 }
|
|
164
|
|
165 /* (non-Javadoc)
|
|
166 * Method declared on IWizardPage.
|
|
167 */
|
|
168 public String getName() {
|
|
169 return name;
|
|
170 }
|
|
171
|
|
172 /* (non-Javadoc)
|
|
173 * Method declared on IWizardPage.
|
|
174 * The default behavior is to ask the wizard for the next page.
|
|
175 */
|
|
176 public IWizardPage getNextPage() {
|
|
177 if (wizard is null) {
|
|
178 return null;
|
|
179 }
|
|
180 return wizard.getNextPage(this);
|
|
181 }
|
|
182
|
|
183 /* (non-Javadoc)
|
|
184 * Method declared on IWizardPage.
|
|
185 * The default behavior is return the cached previous back or,
|
|
186 * lacking that, to ask the wizard for the previous page.
|
|
187 */
|
|
188 public IWizardPage getPreviousPage() {
|
|
189 if (previousPage !is null) {
|
|
190 return previousPage;
|
|
191 }
|
|
192
|
|
193 if (wizard is null) {
|
|
194 return null;
|
|
195 }
|
|
196
|
|
197 return wizard.getPreviousPage(this);
|
|
198 }
|
|
199
|
|
200 /**
|
|
201 * The <code>WizardPage</code> implementation of this method declared on
|
|
202 * <code>DialogPage</code> returns the shell of the container.
|
|
203 * The advantage of this implementation is that the shell is accessable
|
|
204 * once the container is created even though this page's control may not
|
|
205 * yet be created.
|
|
206 */
|
|
207 public Shell getShell() {
|
|
208
|
|
209 IWizardContainer container = getContainer();
|
|
210 if (container is null) {
|
|
211 return null;
|
|
212 }
|
|
213
|
|
214 // Ask the wizard since our contents may not have been created.
|
|
215 return container.getShell();
|
|
216 }
|
|
217
|
|
218 /* (non-Javadoc)
|
|
219 * Method declared on IWizardPage.
|
|
220 */
|
|
221 public IWizard getWizard() {
|
|
222 return wizard;
|
|
223 }
|
|
224
|
|
225 /**
|
|
226 * Returns whether this page is the current one in the wizard's container.
|
|
227 *
|
|
228 * @return <code>true</code> if the page is active,
|
|
229 * and <code>false</code> otherwise
|
|
230 */
|
|
231 protected bool isCurrentPage() {
|
|
232 return (getContainer() !is null && this is getContainer()
|
|
233 .getCurrentPage());
|
|
234 }
|
|
235
|
|
236 /**
|
|
237 * The <code>WizardPage</code> implementation of this <code>IWizard</code> method
|
|
238 * returns the value of an internal state variable set by
|
|
239 * <code>setPageComplete</code>. Subclasses may extend.
|
|
240 */
|
|
241 public bool isPageComplete() {
|
|
242 return isPageComplete_;
|
|
243 }
|
|
244
|
|
245 /**
|
|
246 * The <code>WizardPage</code> implementation of this <code>IDialogPage</code>
|
|
247 * method extends the <code>DialogPage</code> implementation to update
|
|
248 * the wizard container title bar. Subclasses may extend.
|
|
249 */
|
|
250 public void setDescription(String description) {
|
|
251 super.setDescription(description);
|
|
252 if (isCurrentPage()) {
|
|
253 getContainer().updateTitleBar();
|
|
254 }
|
|
255 }
|
|
256
|
|
257 /**
|
|
258 * The <code>WizardPage</code> implementation of this method
|
|
259 * declared on <code>DialogPage</code> updates the container
|
|
260 * if this is the current page.
|
|
261 */
|
|
262 public void setErrorMessage(String newMessage) {
|
|
263 super.setErrorMessage(newMessage);
|
|
264 if (isCurrentPage()) {
|
|
265 getContainer().updateMessage();
|
|
266 }
|
|
267 }
|
|
268
|
|
269 /**
|
|
270 * The <code>WizardPage</code> implementation of this method
|
|
271 * declared on <code>DialogPage</code> updates the container
|
|
272 * if this page is the current page.
|
|
273 */
|
|
274 public void setImageDescriptor(ImageDescriptor image) {
|
|
275 super.setImageDescriptor(image);
|
|
276 if (isCurrentPage()) {
|
|
277 getContainer().updateTitleBar();
|
|
278 }
|
|
279 }
|
|
280
|
|
281 /**
|
|
282 * The <code>WizardPage</code> implementation of this method
|
|
283 * declared on <code>DialogPage</code> updates the container
|
|
284 * if this is the current page.
|
|
285 */
|
|
286 public void setMessage(String newMessage, int newType) {
|
|
287 super.setMessage(newMessage, newType);
|
|
288 if (isCurrentPage()) {
|
|
289 getContainer().updateMessage();
|
|
290 }
|
|
291 }
|
|
292
|
|
293 /**
|
|
294 * Sets whether this page is complete.
|
|
295 * <p>
|
|
296 * This information is typically used by the wizard to decide
|
|
297 * when it is okay to move on to the next page or finish up.
|
|
298 * </p>
|
|
299 *
|
|
300 * @param complete <code>true</code> if this page is complete, and
|
|
301 * and <code>false</code> otherwise
|
|
302 * @see #isPageComplete()
|
|
303 */
|
|
304 public void setPageComplete(bool complete) {
|
|
305 isPageComplete_ = complete;
|
|
306 if (isCurrentPage()) {
|
|
307 getContainer().updateButtons();
|
|
308 }
|
|
309 }
|
|
310
|
|
311 /* (non-Javadoc)
|
|
312 * Method declared on IWizardPage.
|
|
313 */
|
|
314 public void setPreviousPage(IWizardPage page) {
|
|
315 previousPage = page;
|
|
316 }
|
|
317
|
|
318 /**
|
|
319 * The <code>WizardPage</code> implementation of this <code>IDialogPage</code>
|
|
320 * method extends the <code>DialogPage</code> implementation to update
|
|
321 * the wizard container title bar. Subclasses may extend.
|
|
322 */
|
|
323 public void setTitle(String title) {
|
|
324 super.setTitle(title);
|
|
325 if (isCurrentPage()) {
|
|
326 getContainer().updateTitleBar();
|
|
327 }
|
|
328 }
|
|
329
|
|
330 /* (non-Javadoc)
|
|
331 * Method declared on IWizardPage.
|
|
332 */
|
|
333 public void setWizard(IWizard newWizard) {
|
|
334 wizard = newWizard;
|
|
335 }
|
|
336
|
|
337 /**
|
|
338 * Returns a printable representation of this wizard page suitable
|
|
339 * only for debug purposes.
|
|
340 */
|
|
341 public String toString() {
|
|
342 return name;
|
|
343 }
|
|
344 }
|