[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Label Decorator problem

To add a decorator for a tree viewer, u need not add a decorator using an extension pt (u can get away with tree viewer label provider).
 
The label provider class:
 
package com.ibm.sdwb.log.util.generictree;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
 
/**
* @author balajik
*
*/
 
public class TreeLabelProvider extends LabelProvider
{
 /**
 * Constructor for TreeLabelProvider.
 */
public TreeLabelProvider()
{
    super();
}
 
public String getText(Object obj)
{
if(obj instanceof AbstractTreeNode)
{
return ((AbstractTreeNode)obj).getLabel();
}
return "";
}
 
/**
* Get the image of the object
*/
public Image getImage(Object obj)
{
return ((AbstractTreeNode)obj).getImage();
}
 
to add a label provider:

treeViewer_.setLabelProvider(new TreeLabelProvider());

The getText and getImage methods are called on all the objects present in a tree viewer. u can add ur implementation to change the text and image.

 

If u want to use decorator extension pt, u might want to use MyPlugin.getDefault().getWorkbench().getDecoratorManager().getLightWeightLabelDecorator("org.myplugin.decorator")) (if u need an custom image for tree viewer elements, either u need to add a custom image in lightweight decorator extension pt definition or implement the same in the class)

eclipse.org article talks about decorators / lightweight decorator. (www.eclipse.org/articles.html)

 

HTH,

Balaji

 

 
"A. V." <not@xxxxxxx> wrote in message news:b876tr$uaj$1@xxxxxxxxxxxxx...
> I am trying to attach a lightweight decorator to a TreeViewer. I added the
> extension point and created the Decorator class (implementing the
> LightweightDecorator interface). The objectClass is my own object in the
> treeviewer. After that i added this line to the code where i was creating
> the treeviewer:
>
> treeviewer.setLabelProvider(new DecoratingLabelProvider(labelProvider,
> MyPlugin.getDefault().getWorkbench().getDecoratorManager("org.myplugin.decor
> ator"));
>
>
> When i run the run-time workbench, isee a new entry in the decorations
> preference page. But enabling and disabling it doesnt do anything. It gives
> me no decorations. I am sure i am missing something small. Does anyone know
> what I am doing wrong?
>
> Thanks
>
>