comparison dwtx/jface/wizard/WizardDialog.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 4878bef4a38e
children a521c486e142
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
17 import dwtx.jface.wizard.IWizard; 17 import dwtx.jface.wizard.IWizard;
18 import dwtx.jface.wizard.IWizardPage; 18 import dwtx.jface.wizard.IWizardPage;
19 import dwtx.jface.wizard.ProgressMonitorPart; 19 import dwtx.jface.wizard.ProgressMonitorPart;
20 20
21 // import java.lang.reflect.InvocationTargetException; 21 // import java.lang.reflect.InvocationTargetException;
22 import tango.util.collection.ArraySeq;
23 import tango.util.collection.HashMap;
24 import tango.util.collection.model.Map;
25 // import java.util.HashMap; 22 // import java.util.HashMap;
26 // import java.util.Map; 23 // import java.util.Map;
27 24
28 import dwt.DWT; 25 import dwt.DWT;
29 import dwt.custom.BusyIndicator; 26 import dwt.custom.BusyIndicator;
61 import dwtx.jface.operation.ModalContext; 58 import dwtx.jface.operation.ModalContext;
62 import dwtx.jface.resource.JFaceResources; 59 import dwtx.jface.resource.JFaceResources;
63 import dwtx.jface.util.SafeRunnable; 60 import dwtx.jface.util.SafeRunnable;
64 61
65 import dwt.dwthelper.utils; 62 import dwt.dwthelper.utils;
63 import dwtx.dwtxhelper.Collection;
66 import dwt.dwthelper.Runnable; 64 import dwt.dwthelper.Runnable;
67 65
68 /** 66 /**
69 * A dialog to show a wizard to the end user. 67 * A dialog to show a wizard to the end user.
70 * <p> 68 * <p>
94 92
95 // The wizard the dialog is currently showing. 93 // The wizard the dialog is currently showing.
96 private IWizard wizard; 94 private IWizard wizard;
97 95
98 // Wizards to dispose 96 // Wizards to dispose
99 private ArraySeq!(Object) createdWizards; 97 private ArrayList createdWizards;
100 98
101 // Current nested wizards 99 // Current nested wizards
102 private ArraySeq!(Object) nestedWizards; 100 private ArrayList nestedWizards;
103 101
104 // The currently displayed page. 102 // The currently displayed page.
105 private IWizardPage currentPage = null; 103 private IWizardPage currentPage = null;
106 104
107 // The number of long running operation executed from the dialog. 105 // The number of long running operation executed from the dialog.
292 * the parent shell 290 * the parent shell
293 * @param newWizard 291 * @param newWizard
294 * the wizard this dialog is working on 292 * the wizard this dialog is working on
295 */ 293 */
296 public this(Shell parentShell, IWizard newWizard) { 294 public this(Shell parentShell, IWizard newWizard) {
297 createdWizards = new ArraySeq!(Object); 295 createdWizards = new ArrayList();
298 nestedWizards = new ArraySeq!(Object); 296 nestedWizards = new ArrayList();
299 pageChangedListeners = new ListenerList(); 297 pageChangedListeners = new ListenerList();
300 pageChangingListeners = new ListenerList(); 298 pageChangingListeners = new ListenerList();
301 299
302 super(parentShell); 300 super(parentShell);
303 setShellStyle(DWT.CLOSE | DWT.MAX | DWT.TITLE | DWT.BORDER 301 setShellStyle(DWT.CLOSE | DWT.MAX | DWT.TITLE | DWT.BORDER
321 * <code>true</code> if the Cancel button should be enabled, 319 * <code>true</code> if the Cancel button should be enabled,
322 * and <code>false</code> if it should be disabled 320 * and <code>false</code> if it should be disabled
323 * @return the saved UI state 321 * @return the saved UI state
324 */ 322 */
325 private Object aboutToStart(bool enableCancelButton) { 323 private Object aboutToStart(bool enableCancelButton) {
326 Map!(Object,Object) savedState = null; 324 Map savedState = null;
327 if (getShell() !is null) { 325 if (getShell() !is null) {
328 // Save focus control 326 // Save focus control
329 Control focusControl = getShell().getDisplay().getFocusControl(); 327 Control focusControl = getShell().getDisplay().getFocusControl();
330 if (focusControl !is null && focusControl.getShell() !is getShell()) { 328 if (focusControl !is null && focusControl.getShell() !is getShell()) {
331 focusControl = null; 329 focusControl = null;
340 arrowCursor = new Cursor(d, DWT.CURSOR_ARROW); 338 arrowCursor = new Cursor(d, DWT.CURSOR_ARROW);
341 cancelButton.setCursor(arrowCursor); 339 cancelButton.setCursor(arrowCursor);
342 // Deactivate shell 340 // Deactivate shell
343 savedState = saveUIState(needsProgressMonitor && enableCancelButton); 341 savedState = saveUIState(needsProgressMonitor && enableCancelButton);
344 if (focusControl !is null) { 342 if (focusControl !is null) {
345 savedState.add(stringcast(FOCUS_CONTROL), focusControl); 343 savedState.put(stringcast(FOCUS_CONTROL), focusControl);
346 } 344 }
347 // Attach the progress monitor part to the cancel button 345 // Attach the progress monitor part to the cancel button
348 if (needsProgressMonitor) { 346 if (needsProgressMonitor) {
349 progressMonitorPart.attachToCancelComponent(cancelButton); 347 progressMonitorPart.attachToCancelComponent(cancelButton);
350 progressMonitorPart.setVisible(true); 348 progressMonitorPart.setVisible(true);
891 * <code>Boolean</code>) 889 * <code>Boolean</code>)
892 * @param key 890 * @param key
893 * the key 891 * the key
894 * @see #saveEnableStateAndSet 892 * @see #saveEnableStateAndSet
895 */ 893 */
896 private void restoreEnableState(Control w, Map!(Object,Object) h, String key) { 894 private void restoreEnableState(Control w, Map h, String key) {
897 if (w !is null) { 895 if (w !is null) {
898 Boolean b = cast(Boolean) h.get(stringcast(key)); 896 Boolean b = cast(Boolean) h.get(stringcast(key));
899 if (b !is null) { 897 if (b !is null) {
900 w.setEnabled(b.booleanValue()); 898 w.setEnabled(b.booleanValue());
901 } 899 }
909 * @param state 907 * @param state
910 * a map containing the saved state as returned by 908 * a map containing the saved state as returned by
911 * <code>saveUIState</code> 909 * <code>saveUIState</code>
912 * @see #saveUIState 910 * @see #saveUIState
913 */ 911 */
914 private void restoreUIState(Map!(Object,Object) state) { 912 private void restoreUIState(Map state) {
915 restoreEnableState(backButton, state, "back"); //$NON-NLS-1$ 913 restoreEnableState(backButton, state, "back"); //$NON-NLS-1$
916 restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$ 914 restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$
917 restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$ 915 restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$
918 restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$ 916 restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$
919 restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$ 917 restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$
978 * @param enabled 976 * @param enabled
979 * <code>true</code> to enable the control, and 977 * <code>true</code> to enable the control, and
980 * <code>false</code> to disable it 978 * <code>false</code> to disable it
981 * @see #restoreEnableState(Control, Map, String) 979 * @see #restoreEnableState(Control, Map, String)
982 */ 980 */
983 private void saveEnableStateAndSet(Control w, Map!(Object,Object) h, String key, 981 private void saveEnableStateAndSet(Control w, Map h, String key,
984 bool enabled) { 982 bool enabled) {
985 if (w !is null) { 983 if (w !is null) {
986 h.add(stringcast(key), w.getEnabled() ? Boolean.TRUE : Boolean.FALSE); 984 h.put(stringcast(key), w.getEnabled() ? Boolean.TRUE : Boolean.FALSE);
987 w.setEnabled(enabled); 985 w.setEnabled(enabled);
988 } 986 }
989 } 987 }
990 988
991 /** 989 /**
999 * enabled, and <code>false</code> if it should be disabled 997 * enabled, and <code>false</code> if it should be disabled
1000 * @return a map containing the saved state suitable for restoring later 998 * @return a map containing the saved state suitable for restoring later
1001 * with <code>restoreUIState</code> 999 * with <code>restoreUIState</code>
1002 * @see #restoreUIState 1000 * @see #restoreUIState
1003 */ 1001 */
1004 private Map!(Object,Object) saveUIState(bool keepCancelEnabled) { 1002 private Map saveUIState(bool keepCancelEnabled) {
1005 Map!(Object,Object) savedState = new HashMap!(Object,Object); 1003 Map savedState = new HashMap(10);
1006 saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$ 1004 saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$
1007 saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$ 1005 saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$
1008 saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$ 1006 saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$
1009 saveEnableStateAndSet(cancelButton, savedState, 1007 saveEnableStateAndSet(cancelButton, savedState,
1010 "cancel", keepCancelEnabled); //$NON-NLS-1$ 1008 "cancel", keepCancelEnabled); //$NON-NLS-1$
1011 saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$ 1009 saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$
1012 if (currentPage !is null) { 1010 if (currentPage !is null) {
1013 savedState.add(stringcast("page"), ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ 1011 savedState.put(stringcast("page"), ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$
1014 } 1012 }
1015 return savedState; 1013 return savedState;
1016 } 1014 }
1017 1015
1018 /** 1016 /**
1090 */ 1088 */
1091 protected void setWizard(IWizard newWizard) { 1089 protected void setWizard(IWizard newWizard) {
1092 wizard = newWizard; 1090 wizard = newWizard;
1093 wizard.setContainer(this); 1091 wizard.setContainer(this);
1094 if (!createdWizards.contains(cast(Object)wizard)) { 1092 if (!createdWizards.contains(cast(Object)wizard)) {
1095 createdWizards.append(cast(Object)wizard); 1093 createdWizards.add(cast(Object)wizard);
1096 // New wizard so just add it to the end of our nested list 1094 // New wizard so just add it to the end of our nested list
1097 nestedWizards.append(cast(Object)wizard); 1095 nestedWizards.add(cast(Object)wizard);
1098 if (pageContainer !is null) { 1096 if (pageContainer !is null) {
1099 // Dialog is already open 1097 // Dialog is already open
1100 // Allow the wizard pages to precreate their page controls 1098 // Allow the wizard pages to precreate their page controls
1101 // This allows the wizard to open to the correct size 1099 // This allows the wizard to open to the correct size
1102 createPageControls(); 1100 createPageControls();
1108 // We have already seen this wizard, if it is the previous wizard 1106 // We have already seen this wizard, if it is the previous wizard
1109 // on the nested list then we assume we have gone back and remove 1107 // on the nested list then we assume we have gone back and remove
1110 // the last wizard from the list 1108 // the last wizard from the list
1111 int size = nestedWizards.size(); 1109 int size = nestedWizards.size();
1112 if (size >= 2 && nestedWizards.get(size - 2) is cast(Object)wizard) { 1110 if (size >= 2 && nestedWizards.get(size - 2) is cast(Object)wizard) {
1113 nestedWizards.removeAt(size - 1); 1111 nestedWizards.remove(size - 1);
1114 } else { 1112 } else {
1115 // Assume we are going forward to revisit a wizard 1113 // Assume we are going forward to revisit a wizard
1116 nestedWizards.append(cast(Object)wizard); 1114 nestedWizards.add(cast(Object)wizard);
1117 } 1115 }
1118 } 1116 }
1119 } 1117 }
1120 1118
1121 /* 1119 /*
1223 if (getShell() !is null && !getShell().isDisposed()) { 1221 if (getShell() !is null && !getShell().isDisposed()) {
1224 if (wizard.needsProgressMonitor()) { 1222 if (wizard.needsProgressMonitor()) {
1225 progressMonitorPart.setVisible(false); 1223 progressMonitorPart.setVisible(false);
1226 progressMonitorPart.removeFromCancelComponent(cancelButton); 1224 progressMonitorPart.removeFromCancelComponent(cancelButton);
1227 } 1225 }
1228 Map!(Object,Object) state = cast(Map!(Object,Object)) savedState; 1226 Map state = cast(Map) savedState;
1229 restoreUIState(state); 1227 restoreUIState(state);
1230 cancelButton.addSelectionListener(cancelListener); 1228 cancelButton.addSelectionListener(cancelListener);
1231 setDisplayCursor(null); 1229 setDisplayCursor(null);
1232 cancelButton.setCursor(null); 1230 cancelButton.setCursor(null);
1233 waitCursor.dispose(); 1231 waitCursor.dispose();