Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Programmatic selection of TreeView nodes?
Programmatic selection of TreeView nodes? [message #448465] Mon, 10 January 2005 18:07 Go to next message
Eclipse UserFriend
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);
}
}
}
}
Re: Programmatic selection of TreeView nodes? [message #448764 is a reply to message #448465] Thu, 13 January 2005 20:28 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
You should ask this on the eclipse.platform newsgroup.

"Mighty M" <fn2o-mycl@spamex.com> wrote in message
news:crug9f$al3$1@www.eclipse.org...
> 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);
> }
> }
> }
> }
>
>
>
Previous Topic:Set cursor in Document
Next Topic:SWT_AWT in commercial projects?
Goto Forum:
  


Current Time: Mon Dec 09 17:54:56 GMT 2019

Powered by FUDForum. Page generated in 0.02165 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top