aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/TestContainerChanges.java
blob: 8b40d787d614be453d827d91a5641bc260b98d40 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
 *
 */
package com.vaadin.tests;

import com.vaadin.ui.Button;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.util.ContainerHierarchicalWrapper;
import com.vaadin.v7.data.util.ContainerOrderedWrapper;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.ListSelect;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.Tree;
import com.vaadin.v7.ui.themes.Reindeer;

/**
 * @author marc
 *
 */
public class TestContainerChanges extends CustomComponent {
    Container cont = new IndexedContainer();
    Container hierarchical = new ContainerHierarchicalWrapper(cont);
    Container ordered = new ContainerOrderedWrapper(cont);

    int cnt = 0;
    Table tbl;

    public TestContainerChanges() {

        cont.addContainerProperty("Asd", String.class, "qwe");
        cont.addContainerProperty("Bar", String.class, "foo");

        VerticalLayout main = new VerticalLayout();
        setCompositionRoot(main);

        main.addComponent(new Label(
                "The same IndexedContainer is wrapped in a ordered/hierarchical wrapper and is set as data source for all components . The buttons only affect the 'original' IndexedContainer."));

        HorizontalLayout h = new HorizontalLayout();

        main.addComponent(h);

        VerticalLayout v = new VerticalLayout();
        h.addComponent(v);
        tbl = new Table();
        tbl.setHeight("200px");
        tbl.setWidth("300px");
        v.addComponent(tbl);
        tbl.setSelectable(true);
        tbl.setMultiSelect(false);
        tbl.setImmediate(true);
        tbl.setEditable(true);
        tbl.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
        // Original container
        tbl.setContainerDataSource(hierarchical);

        Table tbl2 = new Table();
        tbl2.setHeight("200px");
        tbl2.setWidth("300px");
        v.addComponent(tbl2);
        tbl2.setSelectable(true);
        tbl2.setMultiSelect(false);
        tbl2.setImmediate(true);
        tbl2.addValueChangeListener(event -> System.err
                .println("Value now " + event.getProperty().getValue()));
        tbl2.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
        // non-ordered container will get wrapped
        tbl2.setContainerDataSource(hierarchical);

        VerticalLayout buttons = new VerticalLayout();
        v.addComponent(buttons);

        Button b = new Button("table.commit()", event -> tbl.commit());
        buttons.addComponent(b);

        b = new Button("indexedcontainer.addItem()",
                event -> cont.addItem(new Integer(cnt++)));
        buttons.addComponent(b);
        b = new Button("indexedcontainer.addItem(null)",
                event -> cont.addItem(null));
        buttons.addComponent(b);
        b = new Button("indexedcontainer.removeItem(table.lastItemId()",
                event -> cont.removeItem(tbl.lastItemId()));
        buttons.addComponent(b);

        b = new Button("indexedcontainer.addContainerProperty()",
                event -> cont.addContainerProperty("prop" + cnt, String.class,
                        "#" + cnt++));
        buttons.addComponent(b);

        b = new Button("indexedcontainer.clear()",
                event -> cont.removeAllItems());
        buttons.addComponent(b);
        b = new Button("table.setContainerDataSource(indexedcontainer)",
                event -> tbl.setContainerDataSource(cont));
        buttons.addComponent(b);
        b = new Button("table.setContainerDataSource(orderedwrapper)",
                event -> tbl.setContainerDataSource(ordered));
        buttons.addComponent(b);
        b = new Button("table.setContainerDataSource(hierarchicalwrapper)",
                event -> tbl.setContainerDataSource(hierarchical));
        buttons.addComponent(b);

        VerticalLayout pl = createPanelLayout();
        Panel p = new Panel("Tree", pl);
        p.setStyleName(Reindeer.PANEL_LIGHT);
        h.addComponent(p);
        Tree tree = new Tree("ITEM_CAPTION_MODE_PROPERTY");
        tree.setContainerDataSource(ordered);
        tree.setItemCaptionPropertyId("Asd");
        tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY);
        pl.addComponent(tree);
        tree = new Tree("ITEM_CAPTION_MODE_ITEM");
        // nonhierarchical container will get wrapped
        tree.setContainerDataSource(ordered);
        tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_ITEM);
        pl.addComponent(tree);

        pl = createPanelLayout();
        p = new Panel("ComboBox", pl);
        p.setStyleName(Reindeer.PANEL_LIGHT);
        h.addComponent(p);
        ComboBox c = new ComboBox("ITEM_CAPTION_MODE_PROPERTY");
        c.setImmediate(true);
        c.setContainerDataSource(cont);
        c.setItemCaptionPropertyId("Asd");
        c.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
        pl.addComponent(c);
        c = new ComboBox("ITEM_CAPTION_MODE_ITEM");
        c.setImmediate(true);
        c.setContainerDataSource(cont);
        c.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_ITEM);
        pl.addComponent(c);

        pl = createPanelLayout();
        p = new Panel("ListBox", pl);
        p.setStyleName(Reindeer.PANEL_LIGHT);
        h.addComponent(p);
        ListSelect l = new ListSelect("ITEM_CAPTION_MODE_PROPERTY");
        l.setContainerDataSource(cont);
        l.setItemCaptionPropertyId("Asd");
        l.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
        pl.addComponent(l);
        l = new ListSelect("ITEM_CAPTION_MODE_ITEM");
        l.setContainerDataSource(cont);
        l.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_ITEM);
        pl.addComponent(l);
    }

    private VerticalLayout createPanelLayout() {
        VerticalLayout pl = new VerticalLayout();
        pl.setMargin(true);
        return pl;
    }
}