Search in sources :

Example 1 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer method paintColumnHeadings.

/**
 * Paints the column headings for the given table.
 *
 * @param table the table to paint the headings for.
 * @param renderContext the RenderContext to paint to.
 */
private void paintColumnHeadings(final WTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    int[] columnOrder = table.getColumnOrder();
    TableModel model = table.getTableModel();
    final int columnCount = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    xml.appendTagOpen("ui:thead");
    xml.appendOptionalAttribute("hidden", !table.isShowColumnHeaders(), "true");
    xml.appendClose();
    for (int i = 0; i < columnCount; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            boolean sortable = model.isSortable(colIndex);
            paintColumnHeading(col, sortable, renderContext);
        }
    }
    xml.appendEndTag("ui:thead");
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 2 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer method paintColumnHeaderFooter.

/**
 * Paints the column headings for the given table.
 *
 * @param table the table to paint the headings for.
 * @param renderContext the RenderContext to paint to.
 * @param renderHeaders true if rendering headers otherwise render footers
 */
private void paintColumnHeaderFooter(final WTable table, final WebXmlRenderContext renderContext, final boolean renderHeaders) {
    XmlStringBuilder xml = renderContext.getWriter();
    int[] columnOrder = table.getColumnOrder();
    TableModel model = table.getTableModel();
    final int columnCount = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    if (renderHeaders) {
        // Headers
        xml.appendTagOpen("ui:thead");
        xml.appendOptionalAttribute("hidden", !table.isShowColumnHeaders(), "true");
        xml.appendClose();
    } else {
        // Footers
        xml.appendTag("tfoot");
        xml.appendTag("tr");
        // Allow for expandable column
        if (table.getExpandMode() != ExpandMode.NONE) {
            xml.appendTag("td");
            xml.appendEndTag("td");
        }
        // Allow for selectable column
        if (table.getSelectMode() != SelectMode.NONE) {
            xml.appendTag("td");
            xml.appendEndTag("td");
        }
    }
    for (int i = 0; i < columnCount; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            if (renderHeaders) {
                // Header
                boolean sortable = model.isSortable(colIndex);
                paintColumnHeading(col, sortable, renderContext);
            } else {
                // Footer
                paintColumnFooting(col, renderContext);
            }
        }
    }
    if (renderHeaders) {
        xml.appendEndTag("ui:thead");
    } else {
        xml.appendEndTag("tr");
        xml.appendEndTag("tfoot");
    }
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 3 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer_Test method testDoPaintExpandModeDynamic.

@Test
public void testDoPaintExpandModeDynamic() throws IOException, SAXException, XpathException {
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(tableModel);
    component.setVisible(true);
    component.setExpandMode(ExpandMode.DYNAMIC);
    assertSchemaMatch(component);
    assertXpathEvaluatesTo("dynamic", "//ui:table/ui:rowexpansion/@mode", component);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 4 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer_Test method testDoPaintToggleSubRowSelection.

@Test
public void testDoPaintToggleSubRowSelection() throws IOException, SAXException, XpathException {
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(tableModel);
    component.setVisible(true);
    component.setSelectMode(WTable.SelectMode.MULTIPLE);
    component.setToggleSubRowSelection(true);
    component.setExpandMode(ExpandMode.CLIENT);
    assertSchemaMatch(component);
    assertXpathExists("//ui:table/ui:rowselection", component);
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:rowselection/@toggle", component);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 5 with TableModel

use of com.github.bordertech.wcomponents.WTable.TableModel in project wcomponents by BorderTech.

the class WTableRenderer_Test method testDoPaintSelectModeSingle.

@Test
public void testDoPaintSelectModeSingle() throws IOException, SAXException, XpathException {
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(tableModel);
    component.setVisible(true);
    component.setSelectMode(WTable.SelectMode.SINGLE);
    assertSchemaMatch(component);
    assertXpathExists("//ui:table/ui:rowselection", component);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Aggregations

TableModel (com.github.bordertech.wcomponents.WTable.TableModel)31 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)27 WTable (com.github.bordertech.wcomponents.WTable)26 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)24 SimpleTableModel (com.github.bordertech.wcomponents.SimpleTableModel)24 Test (org.junit.Test)24 WTextField (com.github.bordertech.wcomponents.WTextField)23 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 WButton (com.github.bordertech.wcomponents.WButton)4 ActionConstraint (com.github.bordertech.wcomponents.WTable.ActionConstraint)4 UIContext (com.github.bordertech.wcomponents.UIContext)2 RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)2 WText (com.github.bordertech.wcomponents.WText)2 ArrayList (java.util.ArrayList)2 WComponent (com.github.bordertech.wcomponents.WComponent)1 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 WTableRowRenderer (com.github.bordertech.wcomponents.WTableRowRenderer)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1