Search in sources :

Example 6 with WTable

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

the class WTableRowRendererRenderer method doRender.

/**
 * Paints the given WTableRowRenderer.
 *
 * @param component the WTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTableRowRenderer renderer = (WTableRowRenderer) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WTable table = renderer.getTable();
    TableModel dataModel = table.getTableModel();
    int[] columnOrder = table.getColumnOrder();
    final int numCols = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    // Get current row details
    RowIdWrapper wrapper = renderer.getCurrentRowIdWrapper();
    List<Integer> rowIndex = wrapper.getRowIndex();
    boolean tableSelectable = table.getSelectMode() != SelectMode.NONE;
    boolean rowSelectable = tableSelectable && dataModel.isSelectable(rowIndex);
    boolean rowSelected = rowSelectable && table.getSelectedRows().contains(wrapper.getRowKey());
    boolean tableExpandable = table.getExpandMode() != WTable.ExpandMode.NONE;
    boolean rowExpandable = tableExpandable && dataModel.isExpandable(rowIndex) && wrapper.hasChildren();
    boolean rowExpanded = rowExpandable && table.getExpandedRows().contains(wrapper.getRowKey());
    String rowIndexAsString = TableUtil.rowIndexListToString(rowIndex);
    xml.appendTagOpen("ui:tr");
    xml.appendAttribute("rowIndex", rowIndexAsString);
    xml.appendOptionalAttribute("unselectable", !rowSelectable, "true");
    xml.appendOptionalAttribute("selected", rowSelected, "true");
    xml.appendOptionalAttribute("expandable", rowExpandable && !rowExpanded, "true");
    xml.appendClose();
    // wrote the column cell.
    // need this before we get into the loop
    boolean isRowHeader = table.isRowHeaders();
    for (int i = 0; i < numCols; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        String cellTag = "ui:td";
        if (col.isVisible()) {
            if (isRowHeader) {
                // The first rendered column will be the row header.
                cellTag = "ui:th";
                // only set one col as the row header.
                isRowHeader = false;
            }
            xml.appendTag(cellTag);
            renderer.getRenderer(colIndex).paint(renderContext);
            xml.appendEndTag(cellTag);
        }
    }
    if (rowExpandable) {
        xml.appendTagOpen("ui:subtr");
        xml.appendOptionalAttribute("open", rowExpanded, "true");
        xml.appendClose();
        if (rowExpanded || table.getExpandMode() == ExpandMode.CLIENT) {
            renderChildren(renderer, renderContext, wrapper.getChildren());
        }
        xml.appendEndTag("ui:subtr");
    }
    xml.appendEndTag("ui:tr");
}
Also used : RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) WTableRowRenderer(com.github.bordertech.wcomponents.WTableRowRenderer) WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 7 with WTable

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

the class WTableRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WTable table = new WTable();
    table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
    table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
    table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
    table.setNoDataMessage(getMaliciousAttribute("ui:table"));
    UIContext uic = createUIContext();
    assertSafeContent(table);
    WButton button = new WButton("dummy");
    table.addAction(button);
    table.addActionConstraint(button, new ActionConstraint(0, 1, false, getMaliciousAttribute("ui:action")));
    assertSafeContent(table);
    TableModel tableModel = createTableModel();
    table.setTableModel(tableModel);
    // clear out cached data from previous renders
    uic.clearScratchMap();
    assertSafeContent(table);
    table.setCaption(getMaliciousAttribute("ui:table"));
    assertSafeContent(table);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) ActionConstraint(com.github.bordertech.wcomponents.WTable.ActionConstraint) WButton(com.github.bordertech.wcomponents.WButton) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 8 with WTable

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

the class WTableRenderer_Test method testDoPaintMissingAttributesColumnStriping.

@Test
public void testDoPaintMissingAttributesColumnStriping() 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));
    component.setTableModel(createTableModel());
    component.setVisible(true);
    component.setStripingType(WTable.StripingType.COLUMNS);
    component.setSeparatorType(WTable.SeparatorType.VERTICAL);
    assertXpathNotExists("//ui:table/@caption", component);
    assertXpathEvaluatesTo("table", "//ui:table/@type", component);
    assertXpathEvaluatesTo("cols", "//ui:table/@striping", component);
    assertXpathEvaluatesTo("vertical", "//ui:table/@separators", component);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 9 with WTable

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

the class WTableRenderer_Test method testDoPaintWithInvisibleColumnAndNoColumnHeaders.

@Test
public void testDoPaintWithInvisibleColumnAndNoColumnHeaders() 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);
    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
    List<Integer> row = new ArrayList<>();
    row.add(0);
    String firstName = (String) tableModel.getValueAt(row, 0);
    String entryDate = (String) tableModel.getValueAt(row, 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 : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) ArrayList(java.util.ArrayList) 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) ActionConstraint(com.github.bordertech.wcomponents.WTable.ActionConstraint) Test(org.junit.Test)

Example 10 with WTable

use of com.github.bordertech.wcomponents.WTable 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);
    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)

Aggregations

WTable (com.github.bordertech.wcomponents.WTable)38 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)30 Test (org.junit.Test)30 WTextField (com.github.bordertech.wcomponents.WTextField)28 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)25 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)23 SimpleTableModel (com.github.bordertech.wcomponents.SimpleTableModel)23 WButton (com.github.bordertech.wcomponents.WButton)5 ActionConstraint (com.github.bordertech.wcomponents.WTable.ActionConstraint)4 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)4 UIContext (com.github.bordertech.wcomponents.UIContext)3 RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)3 ArrayList (java.util.ArrayList)2 Margin (com.github.bordertech.wcomponents.Margin)1 LevelDetails (com.github.bordertech.wcomponents.SimpleBeanBoundTableModel.LevelDetails)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WTableRowRenderer (com.github.bordertech.wcomponents.WTableRowRenderer)1 WText (com.github.bordertech.wcomponents.WText)1