summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tickets/Ticket2009.java
blob: f641c507dfbe4a8c7692a181fbcb223fb9812113 (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
package com.vaadin.tests.tickets;

import com.vaadin.data.Container;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.tests.TestForTablesInitialColumnWidthLogicRendering;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Tree;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class Ticket2009 extends com.vaadin.Application {

    TextField f = new TextField();

    @Override
    public void init() {
        final LegacyWindow main = new LegacyWindow(getClass().getName()
                .substring(getClass().getName().lastIndexOf(".") + 1));
        setMainWindow(main);

        HorizontalLayout ol = new HorizontalLayout();
        main.setContent(ol);
        ol.setSizeFull();

        Panel p = new Panel("Tree test");
        p.setSizeFull();

        Tree t = new Tree();

        t.addItem("Foo");
        t.addItem("Bar");

        final VerticalLayout events = new VerticalLayout();

        t.addListener(new ItemClickEvent.ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                events.addComponent(new Label(new Label("Click:"
                        + (event.isDoubleClick() ? "double" : "single")
                        + " button:" + event.getButton() + " propertyId:"
                        + event.getPropertyId() + " itemID:"
                        + event.getItemId() + " item:" + event.getItem())));

            }
        });

        main.addComponent(p);
        p.addComponent(t);
        p.addComponent(events);

        Panel p2 = new Panel("Table test (try dbl click also)");
        p2.setSizeFull();

        final VerticalLayout events2 = new VerticalLayout();
        Table table = TestForTablesInitialColumnWidthLogicRendering
                .getTestTable(5, 100);
        table.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
        table.addListener(new ItemClickEvent.ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                events2.addComponent(new Label("Click:"
                        + (event.isDoubleClick() ? "double" : "single")
                        + " button:" + event.getButton() + " propertyId:"
                        + event.getPropertyId() + " itemID:"
                        + event.getItemId() + " item:" + event.getItem()));
                if (event.isDoubleClick()) {
                    new PropertyEditor(event);
                }

            }
        });
        p2.addComponent(table);
        p2.addComponent(events2);

        main.addComponent(p2);

    }

    class PropertyEditor extends Window {

        private static final int W = 300;
        private static final int H = 150;

        private Container c;
        private Object itemid;
        private Object propertyid;

        TextField editor = new TextField();
        Button done = new Button("Done");

        PropertyEditor(ItemClickEvent event) {
            c = (Container) event.getSource();

            propertyid = event.getPropertyId();
            itemid = event.getItemId();

            setCaption("Editing " + itemid + " : " + propertyid);

            editor.setPropertyDataSource(c.getContainerProperty(itemid,
                    propertyid));
            addComponent(editor);
            addComponent(done);

            setWidth(W + "px");
            setHeight(H + "px");

            setPositionX(event.getClientX() - W / 2);
            setPositionY(event.getClientY() - H / 2);

            getMainWindow().addWindow(this);

            done.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    getMainWindow().removeWindow(PropertyEditor.this);
                }
            });

        }

    }

}