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.

ProgrammaticUnselectInRange.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.data.Property;
  3. import com.vaadin.data.Property.ValueChangeEvent;
  4. import com.vaadin.tests.components.TestBase;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Button.ClickEvent;
  7. import com.vaadin.ui.Label;
  8. import com.vaadin.ui.Table;
  9. public class ProgrammaticUnselectInRange extends TestBase {
  10. private static final String PROPERTY = "property";
  11. final Label selectionLabel = new Label();
  12. final Table table = new Table();
  13. @Override
  14. protected void setup() {
  15. table.addContainerProperty(PROPERTY, Integer.class, "");
  16. table.setMultiSelect(true);
  17. table.setSelectable(true);
  18. table.setImmediate(true);
  19. table.setPageLength(5);
  20. for (int i = 0; i < 5; i++) {
  21. Integer value = Integer.valueOf(i + 1);
  22. table.addItem(new Object[] { value }, value);
  23. }
  24. table.addListener(new Property.ValueChangeListener() {
  25. @Override
  26. public void valueChange(ValueChangeEvent event) {
  27. updateSelectionLabel();
  28. }
  29. });
  30. addComponent(table);
  31. addComponent(selectionLabel);
  32. addComponent(new Button("Deselect item 2", new Button.ClickListener() {
  33. @Override
  34. public void buttonClick(ClickEvent event) {
  35. table.unselect(Integer.valueOf(2));
  36. }
  37. }));
  38. updateSelectionLabel();
  39. }
  40. private void updateSelectionLabel() {
  41. if (table.isSelected(Integer.valueOf(2))) {
  42. selectionLabel.setValue("Item 2 is selected");
  43. } else {
  44. selectionLabel.setValue("Item 2 is not selected");
  45. }
  46. }
  47. @Override
  48. protected String getDescription() {
  49. return "Selecting items 1 - 3 using shift click, deselecting item 2 using the button and selecting item 5 using ctrl should keep item 2 deselected according to the server";
  50. }
  51. @Override
  52. protected Integer getTicketNumber() {
  53. // TODO Auto-generated method stub
  54. return null;
  55. }
  56. }