Mercurial > projects > dwt-addons
annotate dwtx/jface/wizard/WizardPage.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | ea8ff534f622 |
children |
rev | line source |
---|---|
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 { | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
65 alias DialogPage.setMessage setMessage; |
35 | 66 |
67 /** | |
68 * This page's name. | |
69 */ | |
70 private String name; | |
71 | |
72 /** | |
73 * The wizard to which this page belongs; <code>null</code> | |
74 * if this page has yet to be added to a wizard. | |
75 */ | |
76 private IWizard wizard = null; | |
77 | |
78 /** | |
79 * Indicates whether this page is complete. | |
80 */ | |
81 private bool isPageComplete_ = true; | |
82 | |
83 /** | |
84 * The page that was shown right before this page became visible; | |
85 * <code>null</code> if none. | |
86 */ | |
87 private IWizardPage previousPage = null; | |
88 | |
89 /** | |
90 * Creates a new wizard page with the given name, and | |
91 * with no title or image. | |
92 * | |
93 * @param pageName the name of the page | |
94 */ | |
95 protected this(String pageName) { | |
96 this(pageName, null, cast(ImageDescriptor) null); | |
97 } | |
98 | |
99 /** | |
100 * Creates a new wizard page with the given name, title, and image. | |
101 * | |
102 * @param pageName the name of the page | |
103 * @param title the title for this wizard page, | |
104 * or <code>null</code> if none | |
105 * @param titleImage the image descriptor for the title of this wizard page, | |
106 * or <code>null</code> if none | |
107 */ | |
108 protected this(String pageName, String title, | |
109 ImageDescriptor titleImage) { | |
110 super(title, titleImage); | |
111 Assert.isNotNull(pageName); // page name must not be null | |
112 name = pageName; | |
113 } | |
114 | |
115 /** | |
116 * The <code>WizardPage</code> implementation of this <code>IWizardPage</code> | |
117 * method returns <code>true</code> if this page is complete (<code>isPageComplete</code>) | |
118 * and there is a next page to flip to. Subclasses may override (extend or reimplement). | |
119 * | |
120 * @see #getNextPage | |
121 * @see #isPageComplete() | |
122 */ | |
123 public bool canFlipToNextPage() { | |
124 return isPageComplete() && getNextPage() !is null; | |
125 } | |
126 | |
127 /** | |
128 * Returns the wizard container for this wizard page. | |
129 * | |
130 * @return the wizard container, or <code>null</code> if this | |
131 * wizard page has yet to be added to a wizard, or the | |
132 * wizard has yet to be added to a container | |
133 */ | |
134 protected IWizardContainer getContainer() { | |
135 if (wizard is null) { | |
136 return null; | |
137 } | |
138 return wizard.getContainer(); | |
139 } | |
140 | |
141 /** | |
142 * Returns the dialog settings for this wizard page. | |
143 * | |
144 * @return the dialog settings, or <code>null</code> if none | |
145 */ | |
146 protected IDialogSettings getDialogSettings() { | |
147 if (wizard is null) { | |
148 return null; | |
149 } | |
150 return wizard.getDialogSettings(); | |
151 } | |
152 | |
153 /* (non-Javadoc) | |
154 * Method declared on IDialogPage. | |
155 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
156 public override Image getImage() { |
35 | 157 Image result = super.getImage(); |
158 | |
159 if (result is null && wizard !is null) { | |
160 return wizard.getDefaultPageImage(); | |
161 } | |
162 | |
163 return result; | |
164 } | |
165 | |
166 /* (non-Javadoc) | |
167 * Method declared on IWizardPage. | |
168 */ | |
169 public String getName() { | |
170 return name; | |
171 } | |
172 | |
173 /* (non-Javadoc) | |
174 * Method declared on IWizardPage. | |
175 * The default behavior is to ask the wizard for the next page. | |
176 */ | |
177 public IWizardPage getNextPage() { | |
178 if (wizard is null) { | |
179 return null; | |
180 } | |
181 return wizard.getNextPage(this); | |
182 } | |
183 | |
184 /* (non-Javadoc) | |
185 * Method declared on IWizardPage. | |
186 * The default behavior is return the cached previous back or, | |
187 * lacking that, to ask the wizard for the previous page. | |
188 */ | |
189 public IWizardPage getPreviousPage() { | |
190 if (previousPage !is null) { | |
191 return previousPage; | |
192 } | |
193 | |
194 if (wizard is null) { | |
195 return null; | |
196 } | |
197 | |
198 return wizard.getPreviousPage(this); | |
199 } | |
200 | |
201 /** | |
202 * The <code>WizardPage</code> implementation of this method declared on | |
203 * <code>DialogPage</code> returns the shell of the container. | |
204 * The advantage of this implementation is that the shell is accessable | |
205 * once the container is created even though this page's control may not | |
206 * yet be created. | |
207 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
208 public override Shell getShell() { |
35 | 209 |
210 IWizardContainer container = getContainer(); | |
211 if (container is null) { | |
212 return null; | |
213 } | |
214 | |
215 // Ask the wizard since our contents may not have been created. | |
216 return container.getShell(); | |
217 } | |
218 | |
219 /* (non-Javadoc) | |
220 * Method declared on IWizardPage. | |
221 */ | |
222 public IWizard getWizard() { | |
223 return wizard; | |
224 } | |
225 | |
226 /** | |
227 * Returns whether this page is the current one in the wizard's container. | |
228 * | |
229 * @return <code>true</code> if the page is active, | |
230 * and <code>false</code> otherwise | |
231 */ | |
232 protected bool isCurrentPage() { | |
233 return (getContainer() !is null && this is getContainer() | |
234 .getCurrentPage()); | |
235 } | |
236 | |
237 /** | |
238 * The <code>WizardPage</code> implementation of this <code>IWizard</code> method | |
239 * returns the value of an internal state variable set by | |
240 * <code>setPageComplete</code>. Subclasses may extend. | |
241 */ | |
242 public bool isPageComplete() { | |
243 return isPageComplete_; | |
244 } | |
245 | |
246 /** | |
247 * The <code>WizardPage</code> implementation of this <code>IDialogPage</code> | |
248 * method extends the <code>DialogPage</code> implementation to update | |
249 * the wizard container title bar. Subclasses may extend. | |
250 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
251 public override void setDescription(String description) { |
35 | 252 super.setDescription(description); |
253 if (isCurrentPage()) { | |
254 getContainer().updateTitleBar(); | |
255 } | |
256 } | |
257 | |
258 /** | |
259 * The <code>WizardPage</code> implementation of this method | |
260 * declared on <code>DialogPage</code> updates the container | |
261 * if this is the current page. | |
262 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
263 public override void setErrorMessage(String newMessage) { |
35 | 264 super.setErrorMessage(newMessage); |
265 if (isCurrentPage()) { | |
266 getContainer().updateMessage(); | |
267 } | |
268 } | |
269 | |
270 /** | |
271 * The <code>WizardPage</code> implementation of this method | |
272 * declared on <code>DialogPage</code> updates the container | |
273 * if this page is the current page. | |
274 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
275 public override void setImageDescriptor(ImageDescriptor image) { |
35 | 276 super.setImageDescriptor(image); |
277 if (isCurrentPage()) { | |
278 getContainer().updateTitleBar(); | |
279 } | |
280 } | |
281 | |
282 /** | |
283 * The <code>WizardPage</code> implementation of this method | |
284 * declared on <code>DialogPage</code> updates the container | |
285 * if this is the current page. | |
286 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
287 public override void setMessage(String newMessage, int newType) { |
35 | 288 super.setMessage(newMessage, newType); |
289 if (isCurrentPage()) { | |
290 getContainer().updateMessage(); | |
291 } | |
292 } | |
293 | |
294 /** | |
295 * Sets whether this page is complete. | |
296 * <p> | |
297 * This information is typically used by the wizard to decide | |
298 * when it is okay to move on to the next page or finish up. | |
299 * </p> | |
300 * | |
301 * @param complete <code>true</code> if this page is complete, and | |
302 * and <code>false</code> otherwise | |
303 * @see #isPageComplete() | |
304 */ | |
305 public void setPageComplete(bool complete) { | |
306 isPageComplete_ = complete; | |
307 if (isCurrentPage()) { | |
308 getContainer().updateButtons(); | |
309 } | |
310 } | |
311 | |
312 /* (non-Javadoc) | |
313 * Method declared on IWizardPage. | |
314 */ | |
315 public void setPreviousPage(IWizardPage page) { | |
316 previousPage = page; | |
317 } | |
318 | |
319 /** | |
320 * The <code>WizardPage</code> implementation of this <code>IDialogPage</code> | |
321 * method extends the <code>DialogPage</code> implementation to update | |
322 * the wizard container title bar. Subclasses may extend. | |
323 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
324 public override void setTitle(String title) { |
35 | 325 super.setTitle(title); |
326 if (isCurrentPage()) { | |
327 getContainer().updateTitleBar(); | |
328 } | |
329 } | |
330 | |
331 /* (non-Javadoc) | |
332 * Method declared on IWizardPage. | |
333 */ | |
334 public void setWizard(IWizard newWizard) { | |
335 wizard = newWizard; | |
336 } | |
337 | |
338 /** | |
339 * Returns a printable representation of this wizard page suitable | |
340 * only for debug purposes. | |
341 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
342 public override String toString() { |
35 | 343 return name; |
344 } | |
345 } |