Skip to main content



      Home
Home » Eclipse Projects » JFace » Image control in TreeViewer
Image control in TreeViewer [message #5320] Thu, 14 May 2009 20:54 Go to next message
Eclipse UserFriend
I have a tree viewer that uses images and color to display the overall
status of children. It's a library manager, of sorts. I have two
problems. In the SWT version, I was able to detect the expand/collapse
state of an item and apply the appropriate image. (Can't stand the line
gaps, so my images include a straight and 'T' line, with status image
overlaid.) The problem is when the tree is first drawn. The label
provider has no way I can tell of detecting whether the branch/item the
element is attached to is expanded or collapsed, so I can't provide a
correct first image.
I manage the images later through a TreeListener/TreeAdapter through
treeCollapsed() and treeExpanded(). This manages the images fine by
looking at the last image to decide what the next should be, but if the
first image is wrong, i.e. a straight line status image instead of a 'T'
status image, i lose the status information.
I can code around this by looking for any status image, but I was hoping
for a suggestion on how to do this in the label provider instead.

#2. Is tree expand/collapse. I would like to programatically expand and
collapse, rather like the autoExpand setting in TreeViewer. I can do this
via SWT, but all the branches come up with no labels!

Any help would be appreciated, thanks.
Re: Image control in TreeViewer [message #6138 is a reply to message #5320] Fri, 15 May 2009 13:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi Allen,

see below...

"Allen D. McDonald" <admcdonald1@verizon.net> wrote in message
news:1ee94cdc5f0875efd0e465705bcf35e5$1@www.eclipse.org...
>I have a tree viewer that uses images and color to display the overall
>status of children. It's a library manager, of sorts. I have two
>problems. In the SWT version, I was able to detect the expand/collapse
>state of an item and apply the appropriate image. (Can't stand the line
>gaps, so my images include a straight and 'T' line, with status image
>overlaid.) The problem is when the tree is first drawn. The label
>provider has no way I can tell of detecting whether the branch/item the
>element is attached to is expanded or collapsed, so I can't provide a
>correct first image.

Yes, this is because we first update the label itself and then the expanded
state in org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem( Widget,
Object, int). You might be out of luck here, but you can always use SWT
directly if JFace gets in your way.

> I manage the images later through a TreeListener/TreeAdapter through
> treeCollapsed() and treeExpanded(). This manages the images fine by
> looking at the last image to decide what the next should be, but if the
> first image is wrong, i.e. a straight line status image instead of a 'T'
> status image, i lose the status information.
> I can code around this by looking for any status image, but I was hoping
> for a suggestion on how to do this in the label provider instead.
>
> #2. Is tree expand/collapse. I would like to programatically expand and
> collapse, rather like the autoExpand setting in TreeViewer. I can do this
> via SWT, but all the branches come up with no labels!

How about this:

void
org.eclipse.jface.viewers.AbstractTreeViewer.setExpandedElem ents(Object[]
elements)
Sets which nodes are expanded in this viewer's tree. The given list contains
the elements that are to be expanded; all other nodes are to be collapsed.



Boris
Re: Image control in TreeViewer [message #6239 is a reply to message #6138] Fri, 15 May 2009 23:26 Go to previous message
Eclipse UserFriend
Thanks, Boris!
I worked around #1 like I thought I could.
For #2, your suggestion gave me impetus to go back and read the inherited
methods for TreeViewer and I came up with
org.eclipse.jface.viewers.AbstractTreeViewer.expandToLevel(i nt level) and
org.eclipse.jface.viewers.AbstractTreeViewer.collapseAll(). There is a
corresponding collapseToLevel() as well.
These fit in quite well with my design.
Thanks again.
Previous Topic:Binding to a TitleAreaDialog (3.4.2)
Next Topic:Databinding with Enum + Combo
Goto Forum:
  


Current Time: Fri May 09 01:49:19 EDT 2025

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

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

Back to the top