Search in sources :

Example 1 with TreeNode

use of com.github.bordertech.wcomponents.util.TreeNode in project wcomponents by BorderTech.

the class TableTreeNode method nextSibling.

/**
 * @return the next sibling of this node, or null if there is none.
 */
protected TableTreeNode nextSibling() {
    TreeNode parent = getParent();
    if (parent != null) {
        int index = parent.getIndex(this) + 1;
        int childCount = parent.getChildCount();
        if (index < childCount) {
            return (TableTreeNode) parent.getChildAt(index);
        }
    }
    return null;
}
Also used : TreeNode(com.github.bordertech.wcomponents.util.TreeNode) AbstractTreeNode(com.github.bordertech.wcomponents.util.AbstractTreeNode)

Example 2 with TreeNode

use of com.github.bordertech.wcomponents.util.TreeNode in project wcomponents by BorderTech.

the class WDataTable method getCurrentPageEndRow.

/**
 * Retrieves the ending row index for the current page. Will always return the row count minus 1 for tables which
 * are not paginated.
 *
 * @return the starting row index for the current page.
 */
private int getCurrentPageEndRow() {
    TableDataModel model = getDataModel();
    int rowsPerPage = getRowsPerPage();
    int endRow = model.getRowCount() - 1;
    if (getPaginationMode() != PaginationMode.NONE) {
        if (model instanceof TreeTableDataModel) {
            // For tree tables, pagination only occurs on first-level nodes (ie. those
            // underneath the root node), however they might not be consecutively
            // numbered. Therefore, the start and end row indices need to be adjusted.
            TreeTableDataModel treeModel = (TreeTableDataModel) model;
            TreeNode root = treeModel.getNodeAtLine(0).getRoot();
            int endNode = Math.min(root.getChildCount() - 1, (getCurrentPage() + 1) * rowsPerPage - 1);
            endRow = // -1 as the root is not included in the table
            ((TableTreeNode) root.getChildAt(endNode)).getRowIndex() - 1 + ((TableTreeNode) root.getChildAt(endNode)).getNodeCount();
        } else {
            endRow = Math.min(model.getRowCount() - 1, (getCurrentPage() + 1) * rowsPerPage - 1);
        }
    }
    return endRow;
}
Also used : TreeNode(com.github.bordertech.wcomponents.util.TreeNode)

Example 3 with TreeNode

use of com.github.bordertech.wcomponents.util.TreeNode in project wcomponents by BorderTech.

the class WDataTable method getCurrentPageStartRow.

/**
 * Retrieves the starting row index for the current page. Will always return zero for tables which are not
 * paginated.
 *
 * @return the starting row index for the current page.
 */
private int getCurrentPageStartRow() {
    int startRow = 0;
    if (getPaginationMode() != PaginationMode.NONE) {
        int rowsPerPage = getRowsPerPage();
        TableDataModel model = getDataModel();
        if (model instanceof TreeTableDataModel) {
            // For tree tables, pagination only occurs on first-level nodes (ie. those
            // underneath the root node), however they might not be consecutively
            // numbered. Therefore, the start and end row indices need to be adjusted.
            TreeTableDataModel treeModel = (TreeTableDataModel) model;
            TreeNode root = treeModel.getNodeAtLine(0).getRoot();
            int startNode = getCurrentPage() * rowsPerPage;
            // -1 as the root is not included in the table
            startRow = ((TableTreeNode) root.getChildAt(startNode)).getRowIndex() - 1;
        } else {
            startRow = getCurrentPage() * rowsPerPage;
        }
    }
    return startRow;
}
Also used : TreeNode(com.github.bordertech.wcomponents.util.TreeNode)

Example 4 with TreeNode

use of com.github.bordertech.wcomponents.util.TreeNode in project wcomponents by BorderTech.

the class TreeMenuExample method mapTreeHierarchy.

/**
 * Recursively maps a tree hierarchy to a hierarchical menu.
 *
 * @param currentComponent the current component in the menu.
 * @param currentNode the current node in the tree.
 * @param selectedMenuText the WText to display the selected menu item.
 */
private void mapTreeHierarchy(final WComponent currentComponent, final StringTreeNode currentNode, final WText selectedMenuText) {
    if (currentNode.isLeaf()) {
        WMenuItem menuItem = new WMenuItem(currentNode.getData(), new ExampleMenuAction(selectedMenuText));
        menuItem.setActionObject(currentNode.getData());
        if (currentComponent instanceof WMenu) {
            ((WMenu) currentComponent).add(menuItem);
        } else {
            ((WSubMenu) currentComponent).add(menuItem);
        }
    } else {
        WSubMenu subMenu = new WSubMenu(currentNode.getData());
        subMenu.setSelectMode(SelectMode.SINGLE);
        if (currentComponent instanceof WMenu) {
            ((WMenu) currentComponent).add(subMenu);
        } else {
            ((WSubMenu) currentComponent).add(subMenu);
        }
        // Expand the first couple of levels in the tree by default.
        if (currentNode.getLevel() < 2) {
            subMenu.setOpen(true);
        }
        for (Iterator<TreeNode> i = currentNode.children(); i.hasNext(); ) {
            mapTreeHierarchy(subMenu, (StringTreeNode) i.next(), selectedMenuText);
        }
    }
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) WMenu(com.github.bordertech.wcomponents.WMenu)

Example 5 with TreeNode

use of com.github.bordertech.wcomponents.util.TreeNode in project wcomponents by BorderTech.

the class WDataTableRenderer method paintPaginationElement.

/**
 * Paint the pagination aspects of the WDataTable.
 * @param table the WDataTable being rendered
 * @param xml the string builder in use
 */
private void paintPaginationElement(final WDataTable table, final XmlStringBuilder xml) {
    TableDataModel model = table.getDataModel();
    xml.appendTagOpen("ui:pagination");
    if (model instanceof TreeTableDataModel) {
        // For tree tables, we only include top-level nodes for pagination.
        TreeNode firstNode = ((TreeTableDataModel) model).getNodeAtLine(0);
        xml.appendAttribute("rows", firstNode == null ? 0 : firstNode.getParent().getChildCount());
    } else {
        xml.appendAttribute("rows", model.getRowCount());
    }
    xml.appendAttribute("rowsPerPage", table.getRowsPerPage());
    xml.appendAttribute("currentPage", table.getCurrentPage());
    switch(table.getPaginationMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case DYNAMIC:
        case SERVER:
            xml.appendAttribute("mode", "dynamic");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown pagination mode: " + table.getPaginationMode());
    }
    xml.appendEnd();
}
Also used : TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) SystemException(com.github.bordertech.wcomponents.util.SystemException) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel)

Aggregations

TreeNode (com.github.bordertech.wcomponents.util.TreeNode)8 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)2 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)2 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)2 UIContext (com.github.bordertech.wcomponents.UIContext)2 WMenu (com.github.bordertech.wcomponents.WMenu)2 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)2 WSubMenu (com.github.bordertech.wcomponents.WSubMenu)2 AbstractTreeNode (com.github.bordertech.wcomponents.util.AbstractTreeNode)2 WComponent (com.github.bordertech.wcomponents.WComponent)1 WDataTable (com.github.bordertech.wcomponents.WDataTable)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1