Mercurial > projects > dwt-addons
comparison dwtx/jface/viewers/TreeViewer.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 | 7ffeace6c47f |
children |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
31 import dwtx.jface.viewers.ILazyTreePathContentProvider; | 31 import dwtx.jface.viewers.ILazyTreePathContentProvider; |
32 import dwtx.jface.viewers.TreePath; | 32 import dwtx.jface.viewers.TreePath; |
33 import dwtx.jface.viewers.TreeExpansionEvent; | 33 import dwtx.jface.viewers.TreeExpansionEvent; |
34 import dwtx.jface.viewers.ViewerCell; | 34 import dwtx.jface.viewers.ViewerCell; |
35 | 35 |
36 import tango.util.collection.LinkSeq; | |
37 import tango.util.collection.model.Seq; | |
38 import tango.util.collection.model.SeqView; | |
39 | 36 |
40 import dwt.DWT; | 37 import dwt.DWT; |
41 import dwt.events.DisposeEvent; | 38 import dwt.events.DisposeEvent; |
42 import dwt.events.DisposeListener; | 39 import dwt.events.DisposeListener; |
43 import dwt.events.TreeEvent; | 40 import dwt.events.TreeEvent; |
52 import dwt.widgets.TreeItem; | 49 import dwt.widgets.TreeItem; |
53 import dwt.widgets.Widget; | 50 import dwt.widgets.Widget; |
54 import dwtx.jface.util.Policy; | 51 import dwtx.jface.util.Policy; |
55 | 52 |
56 import dwt.dwthelper.utils; | 53 import dwt.dwthelper.utils; |
54 import dwtx.dwtxhelper.Collection; | |
57 import dwt.dwthelper.Runnable; | 55 import dwt.dwthelper.Runnable; |
58 | 56 |
59 /** | 57 /** |
60 * A concrete viewer based on an DWT <code>Tree</code> control. | 58 * A concrete viewer based on an DWT <code>Tree</code> control. |
61 * <p> | 59 * <p> |
358 } | 356 } |
359 | 357 |
360 /* | 358 /* |
361 * (non-Javadoc) Method declared in AbstractTreeViewer. | 359 * (non-Javadoc) Method declared in AbstractTreeViewer. |
362 */ | 360 */ |
363 protected override void setSelection(SeqView!(Item) items) { | 361 protected override void setSelection(List items) { |
364 | 362 |
365 Item[] current = getSelection(getTree()); | 363 Item[] current = getSelection(getTree()); |
366 | 364 |
367 // Don't bother resetting the same selection | 365 // Don't bother resetting the same selection |
368 if (isSameSelection(items, current)) { | 366 if (isSameSelection(items, current)) { |
369 return; | 367 return; |
370 } | 368 } |
371 | 369 |
372 getTree().setSelection( cast(TreeItem[]) items.toArray()); | 370 getTree().setSelection( arraycast!(TreeItem)( items.toArray())); |
373 } | 371 } |
374 | 372 |
375 /* | 373 /* |
376 * (non-Javadoc) Method declared in AbstractTreeViewer. | 374 * (non-Javadoc) Method declared in AbstractTreeViewer. |
377 */ | 375 */ |
438 * @since 3.2 | 436 * @since 3.2 |
439 */ | 437 */ |
440 public void setChildCount(Object elementOrTreePath, int count) { | 438 public void setChildCount(Object elementOrTreePath, int count) { |
441 if (checkBusy()) | 439 if (checkBusy()) |
442 return; | 440 return; |
443 preservingSelection(new class(elementOrTreePath,count) Runnable { | 441 preservingSelection( dgRunnable((Object elementOrTreePath_, int count_) { |
444 Object elementOrTreePath_; | 442 if (internalIsInputOrEmptyPath(elementOrTreePath_)) { |
445 int count_; | 443 getTree().setItemCount(count_); |
446 this(Object a,int b){ | 444 return; |
447 elementOrTreePath_=a; | 445 } |
448 count_=b; | 446 Widget[] items = internalFindItems(elementOrTreePath_); |
449 } | 447 for (int i = 0; i < items.length; i++) { |
450 public void run() { | 448 TreeItem treeItem = cast(TreeItem) items[i]; |
451 if (internalIsInputOrEmptyPath(elementOrTreePath_)) { | 449 treeItem.setItemCount(count_); |
452 getTree().setItemCount(count_); | 450 } |
453 return; | 451 }, elementOrTreePath,count )); |
454 } | |
455 Widget[] items = internalFindItems(elementOrTreePath_); | |
456 for (int i = 0; i < items.length; i++) { | |
457 TreeItem treeItem = cast(TreeItem) items[i]; | |
458 treeItem.setItemCount(count_); | |
459 } | |
460 } | |
461 }); | |
462 } | 452 } |
463 | 453 |
464 /** | 454 /** |
465 * For a TreeViewer with a tree with the VIRTUAL style bit set, replace the | 455 * For a TreeViewer with a tree with the VIRTUAL style bit set, replace the |
466 * given parent's child at index with the given element. If the given parent | 456 * given parent's child at index with the given element. If the given parent |
883 */ | 873 */ |
884 public void remove(Object parentOrTreePath_, int index_) { | 874 public void remove(Object parentOrTreePath_, int index_) { |
885 if (checkBusy()) | 875 if (checkBusy()) |
886 return; | 876 return; |
887 preservingSelection(new class((cast(TreeSelection) getSelection()).getPaths(),parentOrTreePath_,index_) Runnable { | 877 preservingSelection(new class((cast(TreeSelection) getSelection()).getPaths(),parentOrTreePath_,index_) Runnable { |
888 Seq!(TreePath) oldSelection; | 878 List oldSelection; |
889 Object parentOrTreePath; | 879 Object parentOrTreePath; |
890 int index; | 880 int index; |
891 this(TreePath[] a,Object b,int c){ | 881 this(TreePath[] a,Object b,int c){ |
892 parentOrTreePath=b; | 882 parentOrTreePath=b; |
893 index=c; | 883 index=c; |
894 oldSelection = new LinkSeq!(TreePath); | 884 oldSelection = new LinkedList(Arrays.asList(a)); |
895 foreach( p; a){ | |
896 oldSelection.append( p ); | |
897 } | |
898 } | 885 } |
899 public void run() { | 886 public void run() { |
900 TreePath removedPath = null; | 887 TreePath removedPath = null; |
901 if (internalIsInputOrEmptyPath(parentOrTreePath)) { | 888 if (internalIsInputOrEmptyPath(parentOrTreePath)) { |
902 Tree tree = cast(Tree) getControl(); | 889 Tree tree = cast(Tree) getControl(); |
924 } | 911 } |
925 } | 912 } |
926 } | 913 } |
927 if (removedPath !is null) { | 914 if (removedPath !is null) { |
928 bool removed = false; | 915 bool removed = false; |
929 int delIdx = 0; | 916 for (Iterator it = oldSelection.iterator(); it |
930 foreach ( path; oldSelection.dup ) { | 917 .hasNext();) { |
918 TreePath path = cast(TreePath) it.next(); | |
931 if (path.startsWith(removedPath, getComparer())) { | 919 if (path.startsWith(removedPath, getComparer())) { |
932 oldSelection.removeAt(delIdx); | 920 it.remove(); |
933 removed = true; | 921 removed = true; |
934 } | 922 } |
935 delIdx++; | |
936 } | 923 } |
937 if (removed) { | 924 if (removed) { |
938 setSelection(new TreeSelection( | 925 setSelection(new TreeSelection( |
939 oldSelection.toArray(), getComparer()), | 926 arraycast!(TreePath)( oldSelection |
927 .toArray(new TreePath[oldSelection | |
928 .size()])), getComparer()), | |
940 false); | 929 false); |
941 } | 930 } |
942 | |
943 } | 931 } |
944 } | 932 } |
945 }); | 933 }); |
946 } | 934 } |
947 | 935 |