aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/table/MultiSelectWithRemovedRow.java
blob: 2d7b23cbb58de69154bf73a8de398f492a49ca2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.vaadin.tests.components.table;

import java.util.Arrays;
import java.util.Collection;

import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.v7.data.util.BeanItemContainer;
import com.vaadin.v7.ui.Table;

@SuppressWarnings("serial")
public class MultiSelectWithRemovedRow extends TestBase {
    public static class Person {
        private final String name;

        public Person(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    @Override
    protected void setup() {
        final Log log = new Log(5);
        addComponent(log);

        final BeanItemContainer<Person> container = new BeanItemContainer<>(
                Person.class,
                Arrays.asList(new Person("Joe"), new Person("William"),
                        new Person("Jack"), new Person("Averell"),
                        new Person("Bob"), new Person("Grat"),
                        new Person("Bill"), new Person("Emmett")));
        final Table table = new Table("Table", container);
        table.setSelectable(true);
        table.setMultiSelect(true);
        table.setImmediate(true);
        addComponent(table);

        Button showButton = new Button("Show selection");
        showButton.addClickListener(event -> {
            Collection<?> selection = (Collection<?>) table.getValue();
            log.log("Selection: " + selection);
        });
        addComponent(showButton);

        Button removeButton = new Button("Remove selection");
        removeButton.addClickListener(event -> {
            Collection<?> selection = (Collection<?>) table.getValue();
            for (Object selected : selection) {
                container.removeItem(selected);
            }
        });
        addComponent(removeButton);

        addComponent(new Button("Remove first selected row", event -> {
            Collection<?> selection = (Collection<?>) table.getValue();
            if (!selection.isEmpty()) {
                Object firstSelected = selection.iterator().next();
                container.removeItem(firstSelected);
            }
        }));
    }

    @Override
    protected String getDescription() {
        return "Multi select using shift should work after removing the currently selected row";
    }

    @Override
    protected Integer getTicketNumber() {
        return Integer.valueOf(8584);
    }
}