java – 如何设置Eclipse / RCP装饰器的颜色?

2019-06-11
我通过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>

在装饰器类我设置装饰后缀,工作正常:

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));     
   }

正如你所看到的,我也尝试设置没有效果的suffic的前景色.后缀与树中的标签颜色相同:黑色.

如何设置装饰后缀的颜色?

我刚刚使用包装类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);
   }
}