comparison dwtx/jface/action/ToolBarManager.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 5df4896124c7
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
15 import dwtx.jface.action.ContributionManager; 15 import dwtx.jface.action.ContributionManager;
16 import dwtx.jface.action.IToolBarManager; 16 import dwtx.jface.action.IToolBarManager;
17 import dwtx.jface.action.MenuManager; 17 import dwtx.jface.action.MenuManager;
18 import dwtx.jface.action.IContributionItem; 18 import dwtx.jface.action.IContributionItem;
19 19
20 import tango.util.collection.ArraySeq;
21 // import java.util.Iterator; 20 // import java.util.Iterator;
22 21
23 import dwt.DWT; 22 import dwt.DWT;
24 import dwt.accessibility.ACC; 23 import dwt.accessibility.ACC;
25 import dwt.accessibility.AccessibleAdapter; 24 import dwt.accessibility.AccessibleAdapter;
33 import dwt.widgets.Menu; 32 import dwt.widgets.Menu;
34 import dwt.widgets.ToolBar; 33 import dwt.widgets.ToolBar;
35 import dwt.widgets.ToolItem; 34 import dwt.widgets.ToolItem;
36 35
37 import dwt.dwthelper.utils; 36 import dwt.dwthelper.utils;
37 import dwtx.dwtxhelper.Collection;
38 38
39 /** 39 /**
40 * A tool bar manager is a contribution manager which realizes itself and its 40 * A tool bar manager is a contribution manager which realizes itself and its
41 * items in a tool bar control. 41 * items in a tool bar control.
42 * <p> 42 * <p>
252 252
253 int oldCount = toolBar.getItemCount(); 253 int oldCount = toolBar.getItemCount();
254 254
255 // clean contains all active items without double separators 255 // clean contains all active items without double separators
256 IContributionItem[] items = getItems(); 256 IContributionItem[] items = getItems();
257 auto clean = new ArraySeq!(Object); 257 ArrayList clean = new ArrayList(items.length);
258 clean.capacity(items.length);
259 IContributionItem separator = null; 258 IContributionItem separator = null;
260 // long cleanStartTime= 0; 259 // long cleanStartTime= 0;
261 // if (DEBUG) { 260 // if (DEBUG) {
262 // cleanStartTime= (new Date()).getTime(); 261 // cleanStartTime= (new Date()).getTime();
263 // } 262 // }
272 // end) 271 // end)
273 separator = ci; 272 separator = ci;
274 } else { 273 } else {
275 if (separator !is null) { 274 if (separator !is null) {
276 if (clean.size() > 0) { 275 if (clean.size() > 0) {
277 clean.append(cast(Object)separator); 276 clean.add(cast(Object)separator);
278 } 277 }
279 separator = null; 278 separator = null;
280 } 279 }
281 clean.append(cast(Object)ci); 280 clean.add(cast(Object)ci);
282 } 281 }
283 } 282 }
284 // if (DEBUG) { 283 // if (DEBUG) {
285 // System.out.println(" Time needed to build clean vector: " + 284 // System.out.println(" Time needed to build clean vector: " +
286 // ((new Date()).getTime() - cleanStartTime)); 285 // ((new Date()).getTime() - cleanStartTime));
287 // } 286 // }
288 287
289 // determine obsolete items (removed or non active) 288 // determine obsolete items (removed or non active)
290 ToolItem[] mi = toolBar.getItems(); 289 ToolItem[] mi = toolBar.getItems();
291 auto toRemove = new ArraySeq!(Object); 290 ArrayList toRemove = new ArrayList(mi.length);
292 toRemove.capacity(mi.length);
293 for (int i = 0; i < mi.length; i++) { 291 for (int i = 0; i < mi.length; i++) {
294 Object data = mi[i].getData(); 292 Object data = mi[i].getData();
295 if (data is null 293 if (data is null
296 || !clean.contains(data) 294 || !clean.contains(data)
297 || (cast(IContributionItem) data && (cast(IContributionItem) data) 295 || (cast(IContributionItem) data && (cast(IContributionItem) data)
298 .isDynamic())) { 296 .isDynamic())) {
299 toRemove.append(mi[i]); 297 toRemove.add(mi[i]);
300 } 298 }
301 } 299 }
302 300
303 // Turn redraw off if the number of items to be added 301 // Turn redraw off if the number of items to be added
304 // is above a certain threshold, to minimize flicker, 302 // is above a certain threshold, to minimize flicker,
329 // add new items 327 // add new items
330 IContributionItem src, dest; 328 IContributionItem src, dest;
331 mi = toolBar.getItems(); 329 mi = toolBar.getItems();
332 int srcIx = 0; 330 int srcIx = 0;
333 int destIx = 0; 331 int destIx = 0;
334 foreach( e; clean ){ 332 for (Iterator e = clean.iterator(); e.hasNext();) {
335 src = cast(IContributionItem) e; 333 src = cast(IContributionItem) e.next();
334
336 335
337 // get corresponding item in DWT widget 336 // get corresponding item in DWT widget
338 if (srcIx < mi.length) { 337 if (srcIx < mi.length) {
339 dest = cast(IContributionItem) mi[srcIx].getData(); 338 dest = cast(IContributionItem) mi[srcIx].getData();
340 } else { 339 } else {