Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » tooltips for the generated editor
tooltips for the generated editor [message #485328] Fri, 11 September 2009 12:01 Go to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

I don't know if this is the right place to ask the question (that's why
I posted to the rcp group as well). I added documentation to the
elements of my meta model. Now I print the documentation in the
generated tree editor in the status line. But sometimes the text is very
long and not all can be read. So I want to add tooltips to the editor in
that way that if I hover an element in the tree a tooltip with its
documentation will appear (maybe after 1 second). How can I achieve this?

best regards,
Gilbert
Re: tooltips for the generated editor [message #485330 is a reply to message #485328] Fri, 11 September 2009 12:11 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Gilbert,

Have you tried some of the snippets? -->
http://wiki.eclipse.org/index.php/JFaceSnippets#Snippet011Cu stomTooltips

Cheers
/Eike

----
http://thegordian.blogspot.com



Gilbert Mirenque schrieb:
> I don't know if this is the right place to ask the question (that's why
> I posted to the rcp group as well). I added documentation to the
> elements of my meta model. Now I print the documentation in the
> generated tree editor in the status line. But sometimes the text is very
> long and not all can be read. So I want to add tooltips to the editor in
> that way that if I hover an element in the tree a tooltip with its
> documentation will appear (maybe after 1 second). How can I achieve this?
>
> best regards,
> Gilbert
>


