tooltips for the generated editor [message #485328] |
Fri, 11 September 2009 12:01 |
Eclipse User |
|
|
|
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 #485340 is a reply to message #485330] |
Fri, 11 September 2009 12:40 |
Eclipse User |
|
|
|
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 #485849 is a reply to message #485525] |
Tue, 15 September 2009 10:06 |
Eclipse User |
|
|
|
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 #485851 is a reply to message #485850] |
Tue, 15 September 2009 10:28 |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03373 seconds