Programmatic selection of TreeView nodes? [message #448465] |
Mon, 10 January 2005 18:07 |
Eclipse User |
|
|
|
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
looking for?
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 =
((IStructuredSelection)treeViewer.getSelection()).toList ();
Iterator i = selectionList.iterator();
while (i.hasNext())
{
// 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
selected?
Iterator x = childrenList.iterator();
int selectedChildrenCount = 0;
while (x.hasNext())
{
if (selectionList.contains(x.next()))
{
selectedChildrenCount++;
}
}
// If none of the selected item's children are selected,
select all of 'em.
if (selectedChildrenCount == 0)
{
// selectionList.add(childrenList);
treeViewer.setSelection(new StructuredSelection
(selectionList), true);
}
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03137 seconds