You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultiSelectWithRemovedRow.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.vaadin.tests.components.table;
  2. import java.util.Arrays;
  3. import java.util.Collection;
  4. import com.vaadin.tests.components.TestBase;
  5. import com.vaadin.tests.util.Log;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.v7.data.util.BeanItemContainer;
  8. import com.vaadin.v7.ui.Table;
  9. @SuppressWarnings("serial")
  10. public class MultiSelectWithRemovedRow extends TestBase {
  11. public static class Person {
  12. private final String name;
  13. public Person(String name) {
  14. this.name = name;
  15. }
  16. public String getName() {
  17. return name;
  18. }
  19. @Override
  20. public String toString() {
  21. return name;
  22. }
  23. }
  24. @Override
  25. protected void setup() {
  26. final Log log = new Log(5);
  27. addComponent(log);
  28. final BeanItemContainer<Person> container = new BeanItemContainer<>(
  29. Person.class,
  30. Arrays.asList(new Person("Joe"), new Person("William"),
  31. new Person("Jack"), new Person("Averell"),
  32. new Person("Bob"), new Person("Grat"),
  33. new Person("Bill"), new Person("Emmett")));
  34. final Table table = new Table("Table", container);
  35. table.setSelectable(true);
  36. table.setMultiSelect(true);
  37. table.setImmediate(true);
  38. addComponent(table);
  39. Button showButton = new Button("Show selection");
  40. showButton.addClickListener(event -> {
  41. Collection<?> selection = (Collection<?>) table.getValue();
  42. log.log("Selection: " + selection);
  43. });
  44. addComponent(showButton);
  45. Button removeButton = new Button("Remove selection");
  46. removeButton.addClickListener(event -> {
  47. Collection<?> selection = (Collection<?>) table.getValue();
  48. for (Object selected : selection) {
  49. container.removeItem(selected);
  50. }
  51. });
  52. addComponent(removeButton);
  53. addComponent(new Button("Remove first selected row", event -> {
  54. Collection<?> selection = (Collection<?>) table.getValue();
  55. if (!selection.isEmpty()) {
  56. Object firstSelected = selection.iterator().next();
  57. container.removeItem(firstSelected);
  58. }
  59. }));
  60. }
  61. @Override
  62. protected String getDescription() {
  63. return "Multi select using shift should work after removing the currently selected row";
  64. }
  65. @Override
  66. protected Integer getTicketNumber() {
  67. return Integer.valueOf(8584);
  68. }
  69. }