Search in sources :

Example 1 with WTree

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

the class WTreeRenderer method handlePaintCustom.

/**
 * Paint the custom tree layout.
 *
 * @param tree the WTree to render
 * @param xml the XML string builder
 */
protected void handlePaintCustom(final WTree tree, final XmlStringBuilder xml) {
    TreeItemModel model = tree.getTreeModel();
    TreeItemIdNode root = tree.getCustomTree();
    Set<String> selectedRows = new HashSet(tree.getSelectedRows());
    Set<String> expandedRows = new HashSet(tree.getExpandedRows());
    WTree.ExpandMode mode = tree.getExpandMode();
    // Process root nodes
    for (TreeItemIdNode node : root.getChildren()) {
        paintCustomItem(tree, mode, model, node, xml, selectedRows, expandedRows);
    }
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) TreeItemModel(com.github.bordertech.wcomponents.TreeItemModel) HashSet(java.util.HashSet)

Example 2 with WTree

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

the class WTreeRenderer method handlePaintItems.

/**
 * Paint the tree items.
 *
 * @param tree the WTree to render
 * @param xml the XML string builder
 */
protected void handlePaintItems(final WTree tree, final XmlStringBuilder xml) {
    TreeItemModel model = tree.getTreeModel();
    int rows = model.getRowCount();
    if (rows > 0) {
        Set<String> selectedRows = new HashSet(tree.getSelectedRows());
        Set<String> expandedRows = new HashSet(tree.getExpandedRows());
        WTree.ExpandMode mode = tree.getExpandMode();
        for (int i = 0; i < rows; i++) {
            List<Integer> rowIndex = new ArrayList<>();
            rowIndex.add(i);
            paintItem(tree, mode, model, rowIndex, xml, selectedRows, expandedRows);
        }
    }
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) TreeItemModel(com.github.bordertech.wcomponents.TreeItemModel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with WTree

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

the class WTreeRenderer method handleOpenItemRequest.

/**
 * Paint the item that was on the open request.
 *
 * @param tree the WTree to render
 * @param xml the XML string builder
 * @param itemId the item id to open
 */
protected void handleOpenItemRequest(final WTree tree, final XmlStringBuilder xml, final String itemId) {
    TreeItemModel model = tree.getTreeModel();
    Set<String> selectedRows = new HashSet(tree.getSelectedRows());
    WTree.ExpandMode mode = tree.getExpandMode();
    // Only want to render the children of the "open item" so only include the open item id in the expanded rows
    Set<String> expandedRows = new HashSet();
    expandedRows.add(itemId);
    if (tree.getCustomTree() == null) {
        List<Integer> rowIndex = tree.getExpandedItemIdIndexMap().get(itemId);
        paintItem(tree, mode, model, rowIndex, xml, selectedRows, expandedRows);
    } else {
        TreeItemIdNode node = tree.getCustomIdNodeMap().get(itemId);
        paintCustomItem(tree, mode, model, node, xml, selectedRows, expandedRows);
    }
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) TreeItemModel(com.github.bordertech.wcomponents.TreeItemModel) HashSet(java.util.HashSet)

Example 4 with WTree

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

the class WTreeRenderer method doRender.

/**
 * Paints the given WTree.
 *
 * @param component the WTree to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTree tree = (WTree) component;
    XmlStringBuilder xml = renderContext.getWriter();
    // Check if rendering an open item request
    String openId = tree.getOpenRequestItemId();
    if (openId != null) {
        handleOpenItemRequest(tree, xml, openId);
        return;
    }
    // Check the tree has tree items (WCAG requirement)
    TreeItemModel model = tree.getTreeModel();
    if (model == null || model.getRowCount() <= 0) {
        LOG.warn("Tree not rendered as it has no items.");
        return;
    }
    xml.appendTagOpen("ui:tree");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("htree", WTree.Type.HORIZONTAL == tree.getType(), "true");
    xml.appendOptionalAttribute("multiple", WTree.SelectMode.MULTIPLE == tree.getSelectMode(), "true");
    xml.appendOptionalAttribute("disabled", tree.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", tree.isHidden(), "true");
    xml.appendOptionalAttribute("required", tree.isMandatory(), "true");
    switch(tree.getExpandMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case LAZY:
            xml.appendAttribute("mode", "lazy");
            break;
        default:
            throw new IllegalStateException("Invalid expand mode: " + tree.getType());
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(tree, renderContext);
    if (tree.getCustomTree() == null) {
        handlePaintItems(tree, xml);
    } else {
        handlePaintCustom(tree, xml);
    }
    DiagnosticRenderUtil.renderDiagnostics(tree, renderContext);
    xml.appendEndTag("ui:tree");
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) TreeItemModel(com.github.bordertech.wcomponents.TreeItemModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 5 with WTree

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

the class WTreeRenderer_Test method testDoPaintWithCustomTree.

@Test
public void testDoPaintWithCustomTree() throws IOException, SAXException, XpathException {
    WTree tree = MockTreeItemData.setupWTreeWithCustom();
    setActiveContext(createUIContext());
    assertSchemaMatch(tree);
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) Test(org.junit.Test)

Aggregations

WTree (com.github.bordertech.wcomponents.WTree)11 Test (org.junit.Test)5 TreeItemModel (com.github.bordertech.wcomponents.TreeItemModel)4 TreeItemIdNode (com.github.bordertech.wcomponents.TreeItemIdNode)3 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 MockTreeItemData (com.github.bordertech.wcomponents.MockTreeItemData)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1