Search in sources :

Example 11 with TableDataModel

use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.

the class WDataTableRenderer_Test method testDoPaintExpandModeDynamic.

@Test
public void testDoPaintExpandModeDynamic() 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);
    component.setExpandMode(ExpandMode.DYNAMIC);
    assertXpathEvaluatesTo("dynamic", "//ui:table/ui:rowexpansion/@mode", 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) Test(org.junit.Test)

Example 12 with TableDataModel

use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.

the class WDataTableRenderer_Test method testDoPaintSelectModeMultipleSelectAllText.

@Test
public void testDoPaintSelectModeMultipleSelectAllText() 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);
    component.setSelectMode(WDataTable.SelectMode.MULTIPLE);
    component.setSelectAllMode(WDataTable.SelectAllType.TEXT);
    assertXpathExists("//ui:table/ui:rowselection", component);
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:rowselection/@multiple", component);
    assertXpathEvaluatesTo("text", "//ui:table/ui:rowselection/@selectAll", 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) Test(org.junit.Test)

Example 13 with TableDataModel

use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.

the class WDataTableRenderer_Test method testDoPaintTableActionsWithConstraints.

@Test
public void testDoPaintTableActionsWithConstraints() throws IOException, SAXException, XpathException {
    final int minSelectedRowCount1 = 1;
    final int maxSelectedRowCount1 = 2;
    final String message1 = "message1";
    final int minSelectedRowCount2 = 1;
    final int maxSelectedRowCount2 = 2;
    final String message2 = "message2";
    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 buttonOne = new WButton(TEST_ACTION_ONE);
    WButton buttonTwo = new WButton(TEST_ACTION_TWO);
    component.addAction(buttonOne);
    component.addAction(buttonTwo);
    component.addActionConstraint(buttonOne, new ActionConstraint(minSelectedRowCount1, maxSelectedRowCount1, true, message1));
    component.addActionConstraint(buttonTwo, new ActionConstraint(minSelectedRowCount2, maxSelectedRowCount2, false, message2));
    assertXpathExists("//ui:table/ui:actions", component);
    assertXpathEvaluatesTo(TEST_ACTION_ONE, "//ui:table/ui:actions/ui:action[1]/html:button", component);
    assertXpathEvaluatesTo(TEST_ACTION_TWO, "//ui:table/ui:actions/ui:action[2]/html:button", component);
    String expectedWarning = "error";
    assertXpathEvaluatesTo(((new Integer(minSelectedRowCount1))).toString(), "//ui:table/ui:actions/ui:action[1]/ui:condition/@minSelectedRows", component);
    assertXpathEvaluatesTo(((new Integer(maxSelectedRowCount1))).toString(), "//ui:table/ui:actions/ui:action[1]/ui:condition/@maxSelectedRows", component);
    assertXpathEvaluatesTo(expectedWarning, "//ui:table/ui:actions/ui:action[1]/ui:condition/@type", component);
    assertXpathEvaluatesTo(message1, "//ui:table/ui:actions/ui:action[1]/ui:condition/@message", component);
    expectedWarning = "warning";
    assertXpathEvaluatesTo(((new Integer(minSelectedRowCount2))).toString(), "//ui:table/ui:actions/ui:action[2]/ui:condition/@minSelectedRows", component);
    assertXpathEvaluatesTo(((new Integer(maxSelectedRowCount2))).toString(), "//ui:table/ui:actions/ui:action[2]/ui:condition/@maxSelectedRows", component);
    assertXpathEvaluatesTo(expectedWarning, "//ui:table/ui:actions/ui:action[2]/ui:condition/@type", component);
    assertXpathEvaluatesTo(message2, "//ui:table/ui:actions/ui:action[2]/ui:condition/@message", component);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) Test(org.junit.Test)

Example 14 with TableDataModel

use of com.github.bordertech.wcomponents.TableDataModel 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());
    }
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) AbstractTreeTableDataModel(com.github.bordertech.wcomponents.AbstractTreeTableDataModel) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) AbstractTableDataModel(com.github.bordertech.wcomponents.AbstractTableDataModel) AbstractTreeTableDataModel(com.github.bordertech.wcomponents.AbstractTreeTableDataModel) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel)

Example 15 with TableDataModel

use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.

the class WDataTableRenderer method doPaintRows.

/**
 * Override paintRow so that we only paint the first-level nodes for tree-tables.
 *
 * @param table the table to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
private void doPaintRows(final WDataTable table, final WebXmlRenderContext renderContext) {
    TableDataModel model = table.getDataModel();
    WRepeater repeater = table.getRepeater();
    List<?> beanList = repeater.getBeanList();
    final int rowCount = beanList.size();
    WComponent row = repeater.getRepeatedComponent();
    for (int i = 0; i < rowCount; i++) {
        if (model instanceof TreeTableDataModel) {
            Integer nodeIdx = (Integer) beanList.get(i);
            TableTreeNode node = ((TreeTableDataModel) model).getNodeAtLine(nodeIdx);
            if (node.getLevel() != 1) {
                // Handled by the layout, so don't paint the row.
                continue;
            }
        }
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = repeater.getRowContext(beanList.get(i), i);
        UIContextHolder.pushContext(rowContext);
        try {
            row.paint(renderContext);
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) UIContext(com.github.bordertech.wcomponents.UIContext) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WRepeater(com.github.bordertech.wcomponents.WRepeater)

Aggregations

TableDataModel (com.github.bordertech.wcomponents.TableDataModel)28 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)24 WDataTable (com.github.bordertech.wcomponents.WDataTable)23 SimpleTableDataModel (com.github.bordertech.wcomponents.SimpleTableDataModel)22 Test (org.junit.Test)22 WTextField (com.github.bordertech.wcomponents.WTextField)21 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)6 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)4 WButton (com.github.bordertech.wcomponents.WButton)4 ActionConstraint (com.github.bordertech.wcomponents.WDataTable.ActionConstraint)4 UIContext (com.github.bordertech.wcomponents.UIContext)3 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)3 WComponent (com.github.bordertech.wcomponents.WComponent)2 WRepeater (com.github.bordertech.wcomponents.WRepeater)2 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)2 AbstractTableDataModel (com.github.bordertech.wcomponents.AbstractTableDataModel)1 AbstractTreeTableDataModel (com.github.bordertech.wcomponents.AbstractTreeTableDataModel)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WText (com.github.bordertech.wcomponents.WText)1