CheckboxTreeviewer previously set checked elements after reload

时光怂恿深爱的人放手 提交于 2019-12-25 08:13:39

问题


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

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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/41261568/checkboxtreeviewer-previously-set-checked-elements-after-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!