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

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.FooterClickEvent;
import com.vaadin.ui.Table.FooterClickListener;
import com.vaadin.ui.Table.HeaderClickEvent;
import com.vaadin.ui.Table.HeaderClickListener;

public class HeaderFooterClickLeftRightMiddle extends TestBase {

    private Log log = new Log(10);

    @Override
    protected void setup() {
        final Table table = new Table();
        table.setColumnReorderingAllowed(true);
        table.setContainerDataSource(createContainer());
        table.setWidth("400px");
        table.setHeight("400px");
        table.setImmediate(true);
        table.setFooterVisible(true);

        CheckBox immediateCheckbox = new CheckBox("Immediate");
        immediateCheckbox.setImmediate(true);
        immediateCheckbox.setValue(table.isImmediate());
        immediateCheckbox.addListener(new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                table.setImmediate((Boolean) event.getProperty().getValue());
            }
        });

        CheckBox headerClickListenerCheckbox = new CheckBox(
                "Header click listener");
        headerClickListenerCheckbox.setImmediate(true);
        headerClickListenerCheckbox.addListener(new ValueChangeListener() {

            private HeaderClickListener headerClickListener = new HeaderClickListener() {

                @Override
                public void headerClick(HeaderClickEvent event) {
                    String type = event.isDoubleClick() ? "Double click"
                            : "Click";
                    log.log(type + " on header "
                            + event.getPropertyId().toString() + " using "
                            + event.getButtonName());
                }

            };

            @Override
            public void valueChange(ValueChangeEvent event) {
                if (table.getListeners(HeaderClickEvent.class).isEmpty()) {
                    table.addListener(headerClickListener);
                } else {
                    table.removeListener(headerClickListener);
                }
            }
        });
        headerClickListenerCheckbox.setValue(true);

        CheckBox footerClickListenerCheckbox = new CheckBox(
                "Footer click listener");
        footerClickListenerCheckbox.setImmediate(true);
        footerClickListenerCheckbox.addListener(new ValueChangeListener() {

            private FooterClickListener footerClickListener = new FooterClickListener() {

                @Override
                public void footerClick(FooterClickEvent event) {
                    String type = event.isDoubleClick() ? "Double click"
                            : "Click";
                    log.log(type + " on footer "
                            + event.getPropertyId().toString() + " using "
                            + event.getButtonName());
                }
            };

            @Override
            public void valueChange(ValueChangeEvent event) {
                if (table.getListeners(FooterClickEvent.class).isEmpty()) {
                    table.addListener(footerClickListener);
                } else {
                    table.removeListener(footerClickListener);
                }
            }
        });
        footerClickListenerCheckbox.setValue(true);

        CheckBox sortEnabledCheckbox = new CheckBox("Sortable");
        sortEnabledCheckbox.setImmediate(true);
        sortEnabledCheckbox.setValue(table.isSortEnabled());
        sortEnabledCheckbox.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                table.setSortEnabled((Boolean) event.getProperty().getValue());
            }
        });

        CheckBox columnReorderingCheckbox = new CheckBox(
                "Column reordering allowed");
        columnReorderingCheckbox.setImmediate(true);
        columnReorderingCheckbox.setValue(table.isColumnReorderingAllowed());
        columnReorderingCheckbox.addListener(new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                table.setColumnReorderingAllowed((Boolean) event.getProperty()
                        .getValue());
            }
        });

        addComponent(immediateCheckbox);
        addComponent(headerClickListenerCheckbox);
        addComponent(footerClickListenerCheckbox);
        addComponent(sortEnabledCheckbox);
        addComponent(columnReorderingCheckbox);
        addComponent(table);
        addComponent(log);

    }

    @Override
    protected String getDescription() {
        return "Tests the header click listener";
    }

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

    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;
    }

}