org.eclipse.ui.decorators得用法

    < extension
         
point ="org.eclipse.ui.decorators" >
      
< decorator
            
icon ="icons/warning_small.gif"
            id
="cnooc.rcp.decorator.node.warning"
            label
="Data Warning Decorator"
            lightweight
="true"
            location
="BOTTOM_LEFT"
            state
="true" >
         
< enablement >
            
< and >
               
< objectClass  name ="com.eplat.cnooc.rcp.node.INode" />
               
< objectState
                     
name ="hasWarning"
                     value
="true" />
            
</ and >
         
</ enablement >
      
</ decorator >
      
< decorator
            
icon ="icons/error_small.gif"
            id
="cnooc.rcp.decorator.node.error"
            label
="Data Error Decorator"
            lightweight
="true"
            location
="BOTTOM_LEFT"
            state
="true" >
         
< enablement >
            
< and >
               
< objectClass  name ="com.eplat.cnooc.rcp.node.INode" />
               
< objectState
                     
name ="hasError"
                     value
="true" />
            
</ and >
         
</ enablement >
      
</ decorator >
   
</ extension >
 
INode是TreeViewer里面节点得对象.
Viewer设置LabelProvider时需要如下:
        viewer.setLabelProvider( new  DecoratingLabelProvider( new  ViewLabelProvider(), Activator.getDefault().getWorkbench()
                .getDecoratorManager().getLabelDecorator()));

写了这个以后还没完, 需要让INode实现IActionFilter接口. eclipse得API中说要么实现IActionFilter接口, 要么实现IAdapter接口, 如果实现后者得话, 系统会调用getAdapter()方法. 不过我还是选择前者.
     /**
     * (non-Javadoc)
     * 
     * 
@see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
     
*/

    
public   boolean  testAttribute(Object target, String name, String value)  {
        
if (name.equals("hasWarning")) {
            
return !getProblems().hasError() && getProblems().hasWarning();
        }
 else if (name.equals("hasError")) {
            
return getProblems().hasError();
        }

        
return false;
    }

意思应该比较明显得, 如果有warning并且没有error得时候warning得decorator生效. 如果有error则error得decorator生效. name参数对应得就是objectState得name参数. value参数对应得objectState得value参数. target参数就是viewer中得节点对象, 不过由于INode实现了IActionFilter接口, 因此这里得target就是this了.
一般来说需要判断得就是根据name获取得值是否等于value, 等于返回true, 否则返回false. 不过这里我不需要判断这个了, 直接根据当前状态返回就好了.
按照eclipse得原理, 理论上应该INode变化以后viewer就会跟着变化, 但是我实验下来有时候好有时候不好.
因此在Editor得verify方法里增加了下面得逻辑:
     /**
     * 校验数据
     * 
     * 
@return
     
*/

    
private   boolean  verify()  {
                
//校验数据
                
//不管是否有error或者warning都需要通知向导树刷新一下节点.
        ExplorerView view = (ExplorerView) getSite().getPage().findView(ExplorerView.class.getName());
        view.refresh((INode) getEditorInput());

        
return true;
    }

现在好了, 只要执行verify方法, viewer就会刷新对应得节点, 以达到显示左下方小图标得目的.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值