comparison dwtx/jface/viewers/TreeSelection.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 ea8ff534f622
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
16 import dwtx.jface.viewers.ITreeSelection; 16 import dwtx.jface.viewers.ITreeSelection;
17 import dwtx.jface.viewers.CustomHashtable; 17 import dwtx.jface.viewers.CustomHashtable;
18 import dwtx.jface.viewers.TreePath; 18 import dwtx.jface.viewers.TreePath;
19 import dwtx.jface.viewers.IElementComparer; 19 import dwtx.jface.viewers.IElementComparer;
20 20
21 import tango.util.collection.ArraySeq;
22 import tango.util.collection.model.Seq;
23 21
24 import dwtx.core.runtime.Assert; 22 import dwtx.core.runtime.Assert;
25 23
26 import dwt.dwthelper.utils; 24 import dwt.dwthelper.utils;
25 import dwtx.dwtxhelper.Collection;
27 26
28 /** 27 /**
29 * A concrete implementation of the <code>ITreeSelection</code> interface, 28 * A concrete implementation of the <code>ITreeSelection</code> interface,
30 * suitable for instantiating. 29 * suitable for instantiating.
31 * <p> 30 * <p>
56 static this(){ 55 static this(){
57 EMPTY = new TreeSelection(); 56 EMPTY = new TreeSelection();
58 } 57 }
59 58
60 private static class InitializeData { 59 private static class InitializeData {
61 Seq!(Object) selection; 60 List selection;
62 TreePath[] paths; 61 TreePath[] paths;
63 CustomHashtable element2TreePaths; 62 CustomHashtable element2TreePaths;
64 63
65 private this(TreePath[] paths, IElementComparer comparer) { 64 private this(TreePath[] paths, IElementComparer comparer) {
66 this.paths= new TreePath[paths.length]; 65 this.paths= new TreePath[paths.length];
67 System.arraycopy(paths, 0, this.paths, 0, paths.length); 66 System.arraycopy(paths, 0, this.paths, 0, paths.length);
68 element2TreePaths = new CustomHashtable(comparer); 67 element2TreePaths = new CustomHashtable(comparer);
69 int size = paths.length; 68 int size = paths.length;
70 auto s = new ArraySeq!(Object); 69 selection = new ArrayList(size);
71 s.capacity(size);
72 selection = s;
73 for (int i = 0; i < size; i++) { 70 for (int i = 0; i < size; i++) {
74 Object lastSegment= paths[i].getLastSegment(); 71 Object lastSegment= paths[i].getLastSegment();
75 Object mapped= element2TreePaths.get(lastSegment); 72 Object mapped= element2TreePaths.get(lastSegment);
76 if (mapped is null) { 73 if (mapped is null) {
77 selection.append(lastSegment); 74 selection.add(lastSegment);
78 element2TreePaths.put(lastSegment, paths[i]); 75 element2TreePaths.put(lastSegment, paths[i]);
79 } else if ( cast(Seq!(Object))mapped ) { 76 } else if ( cast(List)mapped ) {
80 (cast(Seq!(Object))mapped).append(paths[i]); 77 (cast(List)mapped).add( cast(Object)paths[i]);
81 } else { 78 } else {
82 Seq!(Object) newMapped= new ArraySeq!(Object); 79 List newMapped= new ArrayList();
83 newMapped.append(mapped); 80 newMapped.add(mapped);
84 newMapped.append(paths[i]); 81 newMapped.add(paths[i]);
85 element2TreePaths.put(lastSegment, cast(Object) newMapped); 82 element2TreePaths.put(lastSegment, cast(Object) newMapped);
86 } 83 }
87 } 84 }
88 } 85 }
89 } 86 }
215 Object value= element2TreePaths is null ? null : element2TreePaths.get(element); 212 Object value= element2TreePaths is null ? null : element2TreePaths.get(element);
216 if (value is null) { 213 if (value is null) {
217 return EMPTY_TREE_PATHS; 214 return EMPTY_TREE_PATHS;
218 } else if (cast(TreePath)value ) { 215 } else if (cast(TreePath)value ) {
219 return [ cast(TreePath)value ]; 216 return [ cast(TreePath)value ];
220 } else if (cast(Seq!(Object))value ) { 217 } else if (cast(List)value ) {
221 auto l= cast(Seq!(Object))value; 218 auto l= cast(List)value;
222 return cast(TreePath[]) l.toArray(); 219 return arraycast!(TreePath)( l.toArray() );
223 } else { 220 } else {
224 // should not happen: 221 // should not happen:
225 Assert.isTrue(false, "Unhandled case"); //$NON-NLS-1$ 222 Assert.isTrue(false, "Unhandled case"); //$NON-NLS-1$
226 return null; 223 return null;
227 } 224 }