<
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 >
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()));
.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;
}
* (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;
}
一般来说需要判断得就是根据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;
}
* 校验数据
*
* @return
*/
private boolean verify() {
//校验数据
//不管是否有error或者warning都需要通知向导树刷新一下节点.
ExplorerView view = (ExplorerView) getSite().getPage().findView(ExplorerView.class.getName());
view.refresh((INode) getEditorInput());
return true;
}