Search in sources :

Example 1 with TreeItemImage

use of com.github.bordertech.wcomponents.TreeItemImage in project wcomponents by BorderTech.

the class WTreeRenderer method paintItem.

/**
 * Iterate of over the rows to render the tree items.
 *
 * @param tree the WTree to render
 * @param mode the expand mode
 * @param model the tree model
 * @param rowIndex the current row index
 * @param xml the XML string builder
 * @param selectedRows the set of selected rows
 * @param expandedRows the set of expanded rows
 */
protected void paintItem(final WTree tree, final WTree.ExpandMode mode, final TreeItemModel model, final List<Integer> rowIndex, final XmlStringBuilder xml, final Set<String> selectedRows, final Set<String> expandedRows) {
    String itemId = model.getItemId(rowIndex);
    boolean selected = selectedRows.remove(itemId);
    boolean expandable = model.isExpandable(rowIndex) && model.hasChildren(rowIndex);
    boolean expanded = expandedRows.remove(itemId);
    TreeItemImage image = model.getItemImage(rowIndex);
    String url = null;
    if (image != null) {
        url = tree.getItemImageUrl(image, itemId);
    }
    xml.appendTagOpen("ui:treeitem");
    xml.appendAttribute("id", tree.getItemIdPrefix() + itemId);
    xml.appendAttribute("label", model.getItemLabel(rowIndex));
    xml.appendOptionalUrlAttribute("imageUrl", url);
    xml.appendOptionalAttribute("selected", selected, "true");
    xml.appendOptionalAttribute("expandable", expandable, "true");
    xml.appendOptionalAttribute("open", expandable && expanded, "true");
    xml.appendClose();
    if (expandable && (mode == WTree.ExpandMode.CLIENT || expanded)) {
        // Get actual child count
        int children = model.getChildCount(rowIndex);
        if (children > 0) {
            for (int i = 0; i < children; i++) {
                // Add next level
                List<Integer> nextRow = new ArrayList<>(rowIndex);
                nextRow.add(i);
                paintItem(tree, mode, model, nextRow, xml, selectedRows, expandedRows);
            }
        }
    }
    xml.appendEndTag("ui:treeitem");
}
Also used : ArrayList(java.util.ArrayList) TreeItemImage(com.github.bordertech.wcomponents.TreeItemImage)

Example 2 with TreeItemImage

use of com.github.bordertech.wcomponents.TreeItemImage in project wcomponents by BorderTech.

the class WTreeRenderer method paintCustomItem.

/**
 * Iterate of over the nodes to render the custom layout of the tree items.
 *
 * @param tree the WTree to render
 * @param mode the expand mode
 * @param model the tree model
 * @param node the current node in the custom tree layout
 * @param xml the XML string builder
 * @param selectedRows the set of selected rows
 * @param expandedRows the set of expanded rows
 */
protected void paintCustomItem(final WTree tree, final WTree.ExpandMode mode, final TreeItemModel model, final TreeItemIdNode node, final XmlStringBuilder xml, final Set<String> selectedRows, final Set<String> expandedRows) {
    String itemId = node.getItemId();
    List<Integer> rowIndex = tree.getRowIndexForCustomItemId(itemId);
    boolean selected = selectedRows.remove(itemId);
    boolean expandable = node.hasChildren();
    boolean expanded = expandedRows.remove(itemId);
    TreeItemImage image = model.getItemImage(rowIndex);
    String url = null;
    if (image != null) {
        url = tree.getItemImageUrl(image, itemId);
    }
    xml.appendTagOpen("ui:treeitem");
    xml.appendAttribute("id", tree.getItemIdPrefix() + itemId);
    xml.appendAttribute("label", model.getItemLabel(rowIndex));
    xml.appendOptionalUrlAttribute("imageUrl", url);
    xml.appendOptionalAttribute("selected", selected, "true");
    xml.appendOptionalAttribute("expandable", expandable, "true");
    xml.appendOptionalAttribute("open", expandable && expanded, "true");
    xml.appendClose();
    // Paint child items
    if (expandable && (mode == WTree.ExpandMode.CLIENT || expanded)) {
        for (TreeItemIdNode childNode : node.getChildren()) {
            paintCustomItem(tree, mode, model, childNode, xml, selectedRows, expandedRows);
        }
    }
    xml.appendEndTag("ui:treeitem");
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) TreeItemImage(com.github.bordertech.wcomponents.TreeItemImage)

Aggregations

TreeItemImage (com.github.bordertech.wcomponents.TreeItemImage)2 TreeItemIdNode (com.github.bordertech.wcomponents.TreeItemIdNode)1 ArrayList (java.util.ArrayList)1