Search in sources :

Example 26 with WDataTable

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;
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WText(com.github.bordertech.wcomponents.WText) WDataTable(com.github.bordertech.wcomponents.WDataTable) WDateField(com.github.bordertech.wcomponents.WDateField)

Example 27 with WDataTable

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");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WDataTable(com.github.bordertech.wcomponents.WDataTable) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 28 with WDataTable

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");
        }
    }
}
Also used : WDataTable(com.github.bordertech.wcomponents.WDataTable) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Example 29 with WDataTable

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);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) Test(org.junit.Test)

Example 30 with WDataTable

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);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

WDataTable (com.github.bordertech.wcomponents.WDataTable)41 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)38 WTextField (com.github.bordertech.wcomponents.WTextField)29 Test (org.junit.Test)28 SimpleTableDataModel (com.github.bordertech.wcomponents.SimpleTableDataModel)23 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)23 WText (com.github.bordertech.wcomponents.WText)8 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)5 WButton (com.github.bordertech.wcomponents.WButton)5 ActionConstraint (com.github.bordertech.wcomponents.WDataTable.ActionConstraint)4 WDateField (com.github.bordertech.wcomponents.WDateField)4 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)3 UIContext (com.github.bordertech.wcomponents.UIContext)2 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)1