Mercurial > projects > dwt-addons
annotate dwtx/jface/wizard/Wizard.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | ef4534de0cf9 |
children |
rev | line source |
---|---|
9 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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.Wizard; | |
14 | |
35 | 15 import dwtx.jface.wizard.IWizard; |
16 import dwtx.jface.wizard.IWizardPage; | |
17 import dwtx.jface.wizard.IWizardContainer; | |
18 | |
9 | 19 |
20 import dwt.graphics.Image; | |
21 import dwt.graphics.RGB; | |
22 import dwt.widgets.Composite; | |
23 import dwt.widgets.Shell; | |
24 import dwtx.core.runtime.Assert; | |
25 import dwtx.jface.dialogs.IDialogSettings; | |
26 import dwtx.jface.resource.ImageDescriptor; | |
27 import dwtx.jface.resource.JFaceResources; | |
28 | |
35 | 29 import dwt.dwthelper.utils; |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
30 import dwtx.dwtxhelper.Collection; |
35 | 31 |
9 | 32 /** |
33 * An abstract base implementation of a wizard. A typical client subclasses | |
34 * <code>Wizard</code> to implement a particular wizard. | |
35 * <p> | |
36 * Subclasses may call the following methods to configure the wizard: | |
37 * <ul> | |
38 * <li><code>addPage</code></li> | |
39 * <li><code>setHelpAvailable</code></li> | |
40 * <li><code>setDefaultPageImageDescriptor</code></li> | |
41 * <li><code>setDialogSettings</code></li> | |
42 * <li><code>setNeedsProgressMonitor</code></li> | |
43 * <li><code>setTitleBarColor</code></li> | |
44 * <li><code>setWindowTitle</code></li> | |
45 * </ul> | |
46 * </p> | |
47 * <p> | |
48 * Subclasses may override these methods if required: | |
49 * <ul> | |
50 * <li>reimplement <code>createPageControls</code></li> | |
51 * <li>reimplement <code>performCancel</code></li> | |
52 * <li>extend <code>addPages</code></li> | |
53 * <li>reimplement <code>performFinish</code></li> | |
54 * <li>extend <code>dispose</code></li> | |
55 * </ul> | |
56 * </p> | |
57 * <p> | |
58 * Note that clients are free to implement <code>IWizard</code> from scratch | |
59 * instead of subclassing <code>Wizard</code>. Correct implementations of | |
60 * <code>IWizard</code> will work with any correct implementation of | |
61 * <code>IWizardPage</code>. | |
62 * </p> | |
63 */ | |
35 | 64 public abstract class Wizard : IWizard { |
9 | 65 /** |
66 * Image registry key of the default image for wizard pages (value | |
67 * <code>"dwtx.jface.wizard.Wizard.pageImage"</code>). | |
68 */ | |
69 public static final String DEFAULT_IMAGE = "dwtx.jface.wizard.Wizard.pageImage";//$NON-NLS-1$ | |
70 | |
71 /** | |
72 * The wizard container this wizard belongs to; <code>null</code> if none. | |
73 */ | |
74 private IWizardContainer container = null; | |
75 | |
76 /** | |
77 * This wizard's list of pages (element type: <code>IWizardPage</code>). | |
78 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
79 private List pages; |
9 | 80 |
81 /** | |
82 * Indicates whether this wizard needs a progress monitor. | |
83 */ | |
35 | 84 private bool needsProgressMonitor_ = false; |
9 | 85 |
86 /** | |
87 * Indicates whether this wizard needs previous and next buttons even if the | |
88 * wizard has only one page. | |
89 */ | |
90 private bool forcePreviousAndNextButtons = false; | |
91 | |
92 /** | |
93 * Indicates whether this wizard supports help. | |
94 */ | |
35 | 95 private bool isHelpAvailable_ = false; |
9 | 96 |
97 /** | |
98 * The default page image for pages without one of their one; | |
99 * <code>null</code> if none. | |
100 */ | |
101 private Image defaultImage = null; | |
102 | |
103 /** | |
104 * The default page image descriptor, used for creating a default page image | |
105 * if required; <code>null</code> if none. | |
106 */ | |
35 | 107 private ImageDescriptor defaultImageDescriptor; |
9 | 108 |
109 /** | |
110 * The color of the wizard title bar; <code>null</code> if none. | |
111 */ | |
112 private RGB titleBarColor = null; | |
113 | |
114 /** | |
115 * The window title string for this wizard; <code>null</code> if none. | |
116 */ | |
117 private String windowTitle = null; | |
118 | |
119 /** | |
120 * The dialog settings for this wizard; <code>null</code> if none. | |
121 */ | |
122 private IDialogSettings dialogSettings = null; | |
123 | |
124 /** | |
125 * Creates a new empty wizard. | |
126 */ | |
35 | 127 protected this() { |
128 //super(); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
129 pages = new ArrayList(); |
35 | 130 defaultImageDescriptor = JFaceResources.getImageRegistry().getDescriptor(DEFAULT_IMAGE); |
9 | 131 } |
132 | |
133 /** | |
134 * Adds a new page to this wizard. The page is inserted at the end of the | |
135 * page list. | |
136 * | |
137 * @param page | |
138 * the new page | |
139 */ | |
140 public void addPage(IWizardPage page) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
141 pages.add(cast(Object)page); |
9 | 142 page.setWizard(this); |
143 } | |
144 | |
145 /** | |
146 * The <code>Wizard</code> implementation of this <code>IWizard</code> | |
147 * method does nothing. Subclasses should extend if extra pages need to be | |
148 * added before the wizard opens. New pages should be added by calling | |
149 * <code>addPage</code>. | |
150 */ | |
151 public void addPages() { | |
152 } | |
153 | |
154 /* | |
155 * (non-Javadoc) Method declared on IWizard. | |
156 */ | |
157 public bool canFinish() { | |
158 // Default implementation is to check if all pages are complete. | |
159 for (int i = 0; i < pages.size(); i++) { | |
35 | 160 if (!(cast(IWizardPage) pages.get(i)).isPageComplete()) { |
9 | 161 return false; |
162 } | |
163 } | |
164 return true; | |
165 } | |
166 | |
167 /** | |
168 * The <code>Wizard</code> implementation of this <code>IWizard</code> | |
169 * method creates all the pages controls using | |
170 * <code>IDialogPage.createControl</code>. Subclasses should reimplement | |
171 * this method if they want to delay creating one or more of the pages | |
172 * lazily. The framework ensures that the contents of a page will be created | |
173 * before attempting to show it. | |
174 */ | |
175 public void createPageControls(Composite pageContainer) { | |
176 // the default behavior is to create all the pages controls | |
177 for (int i = 0; i < pages.size(); i++) { | |
35 | 178 IWizardPage page = cast(IWizardPage) pages.get(i); |
9 | 179 page.createControl(pageContainer); |
180 // page is responsible for ensuring the created control is | |
181 // accessable | |
182 // via getControl. | |
183 Assert.isNotNull(page.getControl()); | |
184 } | |
185 } | |
186 | |
187 /** | |
188 * The <code>Wizard</code> implementation of this <code>IWizard</code> | |
189 * method disposes all the pages controls using | |
190 * <code>DialogPage.dispose</code>. Subclasses should extend this method | |
191 * if the wizard instance maintains addition DWT resource that need to be | |
192 * disposed. | |
193 */ | |
194 public void dispose() { | |
195 // notify pages | |
196 for (int i = 0; i < pages.size(); i++) { | |
35 | 197 (cast(IWizardPage) pages.get(i)).dispose(); |
9 | 198 } |
199 // dispose of image | |
200 if (defaultImage !is null) { | |
201 JFaceResources.getResources().destroyImage(defaultImageDescriptor); | |
202 defaultImage = null; | |
203 } | |
204 } | |
205 | |
206 /* | |
207 * (non-Javadoc) Method declared on IWizard. | |
208 */ | |
209 public IWizardContainer getContainer() { | |
210 return container; | |
211 } | |
212 | |
213 /* | |
214 * (non-Javadoc) Method declared on IWizard. | |
215 */ | |
216 public Image getDefaultPageImage() { | |
217 if (defaultImage is null) { | |
218 defaultImage = JFaceResources.getResources().createImageWithDefault(defaultImageDescriptor); | |
219 } | |
220 return defaultImage; | |
221 } | |
222 | |
223 /* | |
224 * (non-Javadoc) Method declared on IWizard. | |
225 */ | |
226 public IDialogSettings getDialogSettings() { | |
227 return dialogSettings; | |
228 } | |
229 | |
230 /* | |
231 * (non-Javadoc) Method declared on IWizard. The default behavior is to | |
232 * return the page that was added to this wizard after the given page. | |
233 */ | |
234 public IWizardPage getNextPage(IWizardPage page) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
235 int index = pages.indexOf( cast(Object)page ); |
9 | 236 if (index is pages.size() - 1 || index is -1) { |
237 // last page or page not found | |
238 return null; | |
239 } | |
35 | 240 return cast(IWizardPage) pages.get(index + 1); |
9 | 241 } |
242 | |
243 /* | |
244 * (non-Javadoc) Method declared on IWizard. | |
245 */ | |
246 public IWizardPage getPage(String name) { | |
247 for (int i = 0; i < pages.size(); i++) { | |
35 | 248 IWizardPage page = cast(IWizardPage) pages.get(i); |
9 | 249 String pageName = page.getName(); |
250 if (pageName.equals(name)) { | |
251 return page; | |
252 } | |
253 } | |
254 return null; | |
255 } | |
256 | |
257 /* | |
258 * (non-Javadoc) Method declared on IWizard. | |
259 */ | |
260 public int getPageCount() { | |
261 return pages.size(); | |
262 } | |
263 | |
264 /* | |
265 * (non-Javadoc) Method declared on IWizard. | |
266 */ | |
267 public IWizardPage[] getPages() { | |
35 | 268 return arraycast!(IWizardPage)( pages.toArray()); |
9 | 269 } |
270 | |
271 /* | |
272 * (non-Javadoc) Method declared on IWizard. The default behavior is to | |
273 * return the page that was added to this wizard before the given page. | |
274 */ | |
275 public IWizardPage getPreviousPage(IWizardPage page) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
35
diff
changeset
|
276 int index = pages.indexOf(cast(Object)page); |
9 | 277 if (index is 0 || index is -1) { |
278 // first page or page not found | |
279 return null; | |
280 } | |
35 | 281 return cast(IWizardPage) pages.get(index - 1); |
9 | 282 } |
283 | |
284 /** | |
285 * Returns the wizard's shell if the wizard is visible. Otherwise | |
286 * <code>null</code> is returned. | |
287 * | |
288 * @return Shell | |
289 */ | |
290 public Shell getShell() { | |
291 if (container is null) { | |
292 return null; | |
293 } | |
294 return container.getShell(); | |
295 } | |
296 | |
297 /* | |
298 * (non-Javadoc) Method declared on IWizard. By default this is the first | |
299 * page inserted into the wizard. | |
300 */ | |
301 public IWizardPage getStartingPage() { | |
302 if (pages.size() is 0) { | |
303 return null; | |
304 } | |
35 | 305 return cast(IWizardPage) pages.get(0); |
9 | 306 } |
307 | |
308 /* | |
309 * (non-Javadoc) Method declared on IWizard. | |
310 */ | |
311 public RGB getTitleBarColor() { | |
312 return titleBarColor; | |
313 } | |
314 | |
315 /* | |
316 * (non-Javadoc) Method declared on IWizard. | |
317 */ | |
318 public String getWindowTitle() { | |
319 return windowTitle; | |
320 } | |
321 | |
322 /* | |
323 * (non-Javadoc) Method declared on IWizard. | |
324 */ | |
325 public bool isHelpAvailable() { | |
35 | 326 return isHelpAvailable_; |
9 | 327 } |
328 | |
329 /* | |
330 * (non-Javadoc) Method declared on IWizard. | |
331 */ | |
332 public bool needsPreviousAndNextButtons() { | |
333 return forcePreviousAndNextButtons || pages.size() > 1; | |
334 } | |
335 | |
336 /* | |
337 * (non-Javadoc) Method declared on IWizard. | |
338 */ | |
339 public bool needsProgressMonitor() { | |
35 | 340 return needsProgressMonitor_; |
9 | 341 } |
342 | |
343 /** | |
344 * The <code>Wizard</code> implementation of this <code>IWizard</code> | |
345 * method does nothing and returns <code>true</code>. Subclasses should | |
346 * reimplement this method if they need to perform any special cancel | |
347 * processing for their wizard. | |
348 */ | |
349 public bool performCancel() { | |
350 return true; | |
351 } | |
352 | |
353 /** | |
354 * Subclasses must implement this <code>IWizard</code> method to perform | |
355 * any special finish processing for their wizard. | |
356 */ | |
357 public abstract bool performFinish(); | |
358 | |
359 /* | |
360 * (non-Javadoc) Method declared on IWizard. | |
361 */ | |
362 public void setContainer(IWizardContainer wizardContainer) { | |
363 container = wizardContainer; | |
364 } | |
365 | |
366 /** | |
367 * Sets the default page image descriptor for this wizard. | |
368 * <p> | |
369 * This image descriptor will be used to generate an image for a page with | |
370 * no image of its own; the image will be computed once and cached. | |
371 * </p> | |
372 * | |
373 * @param imageDescriptor | |
374 * the default page image descriptor | |
375 */ | |
376 public void setDefaultPageImageDescriptor(ImageDescriptor imageDescriptor) { | |
377 defaultImageDescriptor = imageDescriptor; | |
378 } | |
379 | |
380 /** | |
381 * Sets the dialog settings for this wizard. | |
382 * <p> | |
383 * The dialog settings is used to record state between wizard invocations | |
384 * (for example, radio button selection, last import directory, etc.) | |
385 * </p> | |
386 * | |
387 * @param settings | |
388 * the dialog settings, or <code>null</code> if none | |
389 * @see #getDialogSettings | |
390 * | |
391 */ | |
392 public void setDialogSettings(IDialogSettings settings) { | |
393 dialogSettings = settings; | |
394 } | |
395 | |
396 /** | |
397 * Controls whether the wizard needs Previous and Next buttons even if it | |
398 * currently contains only one page. | |
399 * <p> | |
400 * This flag should be set on wizards where the first wizard page adds | |
401 * follow-on wizard pages based on user input. | |
402 * </p> | |
403 * | |
404 * @param b | |
405 * <code>true</code> to always show Next and Previous buttons, | |
406 * and <code>false</code> to suppress Next and Previous buttons | |
407 * for single page wizards | |
408 */ | |
409 public void setForcePreviousAndNextButtons(bool b) { | |
410 forcePreviousAndNextButtons = b; | |
411 } | |
412 | |
413 /** | |
414 * Sets whether help is available for this wizard. | |
415 * <p> | |
416 * The result of this method is typically used by the container to show or | |
417 * hide the Help button. | |
418 * </p> | |
419 * | |
420 * @param b | |
421 * <code>true</code> if help is available, and | |
422 * <code>false</code> if this wizard is helpless | |
423 * @see #isHelpAvailable() | |
424 */ | |
425 public void setHelpAvailable(bool b) { | |
35 | 426 isHelpAvailable_ = b; |
9 | 427 } |
428 | |
429 /** | |
430 * Sets whether this wizard needs a progress monitor. | |
431 * | |
432 * @param b | |
433 * <code>true</code> if a progress monitor is required, and | |
434 * <code>false</code> if none is needed | |
435 * @see #needsProgressMonitor() | |
436 */ | |
437 public void setNeedsProgressMonitor(bool b) { | |
35 | 438 needsProgressMonitor_ = b; |
9 | 439 } |
440 | |
441 /** | |
442 * Sets the title bar color for this wizard. | |
443 * | |
444 * @param color | |
445 * the title bar color | |
446 */ | |
447 public void setTitleBarColor(RGB color) { | |
448 titleBarColor = color; | |
449 } | |
450 | |
451 /** | |
452 * Sets the window title for the container that hosts this page to the given | |
453 * string. | |
454 * | |
455 * @param newTitle | |
456 * the window title for the container | |
457 */ | |
458 public void setWindowTitle(String newTitle) { | |
459 windowTitle = newTitle; | |
460 if (container !is null) { | |
461 container.updateWindowTitle(); | |
462 } | |
463 } | |
464 } |