public boolean visitTree()

in tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java [543:664]


  public boolean visitTree(final VisitContext context, final VisitCallback callback) {
    boolean skipIterationHint = context.getHints().contains(VisitHint.SKIP_ITERATION);
    if (skipIterationHint) {
      return super.visitTree(context, callback);
    }
    FacesContext facesContext = context.getFacesContext();
    pushComponentToEL(facesContext, this);
    if (!isVisitable(context)) {
      return false;
    }

    // save the current row index
    int oldRowIndex = getRowIndex();
    try {
      // set row index to -1 to process the facets and to get the rowless clientId
      setRowIndex(-1);
      VisitResult visitResult = context.invokeVisitCallback(this, callback);
      switch (visitResult) {
        case COMPLETE:
          //we are done nothing has to be processed anymore
          return true;
        case REJECT:
          return false;
        default:
          // accept; determine if we need to visit our children
          Collection<String> subtreeIdsToVisit = context.getSubtreeIdsToVisit(this);
          boolean doVisitChildren = subtreeIdsToVisit != null && !subtreeIdsToVisit.isEmpty();
          if (doVisitChildren) {
            // visit the facets of the component
            if (getFacetCount() > 0) {
              for (UIComponent facet : getFacets().values()) {
                if (facet.visitTree(context, callback)) {
                  return true;
                }
              }
            }
            // visit every column directly without visiting its children
            // (the children of every UIColumn will be visited later for
            // every row) and also visit the column's facets
            for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
              UIComponent child = getChildren().get(i);
              if (child instanceof UIColumn) {
                VisitResult columnResult = context.invokeVisitCallback(child, callback);
                if (columnResult == VisitResult.COMPLETE) {
                  return true;
                }
                if (child.getFacetCount() > 0) {
                  for (UIComponent facet : child.getFacets().values()) {
                    if (facet.visitTree(context, callback)) {
                      return true;
                    }
                  }
                }
              }
            }
            if (VisitContext.ALL_IDS == subtreeIdsToVisit) {
              // iterate over all rows
              int rowsToProcess = getRows();
              // if getRows() returns 0, all rows have to be processed
              if (rowsToProcess == 0) {
                rowsToProcess = getRowCount();
              }
              int rowIndex = getFirst();
              for (int rowsProcessed = 0; rowsProcessed < rowsToProcess; rowsProcessed++, rowIndex++) {
                setRowIndex(rowIndex);
                if (!isRowAvailable()) {
                  return false;
                }
                // visit the children of every child of the UIData that is an instance of UIColumn
                for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
                  UIComponent child = getChildren().get(i);
                  if (child instanceof UIColumn) {
                    for (int j = 0, grandChildCount = child.getChildCount(); j < grandChildCount; j++) {
                      UIComponent grandchild = child.getChildren().get(j);
                      if (grandchild.visitTree(context, callback)) {
                        return true;
                      }
                    }
                  }
                }
              }
            } else {
              Set<Integer> rowsToVisit = getRowsToVisit(facesContext, subtreeIdsToVisit);
              if (rowsToVisit.isEmpty()) {
                return false;
              }
              // iterate over the rows to visit
              for (Integer rowIndex : rowsToVisit) {
                setRowIndex(rowIndex);
                if (!isRowAvailable()) {
                  return false;
                }
                // visit the children of every child of the UIData that is an instance of UIColumn
                for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
                  final UIComponent child = getChildren().get(i);
                  if (child instanceof UIColumn) {
                    if (child instanceof AbstractUIRow) {
                      if (child.visitTree(context, callback)) {
                        return true;
                      }
                    } else {
                      for (int j = 0, grandChildCount = child.getChildCount(); j < grandChildCount; j++) {
                        UIComponent grandchild = child.getChildren().get(j);
                        if (grandchild.visitTree(context, callback)) {
                          return true;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
      }
    } finally {
      // pop the component from EL and restore the old row index
      popComponentFromEL(facesContext);
      setRowIndex(oldRowIndex);
    }
    // Return false to allow the visiting to continue
    return false;
  }