Mercurial > projects > dwt-addons
comparison dwtx/jface/wizard/WizardDialog.d @ 35:ef4534de0cf9
remaining files
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 05 Apr 2008 04:49:22 +0200 |
parents | 6c14e54dfc11 |
children | 644f1334b451 |
comparison
equal
deleted
inserted
replaced
34:b3c8e32d406f | 35:ef4534de0cf9 |
---|---|
10 * Chris Gross (schtoo@schtoo.com) - patch for bug 16179 | 10 * Chris Gross (schtoo@schtoo.com) - patch for bug 16179 |
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Frank Benoit <benoit@tionex.de> | 12 * Frank Benoit <benoit@tionex.de> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwtx.jface.wizard.WizardDialog; | 14 module dwtx.jface.wizard.WizardDialog; |
15 pragma( msg, "FIXME dwtx.jface.wizard.WizardDialog"); | 15 |
16 class WizardDialog { | 16 import dwtx.jface.wizard.IWizardContainer2; |
17 } | 17 import dwtx.jface.wizard.IWizard; |
18 | 18 import dwtx.jface.wizard.IWizardPage; |
19 | 19 import dwtx.jface.wizard.ProgressMonitorPart; |
20 /++ | 20 |
21 import java.lang.reflect.InvocationTargetException; | 21 // import java.lang.reflect.InvocationTargetException; |
22 import java.util.ArrayList; | 22 import tango.util.collection.ArraySeq; |
23 import java.util.HashMap; | 23 import tango.util.collection.HashMap; |
24 import java.util.Map; | 24 import tango.util.collection.model.Map; |
25 // import java.util.HashMap; | |
26 // import java.util.Map; | |
25 | 27 |
26 import dwt.DWT; | 28 import dwt.DWT; |
27 import dwt.custom.BusyIndicator; | 29 import dwt.custom.BusyIndicator; |
28 import dwt.events.HelpEvent; | 30 import dwt.events.HelpEvent; |
29 import dwt.events.HelpListener; | 31 import dwt.events.HelpListener; |
58 import dwtx.jface.operation.IRunnableWithProgress; | 60 import dwtx.jface.operation.IRunnableWithProgress; |
59 import dwtx.jface.operation.ModalContext; | 61 import dwtx.jface.operation.ModalContext; |
60 import dwtx.jface.resource.JFaceResources; | 62 import dwtx.jface.resource.JFaceResources; |
61 import dwtx.jface.util.SafeRunnable; | 63 import dwtx.jface.util.SafeRunnable; |
62 | 64 |
65 import dwt.dwthelper.utils; | |
66 import dwt.dwthelper.Runnable; | |
67 | |
63 /** | 68 /** |
64 * A dialog to show a wizard to the end user. | 69 * A dialog to show a wizard to the end user. |
65 * <p> | 70 * <p> |
66 * In typical usage, the client instantiates this class with a particular | 71 * In typical usage, the client instantiates this class with a particular |
67 * wizard. The dialog serves as the wizard container and orchestrates the | 72 * wizard. The dialog serves as the wizard container and orchestrates the |
77 * <p> | 82 * <p> |
78 * Clients may subclass <code>WizardDialog</code>, although this is rarely | 83 * Clients may subclass <code>WizardDialog</code>, although this is rarely |
79 * required. | 84 * required. |
80 * </p> | 85 * </p> |
81 */ | 86 */ |
82 public class WizardDialog extends TitleAreaDialog implements IWizardContainer2, | 87 public class WizardDialog : TitleAreaDialog, IWizardContainer2, |
83 IPageChangeProvider { | 88 IPageChangeProvider { |
84 /** | 89 /** |
85 * Image registry key for error message image (value | 90 * Image registry key for error message image (value |
86 * <code>"dialog_title_error_image"</code>). | 91 * <code>"dialog_title_error_image"</code>). |
87 */ | 92 */ |
88 public static final String WIZ_IMG_ERROR = "dialog_title_error_image"; //$NON-NLS-1$ | 93 public static const String WIZ_IMG_ERROR = "dialog_title_error_image"; //$NON-NLS-1$ |
89 | 94 |
90 // The wizard the dialog is currently showing. | 95 // The wizard the dialog is currently showing. |
91 private IWizard wizard; | 96 private IWizard wizard; |
92 | 97 |
93 // Wizards to dispose | 98 // Wizards to dispose |
94 private ArrayList createdWizards = new ArrayList(); | 99 private ArraySeq!(Object) createdWizards; |
95 | 100 |
96 // Current nested wizards | 101 // Current nested wizards |
97 private ArrayList nestedWizards = new ArrayList(); | 102 private ArraySeq!(Object) nestedWizards; |
98 | 103 |
99 // The currently displayed page. | 104 // The currently displayed page. |
100 private IWizardPage currentPage = null; | 105 private IWizardPage currentPage = null; |
101 | 106 |
102 // The number of long running operation executed from the dialog. | 107 // The number of long running operation executed from the dialog. |
133 | 138 |
134 private bool isMovingToPreviousPage = false; | 139 private bool isMovingToPreviousPage = false; |
135 | 140 |
136 private Composite pageContainer; | 141 private Composite pageContainer; |
137 | 142 |
138 private PageContainerFillLayout pageContainerLayout = new PageContainerFillLayout( | 143 private PageContainerFillLayout pageContainerLayout; |
139 5, 5, 300, 225); | |
140 | 144 |
141 private int pageWidth = DWT.DEFAULT; | 145 private int pageWidth = DWT.DEFAULT; |
142 | 146 |
143 private int pageHeight = DWT.DEFAULT; | 147 private int pageHeight = DWT.DEFAULT; |
144 | 148 |
145 private static final String FOCUS_CONTROL = "focusControl"; //$NON-NLS-1$ | 149 private static const String FOCUS_CONTROL = "focusControl"; //$NON-NLS-1$ |
146 | 150 |
147 private bool lockedUI = false; | 151 private bool lockedUI = false; |
148 | 152 |
149 private ListenerList pageChangedListeners = new ListenerList(); | 153 private ListenerList pageChangedListeners; |
150 | 154 |
151 private ListenerList pageChangingListeners = new ListenerList(); | 155 private ListenerList pageChangingListeners; |
152 | 156 |
153 /** | 157 /** |
154 * A layout for a container which includes several pages, like a notebook, | 158 * A layout for a container which includes several pages, like a notebook, |
155 * wizard, or preference dialog. The size computed by this layout is the | 159 * wizard, or preference dialog. The size computed by this layout is the |
156 * maximum width and height of all pages currently inserted into the | 160 * maximum width and height of all pages currently inserted into the |
157 * container. | 161 * container. |
158 */ | 162 */ |
159 protected class PageContainerFillLayout extends Layout { | 163 protected class PageContainerFillLayout : Layout { |
160 /** | 164 /** |
161 * The margin width; <code>5</code> pixels by default. | 165 * The margin width; <code>5</code> pixels by default. |
162 */ | 166 */ |
163 public int marginWidth = 5; | 167 public int marginWidth = 5; |
164 | 168 |
187 * @param minW | 191 * @param minW |
188 * the minimum width | 192 * the minimum width |
189 * @param minH | 193 * @param minH |
190 * the minimum height | 194 * the minimum height |
191 */ | 195 */ |
192 public PageContainerFillLayout(int mw, int mh, int minW, int minH) { | 196 public this(int mw, int mh, int minW, int minH) { |
197 pageContainerLayout = new PageContainerFillLayout( 5, 5, 300, 225); | |
193 marginWidth = mw; | 198 marginWidth = mw; |
194 marginHeight = mh; | 199 marginHeight = mh; |
195 minimumWidth = minW; | 200 minimumWidth = minW; |
196 minimumHeight = minH; | 201 minimumHeight = minH; |
197 } | 202 } |
286 * @param parentShell | 291 * @param parentShell |
287 * the parent shell | 292 * the parent shell |
288 * @param newWizard | 293 * @param newWizard |
289 * the wizard this dialog is working on | 294 * the wizard this dialog is working on |
290 */ | 295 */ |
291 public WizardDialog(Shell parentShell, IWizard newWizard) { | 296 public this(Shell parentShell, IWizard newWizard) { |
297 createdWizards = new ArraySeq!(Object); | |
298 nestedWizards = new ArraySeq!(Object); | |
299 pageChangedListeners = new ListenerList(); | |
300 pageChangingListeners = new ListenerList(); | |
301 | |
292 super(parentShell); | 302 super(parentShell); |
293 setShellStyle(DWT.CLOSE | DWT.MAX | DWT.TITLE | DWT.BORDER | 303 setShellStyle(DWT.CLOSE | DWT.MAX | DWT.TITLE | DWT.BORDER |
294 | DWT.APPLICATION_MODAL | DWT.RESIZE | getDefaultOrientation()); | 304 | DWT.APPLICATION_MODAL | DWT.RESIZE | getDefaultOrientation()); |
295 setWizard(newWizard); | 305 setWizard(newWizard); |
296 // since VAJava can't initialize an instance var with an anonymous | 306 // since VAJava can't initialize an instance var with an anonymous |
297 // class outside a constructor we do it here: | 307 // class outside a constructor we do it here: |
298 cancelListener = new SelectionAdapter() { | 308 cancelListener = new class SelectionAdapter { |
299 public void widgetSelected(SelectionEvent e) { | 309 public void widgetSelected(SelectionEvent e) { |
300 cancelPressed(); | 310 cancelPressed(); |
301 } | 311 } |
302 }; | 312 }; |
303 } | 313 } |
311 * <code>true</code> if the Cancel button should be enabled, | 321 * <code>true</code> if the Cancel button should be enabled, |
312 * and <code>false</code> if it should be disabled | 322 * and <code>false</code> if it should be disabled |
313 * @return the saved UI state | 323 * @return the saved UI state |
314 */ | 324 */ |
315 private Object aboutToStart(bool enableCancelButton) { | 325 private Object aboutToStart(bool enableCancelButton) { |
316 Map savedState = null; | 326 Map!(Object,Object) savedState = null; |
317 if (getShell() !is null) { | 327 if (getShell() !is null) { |
318 // Save focus control | 328 // Save focus control |
319 Control focusControl = getShell().getDisplay().getFocusControl(); | 329 Control focusControl = getShell().getDisplay().getFocusControl(); |
320 if (focusControl !is null && focusControl.getShell() !is getShell()) { | 330 if (focusControl !is null && focusControl.getShell() !is getShell()) { |
321 focusControl = null; | 331 focusControl = null; |
330 arrowCursor = new Cursor(d, DWT.CURSOR_ARROW); | 340 arrowCursor = new Cursor(d, DWT.CURSOR_ARROW); |
331 cancelButton.setCursor(arrowCursor); | 341 cancelButton.setCursor(arrowCursor); |
332 // Deactivate shell | 342 // Deactivate shell |
333 savedState = saveUIState(needsProgressMonitor && enableCancelButton); | 343 savedState = saveUIState(needsProgressMonitor && enableCancelButton); |
334 if (focusControl !is null) { | 344 if (focusControl !is null) { |
335 savedState.put(FOCUS_CONTROL, focusControl); | 345 savedState.add(stringcast(FOCUS_CONTROL), focusControl); |
336 } | 346 } |
337 // Attach the progress monitor part to the cancel button | 347 // Attach the progress monitor part to the cancel button |
338 if (needsProgressMonitor) { | 348 if (needsProgressMonitor) { |
339 progressMonitorPart.attachToCancelComponent(cancelButton); | 349 progressMonitorPart.attachToCancelComponent(cancelButton); |
340 progressMonitorPart.setVisible(true); | 350 progressMonitorPart.setVisible(true); |
341 } | 351 } |
342 } | 352 } |
343 return savedState; | 353 return cast(Object) savedState; |
344 } | 354 } |
345 | 355 |
346 /** | 356 /** |
347 * The Back button has been pressed. | 357 * The Back button has been pressed. |
348 */ | 358 */ |
440 * (non-Javadoc) Method declared on Window. | 450 * (non-Javadoc) Method declared on Window. |
441 */ | 451 */ |
442 protected void configureShell(Shell newShell) { | 452 protected void configureShell(Shell newShell) { |
443 super.configureShell(newShell); | 453 super.configureShell(newShell); |
444 // Register help listener on the shell | 454 // Register help listener on the shell |
445 newShell.addHelpListener(new HelpListener() { | 455 newShell.addHelpListener(new class HelpListener { |
446 public void helpRequested(HelpEvent event) { | 456 public void helpRequested(HelpEvent event) { |
447 // call perform help on the current page | 457 // call perform help on the current page |
448 if (currentPage !is null) { | 458 if (currentPage !is null) { |
449 currentPage.performHelp(); | 459 currentPage.performHelp(); |
450 } | 460 } |
462 * | 472 * |
463 * @param parent | 473 * @param parent |
464 * the parent composite to contain the buttons | 474 * the parent composite to contain the buttons |
465 */ | 475 */ |
466 protected void createButtonsForButtonBar(Composite parent) { | 476 protected void createButtonsForButtonBar(Composite parent) { |
467 ((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; | 477 (cast(GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; |
468 if (wizard.isHelpAvailable()) { | 478 if (wizard.isHelpAvailable()) { |
469 helpButton = createButton(parent, IDialogConstants.HELP_ID, | 479 helpButton = createButton(parent, IDialogConstants.HELP_ID, |
470 IDialogConstants.HELP_LABEL, false); | 480 IDialogConstants.HELP_LABEL, false); |
471 } | 481 } |
472 if (wizard.needsPreviousAndNextButtons()) { | 482 if (wizard.needsPreviousAndNextButtons()) { |
505 * the parent button bar | 515 * the parent button bar |
506 * @return the new Cancel button | 516 * @return the new Cancel button |
507 */ | 517 */ |
508 private Button createCancelButton(Composite parent) { | 518 private Button createCancelButton(Composite parent) { |
509 // increment the number of columns in the button bar | 519 // increment the number of columns in the button bar |
510 ((GridLayout) parent.getLayout()).numColumns++; | 520 (cast(GridLayout) parent.getLayout()).numColumns++; |
511 Button button = new Button(parent, DWT.PUSH); | 521 Button button = new Button(parent, DWT.PUSH); |
512 button.setText(IDialogConstants.CANCEL_LABEL); | 522 button.setText(IDialogConstants.CANCEL_LABEL); |
513 setButtonLayoutData(button); | 523 setButtonLayoutData(button); |
514 button.setFont(parent.getFont()); | 524 button.setFont(parent.getFont()); |
515 button.setData(new Integer(IDialogConstants.CANCEL_ID)); | 525 button.setData(new Integer(IDialogConstants.CANCEL_ID)); |
555 | 565 |
556 /* | 566 /* |
557 * (non-Javadoc) Method declared on Dialog. | 567 * (non-Javadoc) Method declared on Dialog. |
558 */ | 568 */ |
559 protected Control createDialogArea(Composite parent) { | 569 protected Control createDialogArea(Composite parent) { |
560 Composite composite = (Composite) super.createDialogArea(parent); | 570 Composite composite = cast(Composite) super.createDialogArea(parent); |
561 // Build the Page container | 571 // Build the Page container |
562 pageContainer = createPageContainer(composite); | 572 pageContainer = createPageContainer(composite); |
563 GridData gd = new GridData(GridData.FILL_BOTH); | 573 GridData gd = new GridData(GridData.FILL_BOTH); |
564 gd.widthHint = pageWidth; | 574 gd.widthHint = pageWidth; |
565 gd.heightHint = pageHeight; | 575 gd.heightHint = pageHeight; |
587 * @param pmlayout | 597 * @param pmlayout |
588 * @return ProgressMonitorPart | 598 * @return ProgressMonitorPart |
589 */ | 599 */ |
590 protected ProgressMonitorPart createProgressMonitorPart( | 600 protected ProgressMonitorPart createProgressMonitorPart( |
591 Composite composite, GridLayout pmlayout) { | 601 Composite composite, GridLayout pmlayout) { |
592 return new ProgressMonitorPart(composite, pmlayout, DWT.DEFAULT) { | 602 return new class(composite, pmlayout, DWT.DEFAULT) ProgressMonitorPart { |
603 | |
593 String currentTask = null; | 604 String currentTask = null; |
605 | |
606 this(Composite c, Layout l, int s ){ | |
607 super(c,l,s); | |
608 } | |
594 | 609 |
595 /* | 610 /* |
596 * (non-Javadoc) | 611 * (non-Javadoc) |
597 * | 612 * |
598 * @see dwtx.jface.wizard.ProgressMonitorPart#setBlocked(dwtx.core.runtime.IStatus) | 613 * @see dwtx.jface.wizard.ProgressMonitorPart#setBlocked(dwtx.core.runtime.IStatus) |
695 * the parent button bar | 710 * the parent button bar |
696 * @return a composite containing the new buttons | 711 * @return a composite containing the new buttons |
697 */ | 712 */ |
698 private Composite createPreviousAndNextButtons(Composite parent) { | 713 private Composite createPreviousAndNextButtons(Composite parent) { |
699 // increment the number of columns in the button bar | 714 // increment the number of columns in the button bar |
700 ((GridLayout) parent.getLayout()).numColumns++; | 715 (cast(GridLayout) parent.getLayout()).numColumns++; |
701 Composite composite = new Composite(parent, DWT.NONE); | 716 Composite composite = new Composite(parent, DWT.NONE); |
702 // create a layout with spacing and margins appropriate for the font | 717 // create a layout with spacing and margins appropriate for the font |
703 // size. | 718 // size. |
704 GridLayout layout = new GridLayout(); | 719 GridLayout layout = new GridLayout(); |
705 layout.numColumns = 0; // will be incremented by createButton | 720 layout.numColumns = 0; // will be incremented by createButton |
728 MessageDialog result = new MessageDialog(getShell(), | 743 MessageDialog result = new MessageDialog(getShell(), |
729 JFaceResources.getString("WizardClosingDialog.title"), //$NON-NLS-1$ | 744 JFaceResources.getString("WizardClosingDialog.title"), //$NON-NLS-1$ |
730 null, | 745 null, |
731 JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$ | 746 JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$ |
732 MessageDialog.QUESTION, | 747 MessageDialog.QUESTION, |
733 new String[] { IDialogConstants.OK_LABEL }, 0); | 748 [ IDialogConstants.OK_LABEL ], 0); |
734 return result; | 749 return result; |
735 } | 750 } |
736 | 751 |
737 /** | 752 /** |
738 * The Finish button has been pressed. | 753 * The Finish button has been pressed. |
748 // list (to save state). | 763 // list (to save state). |
749 if (wizard.performFinish()) { | 764 if (wizard.performFinish()) { |
750 // Call perform finish on outer wizards in the nested chain | 765 // Call perform finish on outer wizards in the nested chain |
751 // (to allow them to save state for example) | 766 // (to allow them to save state for example) |
752 for (int i = 0; i < nestedWizards.size() - 1; i++) { | 767 for (int i = 0; i < nestedWizards.size() - 1; i++) { |
753 ((IWizard) nestedWizards.get(i)).performFinish(); | 768 (cast(IWizard) nestedWizards.get(i)).performFinish(); |
754 } | 769 } |
755 // Hard close the dialog. | 770 // Hard close the dialog. |
756 setReturnCode(OK); | 771 setReturnCode(OK); |
757 hardClose(); | 772 hardClose(); |
758 } | 773 } |
791 * <code>false</code> if it is still open | 806 * <code>false</code> if it is still open |
792 */ | 807 */ |
793 private bool hardClose() { | 808 private bool hardClose() { |
794 // inform wizards | 809 // inform wizards |
795 for (int i = 0; i < createdWizards.size(); i++) { | 810 for (int i = 0; i < createdWizards.size(); i++) { |
796 IWizard createdWizard = (IWizard) createdWizards.get(i); | 811 IWizard createdWizard = cast(IWizard) createdWizards.get(i); |
797 createdWizard.dispose(); | 812 createdWizard.dispose(); |
798 // Remove this dialog as a parent from the managed wizard. | 813 // Remove this dialog as a parent from the managed wizard. |
799 // Note that we do this after calling dispose as the wizard or | 814 // Note that we do this after calling dispose as the wizard or |
800 // its pages may need access to the container during | 815 // its pages may need access to the container during |
801 // dispose code | 816 // dispose code |
834 * @param eventType | 849 * @param eventType |
835 * @return <code>true</code> if page changing listener completes | 850 * @return <code>true</code> if page changing listener completes |
836 * successfully, <code>false</code> otherwise | 851 * successfully, <code>false</code> otherwise |
837 */ | 852 */ |
838 private bool doPageChanging(IWizardPage targetPage) { | 853 private bool doPageChanging(IWizardPage targetPage) { |
839 PageChangingEvent e = new PageChangingEvent(this, getCurrentPage(), | 854 PageChangingEvent e = new PageChangingEvent(this, cast(Object)getCurrentPage(), |
840 targetPage); | 855 cast(Object)targetPage); |
841 firePageChanging(e); | 856 firePageChanging(e); |
842 // Prevent navigation if necessary | 857 // Prevent navigation if necessary |
843 return e.doit; | 858 return e.doit; |
844 } | 859 } |
845 | 860 |
876 * <code>bool</code>) | 891 * <code>bool</code>) |
877 * @param key | 892 * @param key |
878 * the key | 893 * the key |
879 * @see #saveEnableStateAndSet | 894 * @see #saveEnableStateAndSet |
880 */ | 895 */ |
881 private void restoreEnableState(Control w, Map h, String key) { | 896 private void restoreEnableState(Control w, Map!(Object,Object) h, String key) { |
882 if (w !is null) { | 897 if (w !is null) { |
883 bool b = (bool) h.get(key); | 898 auto b = cast(Boolean) h.get(stringcast(key)); |
884 if (b !is null) { | 899 if (b !is null) { |
885 w.setEnabled(b.booleanValue()); | 900 w.setEnabled(b.booleanValue()); |
886 } | 901 } |
887 } | 902 } |
888 } | 903 } |
894 * @param state | 909 * @param state |
895 * a map containing the saved state as returned by | 910 * a map containing the saved state as returned by |
896 * <code>saveUIState</code> | 911 * <code>saveUIState</code> |
897 * @see #saveUIState | 912 * @see #saveUIState |
898 */ | 913 */ |
899 private void restoreUIState(Map state) { | 914 private void restoreUIState(Map!(Object,Object) state) { |
900 restoreEnableState(backButton, state, "back"); //$NON-NLS-1$ | 915 restoreEnableState(backButton, state, "back"); //$NON-NLS-1$ |
901 restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$ | 916 restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$ |
902 restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$ | 917 restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$ |
903 restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$ | 918 restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$ |
904 restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$ | 919 restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$ |
905 Object pageValue = state.get("page"); //$NON-NLS-1$ | 920 Object pageValue = state.get(stringcast("page")); //$NON-NLS-1$ |
906 if (pageValue !is null) { | 921 if (pageValue !is null) { |
907 ((ControlEnableState) pageValue).restore(); | 922 (cast(ControlEnableState) pageValue).restore(); |
908 } | 923 } |
909 } | 924 } |
910 | 925 |
911 /** | 926 /** |
912 * This implementation of IRunnableContext#run(bool, bool, | 927 * This implementation of IRunnableContext#run(bool, bool, |
922 * attempt to change the UI state of the wizard in the long-running | 937 * attempt to change the UI state of the wizard in the long-running |
923 * operation will be nullified when original UI state is restored. | 938 * operation will be nullified when original UI state is restored. |
924 * | 939 * |
925 */ | 940 */ |
926 public void run(bool fork, bool cancelable, | 941 public void run(bool fork, bool cancelable, |
927 IRunnableWithProgress runnable) throws InvocationTargetException, | 942 IRunnableWithProgress runnable) { |
928 InterruptedException { | |
929 // The operation can only be canceled if it is executed in a separate | 943 // The operation can only be canceled if it is executed in a separate |
930 // thread. | 944 // thread. |
931 // Otherwise the UI is blocked anyway. | 945 // Otherwise the UI is blocked anyway. |
932 Object state = null; | 946 Object state = null; |
933 if (activeRunningOperations is 0) { | 947 if (activeRunningOperations is 0) { |
964 * @param enabled | 978 * @param enabled |
965 * <code>true</code> to enable the control, and | 979 * <code>true</code> to enable the control, and |
966 * <code>false</code> to disable it | 980 * <code>false</code> to disable it |
967 * @see #restoreEnableState(Control, Map, String) | 981 * @see #restoreEnableState(Control, Map, String) |
968 */ | 982 */ |
969 private void saveEnableStateAndSet(Control w, Map h, String key, | 983 private void saveEnableStateAndSet(Control w, Map!(Object,Object) h, String key, |
970 bool enabled) { | 984 bool enabled) { |
971 if (w !is null) { | 985 if (w !is null) { |
972 h.put(key, w.getEnabled() ? bool.TRUE : bool.FALSE); | 986 h.add(stringcast(key), w.getEnabled() ? Boolean.TRUE : Boolean.FALSE); |
973 w.setEnabled(enabled); | 987 w.setEnabled(enabled); |
974 } | 988 } |
975 } | 989 } |
976 | 990 |
977 /** | 991 /** |
985 * enabled, and <code>false</code> if it should be disabled | 999 * enabled, and <code>false</code> if it should be disabled |
986 * @return a map containing the saved state suitable for restoring later | 1000 * @return a map containing the saved state suitable for restoring later |
987 * with <code>restoreUIState</code> | 1001 * with <code>restoreUIState</code> |
988 * @see #restoreUIState | 1002 * @see #restoreUIState |
989 */ | 1003 */ |
990 private Map saveUIState(bool keepCancelEnabled) { | 1004 private Map!(Object,Object) saveUIState(bool keepCancelEnabled) { |
991 Map savedState = new HashMap(10); | 1005 Map!(Object,Object) savedState = new HashMap!(Object,Object); |
992 saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$ | 1006 saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$ |
993 saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$ | 1007 saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$ |
994 saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$ | 1008 saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$ |
995 saveEnableStateAndSet(cancelButton, savedState, | 1009 saveEnableStateAndSet(cancelButton, savedState, |
996 "cancel", keepCancelEnabled); //$NON-NLS-1$ | 1010 "cancel", keepCancelEnabled); //$NON-NLS-1$ |
997 saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$ | 1011 saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$ |
998 if (currentPage !is null) { | 1012 if (currentPage !is null) { |
999 savedState | 1013 savedState.add(stringcast("page"), ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ |
1000 .put( | |
1001 "page", ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ | |
1002 } | 1014 } |
1003 return savedState; | 1015 return savedState; |
1004 } | 1016 } |
1005 | 1017 |
1006 /** | 1018 /** |
1077 * the wizard | 1089 * the wizard |
1078 */ | 1090 */ |
1079 protected void setWizard(IWizard newWizard) { | 1091 protected void setWizard(IWizard newWizard) { |
1080 wizard = newWizard; | 1092 wizard = newWizard; |
1081 wizard.setContainer(this); | 1093 wizard.setContainer(this); |
1082 if (!createdWizards.contains(wizard)) { | 1094 if (!createdWizards.contains(cast(Object)wizard)) { |
1083 createdWizards.add(wizard); | 1095 createdWizards.append(cast(Object)wizard); |
1084 // New wizard so just add it to the end of our nested list | 1096 // New wizard so just add it to the end of our nested list |
1085 nestedWizards.add(wizard); | 1097 nestedWizards.append(cast(Object)wizard); |
1086 if (pageContainer !is null) { | 1098 if (pageContainer !is null) { |
1087 // Dialog is already open | 1099 // Dialog is already open |
1088 // Allow the wizard pages to precreate their page controls | 1100 // Allow the wizard pages to precreate their page controls |
1089 // This allows the wizard to open to the correct size | 1101 // This allows the wizard to open to the correct size |
1090 createPageControls(); | 1102 createPageControls(); |
1095 } else { | 1107 } else { |
1096 // We have already seen this wizard, if it is the previous wizard | 1108 // We have already seen this wizard, if it is the previous wizard |
1097 // on the nested list then we assume we have gone back and remove | 1109 // on the nested list then we assume we have gone back and remove |
1098 // the last wizard from the list | 1110 // the last wizard from the list |
1099 int size = nestedWizards.size(); | 1111 int size = nestedWizards.size(); |
1100 if (size >= 2 && nestedWizards.get(size - 2) is wizard) { | 1112 if (size >= 2 && nestedWizards.get(size - 2) is cast(Object)wizard) { |
1101 nestedWizards.remove(size - 1); | 1113 nestedWizards.removeAt(size - 1); |
1102 } else { | 1114 } else { |
1103 // Assume we are going forward to revisit a wizard | 1115 // Assume we are going forward to revisit a wizard |
1104 nestedWizards.add(wizard); | 1116 nestedWizards.append(cast(Object)wizard); |
1105 } | 1117 } |
1106 } | 1118 } |
1107 } | 1119 } |
1108 | 1120 |
1109 /* | 1121 /* |
1128 // Update for the new page in a busy cursor if possible | 1140 // Update for the new page in a busy cursor if possible |
1129 if (getContents() is null) { | 1141 if (getContents() is null) { |
1130 updateForPage(page); | 1142 updateForPage(page); |
1131 } else { | 1143 } else { |
1132 final IWizardPage finalPage = page; | 1144 final IWizardPage finalPage = page; |
1133 BusyIndicator.showWhile(getContents().getDisplay(), new Runnable() { | 1145 BusyIndicator.showWhile(getContents().getDisplay(), new class Runnable { |
1134 public void run() { | 1146 public void run() { |
1135 updateForPage(finalPage); | 1147 updateForPage(finalPage); |
1136 } | 1148 } |
1137 }); | 1149 }); |
1138 } | 1150 } |
1155 // the page is responsible for ensuring the created control is | 1167 // the page is responsible for ensuring the created control is |
1156 // accessable | 1168 // accessable |
1157 // via getControl. | 1169 // via getControl. |
1158 Assert.isNotNull(page.getControl(), JFaceResources.format( | 1170 Assert.isNotNull(page.getControl(), JFaceResources.format( |
1159 JFaceResources.getString("WizardDialog.missingSetControl"), //$NON-NLS-1$ | 1171 JFaceResources.getString("WizardDialog.missingSetControl"), //$NON-NLS-1$ |
1160 new Object[] { page.getName() })); | 1172 [ page.getName() ])); |
1161 // ensure the dialog is large enough for this page | 1173 // ensure the dialog is large enough for this page |
1162 updateSize(page); | 1174 updateSize(page); |
1163 } | 1175 } |
1164 // make the new page visible | 1176 // make the new page visible |
1165 IWizardPage oldPage = currentPage; | 1177 IWizardPage oldPage = currentPage; |
1211 if (getShell() !is null) { | 1223 if (getShell() !is null) { |
1212 if (wizard.needsProgressMonitor()) { | 1224 if (wizard.needsProgressMonitor()) { |
1213 progressMonitorPart.setVisible(false); | 1225 progressMonitorPart.setVisible(false); |
1214 progressMonitorPart.removeFromCancelComponent(cancelButton); | 1226 progressMonitorPart.removeFromCancelComponent(cancelButton); |
1215 } | 1227 } |
1216 Map state = (Map) savedState; | 1228 Map!(Object,Object) state = cast(Map!(Object,Object)) savedState; |
1217 restoreUIState(state); | 1229 restoreUIState(state); |
1218 cancelButton.addSelectionListener(cancelListener); | 1230 cancelButton.addSelectionListener(cancelListener); |
1219 setDisplayCursor(null); | 1231 setDisplayCursor(null); |
1220 cancelButton.setCursor(null); | 1232 cancelButton.setCursor(null); |
1221 waitCursor.dispose(); | 1233 waitCursor.dispose(); |
1222 waitCursor = null; | 1234 waitCursor = null; |
1223 arrowCursor.dispose(); | 1235 arrowCursor.dispose(); |
1224 arrowCursor = null; | 1236 arrowCursor = null; |
1225 Control focusControl = (Control) state.get(FOCUS_CONTROL); | 1237 Control focusControl = cast(Control) state.get(stringcast(FOCUS_CONTROL)); |
1226 if (focusControl !is null) { | 1238 if (focusControl !is null) { |
1227 focusControl.setFocus(); | 1239 focusControl.setFocus(); |
1228 } | 1240 } |
1229 } | 1241 } |
1230 } | 1242 } |
1239 updateTitleBar(); | 1251 updateTitleBar(); |
1240 // Update the buttons | 1252 // Update the buttons |
1241 updateButtons(); | 1253 updateButtons(); |
1242 | 1254 |
1243 // Fires the page change event | 1255 // Fires the page change event |
1244 firePageChanged(new PageChangedEvent(this, getCurrentPage())); | 1256 firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage())); |
1245 } | 1257 } |
1246 | 1258 |
1247 /* | 1259 /* |
1248 * (non-Javadoc) Method declared on IWizardContainer. | 1260 * (non-Javadoc) Method declared on IWizardContainer. |
1249 */ | 1261 */ |
1285 if (currentPage is null) { | 1297 if (currentPage is null) { |
1286 return; | 1298 return; |
1287 } | 1299 } |
1288 | 1300 |
1289 pageMessage = currentPage.getMessage(); | 1301 pageMessage = currentPage.getMessage(); |
1290 if (pageMessage !is null && currentPage instanceof IMessageProvider) { | 1302 if (pageMessage !is null && cast(IMessageProvider)currentPage ) { |
1291 pageMessageType = ((IMessageProvider) currentPage).getMessageType(); | 1303 pageMessageType = (cast(IMessageProvider) currentPage).getMessageType(); |
1292 } else { | 1304 } else { |
1293 pageMessageType = IMessageProvider.NONE; | 1305 pageMessageType = IMessageProvider.NONE; |
1294 } | 1306 } |
1295 if (pageMessage is null) { | 1307 if (pageMessage is null) { |
1296 setMessage(pageDescription); | 1308 setMessage(pageDescription); |
1422 * (non-Javadoc) | 1434 * (non-Javadoc) |
1423 * | 1435 * |
1424 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() | 1436 * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() |
1425 */ | 1437 */ |
1426 public Object getSelectedPage() { | 1438 public Object getSelectedPage() { |
1427 return getCurrentPage(); | 1439 return cast(Object)getCurrentPage(); |
1428 } | 1440 } |
1429 | 1441 |
1430 /* | 1442 /* |
1431 * (non-Javadoc) | 1443 * (non-Javadoc) |
1432 * | 1444 * |
1433 * @see dwtx.jface.dialog.IPageChangeProvider#addPageChangedListener() | 1445 * @see dwtx.jface.dialog.IPageChangeProvider#addPageChangedListener() |
1434 */ | 1446 */ |
1435 public void addPageChangedListener(IPageChangedListener listener) { | 1447 public void addPageChangedListener(IPageChangedListener listener) { |
1436 pageChangedListeners.add(listener); | 1448 pageChangedListeners.add(cast(Object)listener); |
1437 } | 1449 } |
1438 | 1450 |
1439 /* | 1451 /* |
1440 * (non-Javadoc) | 1452 * (non-Javadoc) |
1441 * | 1453 * |
1442 * @see dwtx.jface.dialog.IPageChangeProvider#removePageChangedListener() | 1454 * @see dwtx.jface.dialog.IPageChangeProvider#removePageChangedListener() |
1443 */ | 1455 */ |
1444 public void removePageChangedListener(IPageChangedListener listener) { | 1456 public void removePageChangedListener(IPageChangedListener listener) { |
1445 pageChangedListeners.remove(listener); | 1457 pageChangedListeners.remove(cast(Object)listener); |
1446 } | 1458 } |
1447 | 1459 |
1448 /** | 1460 /** |
1449 * Notifies any selection changed listeners that the selected page has | 1461 * Notifies any selection changed listeners that the selected page has |
1450 * changed. Only listeners registered at the time this method is called are | 1462 * changed. Only listeners registered at the time this method is called are |
1455 * | 1467 * |
1456 * @see IPageChangedListener#pageChanged | 1468 * @see IPageChangedListener#pageChanged |
1457 * | 1469 * |
1458 * @since 3.1 | 1470 * @since 3.1 |
1459 */ | 1471 */ |
1460 protected void firePageChanged(final PageChangedEvent event) { | 1472 protected void firePageChanged(PageChangedEvent event) { |
1461 Object[] listeners = pageChangedListeners.getListeners(); | 1473 Object[] listeners = pageChangedListeners.getListeners(); |
1462 for (int i = 0; i < listeners.length; ++i) { | 1474 for (int i = 0; i < listeners.length; ++i) { |
1463 final IPageChangedListener l = (IPageChangedListener) listeners[i]; | 1475 SafeRunnable.run(new class SafeRunnable { |
1464 SafeRunnable.run(new SafeRunnable() { | 1476 PageChangedEvent event_; |
1477 IPageChangedListener l; | |
1478 this(){ | |
1479 l = cast(IPageChangedListener) listeners[i]; | |
1480 event_=event; | |
1481 } | |
1465 public void run() { | 1482 public void run() { |
1466 l.pageChanged(event); | 1483 l.pageChanged(event_); |
1467 } | 1484 } |
1468 }); | 1485 }); |
1469 } | 1486 } |
1470 } | 1487 } |
1471 | 1488 |
1477 * @param listener | 1494 * @param listener |
1478 * a page changing listener | 1495 * a page changing listener |
1479 * @since 3.3 | 1496 * @since 3.3 |
1480 */ | 1497 */ |
1481 public void addPageChangingListener(IPageChangingListener listener) { | 1498 public void addPageChangingListener(IPageChangingListener listener) { |
1482 pageChangingListeners.add(listener); | 1499 pageChangingListeners.add(cast(Object)listener); |
1483 } | 1500 } |
1484 | 1501 |
1485 /** | 1502 /** |
1486 * Removes the provided page changing listener from the list of page | 1503 * Removes the provided page changing listener from the list of page |
1487 * changing listeners registered for the dialog. | 1504 * changing listeners registered for the dialog. |
1489 * @param listener | 1506 * @param listener |
1490 * a page changing listener | 1507 * a page changing listener |
1491 * @since 3.3 | 1508 * @since 3.3 |
1492 */ | 1509 */ |
1493 public void removePageChangingListener(IPageChangingListener listener) { | 1510 public void removePageChangingListener(IPageChangingListener listener) { |
1494 pageChangingListeners.remove(listener); | 1511 pageChangingListeners.remove(cast(Object)listener); |
1495 } | 1512 } |
1496 | 1513 |
1497 /** | 1514 /** |
1498 * Notifies any page changing listeners that the currently selected dialog | 1515 * Notifies any page changing listeners that the currently selected dialog |
1499 * page is changing. Only listeners registered at the time this method is | 1516 * page is changing. Only listeners registered at the time this method is |
1503 * a selection changing event | 1520 * a selection changing event |
1504 * | 1521 * |
1505 * @see IPageChangingListener#handlePageChanging(PageChangingEvent) | 1522 * @see IPageChangingListener#handlePageChanging(PageChangingEvent) |
1506 * @since 3.3 | 1523 * @since 3.3 |
1507 */ | 1524 */ |
1508 protected void firePageChanging(final PageChangingEvent event) { | 1525 protected void firePageChanging(PageChangingEvent event) { |
1509 Object[] listeners = pageChangingListeners.getListeners(); | 1526 Object[] listeners = pageChangingListeners.getListeners(); |
1510 for (int i = 0; i < listeners.length; ++i) { | 1527 for (int i = 0; i < listeners.length; ++i) { |
1511 final IPageChangingListener l = (IPageChangingListener) listeners[i]; | 1528 SafeRunnable.run(new class SafeRunnable { |
1512 SafeRunnable.run(new SafeRunnable() { | 1529 PageChangingEvent event_; |
1530 IPageChangingListener l; | |
1531 this(){ | |
1532 l = cast(IPageChangingListener) listeners[i]; | |
1533 event_=event; | |
1534 } | |
1513 public void run() { | 1535 public void run() { |
1514 l.handlePageChanging(event); | 1536 l.handlePageChanging(event_); |
1515 } | 1537 } |
1516 }); | 1538 }); |
1517 } | 1539 } |
1518 } | 1540 } |
1519 } | 1541 } |
1520 ++/ |