aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxDataSourceChange.java
blob: afbb1b4e48b93c843210c968203f1ee40ab87663 (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
package com.vaadin.tests.components.combobox;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.Table;

@SuppressWarnings("serial")
public class ComboBoxDataSourceChange extends TestBase {

    private ComboBox cb2;

    @Override
    protected void setup() {
        final IndexedContainer ds1 = new IndexedContainer();
        // ds1.addContainerProperty("caption", String.class, "");
        for (int i = 0; i < 32; i++) {
            ds1.addItem("ds1-" + i);
        }

        final IndexedContainer ds2 = new IndexedContainer();
        // ds2.addContainerProperty("caption", String.class, "");
        for (int i = 0; i < 32; i++) {
            ds2.addItem("ds2-" + i);
        }

        HorizontalLayout hl = new HorizontalLayout();
        hl.setWidth("100%");

        cb2 = new ComboBox();
        cb2.setImmediate(true);
        hl.addComponent(cb2);
        HorizontalLayout state = new HorizontalLayout();
        state.setSpacing(true);
        hl.addComponent(state);

        final Label currentValue = new Label();
        currentValue.setCaption("Current Value:");
        currentValue.setSizeUndefined();
        final Label currentDS = new Label();
        currentDS.setCaption("Current DS:");
        currentDS.setSizeUndefined();
        state.addComponent(currentValue);
        state.addComponent(currentDS);

        Table t = new Table("ds1");
        t.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
        t.setContainerDataSource(ds1);
        state.addComponent(t);

        Button b = new Button("Use ds1");
        b.addClickListener(event -> {
            cb2.setContainerDataSource(ds1);
            currentDS.setValue("ds1");
        });
        state.addComponent(b);

        t = new Table("ds2");
        t.setContainerDataSource(ds2);
        t.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
        state.addComponent(t);

        b = new Button("Use ds2");
        b.addClickListener(event -> {
            cb2.setContainerDataSource(ds2);
            currentDS.setValue("ds2");
        });
        state.addComponent(b);

        addComponent(hl);

        cb2.addValueChangeListener(event -> currentValue
                .setValue(String.valueOf(event.getProperty().getValue())));
    }

    @Override
    protected String getDescription() {
        return "A test for combobox and its container changes.";
    }

    @Override
    protected Integer getTicketNumber() {
        // TODO should be list of integers applies for #5279
        return 4607;
    }

}