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;
}
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;
}
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;
}
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);
}
}
}
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();
}
Aggregations