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.

MoveGridAndAddRow.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.vaadin.tests.components.grid;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.vaadin.data.ValueProvider;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.tests.components.AbstractTestUIWithLog;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.Grid;
  9. import com.vaadin.ui.HorizontalLayout;
  10. import com.vaadin.ui.Label;
  11. import com.vaadin.ui.VerticalLayout;
  12. public class MoveGridAndAddRow extends AbstractTestUIWithLog {
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. final VerticalLayout layout = new VerticalLayout();
  16. final VerticalLayout anotherLayout = new VerticalLayout();
  17. anotherLayout.addComponent(new Label("This is another layout"));
  18. final Grid<String> grid = new Grid<>();
  19. grid.addColumn(ValueProvider.identity()).setCaption("A");
  20. List<String> items = new ArrayList<>();
  21. items.add("1");
  22. grid.setItems(items);
  23. final Button button = new Button("Add row and remove this button");
  24. button.setId("add");
  25. button.addClickListener(event -> {
  26. items.add("2");
  27. grid.setItems(items);
  28. button.setVisible(false);
  29. });
  30. Button move = new Button("Move grid to other layout");
  31. move.setId("move");
  32. move.addClickListener(event -> anotherLayout.addComponent(grid));
  33. layout.addComponents(button, move, grid);
  34. addComponent(new HorizontalLayout(layout, anotherLayout));
  35. }
  36. }