@Override public void execute(final ActionEvent event) { StringBuffer buf = new StringBuffer(preface); buf.append("\n"); for (Object selected : wTable.getSelectedRows()) { // The Model uses the "bean" as the key PersonBean person = (PersonBean) selected; buf.append(person.toString()).append("\n"); } selectionText.setText(buf.toString()); } };
@Override public void execute(final ActionEvent event) { StringBuffer buf = new StringBuffer(preface); buf.append("\n"); for (Object selected : table.getSelectedRows()) { // The Model uses the "bean" as the key PersonBean person = (PersonBean) selected; buf.append(person.toString()).append('\n'); } selectionText.setText(buf.toString()); } };
/** * @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 WTable table, final WText selected) { Set<?> rows = table.getSelectedRows(); if (rows.isEmpty()) { selected.setText("No Rows Selected"); } else { StringBuffer out = new StringBuffer("Selected: "); boolean firstRow = true; for (Object row : rows) { if (firstRow) { firstRow = false; } else { out.append(", "); } out.append(row); } selected.setText(out.toString()); } }
private int calculateOtherSelectedRows(WTable table) { WTable.TableRepeater repeater = table.getRepeater(); List<RowIdWrapper> wrappers = repeater.getBeanList(); Set<?> otherSelectedRows = new HashSet<>(table.getSelectedRows()); for (RowIdWrapper wrapper : wrappers) { Object rowKey = wrapper.getRowKey(); if (table.getSelectedRows().contains(rowKey)) { otherSelectedRows.remove(rowKey); } } return otherSelectedRows.size(); }
Set<?> otherSelectedRows = new HashSet<>(table.getSelectedRows()); if (table.getSelectedRows().contains(rowKey)) { otherSelectedRows.remove(rowKey);
/** * Test setSelectedRows - null input. */ @Test public void testSetSelectedRowsNull() { WTable table = new WTable(); Set<Object> selectedRows = new HashSet<Object>(Arrays.asList(Arrays.asList(2), Arrays. asList(3))); table.setSelectedRows(null); table.setLocked(true); setActiveContext(createUIContext()); table.setSelectedRows(selectedRows); Assert.assertTrue("Incorrect selected rows", table.getSelectedRows().size() == 2); resetContext(); Assert.assertTrue("Default selected rows should be empty", table.getSelectedRows().size() == 0); }
Set<?> oldSelections = getSelectedRows(); Set<Object> newSelections;
@Test public void testSingleHandleSelectionRequest() { WTable table = new WTable(); table.setSelectMode(WTable.SelectMode.SINGLE); table.setTableModel(createModel(new String[100][1])); table.setLocked(true); setActiveContext(createUIContext()); Set<Object> selected = new HashSet<Object>(Arrays.asList(5, 6, 7)); MockRequest request = new MockRequest(); request.setParameter(table.getId() + "-h", "x"); request.setParameter(table.getId() + ".selected", new String[]{"5", "6", "7"}); table.handleRequest(request); Assert.assertEquals("Should only have selected the first item after handleRequest", 1, table.getSelectedRows() .size()); Assert.assertTrue("Should only have selected the first item after handleRequest", selected.containsAll(table.getSelectedRows())); resetContext(); Assert.assertTrue("Incorrect default selection after handleRequest", table.getSelectedRows().isEmpty()); }
Assert.assertEquals("Incorrect selection after handleRequest", 3, table.getSelectedRows(). size()); Assert .assertTrue("Incorrect selection rows after handleRequest", table.getSelectedRows(). containsAll(selected)); table.getSelectedRows().isEmpty()); getSelectedRows() .isEmpty()); Assert.assertTrue("Incorrect default selection after handleRequest with no selection set", table .getSelectedRows().isEmpty());
7, table.getSelectedRows().size()); Assert.assertEquals("Incorrect number of selections on other pages after more selections", 3, otherSelectedRows); 9, table.getSelectedRows().size()); Assert.assertEquals("Incorrect number of selections on other pages after page change", 7, otherSelectedRows); 7, table.getSelectedRows().size()); Assert.assertEquals("Incorrect number of selections on other pages after page change", 5, otherSelectedRows); otherSelectedRows = calculateOtherSelectedRows(table); Assert.assertEquals("Incorrect number of total selections pages after page change", 7, table.getSelectedRows().size()); Assert.assertEquals("Incorrect number of selections on other pages after page change", 4, otherSelectedRows);
boolean rowSelected = rowSelectable && table.getSelectedRows().contains(wrapper.getRowKey());