Mercurial > projects > dwt-addons
diff dwtx/jface/internal/provisional/action/ToolBarManager2.d @ 35:ef4534de0cf9
remaining files
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 05 Apr 2008 04:49:22 +0200 |
parents | |
children | ea8ff534f622 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/internal/provisional/action/ToolBarManager2.d Sat Apr 05 04:49:22 2008 +0200 @@ -0,0 +1,191 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + ******************************************************************************/ + +module dwtx.jface.internal.provisional.action.ToolBarManager2; + +import dwtx.jface.internal.provisional.action.IToolBarManager2; +import dwtx.jface.action.IContributionManagerOverrides; + +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.ToolBar; +import dwtx.core.runtime.ListenerList; +import dwtx.jface.action.ToolBarManager; +import dwtx.jface.util.IPropertyChangeListener; +import dwtx.jface.util.PropertyChangeEvent; + +import dwt.dwthelper.utils; + +/** + * Extends <code>ToolBarManager</code> to implement <code>IToolBarManager2</code>. + * + * <p> + * <strong>EXPERIMENTAL</strong>. 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. + * </p> + * + * @since 3.2 + */ +public class ToolBarManager2 : ToolBarManager, IToolBarManager2 { + + // delegate to super + public ToolBar createControl(Composite parent) { + return super.createControl(parent); + } + public ToolBar getControl() { + return super.getControl(); + } + public void dispose() { + super.dispose(); + } + public void setOverrides(IContributionManagerOverrides newOverrides) { + super.setOverrides(newOverrides); + } + + /** + * A collection of objects listening to changes to this manager. This + * collection is <code>null</code> if there are no listeners. + */ + private /+transient+/ ListenerList listenerList = null; + + /** + * Creates a new tool bar manager with the default DWT button style. Use the + * <code>createControl</code> method to create the tool bar control. + */ + public this() { + super(); + } + + /** + * Creates a tool bar manager with the given DWT button style. Use the + * <code>createControl</code> method to create the tool bar control. + * + * @param style + * the tool bar item style + * @see dwt.widgets.ToolBar for valid style bits + */ + public this(int style) { + super(style); + } + + /** + * Creates a tool bar manager for an existing tool bar control. This manager + * becomes responsible for the control, and will dispose of it when the + * manager is disposed. + * + * @param toolbar + * the tool bar control + */ + public this(ToolBar toolbar) { + super(toolbar); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IToolBarManager2#createControl2(dwt.widgets.Composite) + */ + public Control createControl2(Composite parent) { + return createControl(parent); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IToolBarManager2#getControl2() + */ + public Control getControl2() { + return getControl(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IToolBarManager2#getItemCount() + */ + public int getItemCount() { + ToolBar toolBar = getControl(); + if (toolBar is null || toolBar.isDisposed()) { + return 0; + } + return toolBar.getItemCount(); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IToolBarManager2#addPropertyChangeListener(dwtx.jface.util.IPropertyChangeListener) + */ + public void addPropertyChangeListener(IPropertyChangeListener listener) { + if (listenerList is null) { + listenerList = new ListenerList(ListenerList.IDENTITY); + } + + listenerList.add(cast(Object)listener); + } + + /* (non-Javadoc) + * @see dwtx.jface.action.IToolBarManager2#removePropertyChangeListener(dwtx.jface.util.IPropertyChangeListener) + */ + public void removePropertyChangeListener(IPropertyChangeListener listener) { + if (listenerList !is null) { + listenerList.remove(cast(Object)listener); + + if (listenerList.isEmpty()) { + listenerList = null; + } + } + } + + /** + * @return the listeners attached to this event manager. + * The listeners currently attached; may be empty, but never + * null. + * + */ + protected final Object[] getListeners() { + final ListenerList list = listenerList; + if (list is null) { + return new Object[0]; + } + + return list.getListeners(); + } + + /* + * Notifies any property change listeners that a property has changed. Only + * listeners registered at the time this method is called are notified. + */ + private void firePropertyChange(PropertyChangeEvent event) { + Object[] list = getListeners(); + for (int i = 0; i < list.length; ++i) { + (cast(IPropertyChangeListener) list[i]).propertyChange(event); + } + } + + /* + * Notifies any property change listeners that a property has changed. Only + * listeners registered at the time this method is called are notified. This + * method avoids creating an event object if there are no listeners + * registered, but calls firePropertyChange(PropertyChangeEvent) if there are. + */ + private void firePropertyChange(String propertyName, + Object oldValue, Object newValue) { + if (listenerList !is null) { + firePropertyChange(new PropertyChangeEvent(this, propertyName, + oldValue, newValue)); + } + } + + /* (non-Javadoc) + * @see dwtx.jface.action.ToolBarManager#relayout(dwt.widgets.ToolBar, int, int) + */ + protected void relayout(ToolBar layoutBar, int oldCount, int newCount) { + super.relayout(layoutBar, oldCount, newCount); + firePropertyChange(PROP_LAYOUT, new Integer(oldCount), new Integer(newCount)); + } +}