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

import java.util.Date;

import com.vaadin.Application;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PopupView;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;

public class Ticket1397 extends Application {

    Window main;

    @Override
    public void init() {
        setTheme("default");
        main = new Window("PopupView test");
        setMainWindow(main);
        Panel panel = new Panel("PopupTest");

        // First test component
        final ObjectProperty prop = new ObjectProperty("fooTextField");

        PopupView.Content content = new PopupView.Content() {
            public String getMinimizedValueAsHTML() {
                return prop.toString();
            }

            public Component getPopupComponent() {
                return new TextField("Edit foo", prop);
            }
        };

        PopupView pe = new PopupView(content);
        pe.setDescription("Click to edit");
        panel.addComponent(pe);

        // Second test component
        PopupView pe2 = new PopupView("fooLabel", new Label("Foooooooooo..."));
        pe2.setDescription("Click to view");
        panel.addComponent(pe2);

        // Third test component
        final ObjectProperty prop2 = new ObjectProperty(new StringBuffer(
                "Text for button"));

        class myButton extends Button {
            public myButton() {
                super("Reverse the property");
                this.addListener(new Button.ClickListener() {
                    public void buttonClick(Button.ClickEvent event) {
                        StringBuffer getContents = (StringBuffer) prop2
                                .getValue();
                        getContents.reverse();

                    }
                });
            }
        }

        final Panel panel2 = new Panel("Editor with a button");
        panel2.addComponent(new myButton());
        PopupView.Content content2 = new PopupView.Content() {
            public String getMinimizedValueAsHTML() {
                return prop2.toString();
            }

            public Component getPopupComponent() {
                return panel2;
            }
        };

        PopupView p3 = new PopupView(content2);
        panel.addComponent(p3);

        // Fourth test component
        final Panel panel3 = new Panel("Editor popup for a property");
        TextField tf2 = new TextField("TextField for editing a property");
        final ObjectProperty op = new ObjectProperty("This is property text.");
        tf2.setPropertyDataSource(op);
        panel3.addComponent(tf2);
        PopupView.Content content3 = new PopupView.Content() {

            public String getMinimizedValueAsHTML() {
                return op.toString();
            }

            public Component getPopupComponent() {
                return panel3;
            }

        };
        PopupView p4 = new PopupView(content3);
        panel.addComponent(p4);

        // Fifth test component
        Table table = new Table("Table for testing purposes");
        for (int i = 0; i < 5; i++) {
            table.addContainerProperty("" + (i + 1), String.class, "");
        }
        table.addContainerProperty("" + 6, PopupView.class, null);
        table.addContainerProperty("" + 7, PopupView.class, null);
        table.setPageLength(20);
        for (int i = 0; i < 1000; i++) {

            final InlineDateField df = new InlineDateField("", new Date());
            PopupView pp = new PopupView(new PopupView.Content() {
                public String getMinimizedValueAsHTML() {
                    return df.toString();
                }

                public Component getPopupComponent() {
                    return df;
                }
            });
            final int lineNum = i;
            PopupView pp2 = new PopupView(new PopupView.Content() {

                TextField tf = new TextField("Editor for line " + lineNum,

                "Try to edit the contents for this textfield on line "
                        + lineNum
                        + " and see how the overview-version changes.");

                public String getMinimizedValueAsHTML() {
                    return "" + tf.toString().length() + " characters of info";
                }

                public Component getPopupComponent() {
                    return tf;
                }

            });
            table.addItem(new Object[] { "1 " + i, "2 " + i, "3 " + i,
                    "4 " + i, "5 " + i, pp, pp2 }, new Integer(i));
        }

        main.addComponent(table);
        main.addComponent(panel);
    }
}