use of com.github.bordertech.wcomponents.WDataTable in project wcomponents by BorderTech.
the class TreeTableHierarchyExample method createTable.
/**
* Creates and configures the table to be used by the example. The table is configured with global rather than user
* data. Although this is not a realistic scenario, it will suffice for this example.
*
* @return a new configured table.
*/
private WDataTable createTable() {
WDataTable tbl = new WDataTable();
tbl.setType(WDataTable.Type.HIERARCHIC);
tbl.addColumn(new WTableColumn("First name", new WText()));
tbl.addColumn(new WTableColumn("Last name", new WText()));
tbl.addColumn(new WTableColumn("DOB", new WDateField()));
tbl.setExpandMode(ExpandMode.CLIENT);
tbl.setStripingType(WDataTable.StripingType.ROWS);
TableTreeNode root = createTree();
tbl.setDataModel(new ExampleTreeTableModel(root));
return tbl;
}
use of com.github.bordertech.wcomponents.WDataTable in project wcomponents by BorderTech.
the class WDataTableRenderer method doRender.
/**
* Paints the given WDataTable.
*
* @param component the WDataTable to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDataTable table = (WDataTable) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:table");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", table.isHidden(), "true");
xml.appendOptionalAttribute("caption", table.getCaption());
switch(table.getType()) {
case TABLE:
xml.appendAttribute("type", "table");
break;
case HIERARCHIC:
xml.appendAttribute("type", "hierarchic");
break;
default:
throw new SystemException("Unknown table type: " + table.getType());
}
switch(table.getStripingType()) {
case ROWS:
xml.appendAttribute("striping", "rows");
break;
case COLUMNS:
xml.appendAttribute("striping", "cols");
break;
case NONE:
break;
default:
throw new SystemException("Unknown striping type: " + table.getStripingType());
}
switch(table.getSeparatorType()) {
case HORIZONTAL:
xml.appendAttribute("separators", "horizontal");
break;
case VERTICAL:
xml.appendAttribute("separators", "vertical");
break;
case BOTH:
xml.appendAttribute("separators", "both");
break;
case NONE:
break;
default:
throw new SystemException("Unknown separator type: " + table.getSeparatorType());
}
xml.appendClose();
if (table.getPaginationMode() != PaginationMode.NONE) {
paintPaginationElement(table, xml);
}
if (table.getSelectMode() != SelectMode.NONE) {
paintRowSelectionElement(table, xml);
}
if (table.getExpandMode() != ExpandMode.NONE) {
paintRowExpansionElement(table, xml);
}
if (table.isSortable()) {
paintSortElement(table, xml);
}
paintColumnHeadings(table, renderContext);
paintRows(table, renderContext);
paintTableActions(table, renderContext);
xml.appendEndTag("ui:table");
}
use of com.github.bordertech.wcomponents.WDataTable in project wcomponents by BorderTech.
the class WDataTableRenderer method paintTableActions.
/**
* Paints the table actions of the table.
*
* @param table the table to paint the table actions for.
* @param renderContext the RenderContext to paint to.
*/
private void paintTableActions(final WDataTable table, final WebXmlRenderContext renderContext) {
XmlStringBuilder xml = renderContext.getWriter();
List<WButton> tableActions = table.getActions();
if (!tableActions.isEmpty()) {
boolean hasActions = false;
for (WButton button : tableActions) {
if (!button.isVisible()) {
continue;
}
if (!hasActions) {
hasActions = true;
xml.appendTag("ui:actions");
}
xml.appendTag("ui:action");
List<WDataTable.ActionConstraint> constraints = table.getActionConstraints(button);
if (constraints != null) {
for (WDataTable.ActionConstraint constraint : constraints) {
int minRows = constraint.getMinSelectedRowCount();
int maxRows = constraint.getMaxSelectedRowCount();
String message = constraint.getMessage();
String type = constraint.isError() ? "error" : "warning";
xml.appendTagOpen("ui:condition");
xml.appendOptionalAttribute("minSelectedRows", minRows > 0, minRows);
xml.appendOptionalAttribute("maxSelectedRows", maxRows > 0, maxRows);
xml.appendAttribute("type", type);
xml.appendAttribute("message", I18nUtilities.format(null, message));
xml.appendEnd();
}
}
button.paint(renderContext);
xml.appendEndTag("ui:action");
}
if (hasActions) {
xml.appendEndTag("ui:actions");
}
}
}
use of com.github.bordertech.wcomponents.WDataTable in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testDoPaintWithInvisibleColumnAndNoColumnHeaders.
@Test
public void testDoPaintWithInvisibleColumnAndNoColumnHeaders() throws IOException, SAXException, XpathException {
WDataTable component = new WDataTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
TableDataModel tableDataModel = createTableModel();
component.setDataModel(tableDataModel);
component.setVisible(true);
final int testColIndex = 1;
final boolean testShowColHeaders = false;
component.getColumn(testColIndex).setVisible(false);
component.setShowColumnHeaders(testShowColHeaders);
// head hidden=true
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/@hidden", component);
// column headers - only COL1 and COL3 showing - in positions 1 and 2 respectively - only 2 cols
assertXpathEvaluatesTo(COL1_HEADING_TEST, "//ui:table/ui:thead/ui:th[1]/ui:decoratedlabel/ui:labelbody", component);
assertXpathEvaluatesTo(COL3_HEADING_TEST, "//ui:table/ui:thead/ui:th[2]/ui:decoratedlabel/ui:labelbody", component);
assertXpathNotExists("//ui:table/ui:thead/ui:th[3]/ui:decoratedlabel/ui:labelbody", component);
// first row - col1 and col3 from model in positions 1 and 2 respectively - only 2 cols showing
String firstName = (String) tableDataModel.getValueAt(0, 0);
String entryDate = (String) tableDataModel.getValueAt(0, 2);
assertXpathEvaluatesTo(firstName, "//ui:table/ui:tbody/ui:tr[1]/ui:td[1]/ui:textfield", component);
assertXpathEvaluatesTo(entryDate, "//ui:table/ui:tbody/ui:tr[1]/ui:td[2]/ui:textfield", component);
assertXpathNotExists("//ui:table/ui:tbody/ui:tr[1]/ui:td[3]/ui:textfield", component);
}
use of com.github.bordertech.wcomponents.WDataTable in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testDoPaintTableActionsInvisibleButton.
@Test
public void testDoPaintTableActionsInvisibleButton() throws IOException, SAXException, XpathException {
WDataTable component = new WDataTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
TableDataModel tableModel = createTableModel();
component.setDataModel(tableModel);
component.setVisible(true);
WButton button1 = new WButton(TEST_ACTION_ONE);
component.addAction(button1);
// Visible
assertXpathExists("//ui:table/ui:actions", component);
// Not Visible
button1.setVisible(false);
assertXpathNotExists("//ui:table/ui:actions", component);
}
Aggregations