0

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
greg-449
  • 109,219
  • 232
  • 102
  • 145
Ankit Sharma
  • 398
  • 1
  • 7
  • 19

1 Answers1

0

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.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • thank @greg-449 for your reply,but still my problem is not solved – Rameshwar Nagpure Dec 21 '16 at 11:46
  • 1
    @RameshwarNagpure Well then you will have to ask a new question with more information because this is all that can be said from the information in the current question. We aren't magicians and can't solve problems with no information. – greg-449 Dec 21 '16 at 11:48
  • please find my question on this link [CheckBoxTreeviewer set old checked element on creating new set of objects](http://stackoverflow.com/questions/41267253/checkboxtreeviewer-set-old-checked-element-on-creating-new-set-of-objects) – Rameshwar Nagpure Dec 21 '16 at 16:13