summaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/tests/tickets/Ticket2104.java
blob: b4fe9ce7e93f9fc228435964c721c5f9b72e0024 (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
package com.itmill.toolkit.tests.tickets;

import com.itmill.toolkit.Application;
import com.itmill.toolkit.data.util.MethodProperty;
import com.itmill.toolkit.event.ItemClickEvent;
import com.itmill.toolkit.event.ItemClickEvent.ItemClickListener;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Table;
import com.itmill.toolkit.ui.Tree;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;

public class Ticket2104 extends Application {

    private static final Label info = new Label(
            "Click event should _always_ come trough. Switching features on/off should immediatly affect the tree (verify w/ debug window)",
            Label.CONTENT_RAW);

    Tree tree = new Tree();
    Table table = new Table();

    @Override
    public void init() {
        Window main = new Window();
        setMainWindow(main);

        main.addComponent(info);

        OrderedLayout ol = new OrderedLayout(
                OrderedLayout.ORIENTATION_HORIZONTAL);
        main.addComponent(ol);
        Button b = new Button("immediate",
                new MethodProperty(tree, "immediate"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("selectable", new MethodProperty(tree, "selectable"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("nullsel", new MethodProperty(tree,
                "nullSelectionAllowed"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("multi", new MethodProperty(tree, "multiSelect"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("icon", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                if (tree.getItemIconPropertyId() == null) {
                    tree.setItemIconPropertyId("icon");
                } else {
                    tree.setItemIconPropertyId(null);
                }

            }
        });
        ol.addComponent(b);

        main.addComponent(tree);
        tree.setImmediate(true);
        tree.setNullSelectionAllowed(false);
        tree.addItem("Root 1");
        tree.addItem("1. Child 1");
        tree.setParent("1. Child 1", "Root 1");
        tree.addItem("1. Child 2");
        tree.setParent("1. Child 2", "Root 1");
        tree.addItem("Root 2");
        tree.addItem("2. Child 1");
        tree.setParent("2. Child 1", "Root 2");
        tree.addItem("2. Child 2");
        tree.setParent("2. Child 2", "Root 2");
        tree.addContainerProperty("icon", ExternalResource.class,
                new ExternalResource(
                        "http://www.itmill.com/res/images/itmill_logo.gif"));

        tree.addListener(new ItemClickListener() {
            public void itemClick(ItemClickEvent event) {
                getMainWindow().addComponent(
                        new Label(event.toString() + " // " + event.getItemId()
                                + "//" + event.getSource()));

            }
        });

        ol = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
        main.addComponent(ol);
        b = new Button("immediate", new MethodProperty(table, "immediate"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("selectable", new MethodProperty(table, "selectable"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("nullsel", new MethodProperty(table,
                "nullSelectionAllowed"));
        b.setImmediate(true);
        ol.addComponent(b);
        b = new Button("multi", new MethodProperty(table, "multiSelect"));
        b.setImmediate(true);
        ol.addComponent(b);
        main.addComponent(table);
        table.setWidth("150px");
        table.setImmediate(true);
        table.setSelectable(true);
        table.setNullSelectionAllowed(false);
        for (int i = 0; i < 10; i++) {
            table.addItem("Item " + i);
        }
        table.addListener(new ItemClickListener() {
            public void itemClick(ItemClickEvent event) {
                getMainWindow().addComponent(
                        new Label(event.toString() + " // " + event.getItemId()
                                + "//" + event.getSource()));

            }
        });
        table.addContainerProperty("Column", String.class, "value");
    }

}