我在 Eclipse/RCP 应用程序中向我的树查看器项目添加了一个装饰器插件.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>
在装饰器类中,我设置了效果很好的装饰后缀:
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));
}
正如你所看到的,我还尝试设置后缀的前景色,但没有效果。后缀与树中标签的颜色相同:黑色。
如何设置装饰后缀的颜色?
我刚刚成功地使用了不同颜色的文本装饰org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fviewers%2FDecoratingStyledCellLabelProvider.html包裹着一个IStyledLabelProvider
, 和ILabelDecorator
.
我认为关键是getStyledText
的方法LabelProvider
,允许自定义文本样式
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)