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.

DisallowedDeselection.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.vaadin.tests.components.grid;
  2. import com.vaadin.data.ValueProvider;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractTestUI;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Grid;
  7. import com.vaadin.ui.Grid.SelectionMode;
  8. import com.vaadin.ui.components.grid.GridSelectionModel;
  9. import com.vaadin.ui.components.grid.SingleSelectionModelImpl;
  10. /**
  11. * @author Vaadin Ltd
  12. *
  13. */
  14. public class DisallowedDeselection extends AbstractTestUI {
  15. @Override
  16. protected void setup(VaadinRequest request) {
  17. Grid<String> grid = new Grid<>();
  18. grid.addColumn(ValueProvider.identity());
  19. grid.setItems("a", "b");
  20. GridSelectionModel<String> model = grid
  21. .setSelectionMode(SelectionMode.SINGLE);
  22. SingleSelectionModelImpl<?> singleSelectionModel = (SingleSelectionModelImpl<?>) model;
  23. singleSelectionModel.setDeselectAllowed(false);
  24. addComponent(grid);
  25. Button allowDeselection = new Button("Allow deselection",
  26. event -> singleSelectionModel.setDeselectAllowed(true));
  27. addComponent(allowDeselection);
  28. }
  29. }