Re: tooltips for the generated editor [message #485340 is a reply to message #485330] Fri, 11 September 2009 12:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Eike,
thanks for the link. I don't really know where to add the tool tips. I
tried to do the following just to test if it works:

in the generated createPages() method I modified it for the first tab
like this

ViewerPane viewerPane =
new ViewerPane(getSite().getPage(), CRUISeMetaModelEditor.this) {
@Override
public Viewer createViewer(Composite composite) {
Tree tree = new Tree(composite, SWT.MULTI);
TreeViewer newTreeViewer = new TreeViewer(tree);
tree.setToolTipText("Test tooltip");
return newTreeViewer;
}
//...
};

But the test tooltip will only be shown if I hover the tree-less area.
Want to say that if I hover the tree and elements of it the tooltip
won't be displayed, only around of the tree it will be displayed. The
other issue is how to determine which element will be hovered actually.
Adding a MouseListener?


Eike Stepper wrote:
> Hi Gilbert,
>
> Have you tried some of the snippets? -->
> http://wiki.eclipse.org/index.php/JFaceSnippets#Snippet011Cu stomTooltips
>
> Cheers
> /Eike
Re: tooltips for the generated editor [message #485357 is a reply to message #485340] Fri, 11 September 2009 13:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Gilbert,

This is definitely a more general JFace or SWT question, not an EMF
specific one... I'm not sure the answer. Hopefully someone will
suggest something.


Gilbert Mirenque wrote:
> Hi Eike,
> thanks for the link. I don't really know where to add the tool tips. I
> tried to do the following just to test if it works:
>
> in the generated createPages() method I modified it for the first tab
> like this
>
> ViewerPane viewerPane =
> new ViewerPane(getSite().getPage(), CRUISeMetaModelEditor.this) {
> @Override
> public Viewer createViewer(Composite composite) {
> Tree tree = new Tree(composite, SWT.MULTI);
> TreeViewer newTreeViewer = new TreeViewer(tree);
> tree.setToolTipText("Test tooltip");
> return newTreeViewer;
> }
> //...
> };
>
> But the test tooltip will only be shown if I hover the tree-less area.
> Want to say that if I hover the tree and elements of it the tooltip
> won't be displayed, only around of the tree it will be displayed. The
> other issue is how to determine which element will be hovered actually.
> Adding a MouseListener?
>
>
> Eike Stepper wrote:
>
>> Hi Gilbert,
>>
>> Have you tried some of the snippets? -->
>> http://wiki.eclipse.org/index.php/JFaceSnippets#Snippet011Cu stomTooltips
>>
>> Cheers
>> /Eike
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: tooltips for the generated editor [message #485525 is a reply to message #485340] Sat, 12 September 2009 13:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Did you take a look at the Snippet Eike referenced? The thing you need
is ColumnViewerToolTipSupport and the really important thing (and I
think here your problem will start) is that you have to use a
ColumnViewerLabelProvider and implement the getTooltipText() method.

If using ColumnViewerLabelProvider (or better a kind of
CellLabelProvider) then you should take a look at
http://wiki.eclipse.org/index.php/JFaceSnippets#Snippet031Ta bleViewerCustomTooltipsMultiSelection

Tom

Gilbert Mirenque schrieb:
> Hi Eike,
> thanks for the link. I don't really know where to add the tool tips. I
> tried to do the following just to test if it works:
>
> in the generated createPages() method I modified it for the first tab
> like this
>
> ViewerPane viewerPane =
> new ViewerPane(getSite().getPage(), CRUISeMetaModelEditor.this) {
> @Override
> public Viewer createViewer(Composite composite) {
> Tree tree = new Tree(composite, SWT.MULTI);
> TreeViewer newTreeViewer = new TreeViewer(tree);
> tree.setToolTipText("Test tooltip");
> return newTreeViewer;
> }
> //...
> };
>
> But the test tooltip will only be shown if I hover the tree-less area.
> Want to say that if I hover the tree and elements of it the tooltip
> won't be displayed, only around of the tree it will be displayed. The
> other issue is how to determine which element will be hovered actually.
> Adding a MouseListener?
>
>
> Eike Stepper wrote:
>> Hi Gilbert,
>>
>> Have you tried some of the snippets? -->
>> http://wiki.eclipse.org/index.php/JFaceSnippets#Snippet011Cu stomTooltips
>>
>> Cheers
>> /Eike
Re: tooltips for the generated editor [message #485849 is a reply to message #485525] Tue, 15 September 2009 10:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Thanks for the snippet links. They helped a lot. Now I tell you what I
did. First I implemented my own CellLabelProvider called
ToolTipCellLabelProvider. The class looks like this:

public class ToolTipCellLabelProvider extends CellLabelProvider{

private AdapterFactory adapterFactory;

public ToolTipCellLabelProvider(AdapterFactory adapterFactory) {
super();
this.adapterFactory = adapterFactory;
}

public String getToolTipText(Object element) {
String text = new
AdapterFactoryItemDelegator(adapterFactory).getText(element) ;
if(element instanceof EObject){
if(((EObject) element).eClass() instanceof EModelElement){
String documentation =
EcoreUtil.getDocumentation((EModelElement)((EObject) element).eClass());
if(documentation != null){
text += " --> " + documentation;
}
}
}
return text;
}

public Point getToolTipShift(Object object) {
return new Point(5,5);
}

public int getToolTipDisplayDelayTime(Object object) {
return 0;
}

public int getToolTipTimeDisplayed(Object object) {
return 5000;
}

public void update(ViewerCell cell) {
cell.setText(cell.getElement().toString());

}
}

Then I added the label provider to the TreeViewer of the first tab in
the generated editor in that way:

ViewerPane viewerPane = new ViewerPane(getSite().getPage(),
CRUISeMetaModelEditor.this) {
@Override
public Viewer createViewer(Composite composite) {
Tree tree = new Tree(composite, SWT.MULTI);
TreeViewer newTreeViewer = new TreeViewer(tree);
///// tooltips
ColumnViewerToolTipSupport.enableFor(newTreeViewer);
ToolTipCellLabelProvider labelProvider = new
ToolTipCellLabelProvider(adapterFactory);
newTreeViewer.setLabelProvider(labelProvider);
//////////////
return newTreeViewer;
}
@Override
public void requestActivation() {
super.requestActivation();
setCurrentViewerPane(this);
}
};

But it doesn't work :( While debugging I noticed that getToolTipText(..)
never is being accessed. So I thought that I don't have to add the
tooltip support for the treeViewer, but for the selectionViewer directly
because there setLabelProvider will be invoked as well (generated) and
the selectionViewer = (TreeViewer)viewerPane.getViewer(); But the
generated LabelProvider which is set is:

new AdapterFactoryLabelProvider.ColorProvider(adapterFactory,
selectionViewer)

As there is no interface for ColorProvider I searched for all
implementing interfaces of ColorProvider and all implementing interfaces
of its super classes and let ToolTipCellLabelProvider implement that by
just delegating it to an ColorProvider instance like this:

ColumnViewerToolTipSupport.enableFor(selectionViewer);
ColorProvider provider = new
AdapterFactoryLabelProvider.ColorProvider(adapterFactory, selectionViewer);
ToolTipCellLabelProvider labelProvider = new
ToolTipCellLabelProvider(provider);
selectionViewer.setLabelProvider(labelProvider);

Now the tooltips worked adequate for all nodes in the tree. But now I
have another problem. The normal texts and little images of the nodes
won't be displayed anymore. As text I only get the toString output of
the object. Do you have any suggestions how to combine both?

best regards,
Gilbert
Re: tooltips for the generated editor [message #485850 is a reply to message #485849] Tue, 15 September 2009 10:11 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You should have better subclassed ColumnLabelProvider.

Tom

Gilbert Mirenque schrieb:
> Thanks for the snippet links. They helped a lot. Now I tell you what I
> did. First I implemented my own CellLabelProvider called
> ToolTipCellLabelProvider. The class looks like this:
>
> public class ToolTipCellLabelProvider extends CellLabelProvider{
>
> private AdapterFactory adapterFactory;
>
> public ToolTipCellLabelProvider(AdapterFactory adapterFactory) {
> super();
> this.adapterFactory = adapterFactory;
> }
>
> public String getToolTipText(Object element) {
> String text = new
> AdapterFactoryItemDelegator(adapterFactory).getText(element) ;
> if(element instanceof EObject){
> if(((EObject) element).eClass() instanceof EModelElement){
> String documentation =
> EcoreUtil.getDocumentation((EModelElement)((EObject) element).eClass());
> if(documentation != null){
> text += " --> " + documentation;
> }
> }
> }
> return text;
> }
>
> public Point getToolTipShift(Object object) {
> return new Point(5,5);
> }
>
> public int getToolTipDisplayDelayTime(Object object) {
> return 0;
> }
>
> public int getToolTipTimeDisplayed(Object object) {
> return 5000;
> }
>
> public void update(ViewerCell cell) {
> cell.setText(cell.getElement().toString());
>
> }
> }
>
> Then I added the label provider to the TreeViewer of the first tab in
> the generated editor in that way:
>
> ViewerPane viewerPane = new ViewerPane(getSite().getPage(),
> CRUISeMetaModelEditor.this) {
> @Override
> public Viewer createViewer(Composite composite) {
> Tree tree = new Tree(composite, SWT.MULTI);
> TreeViewer newTreeViewer = new TreeViewer(tree);
> ///// tooltips
> ColumnViewerToolTipSupport.enableFor(newTreeViewer);
> ToolTipCellLabelProvider labelProvider = new
> ToolTipCellLabelProvider(adapterFactory);
> newTreeViewer.setLabelProvider(labelProvider);
> //////////////
> return newTreeViewer;
> }
> @Override
> public void requestActivation() {
> super.requestActivation();
> setCurrentViewerPane(this);
> }
> };
>
> But it doesn't work :( While debugging I noticed that getToolTipText(..)
> never is being accessed. So I thought that I don't have to add the
> tooltip support for the treeViewer, but for the selectionViewer directly
> because there setLabelProvider will be invoked as well (generated) and
> the selectionViewer = (TreeViewer)viewerPane.getViewer(); But the
> generated LabelProvider which is set is:
>
> new AdapterFactoryLabelProvider.ColorProvider(adapterFactory,
> selectionViewer)
>
> As there is no interface for ColorProvider I searched for all
> implementing interfaces of ColorProvider and all implementing interfaces
> of its super classes and let ToolTipCellLabelProvider implement that by
> just delegating it to an ColorProvider instance like this:
>
> ColumnViewerToolTipSupport.enableFor(selectionViewer);
> ColorProvider provider = new
> AdapterFactoryLabelProvider.ColorProvider(adapterFactory, selectionViewer);
> ToolTipCellLabelProvider labelProvider = new
> ToolTipCellLabelProvider(provider);
> selectionViewer.setLabelProvider(labelProvider);
>
> Now the tooltips worked adequate for all nodes in the tree. But now I
> have another problem. The normal texts and little images of the nodes
> won't be displayed anymore. As text I only get the toString output of
> the object. Do you have any suggestions how to combine both?
>
> best regards,
> Gilbert
Re: tooltips for the generated editor [message #485851 is a reply to message #485850] Tue, 15 September 2009 10:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Oh thanks Tom,

> You should have better subclassed ColumnLabelProvider.

this brought the solution. But the mistake was of other nature. In
CellLabelProvider the update method is abstract and I still had the
implementation of the snippet from the wiki. I didn't considered it
anymore. With ColumnLabelProvider I don't need to implement the update
method and the result is very nice :) Thanks a lot.

Gilbert
Re: tooltips for the generated editor [message #485896 is a reply to message #485850] Tue, 15 September 2009 13:36 Go to previous message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Tom, with one of your blog entries I got the tooltips now nice looking,
too :)

Thanks for your help
Previous Topic:Console view in RCP hangs for many messages
Next Topic:Saving editor layout
Goto Forum:
  


Current Time: Fri Apr 26 07:25:31 GMT 2024

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

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

Back to the top