|Programmatic selection of TreeView nodes? [message #448465]
||Mon, 10 January 2005 18:07
Originally posted by: fn2o-mycl.spamex.com|
How can I programmatically select nodes of a tree using the TreeViewer's
setSelection () method? What is the TreeView.setSelection () method
Here's a routine where I try to select all of a tree nodes children if
none are selected. It doesn't work however.
Also, I'm getting a "java.lang.UnsupportedOperationException at
java.util.AbstractList.add(Unknown Source)" when trying to add the child
nodes to the selection. What have I done wrong?
public void selectionChanged(SelectionChangedEvent event)
System.out.println ("SymbolDragListener.dragStart ()");
// Is there anything selected?
boolean hasSelection = !treeViewer.getSelection().isEmpty();
if (hasSelection == true)
// Loop though the selected items.
List selectionList =
Iterator i = selectionList.iterator();
// Get the children of this selected item.
Object unknown = i.next();
if (unknown instanceof MyNode)
MyNode parent = (MyNode) unknown;
List childrenList = parent.getChildren();
// How many of the selected item's children are also
Iterator x = childrenList.iterator();
int selectedChildrenCount = 0;
// If none of the selected item's children are selected,
select all of 'em.
if (selectedChildrenCount == 0)
Powered by FUDForum
. Page generated in 0.02543 seconds