comparison dwtx/jface/action/SubMenuManager.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 46a6e0e6ccd4
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
17 import dwtx.jface.action.IMenuListener; 17 import dwtx.jface.action.IMenuListener;
18 import dwtx.jface.action.IContributionItem; 18 import dwtx.jface.action.IContributionItem;
19 import dwtx.jface.action.IContributionManager; 19 import dwtx.jface.action.IContributionManager;
20 import dwtx.jface.action.SubContributionItem; 20 import dwtx.jface.action.SubContributionItem;
21 21
22 import tango.util.collection.HashMap;
23 import tango.util.collection.model.Map;
24 22
25 import dwt.widgets.Composite; 23 import dwt.widgets.Composite;
26 import dwt.widgets.CoolBar; 24 import dwt.widgets.CoolBar;
27 import dwt.widgets.Menu; 25 import dwt.widgets.Menu;
28 import dwt.widgets.ToolBar; 26 import dwt.widgets.ToolBar;
29 import dwtx.core.runtime.Assert; 27 import dwtx.core.runtime.Assert;
30 import dwtx.core.runtime.ListenerList; 28 import dwtx.core.runtime.ListenerList;
31 29
32 import dwt.dwthelper.utils; 30 import dwt.dwthelper.utils;
31 import dwtx.dwtxhelper.Collection;
33 32
34 /** 33 /**
35 * A <code>SubMenuManager</code> is used to define a set of contribution 34 * A <code>SubMenuManager</code> is used to define a set of contribution
36 * items within a parent manager. Once defined, the visibility of the entire set can 35 * items within a parent manager. Once defined, the visibility of the entire set can
37 * be changed as a unit. 36 * be changed as a unit.
53 /** 52 /**
54 * Maps each submenu in the manager to a wrapper. The wrapper is used to 53 * Maps each submenu in the manager to a wrapper. The wrapper is used to
55 * monitor additions and removals. If the visibility of the manager is modified 54 * monitor additions and removals. If the visibility of the manager is modified
56 * the visibility of the submenus is also modified. 55 * the visibility of the submenus is also modified.
57 */ 56 */
58 private Map!(Object,Object) mapMenuToWrapper; 57 private Map mapMenuToWrapper;
59 58
60 /** 59 /**
61 * List of registered menu listeners (element type: <code>IMenuListener</code>). 60 * List of registered menu listeners (element type: <code>IMenuListener</code>).
62 */ 61 */
63 private ListenerList menuListeners; 62 private ListenerList menuListeners;
120 // See bugs 64024 and 73715 for details. 119 // See bugs 64024 and 73715 for details.
121 // important to dispose menu wrappers before call to super, 120 // important to dispose menu wrappers before call to super,
122 // otherwise super's call to removeAll will remove them 121 // otherwise super's call to removeAll will remove them
123 // before they can be disposed 122 // before they can be disposed
124 if (mapMenuToWrapper !is null) { 123 if (mapMenuToWrapper !is null) {
125 foreach( v; mapMenuToWrapper.elements() ){ 124 Iterator iter = mapMenuToWrapper.values().iterator();
126 SubMenuManager wrapper = cast(SubMenuManager) v; 125 while (iter.hasNext()) {
126 SubMenuManager wrapper = cast(SubMenuManager) iter.next();
127 wrapper.disposeManager(); 127 wrapper.disposeManager();
128 } 128 }
129 mapMenuToWrapper.clear(); 129 mapMenuToWrapper.clear();
130 mapMenuToWrapper = null; 130 mapMenuToWrapper = null;
131 } 131 }
262 * 262 *
263 * @return the menu wrapper 263 * @return the menu wrapper
264 */ 264 */
265 protected IMenuManager getWrapper(IMenuManager mgr) { 265 protected IMenuManager getWrapper(IMenuManager mgr) {
266 if (mapMenuToWrapper is null) { 266 if (mapMenuToWrapper is null) {
267 mapMenuToWrapper = new HashMap!(Object,Object); 267 mapMenuToWrapper = new HashMap(4);
268 } 268 }
269 SubMenuManager wrapper = cast(SubMenuManager) mapMenuToWrapper.get(cast(Object)mgr); 269 SubMenuManager wrapper = cast(SubMenuManager) mapMenuToWrapper.get(cast(Object)mgr);
270 if (wrapper is null) { 270 if (wrapper is null) {
271 wrapper = wrapMenu(mgr); 271 wrapper = wrapMenu(mgr);
272 mapMenuToWrapper.add(cast(Object)mgr, wrapper); 272 mapMenuToWrapper.put(cast(Object)mgr, wrapper);
273 } 273 }
274 return wrapper; 274 return wrapper;
275 } 275 }
276 276
277 /* (non-Javadoc) 277 /* (non-Javadoc)
306 * Remove all contribution items. 306 * Remove all contribution items.
307 */ 307 */
308 public override void removeAll() { 308 public override void removeAll() {
309 super.removeAll(); 309 super.removeAll();
310 if (mapMenuToWrapper !is null) { 310 if (mapMenuToWrapper !is null) {
311 foreach( v; mapMenuToWrapper.elements() ){ 311 Iterator iter = mapMenuToWrapper.values().iterator();
312 SubMenuManager wrapper = cast(SubMenuManager) v; 312 while (iter.hasNext()) {
313 SubMenuManager wrapper = cast(SubMenuManager) iter.next();
313 wrapper.removeAll(); 314 wrapper.removeAll();
314 } 315 }
315 mapMenuToWrapper.clear(); 316 mapMenuToWrapper.clear();
316 mapMenuToWrapper = null; 317 mapMenuToWrapper = null;
317 } 318 }
350 * @see dwtx.jface.action.SubContributionManager#setVisible(bool) 351 * @see dwtx.jface.action.SubContributionManager#setVisible(bool)
351 */ 352 */
352 public override void setVisible(bool visible) { 353 public override void setVisible(bool visible) {
353 super.setVisible(visible); 354 super.setVisible(visible);
354 if (mapMenuToWrapper !is null) { 355 if (mapMenuToWrapper !is null) {
355 foreach( v; mapMenuToWrapper.elements() ){ 356 Iterator iter = mapMenuToWrapper.values().iterator();
356 SubMenuManager wrapper = cast(SubMenuManager) v; 357 while (iter.hasNext()) {
358 SubMenuManager wrapper = cast(SubMenuManager) iter.next();
357 wrapper.setVisible(visible); 359 wrapper.setVisible(visible);
358 } 360 }
359 } 361 }
360 } 362 }
361 363