/** * Collapses the items recursively. * * Collapse all the children recursively starting from an item. Operation * succeeds only if all expandable items are collapsed. * * @param startItemId * @return True if the collapse operation succeeded */ public boolean collapseItemsRecursively(Object startItemId) { boolean result = true; // Initial stack final Stack<Object> todo = new Stack<Object>(); todo.add(startItemId); // Collapse recursively while (!todo.isEmpty()) { final Object id = todo.pop(); if (areChildrenAllowed(id) && !collapseItem(id)) { result = false; } if (hasChildren(id)) { todo.addAll(getChildren(id)); } } return result; }
/** * Expands the items recursively * * Expands all the children recursively starting from an item. Operation * succeeds only if all expandable items are expanded. * * @param startItemId * @return True if the expand operation succeeded */ public boolean expandItemsRecursively(Object startItemId) { boolean result = true; // Initial stack final Stack<Object> todo = new Stack<Object>(); todo.add(startItemId); // Expands recursively while (!todo.isEmpty()) { final Object id = todo.pop(); if (areChildrenAllowed(id) && !expandItem(id, false)) { result = false; } if (hasChildren(id)) { todo.addAll(getChildren(id)); } } markAsDirty(); return result; }
/** * If the event is on a node that can not have children (see * {@link Tree#areChildrenAllowed(Object)}), this method returns the * parent item id of the target item (see {@link #getItemIdOver()} ). * The identifier of the parent node is also returned if the cursor is * on the top part of node. Else this method returns the same as * {@link #getItemIdOver()}. * <p> * In other words this method returns the identifier of the "folder" * into the drag operation is targeted. * <p> * If the method returns null, the current target is on a root node or * on other undefined area over the tree component. * <p> * The default Tree implementation marks the targetted tree node with * CSS classnames v-tree-node-dragfolder and * v-tree-node-caption-dragfolder (for the caption element). */ public Object getItemIdInto() { Object itemIdOver = getItemIdOver(); if (areChildrenAllowed(itemIdOver) && getDropLocation() == VerticalDropLocation.MIDDLE) { return itemIdOver; } return getParent(itemIdOver); }
/** * Expands an item. * * @param itemId * the item id. * @param sendChildTree * flag to indicate if client needs subtree or not (may be * cached) * @return True if the expand operation succeeded */ private boolean expandItem(Object itemId, boolean sendChildTree) { // Succeeds if the node is already expanded if (isExpanded(itemId)) { return true; } // Nodes that can not have children are not expandable if (!areChildrenAllowed(itemId)) { return false; } // Expands expanded.add(itemId); expandedItemId = itemId; if (initialPaint) { markAsDirty(); } else if (sendChildTree) { requestPartialRepaint(); } fireExpandEvent(itemId); return true; }
@Override public boolean accept(DragAndDropEvent dragEvent) { try { // must be over tree node and in the middle of it (not top or // bottom // part) TreeTargetDetails eventDetails = (TreeTargetDetails) dragEvent .getTargetDetails(); Object itemIdOver = eventDetails.getItemIdOver(); if (!eventDetails.getTarget().areChildrenAllowed(itemIdOver)) { return false; } // return true if directly over return eventDetails .getDropLocation() == VerticalDropLocation.MIDDLE; } catch (Exception e) { return false; } }
final boolean isNode = areChildrenAllowed(itemId); if (isNode) { target.startTag("node"); selectedKeys.add(key); if (areChildrenAllowed(itemId) && isExpanded(itemId)) { target.addAttribute("expanded", true); expandedKeys.add(key); && areChildrenAllowed(itemId)) { iteratorStack.push(getChildren(itemId).iterator()); } else {