Mercurial > projects > dwt-addons
comparison dwtx/jface/action/SubContributionManager.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 | 644f1334b451 |
children |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
17 import dwtx.jface.action.IAction; | 17 import dwtx.jface.action.IAction; |
18 import dwtx.jface.action.SubContributionItem; | 18 import dwtx.jface.action.SubContributionItem; |
19 import dwtx.jface.action.IContributionItem; | 19 import dwtx.jface.action.IContributionItem; |
20 import dwtx.jface.action.IContributionManagerOverrides; | 20 import dwtx.jface.action.IContributionManagerOverrides; |
21 | 21 |
22 import tango.util.collection.HashMap; | |
23 import tango.util.collection.model.Map; | |
24 import tango.util.collection.model.Iterator; | |
25 | 22 |
26 import dwt.dwthelper.utils; | 23 import dwt.dwthelper.utils; |
24 import dwtx.dwtxhelper.Collection; | |
27 | 25 |
28 /** | 26 /** |
29 * A <code>SubContributionManager</code> is used to define a set of contribution | 27 * A <code>SubContributionManager</code> is used to define a set of contribution |
30 * items within a parent manager. Once defined, the visibility of the entire set can | 28 * items within a parent manager. Once defined, the visibility of the entire set can |
31 * be changed as a unit. | 29 * be changed as a unit. |
38 | 36 |
39 /** | 37 /** |
40 * Maps each item in the manager to a wrapper. The wrapper is used to | 38 * Maps each item in the manager to a wrapper. The wrapper is used to |
41 * control the visibility of each item. | 39 * control the visibility of each item. |
42 */ | 40 */ |
43 private Map!(Object,Object) mapItemToWrapper; | 41 private Map mapItemToWrapper; |
44 | 42 |
45 /** | 43 /** |
46 * The visibility of the manager, | 44 * The visibility of the manager, |
47 */ | 45 */ |
48 private bool visible = false; | 46 private bool visible = false; |
53 * @param mgr the parent contribution manager. All contributions made to the | 51 * @param mgr the parent contribution manager. All contributions made to the |
54 * <code>SubContributionManager</code> are forwarded and appear in the | 52 * <code>SubContributionManager</code> are forwarded and appear in the |
55 * parent manager. | 53 * parent manager. |
56 */ | 54 */ |
57 public this(IContributionManager mgr) { | 55 public this(IContributionManager mgr) { |
58 mapItemToWrapper = new HashMap!(Object,Object); | 56 mapItemToWrapper = new HashMap(); |
59 //super(); | 57 //super(); |
60 parentMgr = mgr; | 58 parentMgr = mgr; |
61 } | 59 } |
62 | 60 |
63 /* (non-Javadoc) | 61 /* (non-Javadoc) |
103 * in the parent manager. Subclasses may extend. | 101 * in the parent manager. Subclasses may extend. |
104 * | 102 * |
105 * @since 3.0 | 103 * @since 3.0 |
106 */ | 104 */ |
107 public void disposeManager() { | 105 public void disposeManager() { |
106 Iterator it = mapItemToWrapper.values().iterator(); | |
108 // Dispose items in addition to removing them. | 107 // Dispose items in addition to removing them. |
109 // See bugs 64024 and 73715 for details. | 108 // See bugs 64024 and 73715 for details. |
110 // Do not use getItems() here as subclasses can override that in bad ways. | 109 // Do not use getItems() here as subclasses can override that in bad ways. |
111 foreach( k,v; mapItemToWrapper ){ | 110 while (it.hasNext()) { |
112 IContributionItem item = cast(IContributionItem) v; | 111 IContributionItem item = cast(IContributionItem) it.next(); |
113 item.dispose(); | 112 item.dispose(); |
114 } | 113 } |
115 removeAll(); | 114 removeAll(); |
116 } | 115 } |
117 | 116 |
131 * Method declared on IContributionManager. | 130 * Method declared on IContributionManager. |
132 * | 131 * |
133 * Returns the items passed to us, not the wrappers. | 132 * Returns the items passed to us, not the wrappers. |
134 */ | 133 */ |
135 public IContributionItem[] getItems() { | 134 public IContributionItem[] getItems() { |
136 IContributionItem[] result = new IContributionItem[mapItemToWrapper | 135 IContributionItem[] result = arraycast!(IContributionItem)(mapItemToWrapper.keySet().toArray()); |
137 .size()]; | |
138 int idx = 0; | |
139 foreach( k,v; mapItemToWrapper ){ | |
140 result[idx] = cast(IContributionItem)k; | |
141 idx++; | |
142 } | |
143 return result; | 136 return result; |
144 } | 137 } |
145 | 138 |
146 /** | 139 /** |
147 * Returns the parent manager. | 140 * Returns the parent manager. |
229 * @param item the item contributed by the client | 222 * @param item the item contributed by the client |
230 * @param wrap the item contributed to the parent manager as a proxy for the item | 223 * @param wrap the item contributed to the parent manager as a proxy for the item |
231 * contributed by the client | 224 * contributed by the client |
232 */ | 225 */ |
233 protected void itemAdded(IContributionItem item, SubContributionItem wrap) { | 226 protected void itemAdded(IContributionItem item, SubContributionItem wrap) { |
234 mapItemToWrapper.add(cast(Object)item, wrap); | 227 mapItemToWrapper.put(cast(Object)item, wrap); |
235 } | 228 } |
236 | 229 |
237 /** | 230 /** |
238 * Notifies that an item has been removed. | 231 * Notifies that an item has been removed. |
239 * <p> | 232 * <p> |
241 * </p> | 234 * </p> |
242 * | 235 * |
243 * @param item the item contributed by the client | 236 * @param item the item contributed by the client |
244 */ | 237 */ |
245 protected void itemRemoved(IContributionItem item) { | 238 protected void itemRemoved(IContributionItem item) { |
246 mapItemToWrapper.removeKey(cast(Object)item); | 239 mapItemToWrapper.remove(cast(Object)item); |
247 } | 240 } |
248 | 241 |
249 /** | 242 /** |
250 * @return fetch all enumeration of wrappers for the item | 243 * @return fetch all enumeration of wrappers for the item |
251 * @deprecated Use getItems(String value) instead. | 244 * @deprecated Use getItems(String value) instead. |
252 */ | 245 */ |
253 public Enumeration items() { | 246 public Enumeration items() { |
254 return new class(mapItemToWrapper.elements()) Enumeration { | 247 return new class(mapItemToWrapper.values().iterator()) Enumeration { |
255 Iterator!(Object) i; | 248 Iterator i; |
256 this(Iterator!(Object) i__){ | 249 this(Iterator i_){ |
257 i = i__; | 250 i = i_; |
258 } | 251 } |
259 public bool hasMoreElements() { | 252 public bool hasMoreElements() { |
260 return i.more(); | 253 return i.hasNext(); |
261 } | 254 } |
262 | 255 |
263 public Object nextElement() { | 256 public Object nextElement() { |
264 return i.get(); | 257 return i.next(); |
265 } | 258 } |
266 }; | 259 }; |
267 } | 260 } |
268 | 261 |
269 /* (non-Javadoc) | 262 /* (non-Javadoc) |
321 | 314 |
322 /* (non-Javadoc) | 315 /* (non-Javadoc) |
323 * Method declared on IContributionManager. | 316 * Method declared on IContributionManager. |
324 */ | 317 */ |
325 public void removeAll() { | 318 public void removeAll() { |
326 foreach( k, v; mapItemToWrapper ){ | 319 Iterator it = mapItemToWrapper.values().iterator(); |
327 IContributionItem item = cast(IContributionItem) v; | 320 while (it.hasNext()) { |
321 IContributionItem item = cast(IContributionItem) it.next(); | |
328 parentMgr.remove(item); | 322 parentMgr.remove(item); |
329 } | 323 } |
330 mapItemToWrapper.clear(); | 324 mapItemToWrapper.clear(); |
331 } | 325 } |
332 | 326 |
338 * @param visible the new visibility | 332 * @param visible the new visibility |
339 */ | 333 */ |
340 public void setVisible(bool visible) { | 334 public void setVisible(bool visible) { |
341 this.visible = visible; | 335 this.visible = visible; |
342 if (mapItemToWrapper.size() > 0) { | 336 if (mapItemToWrapper.size() > 0) { |
343 foreach( k, v; mapItemToWrapper ){ | 337 Iterator it = mapItemToWrapper.values().iterator(); |
344 IContributionItem item = cast(IContributionItem) v; | 338 while (it.hasNext()) { |
339 IContributionItem item = cast(IContributionItem) it.next(); | |
345 item.setVisible(visible); | 340 item.setVisible(visible); |
346 } | 341 } |
347 parentMgr.markDirty(); | 342 parentMgr.markDirty(); |
348 } | 343 } |
349 } | 344 } |