This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem setting focus for a newly added child element in TreeViewer  RSS feed

 
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
Posts: 21044
85
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 ...



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!