@Override
public void onRequest() {
final PFlexTable flexTable1 = new PFlexTable();
flexTable1.ensureDebugId("flexTable1");
final PLabel cell11 = new PLabel("Cell_1_1");
cell11.ensureDebugId("cell11");
flexTable1.setWidget(0, 0, new PLabel("Cell_0_0"));
flexTable1.setWidget(0, 1, new PLabel("Cell_0_1"));
flexTable1.setWidget(1, 0, new PLabel("Cell_1_0"));
flexTable1.setWidget(1, 1, cell11);
flexTable1.setBorderWidth(1);
flexTable1.setCellPadding(2);
flexTable1.setCellSpacing(3);
PRootPanel.get().add(flexTable1);
register(flexTable1);
register(cell11);
}
});
WebElement flexTable1 = findElementById("flexTable1");
Assert.assertEquals(flexTable1.getAttribute("border"), "1");
Assert.assertEquals(flexTable1.getAttribute("cellPadding"), "2");
Assert.assertEquals(flexTable1.getAttribute("cellSpacing"), "3");
List<WebElement> rows = flexTable1.findElements(By.tagName("tr"));
Assert.assertEquals(rows.size(), 2);
List<WebElement> cells = flexTable1.findElements(By.tagName("td"));
Assert.assertEquals(cells.size(), 4);
Assert.assertEquals(cells.get(0).getText(), "Cell_0_0");
final PFlexTable pFlexTable1 = get("flexTable1");
Assert.assertEquals(2, pFlexTable1.getRowCount());
Assert.assertEquals(2, pFlexTable1.getCellCount(0));
// clear cell, insert new elements
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PFlexTable flexTable1 = get("flexTable1");
final PLabel cell11 = get("cell11");
flexTable1.remove(cell11);
flexTable1.insertRow(0);
flexTable1.setWidget(0, 0, new PLabel("Cell_2_0"));
flexTable1.setWidget(0, 1, new PLabel("Cell_2_1"));
flexTable1.setWidget(3, 0, new PLabel("Cell_3_0"));
flexTable1.setWidget(3, 1, new PLabel("Cell_3_1"));
}
});
flexTable1 = findElementById("flexTable1");
rows = flexTable1.findElements(By.tagName("tr"));
Assert.assertEquals(rows.size(), 4);
cells = flexTable1.findElements(By.tagName("td"));
Assert.assertEquals(cells.size(), 8);
Assert.assertEquals(cells.get(0).getText(), "Cell_2_0");
Assert.assertEquals(cells.get(1).getText(), "Cell_2_1");
Assert.assertEquals(cells.get(2).getText(), "Cell_0_0");
Assert.assertEquals(cells.get(3).getText(), "Cell_0_1");
Assert.assertEquals(cells.get(4).getText(), "Cell_1_0");
Assert.assertEquals(cells.get(5).getText(), "");
Assert.assertEquals(cells.get(6).getText(), "Cell_3_0");
Assert.assertEquals(cells.get(7).getText(), "Cell_3_1");
Assert.assertEquals(4, pFlexTable1.getRowCount());
Assert.assertEquals(2, pFlexTable1.getCellCount(0));
// remove row, add/remove row style, add/remove column style, add/remove cell style
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PFlexTable flexTable1 = get("flexTable1");
flexTable1.removeRow(2);
flexTable1.getRowFormatter().addStyleName(1, "row1");
flexTable1.getRowFormatter().addStyleName(2, "row2");
flexTable1.getRowFormatter().addStyleName(2, "row2bis");
flexTable1.getRowFormatter().addStyleName(2, "row2ter");
flexTable1.getRowFormatter().removeStyleName(2, "row2bis");
flexTable1.getColumnFormatter().addStyleName(0, "col0");
flexTable1.getColumnFormatter().addStyleName(1, "col1");
flexTable1.getColumnFormatter().addStyleName(1, "col1bis");
flexTable1.getColumnFormatter().addStyleName(1, "col1ter");
flexTable1.getColumnFormatter().removeStyleName(1, "col1bis");
flexTable1.getCellFormatter().addStyleName(1, 1, "cell11");
flexTable1.getCellFormatter().addStyleName(2, 0, "cell20");
flexTable1.getCellFormatter().addStyleName(2, 0, "cell20bis");
flexTable1.getCellFormatter().addStyleName(2, 0, "cell20ter");
flexTable1.getCellFormatter().removeStyleName(2, 0, "cell20bis");
}
});
flexTable1 = findElementById("flexTable1");
rows = flexTable1.findElements(By.tagName("tr"));
cells = flexTable1.findElements(By.tagName("td"));
final List<WebElement> cols = flexTable1.findElements(By.tagName("col"));
Assert.assertEquals(3, rows.size());
Assert.assertEquals(6, cells.size());
Assert.assertEquals(2, cols.size());
Assert.assertTrue(rows.get(1).getAttribute("class").contains("row1"));
Assert.assertTrue(rows.get(2).getAttribute("class").contains("row2"));
Assert.assertTrue(rows.get(2).getAttribute("class").contains("row2ter"));
Assert.assertTrue(!rows.get(2).getAttribute("class").contains("row2bis"));
Assert.assertTrue(cols.get(0).getAttribute("class").contains("col0"));
Assert.assertTrue(cols.get(1).getAttribute("class").contains("col1"));
Assert.assertTrue(cols.get(1).getAttribute("class").contains("col1ter"));
Assert.assertTrue(!cols.get(1).getAttribute("class").contains("col1bis"));
Assert.assertTrue(cells.get(3).getAttribute("class").contains("cell11"));
Assert.assertTrue(cells.get(4).getAttribute("class").contains("cell20"));
Assert.assertTrue(cells.get(4).getAttribute("class").contains("cell20ter"));
Assert.assertTrue(!cells.get(4).getAttribute("class").contains("cell20bis"));
final PLabel cell00 = (PLabel) pFlexTable1.getWidget(0, 0);
final PLabel cell31 = (PLabel) pFlexTable1.getWidget(2, 1);
Assert.assertEquals("Cell_2_0", cell00.getText());
Assert.assertEquals("Cell_3_1", cell31.getText());
// colspan / rowspan
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PFlexTable flexTable1 = get("flexTable1");
flexTable1.setWidget(3, 0, new PLabel("Cell_4_0"));
flexTable1.setWidget(4, 0, new PLabel("Cell_5_0"));
flexTable1.setWidget(4, 1, new PLabel("Cell_5_1"));
flexTable1.setWidget(5, 0, new PLabel("Cell_6_0"));
flexTable1.getFlexCellFormatter().setColSpan(3, 0, 2);
flexTable1.getFlexCellFormatter().setRowSpan(4, 1, 2);
}
});