[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.rcp] Re: tooltips for the generated editor
|
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