|
Re: LightweightLabelDecorator: how can I decorate a custom tree (eg. based on some TreeNode)? [message #297765 is a reply to message #297721] |
Thu, 19 January 2006 14:24 |
stefan birman Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Hello All,
I found a solution for my problem:
1. Register the lightweight label decorator in plugin.xml as follows :
<extension
point="org.eclipse.ui.decorators">
<decorator
adaptable="false"
class="my.plugin.outline.SomeLabelDecorator"
id="my.plugin.outline.SomeLabelDecorator"
label="Some Super Decorator"
lightweight="true"
location="TOP_LEFT"
state="true">
<enablement>
<objectClass name="my.plugin.outline.SomeObject"/>
</enablement>
<description>
Some description.
</description>
</decorator>
</extension>
2. Create class that implements ILightweightLabelDecorator:
public class AccessLabelDecorator extends LabelProvider implements
ILightweightLabelDecorator {
public void decorate(Object element, IDecoration decoration) {
// decorating code in here
}
}
3. Register label decorator with the viewer:
viewer.setLabelProvider(new DecoratingLabelProvider(
new SomeLabelProvider(), MyPlugin.getDefault()
.getWorkbench().getDecoratorManager()
.getLabelDecorator());
For more details you can dig in sources starting with
getLabelDecorator() method and DecoratingLabelProvider() constructor.
Thanks to Mia Stern and Tod Creasey for their thread : Lightweight
decorators and enablement.
news.eclipse.org rules!
Stefan.
PS : For fast browsing in sources I recomand shortcuts : CTRL-o, CTRL-t,
or CTRL-click over the objects.
stefan wrote:
> Hello,
>
> I try to decorate a custom tree/outline view (eg. TreeNode) using
> lightweight label decorators. I created a lightweight decorator and
> register it in the decorators extension point;the enablement is
> triggered for the TreeNode object and still decorator doesn't show up.
>
> I tried to use the same decorator with an IResource enablement
> and the decorations appear (eg. objects in Navigator show the decoration).
>
> Also searched the newsgroup for a solution and I saw other people
> having similar issues (eg Decorator problem, by Eric Fu). I made
> TreeNode to implement IAdaptable and to return an IFile if an adapter of
> kind IResource/IFile is requested for it; the enablement is triggered by
> either one of : IResource, IFile or TreeNode. The decorations still
> don't appear. I set the enablement to be IResource, still doesn't work.
>
> How can I decorate objects in a tree based on custom objects, using
> LightweightLabelDecorator? TreeNode must extend IResource?
> Can you give a code example or point me to a tutorial, other than
> article Understanding Decorators in Eclipse?
>
> Any help is appreciated,
> Stefan.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02858 seconds