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