/**
   * Pass in an element, and this will update its parents' check states
   *
   * @param element the SelectableElement which will have its parents' check state updated
   */
  private void setSelectedTypeForParent(SelectableElement element) {
    SelectableElement parent = element.getParent();
    if (parent != null) {

      if (SelectableElement.doAllChildrenHaveSelectedType(parent, SelectedType.UNSELECTED)) {
        parent.setSelectedType(SelectedType.UNSELECTED);
      } else if (SelectableElement.doAllChildrenHaveSelectedType(parent, SelectedType.SELECTED)) {
        parent.setSelectedType(SelectedType.SELECTED);
      } else {
        parent.setSelectedType(SelectedType.LEAVE);
      }

      setSelectedTypeForParent(parent);
    }
  }
 /**
  * Pass in an element, and this will update its children's check states
  *
  * @param parent the SelectableElement which will have its children's check state updated
  */
 private void setSelectedTypeForChildren(SelectableElement parent) {
   for (int i = 0; i < parent.getNumberOfChildren(); i++) {
     parent.getChild(i).setSelectedType(parent.getSelectedType());
     setSelectedTypeForChildren(parent.getChild(i));
   }
 }