Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem setting focus for a newly added child element in TreeViewer

 
b gorle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

My treeviewer contains both parent and child elements. When I am trying to add a new child element for a particular parent element, some how the focus is getting lost. My code goes like this

protected void setSelectionToViewer(final Collection theSelection)

{

if (theSelection != null && !theSelection.isEmpty())

{

// Try to select the items in the current content viewer of the editor.

Object[] asArray = theSelection.toArray();

if (collectionViewer != null && asArray != null

&& asArray.length > 0 && asArray[0] != null)

{

collectionViewer.getViewer().reveal(asArray[0]);

collectionViewer.getViewer().setSelection(new StructuredSelection(asArray), true);

collectionViewer.getViewer().getControl().setFocus();

//myTreeViewer.getControl().setFocus();

}

}

}

Any help is highly appreciated. Thanks in advances bgorle.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.
 
b gorle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quick quiz for you:
which is easier to read, in the way you're used to seeing it

1)
class FirstProgram
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}

or
2)


or
3)
 
b gorle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for that!! Please check it now. Also if you are unable to understand below code please suggest what is the general procedure to set Focus for a newly added child element in a treeview. When I add an element, the focus should be on the newly added element, but for some reason i am unable to set the focus and it is lost ...



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic