我通过plugin.xml在 Eclipse/RCP 应用程序中向我的树查看器项添加了一个装饰器:
<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>
Run Code Online (Sandbox Code Playgroud)
在装饰器类中,我设置了可以正常工作的装饰后缀:
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));
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我还尝试设置没有效果的足够的前景色。后缀与树中的标签颜色相同:黑色。
如何设置装饰后缀的颜色?
我刚刚使用包装类成功获得了不同颜色的文本TreeElementDecoratingLabelProvider装饰 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);
}
}
Run Code Online (Sandbox Code Playgroud)