summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/tests/book/TableEditable.java
blob: 78a4b808bd378f772b15e200170866c77aa3d8bd (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
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.vaadin.tests.book;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.OrderedLayout;
import com.vaadin.ui.Table;

public class TableEditable extends CustomComponent {
    /* A layout needed for the example. */
    OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);

    TableEditable() {
        setCompositionRoot(layout);

        // Create a table. It is by default not editable.
        final Table table = new Table();

        // Define the names and data types of columns.
        table.addContainerProperty("Date", Date.class, null);
        table.addContainerProperty("Work", Boolean.class, null);
        table.addContainerProperty("Comments", String.class, null);

        // Add a few items in the table.
        for (int i = 0; i < 100; i++) {
            Calendar calendar = new GregorianCalendar(2008, 0, 1);
            calendar.add(Calendar.DAY_OF_YEAR, i);

            // Create the table row.
            table.addItem(new Object[] { calendar.getTime(),
                    new Boolean(false), "" }, new Integer(i)); // Item
                                                               // identifier
        }

        table.setPageLength(8);
        layout.addComponent(table);

        final CheckBox switchEditable = new CheckBox("Editable");
        switchEditable.addListener(new Property.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                table.setEditable(((Boolean) event.getProperty().getValue())
                        .booleanValue());
            }
        });
        switchEditable.setImmediate(true);
        layout.addComponent(switchEditable);
    }
}