2011-02-04 44 views
4

我在Eclipse中/ RCP應用到我的樹查看的項目增加了一個裝飾用的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的前景色。後綴與樹中的標籤具有相同的顏色:黑色。

如何設置裝飾後綴的顏色?

回答

1

我剛剛成功使用org.eclipse.jface的包裝類TreeElementDecoratingLabelProvider得到一個不同顏色的文飾的定製造型。觀看者。裝飾標籤提供者

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

我想你應該嘗試改變順序 - 先設置setForegroundColor(),然後添加一個後綴。

提示:不要自己初始化任何顏色,你可以使用Display.getDefault()getSystemColor(SWT.COLOR_GREEN);那麼你需要關心處理這種顏色 - 它被系統釋放。

+0

無論您是先調用setForegroundColor(..)還是先調用addSuffix(..),都沒有區別。後綴與文本的其餘部分仍然具有相同的顏色。 – 2011-03-09 10:27:38

1

你的裝飾需要實現org.eclipse.jface.viewers.IColorDecorator是否需要提供各種顏色

+0

我的TopicDecorator現在也實現了IColorDecorator。實現方法decorateBackground和decorateForeground都會靜態返回\t一種不同的顏色,但裝飾器字符串ist仍爲黑色,並帶有白色背景。 – 2011-03-23 07:56:05

+0

確保選中「使用混合字體和顏色」首選項(Prefereces-> General-> Apperance)並禁用所有其他裝飾器(General-> Appearance-> Label裝飾器)並查看其是否可用 – 2011-03-23 09:27:29