/**
   * @param element
   * @param state
   */
  protected void updateCheckState(final Object element, final boolean state) {
    if (state) {
      // Add the item (or its children) to the cache

      ITreeContentProvider contentProvider = null;
      if (getContentProvider() instanceof ITreeContentProvider) {
        contentProvider = (ITreeContentProvider) getContentProvider();
      }

      if (contentProvider != null) {
        Object[] children = contentProvider.getChildren(element);
        if (children != null && children.length > 0) {
          for (int i = 0; i < children.length; i++) {
            updateCheckState(children[i], state);
          }
        } else {
          checkState.add(element);
        }
      } else {
        checkState.add(element);
      }
    } else if (checkState != null) {
      // Remove the item (or its children) from the cache
      ITreeContentProvider contentProvider = null;
      if (getContentProvider() instanceof ITreeContentProvider) {
        contentProvider = (ITreeContentProvider) getContentProvider();
      }

      if (contentProvider != null) {
        Object[] children = contentProvider.getChildren(element);
        if (children != null && children.length > 0) {
          for (int i = 0; i < children.length; i++) {
            updateCheckState(children[i], state);
          }
        }
      }
      checkState.remove(element);
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object[])
  */
 public void remove(Object[] elementsOrTreePaths) {
   for (int i = 0; i < elementsOrTreePaths.length; i++) {
     updateCheckState(elementsOrTreePaths[i], false);
   }
   super.remove(elementsOrTreePaths);
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object)
  */
 public void remove(Object elementsOrTreePaths) {
   updateCheckState(elementsOrTreePaths, false);
   super.remove(elementsOrTreePaths);
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.ICheckable#setChecked(java.lang.Object, boolean)
  */
 public boolean setChecked(Object element, boolean state) {
   updateCheckState(element, state);
   return super.setChecked(element, state);
 }