Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Decorators like in CVS/SVN plug-in
Decorators like in CVS/SVN plug-in [message #330150] Thu, 17 July 2008 10:41 Go to next message
Matthias Treitler is currently offline Matthias TreitlerFriend
Messages: 117
Registered: July 2009
Senior Member
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 #330154 is a reply to message #330150] Thu, 17 July 2008 13:18 Go to previous messageGo to next message
Jakub Jurkiewicz is currently offline Jakub JurkiewiczFriend
Messages: 38
Registered: July 2009
Member
Matthias pisze:
> 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
>
Hi,

I don't know how to achieve this, however, you can look at the cvs
source code and see how it is done.
Here: http://wiki.eclipse.org/index.php/CVS_Howto you have the
information, how to get the Eclipse source code from the repository.

--
kind regards,
Jakub

http://eclipser-blog.blogspot.com/
http://eclipse-po-polsku.blogspot.com/
Re: Decorators like in CVS/SVN plug-in [message #330162 is a reply to message #330150] Thu, 17 July 2008 15:36 Go to previous messageGo to next message
Michael Valenta is currently offline Michael ValentaFriend
Messages: 35
Registered: July 2009
Member
Matthias,

I believe that you just need to use the IDecoration#setForegroundColor
method when your are asked to provide your decoration.

Michael

Matthias wrote:
> 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 #330164 is a reply to message #330162] Thu, 17 July 2008 16:38 Go to previous messageGo to next message
Matthias Treitler is currently offline Matthias TreitlerFriend
Messages: 117
Registered: July 2009
Senior Member
Hi,

hmm I am afraid this does not work. If I call this API than the whole
label gets colored not only the "decoration". I am using EMF's generated
AdapterFactory to display my models but that should not make any
difference.


Thanks,
Matthias
Re: Decorators like in CVS/SVN plug-in [message #330165 is a reply to message #330154] Thu, 17 July 2008 16:41 Go to previous messageGo to next message
Matthias Treitler is currently offline Matthias TreitlerFriend
Messages: 117
Registered: July 2009
Senior Member
Hi!

Yes I had had already a look at this piece of code, but they do there a
lot of things... But they are also setting foreground color with a
provided color and it seems that it works for them...

As posted previously I am display my model instance with help of EMF
AdapterFactory, but that should not make any difference, or?

Thanks,
Matthias
Re: Decorators like in CVS/SVN plug-in [message #330215 is a reply to message #330164] Mon, 21 July 2008 15:01 Go to previous messageGo to next message
Michael Valenta is currently offline Michael ValentaFriend
Messages: 35
Registered: July 2009
Member
Oops, you're right. I don't know if or how you can programmatically
change the decoration color but the user can change it by going to the
General/Appearance/Colors and Fonts preference page. If you expand the
Basic category, you will see the Decoration color which you can change.
This means that the viewer is using a theme to set the color. Given this
it's not clear that you would be able to set the color programmatically.
You may want to look at the DecoratingLabelProvider to see how it sets
the color.

Michael

Matthias wrote:
> Hi,
>
> hmm I am afraid this does not work. If I call this API than the whole
> label gets colored not only the "decoration". I am using EMF's generated
> AdapterFactory to display my models but that should not make any
> difference.
>
>
> Thanks,
> Matthias
>
Re: Decorators like in CVS/SVN plug-in [message #498791 is a reply to message #330164] Wed, 18 November 2009 16:07 Go to previous messageGo to next message
Fedronic valere is currently offline Fedronic valereFriend
Messages: 2
Registered: July 2009
Junior Member
Hi Matthias,

I am trying to do exactly what you described [different font color for the label decoration].
I was wondering if you finally manage to make it work?

Thanks, I am going back to the cvs plugin sources Wink
Valère.
Re: Decorators like in CVS/SVN plug-in [message #498804 is a reply to message #498791] Wed, 18 November 2009 16:49 Go to previous message
Fedronic valere is currently offline Fedronic valereFriend
Messages: 2
Registered: July 2009
Junior Member
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.

Previous Topic:How to be more faster when eclipse launcing
Next Topic:cross bookmarks or project location hyperlinks
Goto Forum:
  


Current Time: Fri Mar 29 02:24:36 GMT 2024

Powered by FUDForum. Page generated in 0.03317 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top