Mercurial > projects > dwt-addons
annotate dwtx/jface/wizard/WizardDialog.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 | c36336245fb1 |
children |
rev | line source |
---|---|
8 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
8 | 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 * Chris Gross (schtoo@schtoo.com) - patch for bug 16179 | |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 module dwtx.jface.wizard.WizardDialog; | |
15 | |
35 | 16 import dwtx.jface.wizard.IWizardContainer2; |
17 import dwtx.jface.wizard.IWizard; | |
18 import dwtx.jface.wizard.IWizardPage; | |
19 import dwtx.jface.wizard.ProgressMonitorPart; | |
8 | 20 |
35 | 21 // import java.lang.reflect.InvocationTargetException; |
22 // import java.util.HashMap; | |
23 // import java.util.Map; | |
8 | 24 |
25 import dwt.DWT; | |
26 import dwt.custom.BusyIndicator; | |
27 import dwt.events.HelpEvent; | |
28 import dwt.events.HelpListener; | |
29 import dwt.events.SelectionAdapter; | |
30 import dwt.events.SelectionEvent; | |
31 import dwt.graphics.Cursor; | |
32 import dwt.graphics.Point; | |
33 import dwt.graphics.Rectangle; | |
34 import dwt.layout.GridData; | |
35 import dwt.layout.GridLayout; | |
36 import dwt.widgets.Button; | |
37 import dwt.widgets.Composite; | |
38 import dwt.widgets.Control; | |
39 import dwt.widgets.Display; | |
40 import dwt.widgets.Label; | |
41 import dwt.widgets.Layout; | |
42 import dwt.widgets.Shell; | |
43 import dwtx.core.runtime.Assert; | |
44 import dwtx.core.runtime.IProgressMonitor; | |
45 import dwtx.core.runtime.IStatus; | |
46 import dwtx.core.runtime.ListenerList; | |
47 import dwtx.jface.dialogs.ControlEnableState; | |
48 import dwtx.jface.dialogs.IDialogConstants; | |
49 import dwtx.jface.dialogs.IMessageProvider; | |
50 import dwtx.jface.dialogs.IPageChangeProvider; | |
51 import dwtx.jface.dialogs.IPageChangedListener; | |
52 import dwtx.jface.dialogs.IPageChangingListener; | |
53 import dwtx.jface.dialogs.MessageDialog; | |
54 import dwtx.jface.dialogs.PageChangedEvent; | |
55 import dwtx.jface.dialogs.PageChangingEvent; | |
56 import dwtx.jface.dialogs.TitleAreaDialog; | |
57 import dwtx.jface.operation.IRunnableWithProgress; | |
58 import dwtx.jface.operation.ModalContext; | |
59 import dwtx.jface.resource.JFaceResources; | |
60 import dwtx.jface.util.SafeRunnable; | |
61 | |
35 | 62 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:
71
diff
changeset
|
63 import dwtx.dwtxhelper.Collection; |
35 | 64 import dwt.dwthelper.Runnable; |
65 | |
8 | 66 /** |
67 * A dialog to show a wizard to the end user. | |
68 * <p> | |
69 * In typical usage, the client instantiates this class with a particular | |
70 * wizard. The dialog serves as the wizard container and orchestrates the | |
71 * presentation of its pages. | |
72 * <p> | |
73 * The standard layout is roughly as follows: it has an area at the top | |
74 * containing both the wizard's title, description, and image; the actual wizard | |
75 * page appears in the middle; below that is a progress indicator (which is made | |
76 * visible if needed); and at the bottom of the page is message line and a | |
77 * button bar containing Help, Next, Back, Finish, and Cancel buttons (or some | |
78 * subset). | |
79 * </p> | |
80 * <p> | |
81 * Clients may subclass <code>WizardDialog</code>, although this is rarely | |
82 * required. | |
83 * </p> | |
84 */ | |
35 | 85 public class WizardDialog : TitleAreaDialog, IWizardContainer2, |
8 | 86 IPageChangeProvider { |
87 /** | |
88 * Image registry key for error message image (value | |
89 * <code>"dialog_title_error_image"</code>). | |
90 */ | |
35 | 91 public static const String WIZ_IMG_ERROR = "dialog_title_error_image"; //$NON-NLS-1$ |
8 | 92 |
93 // The wizard the dialog is currently showing. | |
94 private IWizard wizard; | |
95 | |
96 // Wizards to dispose | |
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:
71
diff
changeset
|
97 private ArrayList createdWizards; |
8 | 98 |
99 // Current nested wizards | |
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:
71
diff
changeset
|
100 private ArrayList nestedWizards; |
8 | 101 |
102 // The currently displayed page. | |
103 private IWizardPage currentPage = null; | |
104 | |
105 // The number of long running operation executed from the dialog. | |
106 private long activeRunningOperations = 0; | |
107 | |
108 // The current page message and description | |
109 private String pageMessage; | |
110 | |
111 private int pageMessageType = IMessageProvider.NONE; | |
112 | |
113 private String pageDescription; | |
114 | |
115 // The progress monitor | |
116 private ProgressMonitorPart progressMonitorPart; | |
117 | |
118 private Cursor waitCursor; | |
119 | |
120 private Cursor arrowCursor; | |
121 | |
122 private MessageDialog windowClosingDialog; | |
123 | |
124 // Navigation buttons | |
125 private Button backButton; | |
126 | |
127 private Button nextButton; | |
128 | |
129 private Button finishButton; | |
130 | |
131 private Button cancelButton; | |
132 | |
133 private Button helpButton; | |
134 | |
135 private SelectionAdapter cancelListener; | |
136 | |
137 private bool isMovingToPreviousPage = false; | |
138 | |
139 private Composite pageContainer; | |
140 | |
35 | 141 private PageContainerFillLayout pageContainerLayout; |
8 | 142 |
143 private int pageWidth = DWT.DEFAULT; | |
144 | |
145 private int pageHeight = DWT.DEFAULT; | |
146 | |
35 | 147 private static const String FOCUS_CONTROL = "focusControl"; //$NON-NLS-1$ |
8 | 148 |
149 private bool lockedUI = false; | |
150 | |
35 | 151 private ListenerList pageChangedListeners; |
8 | 152 |
35 | 153 private ListenerList pageChangingListeners; |
8 | 154 |
155 /** | |
156 * A layout for a container which includes several pages, like a notebook, | |
157 * wizard, or preference dialog. The size computed by this layout is the | |
158 * maximum width and height of all pages currently inserted into the | |
159 * container. | |
160 */ | |
35 | 161 protected class PageContainerFillLayout : Layout { |
8 | 162 /** |
163 * The margin width; <code>5</code> pixels by default. | |
164 */ | |
165 public int marginWidth = 5; | |
166 | |
167 /** | |
168 * The margin height; <code>5</code> pixels by default. | |
169 */ | |
170 public int marginHeight = 5; | |
171 | |
172 /** | |
173 * The minimum width; <code>0</code> pixels by default. | |
174 */ | |
175 public int minimumWidth = 0; | |
176 | |
177 /** | |
178 * The minimum height; <code>0</code> pixels by default. | |
179 */ | |
180 public int minimumHeight = 0; | |
181 | |
182 /** | |
183 * Creates new layout object. | |
184 * | |
185 * @param mw | |
186 * the margin width | |
187 * @param mh | |
188 * the margin height | |
189 * @param minW | |
190 * the minimum width | |
191 * @param minH | |
192 * the minimum height | |
193 */ | |
35 | 194 public this(int mw, int mh, int minW, int minH) { |
8 | 195 marginWidth = mw; |
196 marginHeight = mh; | |
197 minimumWidth = minW; | |
198 minimumHeight = minH; | |
199 } | |
200 | |
201 /* | |
202 * (non-Javadoc) Method declared on Layout. | |
203 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
204 public override Point computeSize(Composite composite, int wHint, int hHint, |
8 | 205 bool force) { |
206 if (wHint !is DWT.DEFAULT && hHint !is DWT.DEFAULT) { | |
207 return new Point(wHint, hHint); | |
208 } | |
209 Point result = null; | |
210 Control[] children = composite.getChildren(); | |
211 if (children.length > 0) { | |
212 result = new Point(0, 0); | |
213 for (int i = 0; i < children.length; i++) { | |
214 Point cp = children[i].computeSize(wHint, hHint, force); | |
215 result.x = Math.max(result.x, cp.x); | |
216 result.y = Math.max(result.y, cp.y); | |
217 } | |
218 result.x = result.x + 2 * marginWidth; | |
219 result.y = result.y + 2 * marginHeight; | |
220 } else { | |
221 Rectangle rect = composite.getClientArea(); | |
222 result = new Point(rect.width, rect.height); | |
223 } | |
224 result.x = Math.max(result.x, minimumWidth); | |
225 result.y = Math.max(result.y, minimumHeight); | |
226 if (wHint !is DWT.DEFAULT) { | |
227 result.x = wHint; | |
228 } | |
229 if (hHint !is DWT.DEFAULT) { | |
230 result.y = hHint; | |
231 } | |
232 return result; | |
233 } | |
234 | |
235 /** | |
236 * Returns the client area for the given composite according to this | |
237 * layout. | |
238 * | |
239 * @param c | |
240 * the composite | |
241 * @return the client area rectangle | |
242 */ | |
243 public Rectangle getClientArea(Composite c) { | |
244 Rectangle rect = c.getClientArea(); | |
245 rect.x = rect.x + marginWidth; | |
246 rect.y = rect.y + marginHeight; | |
247 rect.width = rect.width - 2 * marginWidth; | |
248 rect.height = rect.height - 2 * marginHeight; | |
249 return rect; | |
250 } | |
251 | |
252 /* | |
253 * (non-Javadoc) Method declared on Layout. | |
254 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
255 public override void layout(Composite composite, bool force) { |
8 | 256 Rectangle rect = getClientArea(composite); |
257 Control[] children = composite.getChildren(); | |
258 for (int i = 0; i < children.length; i++) { | |
259 children[i].setBounds(rect); | |
260 } | |
261 } | |
262 | |
263 /** | |
264 * Lays outs the page according to this layout. | |
265 * | |
266 * @param w | |
267 * the control | |
268 */ | |
269 public void layoutPage(Control w) { | |
270 w.setBounds(getClientArea(w.getParent())); | |
271 } | |
272 | |
273 /** | |
274 * Sets the location of the page so that its origin is in the upper left | |
275 * corner. | |
276 * | |
277 * @param w | |
278 * the control | |
279 */ | |
280 public void setPageLocation(Control w) { | |
281 w.setLocation(marginWidth, marginHeight); | |
282 } | |
283 } | |
284 | |
285 /** | |
286 * Creates a new wizard dialog for the given wizard. | |
287 * | |
288 * @param parentShell | |
289 * the parent shell | |
290 * @param newWizard | |
291 * the wizard this dialog is working on | |
292 */ | |
35 | 293 public this(Shell parentShell, IWizard newWizard) { |
118
a521c486e142
Fix: member variable initialized in wrong place
Frank Benoit <benoit@tionex.de>
parents:
104
diff
changeset
|
294 pageContainerLayout = new PageContainerFillLayout( 5, 5, 300, 225); |
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:
71
diff
changeset
|
295 createdWizards = new ArrayList(); |
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:
71
diff
changeset
|
296 nestedWizards = new ArrayList(); |
35 | 297 pageChangedListeners = new ListenerList(); |
298 pageChangingListeners = new ListenerList(); | |
299 | |
8 | 300 super(parentShell); |
301 setShellStyle(DWT.CLOSE | DWT.MAX | DWT.TITLE | DWT.BORDER | |
302 | DWT.APPLICATION_MODAL | DWT.RESIZE | getDefaultOrientation()); | |
303 setWizard(newWizard); | |
304 // since VAJava can't initialize an instance var with an anonymous | |
305 // class outside a constructor we do it here: | |
35 | 306 cancelListener = new class SelectionAdapter { |
8 | 307 public void widgetSelected(SelectionEvent e) { |
308 cancelPressed(); | |
309 } | |
310 }; | |
311 } | |
312 | |
313 /** | |
314 * About to start a long running operation triggered through the wizard. | |
315 * Shows the progress monitor and disables the wizard's buttons and | |
316 * controls. | |
317 * | |
318 * @param enableCancelButton | |
319 * <code>true</code> if the Cancel button should be enabled, | |
320 * and <code>false</code> if it should be disabled | |
321 * @return the saved UI state | |
322 */ | |
323 private Object aboutToStart(bool enableCancelButton) { | |
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:
71
diff
changeset
|
324 Map savedState = null; |
8 | 325 if (getShell() !is null) { |
326 // Save focus control | |
327 Control focusControl = getShell().getDisplay().getFocusControl(); | |
328 if (focusControl !is null && focusControl.getShell() !is getShell()) { | |
329 focusControl = null; | |
330 } | |
331 bool needsProgressMonitor = wizard.needsProgressMonitor(); | |
332 cancelButton.removeSelectionListener(cancelListener); | |
333 // Set the busy cursor to all shells. | |
334 Display d = getShell().getDisplay(); | |
335 waitCursor = new Cursor(d, DWT.CURSOR_WAIT); | |
336 setDisplayCursor(waitCursor); | |
337 // Set the arrow cursor to the cancel component. | |
338 arrowCursor = new Cursor(d, DWT.CURSOR_ARROW); | |
339 cancelButton.setCursor(arrowCursor); | |
340 // Deactivate shell | |
341 savedState = saveUIState(needsProgressMonitor && enableCancelButton); | |
342 if (focusControl !is null) { | |
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:
71
diff
changeset
|
343 savedState.put(stringcast(FOCUS_CONTROL), focusControl); |
8 | 344 } |
345 // Attach the progress monitor part to the cancel button | |
346 if (needsProgressMonitor) { | |
347 progressMonitorPart.attachToCancelComponent(cancelButton); | |
348 progressMonitorPart.setVisible(true); | |
349 } | |
350 } | |
35 | 351 return cast(Object) savedState; |
8 | 352 } |
353 | |
354 /** | |
355 * The Back button has been pressed. | |
356 */ | |
357 protected void backPressed() { | |
358 IWizardPage page = currentPage.getPreviousPage(); | |
359 if (page is null) { | |
360 // should never happen since we have already visited the page | |
361 return; | |
362 } | |
363 | |
364 // set flag to indicate that we are moving back | |
365 isMovingToPreviousPage = true; | |
366 // show the page | |
367 showPage(page); | |
368 } | |
369 | |
370 /* | |
371 * (non-Javadoc) Method declared on Dialog. | |
372 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
373 protected override void buttonPressed(int buttonId) { |
8 | 374 switch (buttonId) { |
375 case IDialogConstants.HELP_ID: { | |
376 helpPressed(); | |
377 break; | |
378 } | |
379 case IDialogConstants.BACK_ID: { | |
380 backPressed(); | |
381 break; | |
382 } | |
383 case IDialogConstants.NEXT_ID: { | |
384 nextPressed(); | |
385 break; | |
386 } | |
387 case IDialogConstants.FINISH_ID: { | |
388 finishPressed(); | |
389 break; | |
390 } | |
391 // The Cancel button has a listener which calls cancelPressed | |
392 // directly | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
183
diff
changeset
|
393 default: |
8 | 394 } |
395 } | |
396 | |
397 /** | |
398 * Calculates the difference in size between the given page and the page | |
399 * container. A larger page results in a positive delta. | |
400 * | |
401 * @param page | |
402 * the page | |
403 * @return the size difference encoded as a | |
404 * <code>new Point(deltaWidth,deltaHeight)</code> | |
405 */ | |
406 private Point calculatePageSizeDelta(IWizardPage page) { | |
407 Control pageControl = page.getControl(); | |
408 if (pageControl is null) { | |
409 // control not created yet | |
410 return new Point(0, 0); | |
411 } | |
412 Point contentSize = pageControl.computeSize(DWT.DEFAULT, DWT.DEFAULT, | |
413 true); | |
414 Rectangle rect = pageContainerLayout.getClientArea(pageContainer); | |
415 Point containerSize = new Point(rect.width, rect.height); | |
416 return new Point(Math.max(0, contentSize.x - containerSize.x), Math | |
417 .max(0, contentSize.y - containerSize.y)); | |
418 } | |
419 | |
420 /* | |
421 * (non-Javadoc) Method declared on Dialog. | |
422 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
423 protected override void cancelPressed() { |
8 | 424 if (activeRunningOperations <= 0) { |
425 // Close the dialog. The check whether the dialog can be | |
426 // closed or not is done in <code>okToClose</code>. | |
427 // This ensures that the check is also evaluated when the user | |
428 // presses the window's close button. | |
429 setReturnCode(CANCEL); | |
430 close(); | |
431 } else { | |
432 cancelButton.setEnabled(false); | |
433 } | |
434 } | |
435 | |
436 /* | |
437 * (non-Javadoc) | |
438 * | |
439 * @see dwtx.jface.window.Window#close() | |
440 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
441 public override bool close() { |
8 | 442 if (okToClose()) { |
443 return hardClose(); | |
444 } | |
445 return false; | |
446 } | |
447 | |
448 /* | |
449 * (non-Javadoc) Method declared on Window. | |
450 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
451 protected override void configureShell(Shell newShell) { |
8 | 452 super.configureShell(newShell); |
453 // Register help listener on the shell | |
35 | 454 newShell.addHelpListener(new class HelpListener { |
8 | 455 public void helpRequested(HelpEvent event) { |
456 // call perform help on the current page | |
457 if (currentPage !is null) { | |
458 currentPage.performHelp(); | |
459 } | |
460 } | |
461 }); | |
462 } | |
463 | |
464 /** | |
465 * Creates the buttons for this dialog's button bar. | |
466 * <p> | |
467 * The <code>WizardDialog</code> implementation of this framework method | |
468 * prevents the parent composite's columns from being made equal width in | |
469 * order to remove the margin between the Back and Next buttons. | |
470 * </p> | |
471 * | |
472 * @param parent | |
473 * the parent composite to contain the buttons | |
474 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
475 protected override void createButtonsForButtonBar(Composite parent) { |
35 | 476 (cast(GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; |
8 | 477 if (wizard.isHelpAvailable()) { |
478 helpButton = createButton(parent, IDialogConstants.HELP_ID, | |
479 IDialogConstants.HELP_LABEL, false); | |
480 } | |
481 if (wizard.needsPreviousAndNextButtons()) { | |
482 createPreviousAndNextButtons(parent); | |
483 } | |
484 finishButton = createButton(parent, IDialogConstants.FINISH_ID, | |
485 IDialogConstants.FINISH_LABEL, true); | |
486 cancelButton = createCancelButton(parent); | |
487 } | |
488 | |
489 /* | |
490 * (non-Javadoc) | |
491 * | |
492 * @see dwtx.jface.dialogs.Dialog#setButtonLayoutData(dwt.widgets.Button) | |
493 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
494 protected override void setButtonLayoutData(Button button) { |
8 | 495 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
496 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
497 | |
498 // On large fonts this can make this dialog huge | |
499 widthHint = Math.min(widthHint, | |
500 button.getDisplay().getBounds().width / 5); | |
501 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
502 data.widthHint = Math.max(widthHint, minSize.x); | |
503 | |
504 button.setLayoutData(data); | |
505 } | |
506 | |
507 /** | |
508 * Creates the Cancel button for this wizard dialog. Creates a standard (<code>DWT.PUSH</code>) | |
509 * button and registers for its selection events. Note that the number of | |
510 * columns in the button bar composite is incremented. The Cancel button is | |
511 * created specially to give it a removeable listener. | |
512 * | |
513 * @param parent | |
514 * the parent button bar | |
515 * @return the new Cancel button | |
516 */ | |
517 private Button createCancelButton(Composite parent) { | |
518 // increment the number of columns in the button bar | |
35 | 519 (cast(GridLayout) parent.getLayout()).numColumns++; |
8 | 520 Button button = new Button(parent, DWT.PUSH); |
521 button.setText(IDialogConstants.CANCEL_LABEL); | |
522 setButtonLayoutData(button); | |
523 button.setFont(parent.getFont()); | |
524 button.setData(new Integer(IDialogConstants.CANCEL_ID)); | |
525 button.addSelectionListener(cancelListener); | |
526 return button; | |
527 } | |
528 | |
529 /** | |
530 * Return the cancel button if the id is a the cancel id. | |
531 * | |
532 * @param id | |
533 * the button id | |
534 * @return the button corresponding to the button id | |
535 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
536 protected override Button getButton(int id) { |
8 | 537 if (id is IDialogConstants.CANCEL_ID) { |
538 return cancelButton; | |
539 } | |
540 return super.getButton(id); | |
541 } | |
542 | |
543 /** | |
544 * The <code>WizardDialog</code> implementation of this | |
545 * <code>Window</code> method calls call <code>IWizard.addPages</code> | |
546 * to allow the current wizard to add extra pages, then | |
547 * <code>super.createContents</code> to create the controls. It then calls | |
548 * <code>IWizard.createPageControls</code> to allow the wizard to | |
549 * pre-create their page controls prior to opening, so that the wizard opens | |
550 * to the correct size. And finally it shows the first page. | |
551 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
552 protected override Control createContents(Composite parent) { |
8 | 553 // Allow the wizard to add pages to itself |
554 // Need to call this now so page count is correct | |
555 // for determining if next/previous buttons are needed | |
556 wizard.addPages(); | |
557 Control contents = super.createContents(parent); | |
558 // Allow the wizard pages to precreate their page controls | |
559 createPageControls(); | |
560 // Show the first page | |
561 showStartingPage(); | |
562 return contents; | |
563 } | |
564 | |
565 /* | |
566 * (non-Javadoc) Method declared on Dialog. | |
567 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
568 protected override Control createDialogArea(Composite parent) { |
35 | 569 Composite composite = cast(Composite) super.createDialogArea(parent); |
8 | 570 // Build the Page container |
571 pageContainer = createPageContainer(composite); | |
572 GridData gd = new GridData(GridData.FILL_BOTH); | |
573 gd.widthHint = pageWidth; | |
574 gd.heightHint = pageHeight; | |
575 pageContainer.setLayoutData(gd); | |
576 pageContainer.setFont(parent.getFont()); | |
577 // Insert a progress monitor | |
578 GridLayout pmlayout = new GridLayout(); | |
579 pmlayout.numColumns = 1; | |
580 progressMonitorPart = createProgressMonitorPart(composite, pmlayout); | |
581 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); | |
582 progressMonitorPart.setLayoutData(gridData); | |
583 progressMonitorPart.setVisible(false); | |
584 // Build the separator line | |
585 Label separator = new Label(composite, DWT.HORIZONTAL | DWT.SEPARATOR); | |
586 separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
587 | |
588 applyDialogFont(progressMonitorPart); | |
589 return composite; | |
590 } | |
591 | |
592 /** | |
593 * Create the progress monitor part in the receiver. | |
594 * | |
595 * @param composite | |
596 * @param pmlayout | |
597 * @return ProgressMonitorPart | |
598 */ | |
599 protected ProgressMonitorPart createProgressMonitorPart( | |
600 Composite composite, GridLayout pmlayout) { | |
35 | 601 return new class(composite, pmlayout, DWT.DEFAULT) ProgressMonitorPart { |
602 | |
8 | 603 String currentTask = null; |
604 | |
35 | 605 this(Composite c, Layout l, int s ){ |
606 super(c,l,s); | |
607 } | |
608 | |
8 | 609 /* |
610 * (non-Javadoc) | |
611 * | |
612 * @see dwtx.jface.wizard.ProgressMonitorPart#setBlocked(dwtx.core.runtime.IStatus) | |
613 */ | |
614 public void setBlocked(IStatus reason) { | |
615 super.setBlocked(reason); | |
616 if (!lockedUI) { | |
617 getBlockedHandler().showBlocked(getShell(), this, reason, | |
618 currentTask); | |
619 } | |
620 } | |
621 | |
622 /* | |
623 * (non-Javadoc) | |
624 * | |
625 * @see dwtx.jface.wizard.ProgressMonitorPart#clearBlocked() | |
626 */ | |
627 public void clearBlocked() { | |
628 super.clearBlocked(); | |
629 if (!lockedUI) { | |
630 getBlockedHandler().clearBlocked(); | |
631 } | |
632 } | |
633 | |
634 /* | |
635 * (non-Javadoc) | |
636 * | |
637 * @see dwtx.jface.wizard.ProgressMonitorPart#beginTask(java.lang.String, | |
638 * int) | |
639 */ | |
640 public void beginTask(String name, int totalWork) { | |
641 super.beginTask(name, totalWork); | |
642 currentTask = name; | |
643 } | |
644 | |
645 /* | |
646 * (non-Javadoc) | |
647 * | |
648 * @see dwtx.jface.wizard.ProgressMonitorPart#setTaskName(java.lang.String) | |
649 */ | |
650 public void setTaskName(String name) { | |
651 super.setTaskName(name); | |
652 currentTask = name; | |
653 } | |
654 | |
655 /* | |
656 * (non-Javadoc) | |
657 * | |
658 * @see dwtx.jface.wizard.ProgressMonitorPart#subTask(java.lang.String) | |
659 */ | |
660 public void subTask(String name) { | |
661 super.subTask(name); | |
662 // If we haven't got anything yet use this value for more | |
663 // context | |
664 if (currentTask is null) { | |
665 currentTask = name; | |
666 } | |
667 } | |
668 }; | |
669 } | |
670 | |
671 /** | |
672 * Creates the container that holds all pages. | |
673 * | |
674 * @param parent | |
675 * @return Composite | |
676 */ | |
677 private Composite createPageContainer(Composite parent) { | |
678 Composite result = new Composite(parent, DWT.NULL); | |
679 result.setLayout(pageContainerLayout); | |
680 return result; | |
681 } | |
682 | |
683 /** | |
684 * Allow the wizard's pages to pre-create their page controls. This allows | |
685 * the wizard dialog to open to the correct size. | |
686 */ | |
687 private void createPageControls() { | |
688 // Allow the wizard pages to precreate their page controls | |
689 // This allows the wizard to open to the correct size | |
690 wizard.createPageControls(pageContainer); | |
691 // Ensure that all of the created pages are initially not visible | |
692 IWizardPage[] pages = wizard.getPages(); | |
693 for (int i = 0; i < pages.length; i++) { | |
694 IWizardPage page = pages[i]; | |
695 if (page.getControl() !is null) { | |
696 page.getControl().setVisible(false); | |
697 } | |
698 } | |
699 } | |
700 | |
701 /** | |
702 * Creates the Previous and Next buttons for this wizard dialog. Creates | |
703 * standard (<code>DWT.PUSH</code>) buttons and registers for their | |
704 * selection events. Note that the number of columns in the button bar | |
705 * composite is incremented. These buttons are created specially to prevent | |
706 * any space between them. | |
707 * | |
708 * @param parent | |
709 * the parent button bar | |
710 * @return a composite containing the new buttons | |
711 */ | |
712 private Composite createPreviousAndNextButtons(Composite parent) { | |
713 // increment the number of columns in the button bar | |
35 | 714 (cast(GridLayout) parent.getLayout()).numColumns++; |
8 | 715 Composite composite = new Composite(parent, DWT.NONE); |
716 // create a layout with spacing and margins appropriate for the font | |
717 // size. | |
718 GridLayout layout = new GridLayout(); | |
719 layout.numColumns = 0; // will be incremented by createButton | |
720 layout.marginWidth = 0; | |
721 layout.marginHeight = 0; | |
722 layout.horizontalSpacing = 0; | |
723 layout.verticalSpacing = 0; | |
724 composite.setLayout(layout); | |
725 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | |
726 | GridData.VERTICAL_ALIGN_CENTER); | |
727 composite.setLayoutData(data); | |
728 composite.setFont(parent.getFont()); | |
729 backButton = createButton(composite, IDialogConstants.BACK_ID, | |
730 IDialogConstants.BACK_LABEL, false); | |
731 nextButton = createButton(composite, IDialogConstants.NEXT_ID, | |
732 IDialogConstants.NEXT_LABEL, false); | |
733 return composite; | |
734 } | |
735 | |
736 /** | |
737 * Creates and return a new wizard closing dialog without openiong it. | |
738 * | |
739 * @return MessageDalog | |
740 */ | |
741 private MessageDialog createWizardClosingDialog() { | |
742 MessageDialog result = new MessageDialog(getShell(), | |
743 JFaceResources.getString("WizardClosingDialog.title"), //$NON-NLS-1$ | |
744 null, | |
745 JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$ | |
746 MessageDialog.QUESTION, | |
35 | 747 [ IDialogConstants.OK_LABEL ], 0); |
8 | 748 return result; |
749 } | |
750 | |
751 /** | |
752 * The Finish button has been pressed. | |
753 */ | |
754 protected void finishPressed() { | |
755 // Wizards are added to the nested wizards list in setWizard. | |
756 // This means that the current wizard is always the last wizard in the | |
757 // list. | |
758 // Note that we first call the current wizard directly (to give it a | |
759 // chance to | |
760 // abort, do work, and save state) then call the remaining n-1 wizards | |
761 // in the | |
762 // list (to save state). | |
763 if (wizard.performFinish()) { | |
764 // Call perform finish on outer wizards in the nested chain | |
765 // (to allow them to save state for example) | |
766 for (int i = 0; i < nestedWizards.size() - 1; i++) { | |
35 | 767 (cast(IWizard) nestedWizards.get(i)).performFinish(); |
8 | 768 } |
769 // Hard close the dialog. | |
770 setReturnCode(OK); | |
771 hardClose(); | |
772 } | |
773 } | |
774 | |
775 /* | |
776 * (non-Javadoc) Method declared on IWizardContainer. | |
777 */ | |
778 public IWizardPage getCurrentPage() { | |
779 return currentPage; | |
780 } | |
781 | |
782 /** | |
783 * Returns the progress monitor for this wizard dialog (if it has one). | |
784 * | |
785 * @return the progress monitor, or <code>null</code> if this wizard | |
786 * dialog does not have one | |
787 */ | |
788 protected IProgressMonitor getProgressMonitor() { | |
789 return progressMonitorPart; | |
790 } | |
791 | |
792 /** | |
793 * Returns the wizard this dialog is currently displaying. | |
794 * | |
795 * @return the current wizard | |
796 */ | |
797 protected IWizard getWizard() { | |
798 return wizard; | |
799 } | |
800 | |
801 /** | |
802 * Closes this window. | |
803 * | |
804 * @return <code>true</code> if the window is (or was already) closed, and | |
805 * <code>false</code> if it is still open | |
806 */ | |
807 private bool hardClose() { | |
808 // inform wizards | |
809 for (int i = 0; i < createdWizards.size(); i++) { | |
35 | 810 IWizard createdWizard = cast(IWizard) createdWizards.get(i); |
8 | 811 createdWizard.dispose(); |
812 // Remove this dialog as a parent from the managed wizard. | |
813 // Note that we do this after calling dispose as the wizard or | |
814 // its pages may need access to the container during | |
815 // dispose code | |
816 createdWizard.setContainer(null); | |
817 } | |
818 return super.close(); | |
819 } | |
820 | |
821 /** | |
822 * The Help button has been pressed. | |
823 */ | |
824 protected void helpPressed() { | |
825 if (currentPage !is null) { | |
826 currentPage.performHelp(); | |
827 } | |
828 } | |
829 | |
830 /** | |
831 * The Next button has been pressed. | |
832 */ | |
833 protected void nextPressed() { | |
834 IWizardPage page = currentPage.getNextPage(); | |
835 if (page is null) { | |
836 // something must have happend getting the next page | |
837 return; | |
838 } | |
839 | |
840 // show the next page | |
841 showPage(page); | |
842 } | |
843 | |
844 /** | |
845 * Notifies page changing listeners and returns result of page changing | |
846 * processing to the sender. | |
847 * | |
848 * @param eventType | |
849 * @return <code>true</code> if page changing listener completes | |
850 * successfully, <code>false</code> otherwise | |
851 */ | |
852 private bool doPageChanging(IWizardPage targetPage) { | |
35 | 853 PageChangingEvent e = new PageChangingEvent(this, cast(Object)getCurrentPage(), |
854 cast(Object)targetPage); | |
8 | 855 firePageChanging(e); |
856 // Prevent navigation if necessary | |
857 return e.doit; | |
858 } | |
859 | |
860 /** | |
861 * Checks whether it is alright to close this wizard dialog and performed | |
862 * standard cancel processing. If there is a long running operation in | |
863 * progress, this method posts an alert message saying that the wizard | |
864 * cannot be closed. | |
865 * | |
866 * @return <code>true</code> if it is alright to close this dialog, and | |
867 * <code>false</code> if it is not | |
868 */ | |
869 private bool okToClose() { | |
870 if (activeRunningOperations > 0) { | |
871 synchronized (this) { | |
872 windowClosingDialog = createWizardClosingDialog(); | |
873 } | |
874 windowClosingDialog.open(); | |
875 synchronized (this) { | |
876 windowClosingDialog = null; | |
877 } | |
878 return false; | |
879 } | |
880 return wizard.performCancel(); | |
881 } | |
882 | |
883 /** | |
884 * Restores the enabled/disabled state of the given control. | |
885 * | |
886 * @param w | |
887 * the control | |
888 * @param h | |
889 * the map (key type: <code>String</code>, element type: | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
890 * <code>Boolean</code>) |
8 | 891 * @param key |
892 * the key | |
893 * @see #saveEnableStateAndSet | |
894 */ | |
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:
71
diff
changeset
|
895 private void restoreEnableState(Control w, Map h, String key) { |
8 | 896 if (w !is null) { |
71 | 897 Boolean b = cast(Boolean) h.get(stringcast(key)); |
8 | 898 if (b !is null) { |
899 w.setEnabled(b.booleanValue()); | |
900 } | |
901 } | |
902 } | |
903 | |
904 /** | |
905 * Restores the enabled/disabled state of the wizard dialog's buttons and | |
906 * the tree of controls for the currently showing page. | |
907 * | |
908 * @param state | |
909 * a map containing the saved state as returned by | |
910 * <code>saveUIState</code> | |
911 * @see #saveUIState | |
912 */ | |
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:
71
diff
changeset
|
913 private void restoreUIState(Map state) { |
8 | 914 restoreEnableState(backButton, state, "back"); //$NON-NLS-1$ |
915 restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$ | |
916 restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$ | |
917 restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$ | |
918 restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$ | |
35 | 919 Object pageValue = state.get(stringcast("page")); //$NON-NLS-1$ |
8 | 920 if (pageValue !is null) { |
35 | 921 (cast(ControlEnableState) pageValue).restore(); |
8 | 922 } |
923 } | |
924 | |
925 /** | |
926 * This implementation of IRunnableContext#run(bool, bool, | |
927 * IRunnableWithProgress) blocks until the runnable has been run, regardless | |
928 * of the value of <code>fork</code>. It is recommended that | |
929 * <code>fork</code> is set to true in most cases. If <code>fork</code> | |
930 * is set to <code>false</code>, the runnable will run in the UI thread | |
931 * and it is the runnable's responsibility to call | |
932 * <code>Display.readAndDispatch()</code> to ensure UI responsiveness. | |
933 * | |
934 * UI state is saved prior to executing the long-running operation and is | |
935 * restored after the long-running operation completes executing. Any | |
936 * attempt to change the UI state of the wizard in the long-running | |
937 * operation will be nullified when original UI state is restored. | |
938 * | |
939 */ | |
940 public void run(bool fork, bool cancelable, | |
35 | 941 IRunnableWithProgress runnable) { |
8 | 942 // The operation can only be canceled if it is executed in a separate |
943 // thread. | |
944 // Otherwise the UI is blocked anyway. | |
945 Object state = null; | |
946 if (activeRunningOperations is 0) { | |
947 state = aboutToStart(fork && cancelable); | |
948 } | |
949 activeRunningOperations++; | |
950 try { | |
951 if (!fork) { | |
952 lockedUI = true; | |
953 } | |
954 ModalContext.run(runnable, fork, getProgressMonitor(), getShell() | |
955 .getDisplay()); | |
956 lockedUI = false; | |
957 } finally { | |
958 activeRunningOperations--; | |
959 // Stop if this is the last one | |
960 if (state !is null) { | |
961 stopped(state); | |
962 } | |
963 } | |
964 } | |
965 | |
966 /** | |
967 * Saves the enabled/disabled state of the given control in the given map, | |
968 * which must be modifiable. | |
969 * | |
970 * @param w | |
971 * the control, or <code>null</code> if none | |
972 * @param h | |
973 * the map (key type: <code>String</code>, element type: | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
974 * <code>Boolean</code>) |
8 | 975 * @param key |
976 * the key | |
977 * @param enabled | |
978 * <code>true</code> to enable the control, and | |
979 * <code>false</code> to disable it | |
980 * @see #restoreEnableState(Control, Map, String) | |
981 */ | |
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:
71
diff
changeset
|
982 private void saveEnableStateAndSet(Control w, Map h, String key, |
8 | 983 bool enabled) { |
984 if (w !is null) { | |
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:
71
diff
changeset
|
985 h.put(stringcast(key), w.getEnabled() ? Boolean.TRUE : Boolean.FALSE); |
8 | 986 w.setEnabled(enabled); |
987 } | |
988 } | |
989 | |
990 /** | |
991 * Captures and returns the enabled/disabled state of the wizard dialog's | |
992 * buttons and the tree of controls for the currently showing page. All | |
993 * these controls are disabled in the process, with the possible exception | |
994 * of the Cancel button. | |
995 * | |
996 * @param keepCancelEnabled | |
997 * <code>true</code> if the Cancel button should remain | |
998 * enabled, and <code>false</code> if it should be disabled | |
999 * @return a map containing the saved state suitable for restoring later | |
1000 * with <code>restoreUIState</code> | |
1001 * @see #restoreUIState | |
1002 */ | |
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:
71
diff
changeset
|
1003 private Map saveUIState(bool keepCancelEnabled) { |
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:
71
diff
changeset
|
1004 Map savedState = new HashMap(10); |
8 | 1005 saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$ |
1006 saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$ | |
1007 saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$ | |
1008 saveEnableStateAndSet(cancelButton, savedState, | |
1009 "cancel", keepCancelEnabled); //$NON-NLS-1$ | |
1010 saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$ | |
1011 if (currentPage !is null) { | |
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:
71
diff
changeset
|
1012 savedState.put(stringcast("page"), ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ |
8 | 1013 } |
1014 return savedState; | |
1015 } | |
1016 | |
1017 /** | |
1018 * Sets the given cursor for all shells currently active for this window's | |
1019 * display. | |
1020 * | |
1021 * @param c | |
1022 * the cursor | |
1023 */ | |
1024 private void setDisplayCursor(Cursor c) { | |
1025 Shell[] shells = getShell().getDisplay().getShells(); | |
1026 for (int i = 0; i < shells.length; i++) { | |
1027 shells[i].setCursor(c); | |
1028 } | |
1029 } | |
1030 | |
1031 /** | |
1032 * Sets the minimum page size used for the pages. | |
1033 * | |
1034 * @param minWidth | |
1035 * the minimum page width | |
1036 * @param minHeight | |
1037 * the minimum page height | |
1038 * @see #setMinimumPageSize(Point) | |
1039 */ | |
1040 public void setMinimumPageSize(int minWidth, int minHeight) { | |
1041 Assert.isTrue(minWidth >= 0 && minHeight >= 0); | |
1042 pageContainerLayout.minimumWidth = minWidth; | |
1043 pageContainerLayout.minimumHeight = minHeight; | |
1044 } | |
1045 | |
1046 /** | |
1047 * Sets the minimum page size used for the pages. | |
1048 * | |
1049 * @param size | |
1050 * the page size encoded as <code>new Point(width,height)</code> | |
1051 * @see #setMinimumPageSize(int,int) | |
1052 */ | |
1053 public void setMinimumPageSize(Point size) { | |
1054 setMinimumPageSize(size.x, size.y); | |
1055 } | |
1056 | |
1057 /** | |
1058 * Sets the size of all pages. The given size takes precedence over computed | |
1059 * sizes. | |
1060 * | |
1061 * @param width | |
1062 * the page width | |
1063 * @param height | |
1064 * the page height | |
1065 * @see #setPageSize(Point) | |
1066 */ | |
1067 public void setPageSize(int width, int height) { | |
1068 pageWidth = width; | |
1069 pageHeight = height; | |
1070 } | |
1071 | |
1072 /** | |
1073 * Sets the size of all pages. The given size takes precedence over computed | |
1074 * sizes. | |
1075 * | |
1076 * @param size | |
1077 * the page size encoded as <code>new Point(width,height)</code> | |
1078 * @see #setPageSize(int,int) | |
1079 */ | |
1080 public void setPageSize(Point size) { | |
1081 setPageSize(size.x, size.y); | |
1082 } | |
1083 | |
1084 /** | |
1085 * Sets the wizard this dialog is currently displaying. | |
1086 * | |
1087 * @param newWizard | |
1088 * the wizard | |
1089 */ | |
1090 protected void setWizard(IWizard newWizard) { | |
1091 wizard = newWizard; | |
1092 wizard.setContainer(this); | |
35 | 1093 if (!createdWizards.contains(cast(Object)wizard)) { |
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:
71
diff
changeset
|
1094 createdWizards.add(cast(Object)wizard); |
8 | 1095 // New wizard so just add it to the end of our nested list |
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:
71
diff
changeset
|
1096 nestedWizards.add(cast(Object)wizard); |
8 | 1097 if (pageContainer !is null) { |
1098 // Dialog is already open | |
1099 // Allow the wizard pages to precreate their page controls | |
1100 // This allows the wizard to open to the correct size | |
1101 createPageControls(); | |
1102 // Ensure the dialog is large enough for the wizard | |
1103 updateSizeForWizard(wizard); | |
1104 pageContainer.layout(true); | |
1105 } | |
1106 } else { | |
1107 // We have already seen this wizard, if it is the previous wizard | |
1108 // on the nested list then we assume we have gone back and remove | |
1109 // the last wizard from the list | |
1110 int size = nestedWizards.size(); | |
35 | 1111 if (size >= 2 && nestedWizards.get(size - 2) is cast(Object)wizard) { |
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:
71
diff
changeset
|
1112 nestedWizards.remove(size - 1); |
8 | 1113 } else { |
1114 // Assume we are going forward to revisit a wizard | |
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:
71
diff
changeset
|
1115 nestedWizards.add(cast(Object)wizard); |
8 | 1116 } |
1117 } | |
1118 } | |
1119 | |
1120 /* | |
1121 * (non-Javadoc) Method declared on IWizardContainer. | |
1122 */ | |
1123 public void showPage(IWizardPage page) { | |
1124 if (page is null || page is currentPage) { | |
1125 return; | |
1126 } | |
1127 | |
1128 if (!isMovingToPreviousPage) { | |
1129 // remember my previous page. | |
1130 page.setPreviousPage(currentPage); | |
1131 } else { | |
1132 isMovingToPreviousPage = false; | |
1133 } | |
1134 | |
1135 // If page changing evaluation unsuccessful, do not change the page | |
1136 if (!doPageChanging(page)) | |
1137 return; | |
1138 | |
1139 // Update for the new page in a busy cursor if possible | |
1140 if (getContents() is null) { | |
1141 updateForPage(page); | |
1142 } else { | |
183 | 1143 BusyIndicator.showWhile(getContents().getDisplay(), dgRunnable( (IWizardPage finalPage) { |
1144 updateForPage(finalPage); | |
1145 }, page )); | |
8 | 1146 } |
1147 } | |
1148 | |
1149 /** | |
1150 * Update the receiver for the new page. | |
1151 * | |
1152 * @param page | |
1153 */ | |
1154 private void updateForPage(IWizardPage page) { | |
1155 // ensure this page belongs to the current wizard | |
1156 if (wizard !is page.getWizard()) { | |
1157 setWizard(page.getWizard()); | |
1158 } | |
1159 // ensure that page control has been created | |
1160 // (this allows lazy page control creation) | |
1161 if (page.getControl() is null) { | |
1162 page.createControl(pageContainer); | |
1163 // the page is responsible for ensuring the created control is | |
1164 // accessable | |
1165 // via getControl. | |
1166 Assert.isNotNull(page.getControl(), JFaceResources.format( | |
1167 JFaceResources.getString("WizardDialog.missingSetControl"), //$NON-NLS-1$ | |
35 | 1168 [ page.getName() ])); |
8 | 1169 // ensure the dialog is large enough for this page |
1170 updateSize(page); | |
1171 } | |
1172 // make the new page visible | |
1173 IWizardPage oldPage = currentPage; | |
1174 currentPage = page; | |
1175 | |
1176 currentPage.setVisible(true); | |
1177 if (oldPage !is null) { | |
1178 oldPage.setVisible(false); | |
1179 } | |
1180 // update the dialog controls | |
1181 update(); | |
1182 } | |
1183 | |
1184 /** | |
1185 * Shows the starting page of the wizard. | |
1186 */ | |
1187 private void showStartingPage() { | |
1188 currentPage = wizard.getStartingPage(); | |
1189 if (currentPage is null) { | |
1190 // something must have happend getting the page | |
1191 return; | |
1192 } | |
1193 // ensure the page control has been created | |
1194 if (currentPage.getControl() is null) { | |
1195 currentPage.createControl(pageContainer); | |
1196 // the page is responsible for ensuring the created control is | |
1197 // accessable | |
1198 // via getControl. | |
1199 Assert.isNotNull(currentPage.getControl()); | |
1200 // we do not need to update the size since the call | |
1201 // to initialize bounds has not been made yet. | |
1202 } | |
1203 // make the new page visible | |
1204 currentPage.setVisible(true); | |
1205 // update the dialog controls | |
1206 update(); | |
1207 } | |
1208 | |
1209 /** | |
1210 * A long running operation triggered through the wizard was stopped either | |
1211 * by user input or by normal end. Hides the progress monitor and restores | |
1212 * the enable state wizard's buttons and controls. | |
1213 * | |
1214 * @param savedState | |
1215 * the saved UI state as returned by <code>aboutToStart</code> | |
1216 * @see #aboutToStart | |
1217 */ | |
1218 private void stopped(Object savedState) { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
1219 if (getShell() !is null && !getShell().isDisposed()) { |
8 | 1220 if (wizard.needsProgressMonitor()) { |
1221 progressMonitorPart.setVisible(false); | |
1222 progressMonitorPart.removeFromCancelComponent(cancelButton); | |
1223 } | |
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:
71
diff
changeset
|
1224 Map state = cast(Map) savedState; |
8 | 1225 restoreUIState(state); |
1226 cancelButton.addSelectionListener(cancelListener); | |
1227 setDisplayCursor(null); | |
1228 cancelButton.setCursor(null); | |
1229 waitCursor.dispose(); | |
1230 waitCursor = null; | |
1231 arrowCursor.dispose(); | |
1232 arrowCursor = null; | |
35 | 1233 Control focusControl = cast(Control) state.get(stringcast(FOCUS_CONTROL)); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
1234 if (focusControl !is null && !focusControl.isDisposed()) { |
8 | 1235 focusControl.setFocus(); |
1236 } | |
1237 } | |
1238 } | |
1239 | |
1240 /** | |
1241 * Updates this dialog's controls to reflect the current page. | |
1242 */ | |
1243 protected void update() { | |
1244 // Update the window title | |
1245 updateWindowTitle(); | |
1246 // Update the title bar | |
1247 updateTitleBar(); | |
1248 // Update the buttons | |
1249 updateButtons(); | |
1250 | |
1251 // Fires the page change event | |
35 | 1252 firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage())); |
8 | 1253 } |
1254 | |
1255 /* | |
1256 * (non-Javadoc) Method declared on IWizardContainer. | |
1257 */ | |
1258 public void updateButtons() { | |
1259 bool canFlipToNextPage = false; | |
1260 bool canFinish = wizard.canFinish(); | |
1261 if (backButton !is null) { | |
1262 backButton.setEnabled(currentPage.getPreviousPage() !is null); | |
1263 } | |
1264 if (nextButton !is null) { | |
1265 canFlipToNextPage = currentPage.canFlipToNextPage(); | |
1266 nextButton.setEnabled(canFlipToNextPage); | |
1267 } | |
1268 finishButton.setEnabled(canFinish); | |
1269 // finish is default unless it is diabled and next is enabled | |
1270 if (canFlipToNextPage && !canFinish) { | |
1271 getShell().setDefaultButton(nextButton); | |
1272 } else { | |
1273 getShell().setDefaultButton(finishButton); | |
1274 } | |
1275 } | |
1276 | |
1277 /** | |
1278 * Update the message line with the page's description. | |
1279 * <p> | |
1280 * A discription is shown only if there is no message or error message. | |
1281 * </p> | |
1282 */ | |
1283 private void updateDescriptionMessage() { | |
1284 pageDescription = currentPage.getDescription(); | |
1285 setMessage(pageDescription); | |
1286 } | |
1287 | |
1288 /* | |
1289 * (non-Javadoc) Method declared on IWizardContainer. | |
1290 */ | |
1291 public void updateMessage() { | |
1292 | |
1293 if (currentPage is null) { | |
1294 return; | |
1295 } | |
1296 | |
1297 pageMessage = currentPage.getMessage(); | |
35 | 1298 if (pageMessage !is null && cast(IMessageProvider)currentPage ) { |
1299 pageMessageType = (cast(IMessageProvider) currentPage).getMessageType(); | |
8 | 1300 } else { |
1301 pageMessageType = IMessageProvider.NONE; | |
1302 } | |
1303 if (pageMessage is null) { | |
1304 setMessage(pageDescription); | |
1305 } else { | |
1306 setMessage(pageMessage, pageMessageType); | |
1307 } | |
1308 setErrorMessage(currentPage.getErrorMessage()); | |
1309 } | |
1310 | |
1311 /** | |
1312 * Changes the shell size to the given size, ensuring that it is no larger | |
1313 * than the display bounds. | |
1314 * | |
1315 * @param width | |
1316 * the shell width | |
1317 * @param height | |
1318 * the shell height | |
1319 */ | |
1320 private void setShellSize(int width, int height) { | |
1321 Rectangle size = getShell().getBounds(); | |
1322 size.height = height; | |
1323 size.width = width; | |
1324 getShell().setBounds(getConstrainedShellBounds(size)); | |
1325 } | |
1326 | |
1327 /** | |
1328 * Computes the correct dialog size for the current page and resizes its | |
1329 * shell if nessessary. Also causes the container to refresh its layout. | |
1330 * | |
1331 * @param page | |
1332 * the wizard page to use to resize the dialog | |
1333 * @since 2.0 | |
1334 */ | |
1335 protected void updateSize(IWizardPage page) { | |
1336 if (page is null || page.getControl() is null) { | |
1337 return; | |
1338 } | |
1339 updateSizeForPage(page); | |
1340 pageContainerLayout.layoutPage(page.getControl()); | |
1341 } | |
1342 | |
1343 /* | |
1344 * (non-Javadoc) | |
1345 * | |
1346 * @see dwtx.jface.wizard.IWizardContainer2#updateSize() | |
1347 */ | |
1348 public void updateSize() { | |
1349 updateSize(currentPage); | |
1350 } | |
1351 | |
1352 /** | |
1353 * Computes the correct dialog size for the given page and resizes its shell | |
1354 * if nessessary. | |
1355 * | |
1356 * @param page | |
1357 * the wizard page | |
1358 */ | |
1359 private void updateSizeForPage(IWizardPage page) { | |
1360 // ensure the page container is large enough | |
1361 Point delta = calculatePageSizeDelta(page); | |
1362 if (delta.x > 0 || delta.y > 0) { | |
1363 // increase the size of the shell | |
1364 Shell shell = getShell(); | |
1365 Point shellSize = shell.getSize(); | |
1366 setShellSize(shellSize.x + delta.x, shellSize.y + delta.y); | |
1367 constrainShellSize(); | |
1368 } | |
1369 } | |
1370 | |
1371 /** | |
1372 * Computes the correct dialog size for the given wizard and resizes its | |
1373 * shell if nessessary. | |
1374 * | |
1375 * @param sizingWizard | |
1376 * the wizard | |
1377 */ | |
1378 private void updateSizeForWizard(IWizard sizingWizard) { | |
1379 Point delta = new Point(0, 0); | |
1380 IWizardPage[] pages = sizingWizard.getPages(); | |
1381 for (int i = 0; i < pages.length; i++) { | |
1382 // ensure the page container is large enough | |
1383 Point pageDelta = calculatePageSizeDelta(pages[i]); | |
1384 delta.x = Math.max(delta.x, pageDelta.x); | |
1385 delta.y = Math.max(delta.y, pageDelta.y); | |
1386 } | |
1387 if (delta.x > 0 || delta.y > 0) { | |
1388 // increase the size of the shell | |
1389 Shell shell = getShell(); | |
1390 Point shellSize = shell.getSize(); | |
1391 setShellSize(shellSize.x + delta.x, shellSize.y + delta.y); | |
1392 } | |
1393 } | |
1394 | |
1395 /* | |
1396 * (non-Javadoc) Method declared on IWizardContainer. | |
1397 */ | |
1398 public void updateTitleBar() { | |
1399 String s = null; | |
1400 if (currentPage !is null) { | |
1401 s = currentPage.getTitle(); | |
1402 } | |
1403 if (s is null) { | |
1404 s = ""; //$NON-NLS-1$ | |
1405 } | |
1406 setTitle(s); | |
1407 if (currentPage !is null) { | |
1408 setTitleImage(currentPage.getImage()); | |
1409 updateDescriptionMessage(); | |
1410 } | |
1411 updateMessage(); | |
1412 } | |
1413 | |
1414 /* | |
1415 * (non-Javadoc) Method declared on IWizardContainer. | |
1416 */ | |
1417 public void updateWindowTitle() { | |
1418 if (getShell() is null) { | |
1419 // Not created yet | |
1420 return; | |
1421 } | |
1422 String title = wizard.getWindowTitle(); | |
1423 if (title is null) { | |
1424 title = ""; //$NON-NLS-1$ | |
1425 } | |
1426 getShell().setText(title); | |
1427 } | |
1428 | |
1429 /* | |
1430 * (non-Javadoc) | |
1431 * | |
1432 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() | |
1433 */ | |
1434 public Object getSelectedPage() { | |
35 | 1435 return cast(Object)getCurrentPage(); |
8 | 1436 } |
1437 | |
1438 /* | |
1439 * (non-Javadoc) | |
1440 * | |
1441 * @see dwtx.jface.dialog.IPageChangeProvider#addPageChangedListener() | |
1442 */ | |
1443 public void addPageChangedListener(IPageChangedListener listener) { | |
35 | 1444 pageChangedListeners.add(cast(Object)listener); |
8 | 1445 } |
1446 | |
1447 /* | |
1448 * (non-Javadoc) | |
1449 * | |
1450 * @see dwtx.jface.dialog.IPageChangeProvider#removePageChangedListener() | |
1451 */ | |
1452 public void removePageChangedListener(IPageChangedListener listener) { | |
35 | 1453 pageChangedListeners.remove(cast(Object)listener); |
8 | 1454 } |
1455 | |
1456 /** | |
1457 * Notifies any selection changed listeners that the selected page has | |
1458 * changed. Only listeners registered at the time this method is called are | |
1459 * notified. | |
1460 * | |
1461 * @param event | |
1462 * a selection changed event | |
1463 * | |
1464 * @see IPageChangedListener#pageChanged | |
1465 * | |
1466 * @since 3.1 | |
1467 */ | |
35 | 1468 protected void firePageChanged(PageChangedEvent event) { |
8 | 1469 Object[] listeners = pageChangedListeners.getListeners(); |
1470 for (int i = 0; i < listeners.length; ++i) { | |
39 | 1471 SafeRunnable.run(new class(cast(IPageChangedListener) listeners[i],event) SafeRunnable { |
35 | 1472 PageChangedEvent event_; |
1473 IPageChangedListener l; | |
39 | 1474 this(IPageChangedListener a, PageChangedEvent b){ |
1475 l = a; | |
1476 event_=b; | |
35 | 1477 } |
8 | 1478 public void run() { |
35 | 1479 l.pageChanged(event_); |
8 | 1480 } |
1481 }); | |
1482 } | |
1483 } | |
1484 | |
1485 /** | |
1486 * Adds a listener for page changes to the list of page changing listeners | |
1487 * registered for this dialog. Has no effect if an identical listener is | |
1488 * already registered. | |
1489 * | |
1490 * @param listener | |
1491 * a page changing listener | |
1492 * @since 3.3 | |
1493 */ | |
1494 public void addPageChangingListener(IPageChangingListener listener) { | |
35 | 1495 pageChangingListeners.add(cast(Object)listener); |
8 | 1496 } |
1497 | |
1498 /** | |
1499 * Removes the provided page changing listener from the list of page | |
1500 * changing listeners registered for the dialog. | |
1501 * | |
1502 * @param listener | |
1503 * a page changing listener | |
1504 * @since 3.3 | |
1505 */ | |
1506 public void removePageChangingListener(IPageChangingListener listener) { | |
35 | 1507 pageChangingListeners.remove(cast(Object)listener); |
8 | 1508 } |
1509 | |
1510 /** | |
1511 * Notifies any page changing listeners that the currently selected dialog | |
1512 * page is changing. Only listeners registered at the time this method is | |
1513 * called are notified. | |
1514 * | |
1515 * @param event | |
1516 * a selection changing event | |
1517 * | |
1518 * @see IPageChangingListener#handlePageChanging(PageChangingEvent) | |
1519 * @since 3.3 | |
1520 */ | |
35 | 1521 protected void firePageChanging(PageChangingEvent event) { |
8 | 1522 Object[] listeners = pageChangingListeners.getListeners(); |
1523 for (int i = 0; i < listeners.length; ++i) { | |
39 | 1524 SafeRunnable.run(new class(cast(IPageChangingListener) listeners[i],event) SafeRunnable { |
35 | 1525 PageChangingEvent event_; |
1526 IPageChangingListener l; | |
39 | 1527 this(IPageChangingListener a, PageChangingEvent b){ |
1528 l = a; | |
1529 event_=b; | |
35 | 1530 } |
8 | 1531 public void run() { |
35 | 1532 l.handlePageChanging(event_); |
8 | 1533 } |
1534 }); | |
1535 } | |
1536 } | |
1537 } |