# HG changeset patch # User Frank Benoit # Date 1207193884 -7200 # Node ID 50b0163e18f888ba64a9fa129b088d71648c08e0 # Parent 7ec2fd279c280c9d2f5f302a8477678e8a7280c7 Sub... diff -r 7ec2fd279c28 -r 50b0163e18f8 dwtx/jface/action/IMenuManager.d --- a/dwtx/jface/action/IMenuManager.d Thu Apr 03 05:17:07 2008 +0200 +++ b/dwtx/jface/action/IMenuManager.d Thu Apr 03 05:38:04 2008 +0200 @@ -33,6 +33,9 @@ *

*/ public interface IMenuManager : IContributionManager, IContributionItem { + + alias IContributionItem.update update; + alias IContributionManager.update update; /** * Adds a menu listener to this menu. * Has no effect if an identical listener is already registered. diff -r 7ec2fd279c28 -r 50b0163e18f8 dwtx/jface/action/SubCoolBarManager.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/action/SubCoolBarManager.d Thu Apr 03 05:38:04 2008 +0200 @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2003, 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: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwtx.jface.action.SubCoolBarManager; + +import dwtx.jface.action.ICoolBarManager; +import dwtx.jface.action.SubContributionManager; +import dwtx.jface.action.IToolBarManager; +import dwtx.jface.action.IMenuManager; +import dwtx.jface.action.ToolBarContributionItem; + +import dwtx.core.runtime.Assert; + +import dwt.dwthelper.utils; + +/** + * A SubCoolBarManager monitors the additional and removal of + * items from a parent manager so that visibility of the entire set can be changed as a + * unit. + * + * @since 3.0 + */ +public class SubCoolBarManager : SubContributionManager, + ICoolBarManager { + + /** + * Constructs a new manager. + * + * @param mgr the parent manager. All contributions made to the + * SubCoolBarManager are forwarded and appear in the + * parent manager. + */ + public this(ICoolBarManager mgr) { + super(mgr); + Assert.isNotNull(cast(Object)mgr); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.ICoolBarManager#add(dwtx.jface.action.IToolBarManager) + */ + public void add(IToolBarManager toolBarManager) { + Assert.isNotNull(cast(Object)toolBarManager); + super.add(new ToolBarContributionItem(toolBarManager)); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.ICoolBarManager#getStyle() + */ + public int getStyle() { + // It is okay to cast down since we only accept coolBarManager objects in the + // constructor + return (cast(ICoolBarManager) getParent()).getStyle(); + } + + /** + * Returns the parent cool bar manager that this sub-manager contributes to. + * + * @return the parent cool bar manager + */ + protected final ICoolBarManager getParentCoolBarManager() { + // Cast is ok because that's the only + // thing we accept in the construtor. + return cast(ICoolBarManager) getParent(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.ICoolBarManager#isLayoutLocked() + */ + public bool getLockLayout() { + return getParentCoolBarManager().getLockLayout(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.ICoolBarManager#lockLayout(bool) + */ + public void setLockLayout(bool value) { + } + + /* (non-Javadoc) + * SubCoolBarManagers do not have control of the global context menu. + */ + public IMenuManager getContextMenuManager() { + return null; + } + + /* (non-Javadoc) + * In SubCoolBarManager we do nothing. + */ + public void setContextMenuManager(IMenuManager menuManager) { + // do nothing + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionManager#update(bool) + */ + public void update(bool force) { + // This method is not governed by visibility. The client may + // call setVisible and then force an update. At that + // point we need to update the parent. + getParentCoolBarManager().update(force); + } + +} diff -r 7ec2fd279c28 -r 50b0163e18f8 dwtx/jface/action/SubMenuManager.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/action/SubMenuManager.d Thu Apr 03 05:38:04 2008 +0200 @@ -0,0 +1,423 @@ +/******************************************************************************* + * Copyright (c) 2000, 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: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwtx.jface.action.SubMenuManager; + +import dwtx.jface.action.SubContributionManager; +import dwtx.jface.action.IMenuManager; +import dwtx.jface.action.IMenuListener; +import dwtx.jface.action.IContributionItem; +import dwtx.jface.action.IContributionManager; +import dwtx.jface.action.SubContributionItem; + +import tango.util.collection.HashMap; +import tango.util.collection.model.Map; + +import dwt.widgets.Composite; +import dwt.widgets.CoolBar; +import dwt.widgets.Menu; +import dwt.widgets.ToolBar; +import dwtx.core.runtime.Assert; +import dwtx.core.runtime.ListenerList; + +import dwt.dwthelper.utils; + +/** + * A SubMenuManager is used to define a set of contribution + * items within a parent manager. Once defined, the visibility of the entire set can + * be changed as a unit. + *

+ * A client may ask for and make additions to a submenu. The visibility of these items + * is also controlled by the visibility of the SubMenuManager. + *

+ */ +public class SubMenuManager : SubContributionManager, + IMenuManager { + + public bool isDirty() { + return super.isDirty(); + } + public bool isVisible() { + return super.isVisible(); + } + + /** + * Maps each submenu in the manager to a wrapper. The wrapper is used to + * monitor additions and removals. If the visibility of the manager is modified + * the visibility of the submenus is also modified. + */ + private Map!(Object,Object) mapMenuToWrapper; + + /** + * List of registered menu listeners (element type: IMenuListener). + */ + private ListenerList menuListeners; + + /** + * The menu listener added to the parent. Lazily initialized + * in addMenuListener. + */ + private IMenuListener menuListener; + + /** + * Constructs a new manager. + * + * @param mgr the parent manager. All contributions made to the + * SubMenuManager are forwarded and appear in the + * parent manager. + */ + public this(IMenuManager mgr) { + menuListeners = new ListenerList(); + super(mgr); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IMenuManager#addMenuListener(dwtx.jface.action.IMenuListener) + */ + public void addMenuListener(IMenuListener listener) { + menuListeners.add(cast(Object)listener); + if (menuListener is null) { + menuListener = new class IMenuListener { + public void menuAboutToShow(IMenuManager manager) { + Object[] listeners = menuListeners.getListeners(); + for (int i = 0; i < listeners.length; ++i) { + (cast(IMenuListener) listeners[i]) + .menuAboutToShow(this.outer); + } + } + }; + } + getParentMenuManager().addMenuListener(menuListener); + } + + /** + * The default implementation of this IContributionItem + * method does nothing. Subclasses may override. + */ + public void dispose() { + // do nothing + } + + /* (non-Javadoc) + * @see dwtx.jface.action.SubContributionManager#disposeManager() + */ + public void disposeManager() { + if (menuListener !is null) { + getParentMenuManager().removeMenuListener(menuListener); + menuListener = null; + clearListenerList(menuListeners); + } + // Dispose wrapped menus in addition to removing them. + // See bugs 64024 and 73715 for details. + // important to dispose menu wrappers before call to super, + // otherwise super's call to removeAll will remove them + // before they can be disposed + if (mapMenuToWrapper !is null) { + foreach( v; mapMenuToWrapper.elements() ){ + SubMenuManager wrapper = cast(SubMenuManager) v; + wrapper.disposeManager(); + } + mapMenuToWrapper.clear(); + mapMenuToWrapper = null; + } + super.disposeManager(); + } + + /** + * Clears all of the listeners in a listener list. TODO Bug 117519 Remove + * this method when fixed. + * + * @param list + * The list to be clear; must not be null. + */ + private final void clearListenerList(ListenerList list) { + Object[] listeners = list.getListeners(); + for (int i = 0; i < listeners.length; i++) { + list.remove(cast(Object)listeners[i]); + } + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#fill(dwt.widgets.Composite) + */ + public void fill(Composite parent) { + if (isVisible()) { + getParentMenuManager().fill(parent); + } + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#fill(dwt.widgets.CoolBar, int) + */ + public void fill(CoolBar parent, int index) { + // do nothing + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#fill(dwt.widgets.Menu, int) + */ + public void fill(Menu parent, int index) { + if (isVisible()) { + getParentMenuManager().fill(parent, index); + } + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#fill(dwt.widgets.ToolBar, int) + */ + public void fill(ToolBar parent, int index) { + if (isVisible()) { + getParentMenuManager().fill(parent, index); + } + } + + /* (non-Javadoc) + * Method declared on IContributionManager. + * + * Returns the item passed to us, not the wrapper. + * In the case of menu's not added by this manager, + * ensure that we return a wrapper for the menu. + */ + public IContributionItem find(String id) { + IContributionItem item = getParentMenuManager().find(id); + if (cast(SubContributionItem)item ) { + // Return the item passed to us, not the wrapper. + item = unwrap(item); + } + + if (cast(IMenuManager)item ) { + // if it is a menu manager wrap it before returning + IMenuManager menu = cast(IMenuManager) item; + item = getWrapper(menu); + } + + return item; + } + + /** + *

+ * The menu returned is wrapped within a SubMenuManager to + * monitor additions and removals. If the visibility of this menu is modified + * the visibility of the submenus is also modified. + *

+ */ + public IMenuManager findMenuUsingPath(String path) { + IContributionItem item = findUsingPath(path); + if (cast(IMenuManager)item ) { + return cast(IMenuManager) item; + } + return null; + } + + /* (non-Javadoc) + * Method declared on IMenuManager. + * + * Returns the item passed to us, not the wrapper. + * + * We use use the same algorithm as MenuManager.findUsingPath, but unwrap + * submenus along so that SubMenuManagers are visible. + */ + public IContributionItem findUsingPath(String path) { + String id = path; + String rest = null; + int separator = path.indexOf('/'); + if (separator !is -1) { + id = path.substring(0, separator); + rest = path.substring(separator + 1); + } + IContributionItem item = find(id); // unwraps item + if (rest !is null && cast(IMenuManager)item ) { + IMenuManager menu = cast(IMenuManager) item; + item = menu.findUsingPath(rest); + } + return item; + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#getId() + */ + public String getId() { + return getParentMenuManager().getId(); + } + + /** + * @return the parent menu manager that this sub-manager contributes to. + */ + protected final IMenuManager getParentMenuManager() { + // Cast is ok because that's the only + // thing we accept in the construtor. + return cast(IMenuManager) getParent(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IMenuManager#getRemoveAllWhenShown() + */ + public bool getRemoveAllWhenShown() { + return false; + } + + /** + * Returns the menu wrapper for a menu manager. + *

+ * The sub menus within this menu are wrapped within a SubMenuManager to + * monitor additions and removals. If the visibility of this menu is modified + * the visibility of the sub menus is also modified. + *

+ * @param mgr the menu manager to be wrapped + * + * @return the menu wrapper + */ + protected IMenuManager getWrapper(IMenuManager mgr) { + if (mapMenuToWrapper is null) { + mapMenuToWrapper = new HashMap!(Object,Object); + } + SubMenuManager wrapper = cast(SubMenuManager) mapMenuToWrapper.get(cast(Object)mgr); + if (wrapper is null) { + wrapper = wrapMenu(mgr); + mapMenuToWrapper.add(cast(Object)mgr, wrapper); + } + return wrapper; + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#isDynamic() + */ + public bool isDynamic() { + return getParentMenuManager().isDynamic(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#isEnabled() + */ + public bool isEnabled() { + return isVisible() && getParentMenuManager().isEnabled(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#isGroupMarker() + */ + public bool isGroupMarker() { + return getParentMenuManager().isGroupMarker(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#isSeparator() + */ + public bool isSeparator() { + return getParentMenuManager().isSeparator(); + } + + /** + * Remove all contribution items. + */ + public void removeAll() { + super.removeAll(); + if (mapMenuToWrapper !is null) { + foreach( v; mapMenuToWrapper.elements() ){ + SubMenuManager wrapper = cast(SubMenuManager) v; + wrapper.removeAll(); + } + mapMenuToWrapper.clear(); + mapMenuToWrapper = null; + } + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IMenuManager#removeMenuListener(dwtx.jface.action.IMenuListener) + */ + public void removeMenuListener(IMenuListener listener) { + menuListeners.remove(cast(Object)listener); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#saveWidgetState() + */ + public void saveWidgetState() { + // do nothing + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#setParent(dwtx.jface.action.IContributionManager) + */ + public void setParent(IContributionManager parent) { + // do nothing, our "parent manager's" parent + // is set when it is added to a manager + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IMenuManager#setRemoveAllWhenShown(bool) + */ + public void setRemoveAllWhenShown(bool removeAll) { + Assert.isTrue(false, "Should not be called on submenu manager"); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see dwtx.jface.action.SubContributionManager#setVisible(bool) + */ + public void setVisible(bool visible) { + super.setVisible(visible); + if (mapMenuToWrapper !is null) { + foreach( v; mapMenuToWrapper.elements() ){ + SubMenuManager wrapper = cast(SubMenuManager) v; + wrapper.setVisible(visible); + } + } + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#update() + */ + public void update() { + // This method is not governed by visibility. The client may + // call setVisible and then force an update. At that + // point we need to update the parent. + getParentMenuManager().update(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionManager#update(bool) + */ + public void update(bool force) { + // This method is not governed by visibility. The client may + // call setVisible and then force an update. At that + // point we need to update the parent. + getParentMenuManager().update(force); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IContributionItem#update(java.lang.String) + */ + public void update(String id) { + getParentMenuManager().update(id); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IMenuManager#updateAll(bool) + */ + public void updateAll(bool force) { + // This method is not governed by visibility. The client may + // call setVisible and then force an update. At that + // point we need to update the parent. + getParentMenuManager().updateAll(force); + } + + /** + * Wraps a menu manager in a sub menu manager, and returns the new wrapper. + * @param menu the menu manager to wrap + * @return the new wrapped menu manager + */ + protected SubMenuManager wrapMenu(IMenuManager menu) { + SubMenuManager mgr = new SubMenuManager(menu); + mgr.setVisible(isVisible()); + return mgr; + } +} diff -r 7ec2fd279c28 -r 50b0163e18f8 dwtx/jface/action/SubStatusLineManager.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/action/SubStatusLineManager.d Thu Apr 03 05:38:04 2008 +0200 @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2000, 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: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwtx.jface.action.SubStatusLineManager; + +import dwtx.jface.action.SubContributionManager; +import dwtx.jface.action.IStatusLineManager; + +import dwt.graphics.Image; +import dwtx.core.runtime.IProgressMonitor; + +import dwt.dwthelper.utils; + +/** + * A SubStatusLineManager is used to define a set of contribution + * items within a parent manager. Once defined, the visibility of the entire set can + * be changed as a unit. + */ +public class SubStatusLineManager : SubContributionManager, + IStatusLineManager { + /** + * Current status line message. + */ + private String message; + + /** + * Current status line error message. + */ + private String errorMessage; + + /** + * Current status line message image. + */ + private Image messageImage; + + /** + * Current status line error image + */ + private Image errorImage; + + /** + * Constructs a new manager. + * + * @param mgr the parent manager. All contributions made to the + * SubStatusLineManager are forwarded and appear in the + * parent manager. + */ + public this(IStatusLineManager mgr) { + super(mgr); + } + + /** + * @return the parent status line manager that this sub-manager contributes + * to + */ + protected final IStatusLineManager getParentStatusLineManager() { + // Cast is ok because that's the only + // thing we accept in the construtor. + return cast(IStatusLineManager) getParent(); + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public IProgressMonitor getProgressMonitor() { + return getParentStatusLineManager().getProgressMonitor(); + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public bool isCancelEnabled() { + return getParentStatusLineManager().isCancelEnabled(); + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public void setCancelEnabled(bool enabled) { + getParentStatusLineManager().setCancelEnabled(enabled); + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public void setErrorMessage(String message) { + this.errorImage = null; + this.errorMessage = message; + if (isVisible()) { + getParentStatusLineManager().setErrorMessage(errorMessage); + } + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public void setErrorMessage(Image image, String message) { + this.errorImage = image; + this.errorMessage = message; + if (isVisible()) { + getParentStatusLineManager().setErrorMessage(errorImage, + errorMessage); + } + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public void setMessage(String message) { + this.messageImage = null; + this.message = message; + if (isVisible()) { + getParentStatusLineManager().setMessage(message); + } + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public void setMessage(Image image, String message) { + this.messageImage = image; + this.message = message; + if (isVisible()) { + getParentStatusLineManager().setMessage(messageImage, message); + } + } + + /* (non-Javadoc) + * Method declared on SubContributionManager. + */ + public void setVisible(bool visible) { + super.setVisible(visible); + if (visible) { + getParentStatusLineManager().setErrorMessage(errorImage, + errorMessage); + getParentStatusLineManager().setMessage(messageImage, message); + } else { + getParentStatusLineManager().setMessage(null, null); + getParentStatusLineManager().setErrorMessage(null, null); + } + } + + /* (non-Javadoc) + * Method declared on IStatusLineManager. + */ + public void update(bool force) { + // This method is not governed by visibility. The client may + // call setVisible and then force an update. At that + // point we need to update the parent. + getParentStatusLineManager().update(force); + } +} diff -r 7ec2fd279c28 -r 50b0163e18f8 dwtx/jface/action/SubToolBarManager.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/action/SubToolBarManager.d Thu Apr 03 05:38:04 2008 +0200 @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 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: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwtx.jface.action.SubToolBarManager; + +import dwtx.jface.action.IToolBarManager; +import dwtx.jface.action.SubContributionManager; + +import dwt.dwthelper.utils; + +/** + * A SubToolBarManager monitors the additional and removal of + * items from a parent manager so that visibility of the entire set can be changed as a + * unit. + */ +public class SubToolBarManager : SubContributionManager, + IToolBarManager { + + /** + * Constructs a new manager. + * + * @param mgr the parent manager. All contributions made to the + * SubToolBarManager are forwarded and appear in the + * parent manager. + */ + public this(IToolBarManager mgr) { + super(mgr); + } + + /** + * @return the parent toolbar manager that this sub-manager contributes to + */ + protected final IToolBarManager getParentToolBarManager() { + // Cast is ok because that's the only + // thing we accept in the construtor. + return cast(IToolBarManager) getParent(); + } + + /* (non-Javadoc) + * Method declared on IToolBarManager. + */ + public void update(bool force) { + // This method is not governed by visibility. The client may + // call setVisible and then force an update. At that + // point we need to update the parent. + getParentToolBarManager().update(force); + } +}