### Eclipse Workspace Patch 1.0 #P org.eclipse.swt Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java,v retrieving revision 1.289 diff -u -r1.289 CTabFolder.java --- Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java 2 Apr 2009 22:35:06 -0000 1.289 +++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java 3 Apr 2009 14:07:08 -0000 @@ -202,6 +202,7 @@ // on Resize Point oldSize; Font oldFont; + CTabFolderPageManager pageManager; // internal constants static final int DEFAULT_WIDTH = 64; @@ -555,6 +556,12 @@ color.dispose(); } } +boolean canLeaveThePage(int oldIndex, int newIndex) { + if (pageManager != null) { + return pageManager.canLeaveThePage(oldIndex, newIndex); + } + return true; +} /* * This class was not intended to be subclassed but this restriction * cannot be enforced without breaking backward compatibility. @@ -1416,6 +1423,16 @@ checkWidget(); return mru; } +/** + * Returns the Page Manager that is used by the CTabfolder before switching between tab-items. + * + * @return the tabfolder's Page Manager, or null if no Page Manager has been set. + * + * @since + */ +public CTabFolderPageManager getPageManager() { + return pageManager; +} int getRightItemEdge (){ int x = getSize().x - borderRight - 3; if (showMin) x -= BUTTON_SIZE; @@ -3185,6 +3202,28 @@ } } /** + * Sets the Page Manager that will be used to by the CTabFolder before + * switching between tab-items. + * The Page Manager should implement the CTabFolderPageManager and + * implement the method canLeaveThePage. + * + * @param pageManager the Page Manager for the CTabFolder + * + * @exception IllegalArgumentException + * + * @exception SWTException + * + * @since + */ +public void setPageManager(CTabFolderPageManager pageManager) { + this.pageManager = pageManager; +} +/** * Set the selection to the tab at the specified item. * * @param item the tab item to be selected @@ -3222,7 +3261,12 @@ showItem(selection); return; } - + /* + * If the user has set a Page Manager for the previously selected tab-item, + * then call the canLeaveThePage() method to do any validations in the Page Manager, + * before switching the tab. Don't change the tab selection if validation fails. + */ + if (selectedIndex != -1 && !canLeaveThePage(selectedIndex, index)) return; int oldIndex = selectedIndex; selectedIndex = index; if (oldIndex != -1) { Index: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderPageManager.java =================================================================== RCS file: Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderPageManager.java diff -N Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderPageManager.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderPageManager.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,25 @@ +package org.eclipse.swt.custom; + +/** + * This is an Interface which provides a mechanism to use a Page Manager for a CTabItem. + * The Page Manager can be used to do any validations as required by the user while switching between tab-items. + * The Page Manager should implement the method canLeaveThePage. + */ + +public interface CTabFolderPageManager { + /** + * This method is called before changing the tab selection of the CTabFolder + * + * @param oldIndex is index of tab selected in the CTabFolder + * @param newIndex is index of the tab that will be selected if this method returns true + * + * @return + * + * @since + */ + public boolean canLeaveThePage(int oldIndex, int newIndex); +}