### Eclipse Workspace Patch 1.0 #P org.eclipse.jface Index: src/org/eclipse/jface/wizard/WizardDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/wizard/WizardDialog.java,v retrieving revision 1.56 diff -u -r1.56 WizardDialog.java --- src/org/eclipse/jface/wizard/WizardDialog.java 27 Sep 2006 20:06:13 -0000 1.56 +++ src/org/eclipse/jface/wizard/WizardDialog.java 2 Oct 2006 15:25:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Chris Gross (schtoo@schtoo.com) - pactch for bug 16179 *******************************************************************************/ package org.eclipse.jface.wizard; @@ -23,8 +24,11 @@ import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.IPageChangeProvider; import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.IPageChangingListener; +import org.eclipse.jface.dialogs.IPageChangingProvider; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.jface.dialogs.PageChangingEvent; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.ModalContext; @@ -70,7 +74,7 @@ * is rarely required. *

*/ -public class WizardDialog extends TitleAreaDialog implements IWizardContainer2, IPageChangeProvider { +public class WizardDialog extends TitleAreaDialog implements IWizardContainer2, IPageChangeProvider, IPageChangingProvider { /** * Image registry key for error message image (value "dialog_title_error_image"). */ @@ -136,6 +140,8 @@ private boolean lockedUI = false; private ListenerList pageChangedListeners = new ListenerList(); + + private ListenerList pageChangingListeners = new ListenerList(); /** * A layout for a container which includes several pages, like @@ -328,6 +334,14 @@ // should never happen since we have already visited the page return; } + + //Notify page changing listeners + PageChangingEvent e = new PageChangingEvent(this, getCurrentPage(),PageChangingEvent.DIRECTION_BACK); + firePageChanging(e); + //prevent navigation if necessary + if (e.doit == false) + return; + // set flag to indicate that we are moving back isMovingToPreviousPage = true; // show the page @@ -675,6 +689,13 @@ * The Finish button has been pressed. */ protected void finishPressed() { + //Notify page changing listeners + PageChangingEvent e = new PageChangingEvent(this, getCurrentPage(),PageChangingEvent.DIRECTION_FINISH); + firePageChanging(e); + //Prevent nagiviation if necessary + if (e.doit == false) + return; + // Wizards are added to the nested wizards list in setWizard. // This means that the current wizard is always the last wizard in the list. // Note that we first call the current wizard directly (to give it a chance to @@ -756,6 +777,14 @@ // something must have happend getting the next page return; } + + //Notify page changing listeners + PageChangingEvent e = new PageChangingEvent(this, getCurrentPage(),PageChangingEvent.DIRECTION_NEXT); + firePageChanging(e); + //Prevent navigation if necessary + if (e.doit == false) + return; + // show the next page showPage(page); } @@ -1363,4 +1392,64 @@ }); } } + + /* + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is a guarantee neither that this API will + * work nor that it will remain the same. Please do not use this API without + * consulting with the Platform/UI team. + *

+ * + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.IPageChangingProvider#addPageChangingListener(org.eclipse.jface.dialogs.IPageChangingListener) + */ + public void addPageChangingListener(IPageChangingListener listener) { + pageChangingListeners.add(listener); + } + + /* + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is a guarantee neither that this API will + * work nor that it will remain the same. Please do not use this API without + * consulting with the Platform/UI team. + *

+ * + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.IPageChangingProvider#removePageChangingdListener(org.eclipse.jface.dialogs.IPageChangingListener) + */ + public void removePageChangingdListener(IPageChangingListener listener) { + pageChangingListeners.remove(listener); + } + + /** + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is a guarantee neither that this API will + * work nor that it will remain the same. Please do not use this API without + * consulting with the Platform/UI team. + *

+ * + * Notifies any selection changing listeners that the selected page + * is changing. + * Only listeners registered at the time this method is called are notified. + * + * @param event a selection changing event + * + * @see IPageChangingListener#pageChanging + * + * @since 3.3 + */ + protected void firePageChanging(final PageChangingEvent event) { + Object[] listeners = pageChangingListeners.getListeners(); + for (int i = 0; i < listeners.length; ++i) { + final IPageChangingListener l = (IPageChangingListener) listeners[i]; + SafeRunnable.run(new SafeRunnable() { + public void run() { + l.pageChanging(event); + } + }); + } + } } Index: src/org/eclipse/jface/dialogs/PageChangingEvent.java =================================================================== RCS file: src/org/eclipse/jface/dialogs/PageChangingEvent.java diff -N src/org/eclipse/jface/dialogs/PageChangingEvent.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jface/dialogs/PageChangingEvent.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Chris Gross (schtoo@schtoo.com) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.dialogs; + +import java.util.EventObject; + +import org.eclipse.core.runtime.Assert; + +/** + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is a guarantee neither that this API will + * work nor that it will remain the same. Please do not use this API without + * consulting with the Platform/UI team. + *

+ * + * Event object describing a page selection being changed. The source of these events + * is a page changing provider. + * + * @see IPageChangingProvider + * @see IPageChangingListener + * + * @since 3.3 + */ +public class PageChangingEvent extends EventObject { + + + private static final long serialVersionUID = 1L; + + /** + * The selected page. + */ + protected Object selectedPage; + + /** + * One of the directional constants below + */ + protected int direction; + + /** + * Constant describing a backward page navigation + */ + public static final int DIRECTION_BACK = 1; + /** + * Constant describing a forward page navigation + */ + public static final int DIRECTION_NEXT = 2; + /** + * Constant describing a finish page navigation + */ + public static final int DIRECTION_FINISH = 3; + + /** + * Public field, determines if page change will continue + */ + public boolean doit = true; + + /** + * Creates a new event for the given source,selected page and direction. + * + * @param source + * the page changing provider + * @param selectedPage + * the selected page. In the JFace provided dialogs this + * will be an IDialogPage. + * @param direction DIRECTION_BACK,DIRECTION_NEXT,DIRECTION_FINISH + */ + public PageChangingEvent(IPageChangingProvider source, + Object selectedPage,int direction) { + super(source); + Assert.isNotNull(selectedPage); + Assert.isTrue(direction == DIRECTION_BACK || direction == DIRECTION_NEXT || direction == DIRECTION_FINISH); + this.direction = direction; + this.selectedPage = selectedPage; + } + + /** + * Returns the selected page. + * + * @return the selected page. In dialogs implemented by JFace, + * this will be an IDialogPage. + */ + public Object getSelectedPage() { + return selectedPage; + } + + /** + * Returns the page change provider that is the source of this event. + * + * @return the originating page change provider + */ + public IPageChangingProvider getPageChangingProvider() { + return (IPageChangingProvider) getSource(); + } + + /** + * Returns a integer constant describing the direction of the page + * change request. + * + * @return DIRECTION_BACK,DIRECTION_NEXT,DIRECTION_FINISH + */ + public int getDirection() { + return direction; + } + +} Index: src/org/eclipse/jface/dialogs/IPageChangingListener.java =================================================================== RCS file: src/org/eclipse/jface/dialogs/IPageChangingListener.java diff -N src/org/eclipse/jface/dialogs/IPageChangingListener.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jface/dialogs/IPageChangingListener.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Chris Gross (schtoo@schtoo.com) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.dialogs; + +/** + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is a guarantee neither that this API will + * work nor that it will remain the same. Please do not use this API without + * consulting with the Platform/UI team. + *

+ * + * A listener which is notified when the current page of the multi-page dialog + * is changing. + * + * @see IPageChangingProvider + * @see PageChangingEvent + * + * @since 3.3 + */ +public interface IPageChangingListener { + + /** + * Notifies that the selected page is changing. The doit field of the + * PageChangingEvent can be set to false to prevent the page from changing. + * + * @param event + * event object describing the change + */ + public void pageChanging(PageChangingEvent event); + +} Index: src/org/eclipse/jface/dialogs/IPageChangingProvider.java =================================================================== RCS file: src/org/eclipse/jface/dialogs/IPageChangingProvider.java diff -N src/org/eclipse/jface/dialogs/IPageChangingProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jface/dialogs/IPageChangingProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Chris Gross (schtoo@schtoo.com) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.dialogs; + +/** + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is a guarantee neither that this API will + * work nor that it will remain the same. Please do not use this API without + * consulting with the Platform/UI team. + *

+ * + * Minimal interface to a page changing provider. Used for dialogs which can + * switch between multiple pages. + * + * @since 3.3 + */ +public interface IPageChangingProvider { + /** + * Returns the currently selected page in the dialog. + * + * @return the selected page in the dialog or null if none is + * selected. The type may be domain specific. In + * the JFace provided dialogs this will be an instance of + * IDialogPage. + */ + Object getSelectedPage(); + + /** + * Adds a listener for page changes in this page changing provider. Has no + * effect if an identical listener is already registered. + * + * @param listener + * a page changing listener + */ + void addPageChangingListener(IPageChangingListener listener); + + /** + * Removes the given page changing listener from this page changing provider. + * Has no effect if an identical listener is not registered. + * + * @param listener + * a page changing listener + */ + void removePageChangingdListener(IPageChangingListener listener); + +}