Search in sources :

Example 21 with WTable

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

the class WTableOptionsExample method createExpandedDataTable.

/**
 * @return a table that has expanded content.
 */
private WTable createExpandedDataTable() {
    WTable table = new WTable();
    addColumns(table);
    table.setType(WTable.Type.TABLE);
    table.setRowsPerPage(DEFAULT_ROWS_PER_PAGE);
    table.setCaption("Expanded content table caption");
    table.setBeanProperty(".");
    // Define the expandable level. The row will expand if the bean has "extra" details
    LevelDetails level1 = new LevelDetails("documents", TravelDocPanel.class);
    // Setup model with column properties and the "expandable" level
    MyBeanBoundTableModel model = new MyBeanBoundTableModel(new String[] { "firstName", "lastName", "dateOfBirth" }, level1);
    model.setSelectable(true);
    model.setEditable(true);
    model.setComparator(0, SimpleBeanBoundTableModel.COMPARABLE_COMPARATOR);
    model.setComparator(1, SimpleBeanBoundTableModel.COMPARABLE_COMPARATOR);
    table.setTableModel(model);
    return table;
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) LevelDetails(com.github.bordertech.wcomponents.SimpleBeanBoundTableModel.LevelDetails)

Example 22 with WTable

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

the class TableUtil method getCurrentRowIndex.

/**
 * This can be used by column components on a {@link WTable} to determine the current row index.
 *
 * @param component the column component
 * @return the row index for the current row, or null if no row details
 */
public static List<Integer> getCurrentRowIndex(final WComponent component) {
    UIContext uic = UIContextHolder.getCurrent();
    // Check have correct context
    if (!(uic instanceof SubUIContext)) {
        return null;
    }
    // Find the table
    WTable table = WebUtilities.getAncestorOfClass(WTable.class, component);
    if (table == null) {
        return null;
    }
    int repeaterIdx = ((SubUIContext) uic).getRowIndex();
    RowIdWrapper wrapper = table.getRepeater().getBeanList().get(repeaterIdx);
    return wrapper.getRowIndex();
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) UIContext(com.github.bordertech.wcomponents.UIContext) WTable(com.github.bordertech.wcomponents.WTable)

Example 23 with WTable

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

the class WTableRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WTable component = new WTable();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WTableRenderer);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) Test(org.junit.Test)

Example 24 with WTable

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

the class WTableRenderer_Test method testDoPaintPaginatedDynamic.

@Test
public void testDoPaintPaginatedDynamic() 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.setPaginationMode(PaginationMode.DYNAMIC);
    setActiveContext(createUIContext());
    assertXpathEvaluatesTo("dynamic", "//ui:table/ui:pagination/@mode", component);
    assertXpathEvaluatesTo((new Integer(component.getCurrentPage())).toString(), "//ui:table/ui:pagination/@currentPage", component);
    assertXpathEvaluatesTo((new Integer(component.getRowsPerPage())).toString(), "//ui:table/ui:pagination/@rowsPerPage", component);
    assertXpathEvaluatesTo((new Integer(tableModel.getRowCount())).toString(), "//ui:table/ui:pagination/@rows", 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 25 with WTable

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

the class WTableRenderer_Test method testDoPaintSelectModeMultipleSelectAllControl.

@Test
public void testDoPaintSelectModeMultipleSelectAllControl() 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.setSelectAllMode(WTable.SelectAllType.CONTROL);
    assertXpathExists("//ui:table/ui:rowselection", component);
    assertXpathEvaluatesTo(TRUE, "//ui:table/ui:rowselection/@multiple", component);
    assertXpathEvaluatesTo("control", "//ui:table/ui:rowselection/@selectAll", component);
    // toggle not available by default
    assertXpathNotExists("//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