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

import com.vaadin.Application;
import com.vaadin.data.Container;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
public class ComboBoxReapperingOldValue extends Application.LegacyApplication
        implements ValueChangeListener {

    ComboBox cbox1 = new ComboBox();
    ComboBox cbox2 = new ComboBox();

    @Override
    public void init() {
        LegacyWindow mainWindow = new LegacyWindow("ComboBoxCacheTest");
        setMainWindow(mainWindow);

        VerticalLayout layout = new VerticalLayout();

        Label lbl = new Label(
                "try selecting value 1 from the first combo box, so that the second combo box will be populated. select a value in second combo box."
                        + "then select a new value from combo box one, after that click on the second combo box. The old selected value appears.");
        layout.addComponent(lbl);

        cbox1.setCaption("Com Box 1");
        cbox1.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
        cbox1.setContainerDataSource(getContainer());
        cbox1.setImmediate(true);
        cbox1.setNullSelectionAllowed(false);
        cbox1.addListener(this);

        layout.addComponent(cbox1);
        layout.addComponent(cbox2);

        cbox2.setCaption("Com Box 2");
        cbox2.setEnabled(false);
        cbox2.setNullSelectionAllowed(false);

        mainWindow.setContent(layout);

    }

    private Container getContainer() {
        IndexedContainer container = new IndexedContainer();
        container.addContainerProperty("na", String.class, null);

        for (int i = 0; i < 10; i++) {
            container.addItem(i);
        }
        return container;
    }

    @Override
    public void valueChange(ValueChangeEvent event) {
        cbox2.removeAllItems();
        if ("1".equals(event.getProperty().getValue().toString())) {
            cbox2.setEnabled(true);
            cbox2.setContainerDataSource(getContainer());
        }
    }

}