Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Tootip for a TreeViewer(How to set a tooltip for TreeViewer)
Tootip for a TreeViewer [message #956788] Wed, 24 October 2012 20:11 Go to next message
Jim Jones is currently offline Jim JonesFriend
Messages: 6
Registered: September 2012
Junior Member
I have a TreeViewer that displays my data ok.
I want to put a Tooltip and found http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java this snippet.
My problem is that I already use a LabelProvider as a labelProvider for my TreeViewer to show text and Images for my nodes but in the linked example snippet a CellLabelProvider is used and if I use that I can not seem to find a way to display my text and icon for my nodes.
So how can I show tooltips in my working TreeViewer?
Re: Tootip for a TreeViewer [message #957334 is a reply to message #956788] Thu, 25 October 2012 06:39 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
You can extend your label provider from CellLabelProvider and in your update() method you have to call...

cell.setText(getText(cell.getElement()));
cell.setImage(getImage(cell.getElement()));


I.e. you would be reusing what you already have in your own label provider.

Jim Jones wrote on Wed, 24 October 2012 16:11
I have a TreeViewer that displays my data ok.
I want to put a Tooltip and found http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java this snippet.
My problem is that I already use a LabelProvider as a labelProvider for my TreeViewer to show text and Images for my nodes but in the linked example snippet a CellLabelProvider is used and if I use that I can not seem to find a way to display my text and icon for my nodes.
So how can I show tooltips in my working TreeViewer?

Re: Tootip for a TreeViewer [message #958150 is a reply to message #957334] Thu, 25 October 2012 20:00 Go to previous messageGo to next message
Jim Jones is currently offline Jim JonesFriend
Messages: 6
Registered: September 2012
Junior Member
Hi Erdal Karaca,
I am not sure I understand your answer.
I am using org.eclipse.jface.viewers.LabelProvider.
So how can I extend my label provider from org.eclipse.jface.viewers.CellLabelProvider?
Also which update() method are you talking about?
Could you please help me understand this? I am new in Eclipse programming.

Thank you
Re: Tootip for a TreeViewer [message #958825 is a reply to message #958150] Fri, 26 October 2012 08:40 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Assuming this is your current label provider:
public class YouLabelProvider extends LabelProvider {
  public String getText() {...}
  public Image getImage() {...}
}


Then, you can rewrite your code like this:

public class YouLabelProvider extends CellLabelProvider {
  public String getText(Object element) {...}
  public Image getImage(Object element) {...}

  public void update(ViewerCell cell) {
    cell.setText(getText(cell.getElement()));
    cell.setImage(getImage(cell.getElement()));
  }
}


Of course, you can directly use the code in getText/getImage to set cell.setText/setImage... but that is up to you...

BTW. this is all related to jface, so you should ask on the jface forum

Jim Jones wrote on Thu, 25 October 2012 16:00
Hi Erdal Karaca,
I am not sure I understand your answer.
I am using org.eclipse.jface.viewers.LabelProvider.
So how can I extend my label provider from org.eclipse.jface.viewers.CellLabelProvider?
Also which update() method are you talking about?
Could you please help me understand this? I am new in Eclipse programming.

Thank you

Re: Tootip for a TreeViewer [message #958842 is a reply to message #958825] Fri, 26 October 2012 08:50 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
it's easier to subclass ColumnLabelProvider.

Tom

Am 26.10.12 10:40, schrieb Erdal Karaca:
> Assuming this is your current label provider:
>
> public class YouLabelProvider extends LabelProvider {
> public String getText() {...}
> public Image getImage() {...}
> }
>
>
> Then, you can rewrite your code like this:
>
>
> public class YouLabelProvider extends CellLabelProvider {
> public String getText(Object element) {...}
> public Image getImage(Object element) {...}
>
> public void update(ViewerCell cell) {
> cell.setText(getText(cell.getElement()));
> cell.setImage(getImage(cell.getElement()));
> }
> }
>
>
> Of course, you can directly use the code in getText/getImage to set
> cell.setText/setImage... but that is up to you...
>
> BTW. this is all related to jface, so you should ask on the jface forum
>
> Jim Jones wrote on Thu, 25 October 2012 16:00
>> Hi Erdal Karaca,
>> I am not sure I understand your answer.
>> I am using org.eclipse.jface.viewers.LabelProvider.
>> So how can I extend my label provider from
>> org.eclipse.jface.viewers.CellLabelProvider?
>> Also which update() method are you talking about?
>> Could you please help me understand this? I am new in Eclipse
>> programming.
>>
>> Thank you
>
>
Re: Tootip for a TreeViewer [message #960301 is a reply to message #958842] Sat, 27 October 2012 10:55 Go to previous message
Jim Jone is currently offline Jim JoneFriend
Messages: 11
Registered: October 2012
Junior Member
Thank you both for your help!
I used a subclass of ColumnLabelProvider and it worked easily!
Previous Topic:How to fill Part with Data?
Next Topic:Manually triggering a class with injections?
Goto Forum:
  


Current Time: Wed Apr 24 20:54:18 GMT 2024

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

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

Back to the top