如何设置Eclipse/RCP装饰器的颜色? [英] How to set the color of an Eclipse/RCP decorator?
问题描述
我通过 plugin.xml 在Eclipse/RCP应用程序中的树查看器项中添加了一个装饰器:
I added a decorator in a Eclipse/RCP application to my tree viewer items by plugin.xml:
<extension point="org.eclipse.ui.decorators">
<decorator
adaptable="true"
class="sernet.verinice.samt.rcp.TopicDecorator"
id="sernet.verinice.samt.rcp.TopicDecorator"
label="ISA Topic decorator"
lightweight="true"
location="BOTTOM_LEFT"
state="true">
<enablement>
<objectClass name="sernet.verinice.model.samt.SamtTopic"/>
</enablement>
</decorator>
在装饰器类中,我设置了可以正常工作的装饰后缀:
In the decorator class i set the decoration suffix which works fine:
public class TopicDecorator extends LabelProvider implements ILightweightLabelDecorator, {
ControlMaturityService maturityService = new ControlMaturityService();
@Override
public void decorate(Object element, IDecoration decoration) {
decoration.addSuffix( new StringBuilder().append(" [")
.append(maturityService.getWeightedMaturity((IControl)element))
.append("]").toString() );
decoration.setForegroundColor(new Color(Display.getCurrent(), 150,90,90));
}
如您所见,我还尝试设置没有效果的足够的前景色.后缀与树中的标签具有相同的颜色:黑色.
As you can see i also tried to set the foreground color of the suffic which has no effect. Suffix has the same color as the label in the tree: black.
如何设置装饰后缀的颜色?
How can i set the color of the decoration suffix?
推荐答案
使用org.eclipse.jface的包装类 TreeElementDecoratingLabelProvider
,我刚刚成功获得了不同的彩色文本修饰.viewers.DecoratingLabelProvider :
I have just had success getting a different coloured text decoration using a wrapper class TreeElementDecoratingLabelProvider
for org.eclipse.jface.viewers.DecoratingLabelProvider
:
public class TreeElementDecoratingLabelProvider extends DecoratingLabelProvider {
public TreeElementDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
super(provider, decorator);
}
@Override
public Color getForeground(Object element) {
//return your color for element...
return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
}
}
这篇关于如何设置Eclipse/RCP装饰器的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!