use of com.github.bordertech.wcomponents.TableTreeNode in project wcomponents by BorderTech.
the class DataTableOptionsExample method createHierarchicDataTable.
/**
* @return a hierarchic table
*/
private WDataTable createHierarchicDataTable() {
WDataTable table = new WDataTable();
table.setType(WDataTable.Type.HIERARCHIC);
table.addColumn(new WTableColumn("Column1", WText.class));
table.addColumn(new WTableColumn("Column2", WText.class));
table.addColumn(new WTableColumn("Column3", WText.class));
table.setRowsPerPage(DEFAULT_ROWS_PER_PAGE);
table.setSummary("Hierarchic table summary");
table.setCaption("Hierarchic table caption");
TableTreeNode root = createHierarchicTree();
table.setDataModel(new ExampleTreeTableModel(root));
return table;
}
use of com.github.bordertech.wcomponents.TableTreeNode in project wcomponents by BorderTech.
the class WDataTableRowRendererRenderer method doRender.
/**
* Paints the given WDataTableRowRenderer.
*
* @param component the WDataTableRowRenderer to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDataTableRowRenderer renderer = (WDataTableRowRenderer) component;
XmlStringBuilder xml = renderContext.getWriter();
WDataTable table = renderer.getTable();
TableDataModel dataModel = table.getDataModel();
UIContext uic = UIContextHolder.getCurrent();
final int numCols = table.getColumnCount();
int[] columnOrder = table.getColumnOrder();
int rowIndex = getRowIndex(table, (SubUIContext) uic);
boolean unselectable = table.getSelectMode() != SelectMode.NONE && !dataModel.isSelectable(rowIndex);
xml.appendTagOpen("ui:tr");
xml.appendAttribute("rowIndex", rowIndex);
xml.appendOptionalAttribute("unselectable", unselectable, "true");
xml.appendOptionalAttribute("selected", table.getSelectedRows().contains(rowIndex), "true");
xml.appendOptionalAttribute("filterValues", getFilterValues(dataModel, rowIndex));
if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
TableTreeNode node = ((TreeTableDataModel) dataModel).getNodeAtLine(rowIndex);
boolean expandable = !node.isLeaf() && !node.isExpanded();
xml.appendOptionalAttribute("expandable", expandable, "true");
}
xml.appendClose();
if (table.isShowRowHeaders()) {
xml.appendTag("ui:th");
renderer.getRowHeader().paint(renderContext);
xml.appendEndTag("ui:th");
}
for (int i = 0; i < numCols; i++) {
int colIndex = columnOrder == null ? i : columnOrder[i];
WTableColumn col = table.getColumn(colIndex);
if (col.isVisible()) {
xml.appendTag("ui:td");
renderer.getRenderer(colIndex).paint(renderContext);
xml.appendEndTag("ui:td");
}
}
if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
TreeTableDataModel treeModel = (TreeTableDataModel) dataModel;
TableTreeNode node = treeModel.getNodeAtLine(rowIndex);
if (!node.isLeaf()) {
xml.appendTagOpen("ui:subtr");
xml.appendOptionalAttribute("open", node.isExpanded(), "true");
xml.appendClose();
if (node.isExpanded() || table.getExpandMode() == ExpandMode.CLIENT) {
WRepeater repeater = table.getRepeater();
// If there a renderer specified by any child, we only paint content that has a specified renderer
boolean rendererPresent = false;
for (Iterator<TreeNode> i = node.children(); !rendererPresent && i.hasNext(); ) {
TableTreeNode child = (TableTreeNode) i.next();
if (child.getRendererClass() != null) {
rendererPresent = true;
}
}
// Paint immediate children only.
if (rendererPresent) {
xml.appendTagOpen("ui:content");
xml.appendOptionalAttribute("spanAllCols", node.isRendererSpansAllCols(), "true");
xml.appendClose();
for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
TableTreeNode child = (TableTreeNode) i.next();
Integer rowId = child.getRowIndex() - 1;
UIContext nodeContext = repeater.getRowContext(rowId);
WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(child.getRendererClass());
if (expandedRenderer != null) {
UIContextHolder.pushContext(nodeContext);
try {
expandedRenderer.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
}
xml.appendEndTag("ui:content");
} else {
for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
TableTreeNode child = (TableTreeNode) i.next();
Integer rowId = child.getRowIndex() - 1;
UIContext nodeContext = repeater.getRowContext(rowId);
UIContextHolder.pushContext(nodeContext);
try {
render(component, renderContext);
} finally {
UIContextHolder.popContext();
}
}
}
}
xml.appendEndTag("ui:subtr");
}
}
xml.appendEndTag("ui:tr");
}
use of com.github.bordertech.wcomponents.TableTreeNode in project wcomponents by BorderTech.
the class DataTableOptionsExample method createHierarchicTree.
/**
* @return a tableTreeNode to be used by a hierachic table
*/
private TableTreeNode createHierarchicTree() {
TableTreeNode root = new TableTreeNode(null);
TableTreeNode row1 = new TableTreeNode(new ExampleBean("A1", "H2", "G3"));
TableTreeNode row2 = new TableTreeNode(new ExampleBean("B1", "G2", "E3"));
TableTreeNode row3 = new TableTreeNode(new ExampleBean("C1", "F2", "C3"));
TableTreeNode row4 = new TableTreeNode(new ExampleBean("D1", "E2", "A3"));
TableTreeNode row5 = new TableTreeNode(new ExampleBean("E1", "D2", "B3"));
TableTreeNode row6 = new TableTreeNode(new ExampleBean("F1", "C2", "D3"));
TableTreeNode row7 = new TableTreeNode(new ExampleBean("G1", "B2", "F3"));
TableTreeNode row8 = new TableTreeNode(new ExampleBean("H1", "A2", "H3"));
TableTreeNode child1 = new TableTreeNode(new ExampleBean("A1-A", "A1-B", "A1-C"));
TableTreeNode child2 = new TableTreeNode(new ExampleBean("C1-A", "C1-B", "C1-C"));
TableTreeNode child3 = new TableTreeNode(new ExampleBean("C2-A", "C2-B", "C2-C"));
TableTreeNode child4 = new TableTreeNode(new ExampleBean("G1-A", "G1-B", "G1-C"));
root.add(row1);
root.add(row2);
root.add(row3);
root.add(row4);
root.add(row5);
root.add(row6);
root.add(row7);
root.add(row8);
row1.add(child1);
row3.add(child2);
row3.add(child3);
row7.add(child4);
return root;
}
use of com.github.bordertech.wcomponents.TableTreeNode in project wcomponents by BorderTech.
the class DataTableOptionsExample method copySelection.
/**
* @param table the table with selected items
* @param selected the text field that will contain a copy of the selected item details
*/
private void copySelection(final WDataTable table, final WText selected) {
List<Integer> rows = table.getSelectedRows();
if (rows.isEmpty()) {
selected.setText("No Rows Selected");
} else {
StringBuffer out = new StringBuffer("Selected: ");
TableDataModel data = table.getDataModel();
boolean firstRow = true;
for (Integer rowIdx : rows) {
if (firstRow) {
firstRow = false;
} else {
out.append(", ");
}
ExampleBean bean;
if (data instanceof TreeTableDataModel) {
TableTreeNode node = ((TreeTableDataModel) data).getNodeAtLine(rowIdx.intValue());
bean = (ExampleBean) node.getData();
} else {
ExampleDataModel node = (ExampleDataModel) data;
bean = node.getData().get(rowIdx.intValue());
}
out.append(bean.getColumn1());
}
selected.setText(out.toString());
}
}
use of com.github.bordertech.wcomponents.TableTreeNode in project wcomponents by BorderTech.
the class TreeTableExample method preparePaintComponent.
/**
* {@inheritDoc}
*/
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
if (!isInitialised()) {
TableTreeNode root = createTree();
table.setDataModel(new ExampleTreeTableModel(root));
setInitialised(true);
}
}
Aggregations