问题描述
我使用了JFace CheckboxTreeviewer并添加了ICheckStateListener以获取已检查元素的结果。
代码如下
I have used JFace CheckboxTreeviewer and added ICheckStateListener to get result of checked elements.Code is as follows
private HashSet<Object> checkElement=new HashSet<Object>();
checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
String childNode=null;
String rootNode=null;
Object changed = event.getElement();
if(changed instanceof ChildFacetNodeVo){
checkElement.add(changed);
ChildFacetNodeVo childFacetNodeVo=(ChildFacetNodeVo)changed;
childNode=childFacetNodeVo.getLabelFacet();
rootNode=childFacetNodeVo.getParent();
//here to get a new result after element checked and put new result to checkboxtreeviewer
List<RootFacetNodeVo> facetNodeVos=createFacetFilter(rootNode,childNode);
if(facetNodeVos!=null){
checkboxTreeViewer.setInput(facetNodeVos);
checkboxTreeViewer.expandToLevel(3);
checkboxTreeViewer.setCheckedElements(checkElement.toArray());
}
}
}
});
现在我需要的是当我检查新元素时,以前检查过的元素不应被取消选中。
当我在CheckboxTreeviewer中设置新输入时,看不到任何内容。
那么我如何在CheckboxTreeviewer中设置预先检查的元素。例如
Now what i need is when i checked the new element the previously checked element should not get unchecked.when i set new input in CheckboxTreeviewer nothing is visible.So how do i set prevously checked element in CheckboxTreeviewer.for example
p1
-----A1 - previous checked
-----A2
-----A3
-----A4
-----A5
p1
-----A6
-----A7
-----A8 - previous checked
-----A8
-----A9
p1
-----A10
-----A11
推荐答案
如果调用 setCheckedElements
,则必须在指定的数组中包含所有应检查的内容。
If you call setCheckedElements
you must include everything that should be checked in the array you specify.
您似乎正在创建要放入树中的一组新对象,因此您将不得不确定需要检查哪些新项目。
You appear to be creating a new set of objects to go in the tree so you will have to work out which of these new items needs to be checked.
您可以调用 checkboxTreeViewer.getCheckedElements()
来获取旧的选中元素(在设置新输入之前执行此操作)。这应该可以帮助您确定需要检查哪些新元素。
You can call checkboxTreeViewer.getCheckedElements()
to get the old checked elements (do this before setting the new input). This should help you work out which of the new elements need to be checked.
这篇关于CheckboxTreeviewer先前在重新加载后设置了选中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!