summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/table/Footer.java
blob: cf6c3b6185dc26c4b84ec4a8726ce0bc0060caca (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
package com.vaadin.tests.components.table;

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

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

    @Override
    protected void setup() {
        HorizontalLayout layout = new HorizontalLayout();
        layout.setSpacing(true);

        final Table table = new Table();
        table.setWidth("400px");
        table.setHeight("400px");

        table.setContainerDataSource(createContainer());
        table.setImmediate(true);

        table.setColumnCollapsingAllowed(true);
        table.setColumnReorderingAllowed(true);

        table.setFooterVisible(true);

        table.setColumnFooter("col1", "Footer1");
        table.setColumnFooter("col2", "Footer2");
        table.setColumnFooter("col3", "Footer3");

        table.setColumnAlignment("col2", Table.ALIGN_CENTER);
        table.setColumnAlignment("col3", Table.ALIGN_RIGHT);

        layout.addComponent(table);

        // Add some options to play with
        VerticalLayout options = new VerticalLayout();
        options.setSpacing(true);

        final CheckBox visible = new CheckBox("Footers Visible", true);
        visible.setImmediate(true);
        visible.addListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                table.setFooterVisible(visible.getValue());

            }
        });

        options.addComponent(visible);

        final TextField footer1Value = new TextField(null, "Footer1");
        footer1Value.setImmediate(true);
        Button footer1Btn = new Button("Change", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                table.setColumnFooter("col1",
                        footer1Value.getValue() == null ? "" : footer1Value
                                .getValue().toString());
            }
        });
        HorizontalLayout footer1 = new HorizontalLayout();
        footer1.addComponent(footer1Value);
        footer1.addComponent(footer1Btn);
        options.addComponent(footer1);

        final TextField footer2Value = new TextField(null, "Footer2");
        footer2Value.setImmediate(true);
        Button footer2Btn = new Button("Change", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                table.setColumnFooter("col2",
                        footer2Value.getValue() == null ? "" : footer2Value
                                .getValue().toString());
            }
        });
        HorizontalLayout footer2 = new HorizontalLayout();
        footer2.addComponent(footer2Value);
        footer2.addComponent(footer2Btn);
        options.addComponent(footer2);

        final TextField footer3Value = new TextField(null, "Footer3");
        footer3Value.setImmediate(true);
        Button footer3Btn = new Button("Change", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                table.setColumnFooter("col3",
                        footer3Value.getValue() == null ? "" : footer3Value
                                .getValue().toString());
            }
        });
        HorizontalLayout footer3 = new HorizontalLayout();
        footer3.addComponent(footer3Value);
        footer3.addComponent(footer3Btn);
        options.addComponent(footer3);

        layout.addComponent(options);

        addComponent(layout);
    }

    @Override
    protected String getDescription() {
        return "Table with footer";
    }

    @Override
    protected Integer getTicketNumber() {
        return 1553;
    }

    private Container createContainer() {
        IndexedContainer container = new IndexedContainer();
        container.addContainerProperty("col1", String.class, "");
        container.addContainerProperty("col2", String.class, "");
        container.addContainerProperty("col3", String.class, "");

        for (int i = 0; i < 100; i++) {
            Item item = container.addItem("item " + i);
            item.getItemProperty("col1").setValue("first" + i);
            item.getItemProperty("col2").setValue("middle" + i);
            item.getItemProperty("col3").setValue("last" + i);
        }

        return container;
    }

}