/**
   * We can use this method to determine if we should redispatch insert event to the corresponding
   * child collection below the cell returned from cell.getNextLeaf() or we should go on and insert
   * next child into a collection containing cell itself.
   *
   * @return true if we should redispatch insert event to the next leaft cell
   */
  private static boolean hasSingleRolesAtRightBoundary(EditorCell cell) {
    if (!(hasSingleRole(cell))) {
      return false;
    }

    if (isOnRightBoundary(cell)) {
      final EditorCell_Collection parentCell = cell.getParent();
      if (parentCell != null) {
        final EditorCell nextLeaf = APICellAdapter.getNextLeaf(cell);
        if (nextLeaf != null) {
          final Wrappers._boolean ancestor = new Wrappers._boolean(false);
          ModelAccess.instance()
              .runReadAction(
                  new Runnable() {
                    public void run() {
                      ancestor.value =
                          SNodeOperations.isAncestor(parentCell.getSNode(), nextLeaf.getSNode());
                    }
                  });
          if (ancestor.value) {
            return true;
          }
        }
        return hasSingleRolesAtRightBoundary(parentCell);
      }
    }
    return true;
  }
  public static EditorCell getSiblingCollectionForInsert(
      @NotNull EditorCell cell, boolean forward) {
    // TODO FIXME rewrite without hasSingleRolesAtLeftBoundary, cleanup ChildrenCollectionFinder
    EditorCell nextLeaf =
        (forward ? APICellAdapter.getNextLeaf(cell) : APICellAdapter.getPrevLeaf(cell));

    if ((APICellAdapter.isBigCell(cell) || APICellAdapter.isLastPositionInBigCell(cell))
        && ((forward ? hasSingleRolesAtRightBoundary(cell) : hasSingleRolesAtLeftBoundary(cell)))
        && nextLeaf != null) {
      // Looking for the next child collection in parents
      return new ChildrenCollectionFinder(nextLeaf, cell, forward, true).find();
    }
    return null;
  }
 public static boolean isOnRightBoundary(EditorCell cell) {
   EditorCell nextLeaf = APICellAdapter.getNextLeaf(cell);
   return nextLeaf == null || nextLeaf.getSNode() != cell.getSNode();
 }