blob: 892505306a64db486b8f8bad8658446fe5eebee2 (
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
|
package com.vaadin.tests.tickets;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import java.util.Set;
import com.vaadin.LegacyApplication;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.UserError;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
public class Ticket2181 extends LegacyApplication implements
Button.ClickListener {
// private static final Object PROPERTY_VALUE = new Object();
// private static final Object PROPERTY_CAPTION = new Object();
private static final String caption = "This is a caption which is very long and nice and perhaps sometimes should be clipped";
LegacyWindow main = new LegacyWindow("#2181 test");
TextField tf1 = new TextField(caption, "Test field - undefined width");
TextField tf2 = new TextField(caption, "Test field - 150px wide");
Button setButton = new Button("Set", this);
private Random random = new Random(123);
private OptionGroup options;
private static ArrayList<String> icons = new ArrayList<String>();
static {
icons.add("icons/64/ok.png");
icons.add("icons/64/arrow-down.png");
icons.add("icons/64/arrow-left.png");
icons.add("icons/64/arrow-right.png");
icons.add("icons/64/arrow-up.png");
}
@Override
public void init() {
setMainWindow(main);
VerticalLayout ol;
ol = new VerticalLayout();
ol.addComponent(tf1);
main.addComponent(ol);
ol = new VerticalLayout();
ol.setWidth("150px");
tf2.setWidth("150px");
ol.addComponent(tf2);
main.addComponent(ol);
main.addComponent(createSelection());
main.addComponent(setButton);
}
private Component createSelection() {
options = new OptionGroup();
options.addItem("Icon");
options.addItem("Caption");
options.addItem("Required");
options.addItem("Error");
options.setMultiSelect(true);
options.select("Caption");
// ol.addComponent(og);
return options;
}
@Override
public void buttonClick(ClickEvent event) {
if (event.getButton() == setButton) {
set();
}
}
private void set() {
@SuppressWarnings("unchecked")
Set<String> values = (Set<String>) options.getValue();
TextField[] tfs = new TextField[] { tf1, tf2 };
for (TextField tf : tfs) {
// Clear all
tf.setCaption(null);
tf.setComponentError(null);
tf.setRequired(false);
tf.setIcon(null);
for (String value : values) {
if (value.equals("Caption")) {
tf.setCaption(caption);
} else if (value.equals("Icon")) {
String timestamp = String.valueOf(new Date().getTime());
tf.setIcon(new ThemeResource(icons.get(random.nextInt(icons
.size())) + "?" + timestamp));
} else if (value.equals("Required")) {
tf.setRequired(true);
} else if (value.equals("Error")) {
tf.setComponentError(new UserError("Nooooo..."));
}
}
}
}
}
|