aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/table/ValueAfterClearingContainer.java
blob: eec32c802fd9b032bd944e7223936661110f9c1a (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.vaadin.tests.components.table;

import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Notification;
import com.vaadin.v7.ui.Table;

public class ValueAfterClearingContainer extends TestBase {

    private static final String PROPERTY_ID = "property";

    private Log log = new Log(5);
    private final Table table = new Table();

    @Override
    protected void setup() {
        log.setId("log");
        table.setId("table");
        table.setSelectable(true);
        table.addContainerProperty(PROPERTY_ID, Integer.class, null);
        table.setImmediate(true);
        table.addValueChangeListener(event -> log
                .log("Value changed to " + event.getProperty().getValue()));
        addComponent(log);

        addComponent(table);
        final CheckBox multiselect = new CheckBox("Multiselect");
        multiselect.setId("multiselect");
        multiselect.addValueChangeListener(event -> {
            Boolean value = multiselect.getValue();
            table.setMultiSelect(value == null ? false : value);
        });
        addComponent(multiselect);
        Button addItemsButton = new Button("Add table items", event -> {
            if (!table.getItemIds().isEmpty()) {
                Notification.show("Only possible when the table is empty");
                return;
            }
            for (int i = 0; i < 5; i++) {
                table.addItem(new Object[] { Integer.valueOf(i) },
                        Integer.valueOf(i));
            }
        });
        addItemsButton.setId("addItemsButton");
        addComponent(addItemsButton);

        Button showValueButton = new Button("Show value",
                event -> log.log("Table selection: " + table.getValue()));
        showValueButton.setId("showValueButton");
        addComponent(showValueButton);

        Button removeItemsFromTableButton = new Button(
                "Remove items from table", event -> table.removeAllItems());
        removeItemsFromTableButton.setId("removeItemsFromTableButton");
        addComponent(removeItemsFromTableButton);

        Button removeItemsFromContainerButton = new Button(
                "Remove items from container",
                event -> table.getContainerDataSource().removeAllItems());
        removeItemsFromContainerButton.setId("removeItemsFromContainerButton");
        addComponent(removeItemsFromContainerButton);
        Button removeItemsFromContainerAndSanitizeButton = new Button(
                "Remove items from container and sanitize", event -> {
                    table.getContainerDataSource().removeAllItems();
                    table.sanitizeSelection();
                });
        removeItemsFromContainerAndSanitizeButton
                .setId("removeItemsFromContainerAndSanitizeButton");
        addComponent(removeItemsFromContainerAndSanitizeButton);
        Button removeSelectedFromTableButton = new Button(
                "Remove selected item from table", event -> {
                    Object selection = table.getValue();
                    if (selection == null) {
                        Notification.show("There is no selection");
                        return;
                    }
                    table.removeItem(selection);
                });
        removeSelectedFromTableButton.setId("removeSelectedFromTableButton");
        addComponent(removeSelectedFromTableButton);
        Button removeSelectedFromContainer = new Button(
                "Remove selected item from container", event -> {
                    Object selection = table.getValue();
                    if (selection == null) {
                        Notification.show("There is no selection");
                        return;
                    }
                    table.getContainerDataSource().removeItem(selection);
                });
        removeSelectedFromContainer.setId("removeSelectedFromContainer");
        addComponent(removeSelectedFromContainer);
    }

    @Override
    protected String getDescription() {
        return "Table value should be cleared when the selected item is removed from the container.";
    }

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

}