Mercurial > projects > dwt-addons
diff 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 |
line wrap: on
line diff
--- a/dwtx/jface/wizard/WizardDialog.d Sat Apr 05 01:45:47 2008 +0200 +++ b/dwtx/jface/wizard/WizardDialog.d Sat Apr 05 04:49:22 2008 +0200 @@ -12,16 +12,18 @@ * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwtx.jface.wizard.WizardDialog; -pragma( msg, "FIXME dwtx.jface.wizard.WizardDialog"); -class WizardDialog { -} +import dwtx.jface.wizard.IWizardContainer2; +import dwtx.jface.wizard.IWizard; +import dwtx.jface.wizard.IWizardPage; +import dwtx.jface.wizard.ProgressMonitorPart; -/++ -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +// import java.lang.reflect.InvocationTargetException; +import tango.util.collection.ArraySeq; +import tango.util.collection.HashMap; +import tango.util.collection.model.Map; +// import java.util.HashMap; +// import java.util.Map; import dwt.DWT; import dwt.custom.BusyIndicator; @@ -60,6 +62,9 @@ import dwtx.jface.resource.JFaceResources; import dwtx.jface.util.SafeRunnable; +import dwt.dwthelper.utils; +import dwt.dwthelper.Runnable; + /** * A dialog to show a wizard to the end user. * <p> @@ -79,22 +84,22 @@ * required. * </p> */ -public class WizardDialog extends TitleAreaDialog implements IWizardContainer2, +public class WizardDialog : TitleAreaDialog, IWizardContainer2, IPageChangeProvider { /** * Image registry key for error message image (value * <code>"dialog_title_error_image"</code>). */ - public static final String WIZ_IMG_ERROR = "dialog_title_error_image"; //$NON-NLS-1$ + public static const String WIZ_IMG_ERROR = "dialog_title_error_image"; //$NON-NLS-1$ // The wizard the dialog is currently showing. private IWizard wizard; // Wizards to dispose - private ArrayList createdWizards = new ArrayList(); + private ArraySeq!(Object) createdWizards; // Current nested wizards - private ArrayList nestedWizards = new ArrayList(); + private ArraySeq!(Object) nestedWizards; // The currently displayed page. private IWizardPage currentPage = null; @@ -135,20 +140,19 @@ private Composite pageContainer; - private PageContainerFillLayout pageContainerLayout = new PageContainerFillLayout( - 5, 5, 300, 225); + private PageContainerFillLayout pageContainerLayout; private int pageWidth = DWT.DEFAULT; private int pageHeight = DWT.DEFAULT; - private static final String FOCUS_CONTROL = "focusControl"; //$NON-NLS-1$ + private static const String FOCUS_CONTROL = "focusControl"; //$NON-NLS-1$ private bool lockedUI = false; - private ListenerList pageChangedListeners = new ListenerList(); + private ListenerList pageChangedListeners; - private ListenerList pageChangingListeners = new ListenerList(); + private ListenerList pageChangingListeners; /** * A layout for a container which includes several pages, like a notebook, @@ -156,7 +160,7 @@ * maximum width and height of all pages currently inserted into the * container. */ - protected class PageContainerFillLayout extends Layout { + protected class PageContainerFillLayout : Layout { /** * The margin width; <code>5</code> pixels by default. */ @@ -189,7 +193,8 @@ * @param minH * the minimum height */ - public PageContainerFillLayout(int mw, int mh, int minW, int minH) { + public this(int mw, int mh, int minW, int minH) { + pageContainerLayout = new PageContainerFillLayout( 5, 5, 300, 225); marginWidth = mw; marginHeight = mh; minimumWidth = minW; @@ -288,14 +293,19 @@ * @param newWizard * the wizard this dialog is working on */ - public WizardDialog(Shell parentShell, IWizard newWizard) { + public this(Shell parentShell, IWizard newWizard) { + createdWizards = new ArraySeq!(Object); + nestedWizards = new ArraySeq!(Object); + pageChangedListeners = new ListenerList(); + pageChangingListeners = new ListenerList(); + super(parentShell); setShellStyle(DWT.CLOSE | DWT.MAX | DWT.TITLE | DWT.BORDER | DWT.APPLICATION_MODAL | DWT.RESIZE | getDefaultOrientation()); setWizard(newWizard); // since VAJava can't initialize an instance var with an anonymous // class outside a constructor we do it here: - cancelListener = new SelectionAdapter() { + cancelListener = new class SelectionAdapter { public void widgetSelected(SelectionEvent e) { cancelPressed(); } @@ -313,7 +323,7 @@ * @return the saved UI state */ private Object aboutToStart(bool enableCancelButton) { - Map savedState = null; + Map!(Object,Object) savedState = null; if (getShell() !is null) { // Save focus control Control focusControl = getShell().getDisplay().getFocusControl(); @@ -332,7 +342,7 @@ // Deactivate shell savedState = saveUIState(needsProgressMonitor && enableCancelButton); if (focusControl !is null) { - savedState.put(FOCUS_CONTROL, focusControl); + savedState.add(stringcast(FOCUS_CONTROL), focusControl); } // Attach the progress monitor part to the cancel button if (needsProgressMonitor) { @@ -340,7 +350,7 @@ progressMonitorPart.setVisible(true); } } - return savedState; + return cast(Object) savedState; } /** @@ -442,7 +452,7 @@ protected void configureShell(Shell newShell) { super.configureShell(newShell); // Register help listener on the shell - newShell.addHelpListener(new HelpListener() { + newShell.addHelpListener(new class HelpListener { public void helpRequested(HelpEvent event) { // call perform help on the current page if (currentPage !is null) { @@ -464,7 +474,7 @@ * the parent composite to contain the buttons */ protected void createButtonsForButtonBar(Composite parent) { - ((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; + (cast(GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; if (wizard.isHelpAvailable()) { helpButton = createButton(parent, IDialogConstants.HELP_ID, IDialogConstants.HELP_LABEL, false); @@ -507,7 +517,7 @@ */ private Button createCancelButton(Composite parent) { // increment the number of columns in the button bar - ((GridLayout) parent.getLayout()).numColumns++; + (cast(GridLayout) parent.getLayout()).numColumns++; Button button = new Button(parent, DWT.PUSH); button.setText(IDialogConstants.CANCEL_LABEL); setButtonLayoutData(button); @@ -557,7 +567,7 @@ * (non-Javadoc) Method declared on Dialog. */ protected Control createDialogArea(Composite parent) { - Composite composite = (Composite) super.createDialogArea(parent); + Composite composite = cast(Composite) super.createDialogArea(parent); // Build the Page container pageContainer = createPageContainer(composite); GridData gd = new GridData(GridData.FILL_BOTH); @@ -589,9 +599,14 @@ */ protected ProgressMonitorPart createProgressMonitorPart( Composite composite, GridLayout pmlayout) { - return new ProgressMonitorPart(composite, pmlayout, DWT.DEFAULT) { + return new class(composite, pmlayout, DWT.DEFAULT) ProgressMonitorPart { + String currentTask = null; + this(Composite c, Layout l, int s ){ + super(c,l,s); + } + /* * (non-Javadoc) * @@ -697,7 +712,7 @@ */ private Composite createPreviousAndNextButtons(Composite parent) { // increment the number of columns in the button bar - ((GridLayout) parent.getLayout()).numColumns++; + (cast(GridLayout) parent.getLayout()).numColumns++; Composite composite = new Composite(parent, DWT.NONE); // create a layout with spacing and margins appropriate for the font // size. @@ -730,7 +745,7 @@ null, JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$ MessageDialog.QUESTION, - new String[] { IDialogConstants.OK_LABEL }, 0); + [ IDialogConstants.OK_LABEL ], 0); return result; } @@ -750,7 +765,7 @@ // Call perform finish on outer wizards in the nested chain // (to allow them to save state for example) for (int i = 0; i < nestedWizards.size() - 1; i++) { - ((IWizard) nestedWizards.get(i)).performFinish(); + (cast(IWizard) nestedWizards.get(i)).performFinish(); } // Hard close the dialog. setReturnCode(OK); @@ -793,7 +808,7 @@ private bool hardClose() { // inform wizards for (int i = 0; i < createdWizards.size(); i++) { - IWizard createdWizard = (IWizard) createdWizards.get(i); + IWizard createdWizard = cast(IWizard) createdWizards.get(i); createdWizard.dispose(); // Remove this dialog as a parent from the managed wizard. // Note that we do this after calling dispose as the wizard or @@ -836,8 +851,8 @@ * successfully, <code>false</code> otherwise */ private bool doPageChanging(IWizardPage targetPage) { - PageChangingEvent e = new PageChangingEvent(this, getCurrentPage(), - targetPage); + PageChangingEvent e = new PageChangingEvent(this, cast(Object)getCurrentPage(), + cast(Object)targetPage); firePageChanging(e); // Prevent navigation if necessary return e.doit; @@ -878,9 +893,9 @@ * the key * @see #saveEnableStateAndSet */ - private void restoreEnableState(Control w, Map h, String key) { + private void restoreEnableState(Control w, Map!(Object,Object) h, String key) { if (w !is null) { - bool b = (bool) h.get(key); + auto b = cast(Boolean) h.get(stringcast(key)); if (b !is null) { w.setEnabled(b.booleanValue()); } @@ -896,15 +911,15 @@ * <code>saveUIState</code> * @see #saveUIState */ - private void restoreUIState(Map state) { + private void restoreUIState(Map!(Object,Object) state) { restoreEnableState(backButton, state, "back"); //$NON-NLS-1$ restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$ restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$ restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$ restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$ - Object pageValue = state.get("page"); //$NON-NLS-1$ + Object pageValue = state.get(stringcast("page")); //$NON-NLS-1$ if (pageValue !is null) { - ((ControlEnableState) pageValue).restore(); + (cast(ControlEnableState) pageValue).restore(); } } @@ -924,8 +939,7 @@ * */ public void run(bool fork, bool cancelable, - IRunnableWithProgress runnable) throws InvocationTargetException, - InterruptedException { + IRunnableWithProgress runnable) { // The operation can only be canceled if it is executed in a separate // thread. // Otherwise the UI is blocked anyway. @@ -966,10 +980,10 @@ * <code>false</code> to disable it * @see #restoreEnableState(Control, Map, String) */ - private void saveEnableStateAndSet(Control w, Map h, String key, + private void saveEnableStateAndSet(Control w, Map!(Object,Object) h, String key, bool enabled) { if (w !is null) { - h.put(key, w.getEnabled() ? bool.TRUE : bool.FALSE); + h.add(stringcast(key), w.getEnabled() ? Boolean.TRUE : Boolean.FALSE); w.setEnabled(enabled); } } @@ -987,8 +1001,8 @@ * with <code>restoreUIState</code> * @see #restoreUIState */ - private Map saveUIState(bool keepCancelEnabled) { - Map savedState = new HashMap(10); + private Map!(Object,Object) saveUIState(bool keepCancelEnabled) { + Map!(Object,Object) savedState = new HashMap!(Object,Object); saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$ saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$ saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$ @@ -996,9 +1010,7 @@ "cancel", keepCancelEnabled); //$NON-NLS-1$ saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$ if (currentPage !is null) { - savedState - .put( - "page", ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ + savedState.add(stringcast("page"), ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ } return savedState; } @@ -1079,10 +1091,10 @@ protected void setWizard(IWizard newWizard) { wizard = newWizard; wizard.setContainer(this); - if (!createdWizards.contains(wizard)) { - createdWizards.add(wizard); + if (!createdWizards.contains(cast(Object)wizard)) { + createdWizards.append(cast(Object)wizard); // New wizard so just add it to the end of our nested list - nestedWizards.add(wizard); + nestedWizards.append(cast(Object)wizard); if (pageContainer !is null) { // Dialog is already open // Allow the wizard pages to precreate their page controls @@ -1097,11 +1109,11 @@ // on the nested list then we assume we have gone back and remove // the last wizard from the list int size = nestedWizards.size(); - if (size >= 2 && nestedWizards.get(size - 2) is wizard) { - nestedWizards.remove(size - 1); + if (size >= 2 && nestedWizards.get(size - 2) is cast(Object)wizard) { + nestedWizards.removeAt(size - 1); } else { // Assume we are going forward to revisit a wizard - nestedWizards.add(wizard); + nestedWizards.append(cast(Object)wizard); } } } @@ -1130,7 +1142,7 @@ updateForPage(page); } else { final IWizardPage finalPage = page; - BusyIndicator.showWhile(getContents().getDisplay(), new Runnable() { + BusyIndicator.showWhile(getContents().getDisplay(), new class Runnable { public void run() { updateForPage(finalPage); } @@ -1157,7 +1169,7 @@ // via getControl. Assert.isNotNull(page.getControl(), JFaceResources.format( JFaceResources.getString("WizardDialog.missingSetControl"), //$NON-NLS-1$ - new Object[] { page.getName() })); + [ page.getName() ])); // ensure the dialog is large enough for this page updateSize(page); } @@ -1213,7 +1225,7 @@ progressMonitorPart.setVisible(false); progressMonitorPart.removeFromCancelComponent(cancelButton); } - Map state = (Map) savedState; + Map!(Object,Object) state = cast(Map!(Object,Object)) savedState; restoreUIState(state); cancelButton.addSelectionListener(cancelListener); setDisplayCursor(null); @@ -1222,7 +1234,7 @@ waitCursor = null; arrowCursor.dispose(); arrowCursor = null; - Control focusControl = (Control) state.get(FOCUS_CONTROL); + Control focusControl = cast(Control) state.get(stringcast(FOCUS_CONTROL)); if (focusControl !is null) { focusControl.setFocus(); } @@ -1241,7 +1253,7 @@ updateButtons(); // Fires the page change event - firePageChanged(new PageChangedEvent(this, getCurrentPage())); + firePageChanged(new PageChangedEvent(this, cast(Object)getCurrentPage())); } /* @@ -1287,8 +1299,8 @@ } pageMessage = currentPage.getMessage(); - if (pageMessage !is null && currentPage instanceof IMessageProvider) { - pageMessageType = ((IMessageProvider) currentPage).getMessageType(); + if (pageMessage !is null && cast(IMessageProvider)currentPage ) { + pageMessageType = (cast(IMessageProvider) currentPage).getMessageType(); } else { pageMessageType = IMessageProvider.NONE; } @@ -1424,7 +1436,7 @@ * @see dwtx.jface.dialogs.IPageChangeProvider#getSelectedPage() */ public Object getSelectedPage() { - return getCurrentPage(); + return cast(Object)getCurrentPage(); } /* @@ -1433,7 +1445,7 @@ * @see dwtx.jface.dialog.IPageChangeProvider#addPageChangedListener() */ public void addPageChangedListener(IPageChangedListener listener) { - pageChangedListeners.add(listener); + pageChangedListeners.add(cast(Object)listener); } /* @@ -1442,7 +1454,7 @@ * @see dwtx.jface.dialog.IPageChangeProvider#removePageChangedListener() */ public void removePageChangedListener(IPageChangedListener listener) { - pageChangedListeners.remove(listener); + pageChangedListeners.remove(cast(Object)listener); } /** @@ -1457,13 +1469,18 @@ * * @since 3.1 */ - protected void firePageChanged(final PageChangedEvent event) { + protected void firePageChanged(PageChangedEvent event) { Object[] listeners = pageChangedListeners.getListeners(); for (int i = 0; i < listeners.length; ++i) { - final IPageChangedListener l = (IPageChangedListener) listeners[i]; - SafeRunnable.run(new SafeRunnable() { + SafeRunnable.run(new class SafeRunnable { + PageChangedEvent event_; + IPageChangedListener l; + this(){ + l = cast(IPageChangedListener) listeners[i]; + event_=event; + } public void run() { - l.pageChanged(event); + l.pageChanged(event_); } }); } @@ -1479,7 +1496,7 @@ * @since 3.3 */ public void addPageChangingListener(IPageChangingListener listener) { - pageChangingListeners.add(listener); + pageChangingListeners.add(cast(Object)listener); } /** @@ -1491,7 +1508,7 @@ * @since 3.3 */ public void removePageChangingListener(IPageChangingListener listener) { - pageChangingListeners.remove(listener); + pageChangingListeners.remove(cast(Object)listener); } /** @@ -1505,16 +1522,20 @@ * @see IPageChangingListener#handlePageChanging(PageChangingEvent) * @since 3.3 */ - protected void firePageChanging(final PageChangingEvent event) { + protected void firePageChanging(PageChangingEvent event) { Object[] listeners = pageChangingListeners.getListeners(); for (int i = 0; i < listeners.length; ++i) { - final IPageChangingListener l = (IPageChangingListener) listeners[i]; - SafeRunnable.run(new SafeRunnable() { + SafeRunnable.run(new class SafeRunnable { + PageChangingEvent event_; + IPageChangingListener l; + this(){ + l = cast(IPageChangingListener) listeners[i]; + event_=event; + } public void run() { - l.handlePageChanging(event); + l.handlePageChanging(event_); } }); } } } -++/ \ No newline at end of file