aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/table/TableToggleVisibility.java
blob: 22cdf7f312e6805c48c71fc195d09441944440fd (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
162
163
164
165
166
167
168
169
170
171
package com.vaadin.tests.components.table;

import java.text.DecimalFormat;

import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

public class TableToggleVisibility extends AbstractTestCase {

    private static final int[] LENGTHS = new int[] { 20, 22, 10 };

    @Override
    public void init() {

        DecimalFormat format = new DecimalFormat("000");
        Table[] tables = new Table[3];
        Button[] buttons = new Button[3];

        VerticalLayout leftComponent = new VerticalLayout();
        leftComponent.setMargin(true);
        leftComponent.setSpacing(true);

        // Toolbar with buttons to hide or show lists

        HorizontalLayout toolBar = new HorizontalLayout();
        toolBar.setSpacing(true);
        toolBar.setMargin(true);

        leftComponent.addComponent(toolBar);
        leftComponent.setExpandRatio(toolBar, 0.0f);

        // List of trucks -----------------------

        tables[0] = new Table("Trucks");
        tables[0].addContainerProperty("Brand", String.class, null);
        tables[0].addContainerProperty("Model", String.class, null);
        tables[0].addContainerProperty("License Plate", String.class, null);

        for (int i = 1; i < LENGTHS[0]; i++) {
            tables[0].addItem(
                    new Object[] { "MAN", "XYZ", "1-ABC-" + format.format(i) },
                    Integer.valueOf(i));
        }
        tables[0].setPageLength(LENGTHS[0]);

        tables[0].setWidth("100%");
        tables[0].setHeight("100%");
        tables[0].setSelectable(true);

        leftComponent.addComponent(tables[0]);
        leftComponent.setExpandRatio(tables[0], 1.0f);

        // List of trailers ----------------------

        tables[1] = new Table("Trailers");
        tables[1].addContainerProperty("Type", String.class, null);
        tables[1].addContainerProperty("License Plate", String.class, null);
        for (int i = 1; i < LENGTHS[1]; i++) {
            tables[1].addItem(
                    new Object[] { "Cooler", "1-QQQ-" + format.format(i) },
                    Integer.valueOf(i));
        }
        tables[1].setPageLength(LENGTHS[1]);

        tables[1].setWidth("100%");
        tables[1].setHeight("100%");
        tables[1].setSelectable(true);

        leftComponent.addComponent(tables[1]);
        leftComponent.setExpandRatio(tables[1], 1.0f);

        // List of drivers ------------------------

        tables[2] = new Table("Drivers");
        tables[2].addContainerProperty("First Name", String.class, null);
        tables[2].addContainerProperty("Last Name", String.class, null);
        tables[2].addContainerProperty("HR ID", String.class, null);
        for (int i = 1; i < LENGTHS[2]; i++) {
            tables[2].addItem(
                    new Object[] { "King", "Vabis", "HR-" + format.format(i) },
                    Integer.valueOf(i));
        }
        tables[2].setPageLength(LENGTHS[2]);

        tables[2].setWidth("100%");
        tables[2].setHeight("100%");
        tables[2].setSelectable(true);

        leftComponent.addComponent(tables[2]);
        leftComponent.setExpandRatio(tables[2], 1.0f);

        leftComponent.setWidth("100%");

        HorizontalSplitPanel split = new HorizontalSplitPanel();
        split.setFirstComponent(leftComponent);

        VerticalLayout rightComponent = new VerticalLayout();
        rightComponent.setMargin(true);
        rightComponent.addComponent(new Label("Left blank!"));
        split.setSecondComponent(rightComponent);

        split.setSizeFull();

        VerticalLayout mainLayout = new VerticalLayout();
        mainLayout.setSizeFull();
        mainLayout.addComponent(split);
        mainLayout.setExpandRatio(split, 1.0f);

        LegacyWindow mainWindow = new LegacyWindow("Visibilitybug Application",
                mainLayout);
        mainWindow.setSizeFull();

        setMainWindow(mainWindow);

        // complete toolbar

        for (int i = 0; i < buttons.length; i++) {
            buttons[i] = new ToggleButton(tables[i]);
            toolBar.addComponent(buttons[i]);
        }

    }

    // Button to switch the visibility of a table.

    private static class ToggleButton extends Button {

        private Table table;

        private ToggleButton(Table table) {
            this.table = table;

            setCaption("- " + table.getCaption());

            addListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {

                    boolean wasVisible = ToggleButton.this.table.isVisible();

                    ToggleButton.this.table.setVisible(!wasVisible);
                    setCaption((wasVisible ? "+ " : "- ")
                            + ToggleButton.this.table.getCaption());
                    setDescription((wasVisible ? "Show " : "Hide ")
                            + "the list with "
                            + ToggleButton.this.table.getCaption());

                }
            });
        }

    }

    @Override
    protected String getDescription() {
        return "Test for hiding and showing tables. Click a button to show/hide one of the tables. The tables are all 100% wide and should be rendered the same way after being hidden and shown again.";
    }

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

}