Decorators like in CVS/SVN plug-in [message #330150] |
Thu, 17 July 2008 06:41  |
Eclipse User |
|
|
|
Hello!
I am registering my decorators at the decorator manager to decorate my
label provider. This works very well. The suffix or prefix text should
appear in another color than the text provided by the label provider. The
CVS/SVN plugins have such a nice feature: they provide versioning
information in a grayed color (in the package explorer), so that the user
can easily distinguish between various information. If I change the color
on the passed IDecorator (I am implmenting ILightWeightLabelDecorator)
then the whole label has the changed color, not only the suffix/prefix
text.
How can I achieve such a behaviour like done in CVS/SVN plug-ins?!? Are
they using decorators or are they doing some other technique?!? Can
someone give me any hints or code how get such results?
Thanks a lot,
Matthias
|
|
|
|
|
|
|
|
|
Re: Decorators like in CVS/SVN plug-in [message #498804 is a reply to message #498791] |
Wed, 18 November 2009 11:49  |
Eclipse User |
|
|
|
Ok, this how i have done it.
I am using my own treeviewer.
The label provider to use is org.eclipse.jface.viewers#DecoratingStyledCellLabelProvider .
############
ILabelDecorator labelDecorator = MyUiPlugin.getDefault().getWorkbench().getDecoratorManager() .getLabelDecorator();
DecoratingStyledCellLabelProvider labelProvider = new DecoratingStyledCellLabelProvider(new MyStyledLabelProvider(), labelDecorator,DecorationContext.DEFAULT_CONTEXT);
viewer = new TreeViewer(parent);
viewer.setLabelProvider(labelProvider);
viewer.setContentProvider(new WorkbenchContentProvider());
#############
The MyStyledLabelProvider is simply a custom class that extends the WorkbenchLabelProvider and implements IStyledLabelProvider. You have to override the getStyledText(..) method.
#############
public StyledString getStyledText(final Object element)
{
String text = getText(element);
if (text != null)
{
return new StyledString(text, new Styler() {
/**
* @see org.eclipse.jface.viewers.StyledString.Styler#applyStyles(or g.eclipse.swt.graphics.TextStyle)
*/
@Override
public void applyStyles(TextStyle textStyle)
{
Color foreground = MyStyledLabelProvider.this.getForeground(element);
if (foreground != null)
textStyle.foreground = foreground;
Color background = MyStyledLabelProvider.this.getBackground(element);
if (background != null)
textStyle.background = background;
}
});
}
return null;
}
#############
My decorator is declared using the org.eclipse.ui.decorators extension point, and my model objects are adapted to IWorkbenchAdapter objects thanks to the org.eclipse.core.runtime.adapters extension point.
Regards,
Valère.
|
|
|
Powered by
FUDForum. Page generated in 0.07367 seconds