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
|
package com.vaadin.tests.tickets;
import com.vaadin.LegacyApplication;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI.LegacyWindow;
public class Ticket124 extends LegacyApplication {
private TextField tf;
private GridLayout gl;
@Override
public void init() {
LegacyWindow w = new LegacyWindow(
"#124: Insert & remove row for GridLayout");
setMainWindow(w);
setTheme("tests-tickets");
// gl = new GridLayout(4, 4);
gl = new GridLayout(2, 2);
tf = new TextField("Row nr");
Button insert = new Button("Insert row", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
insertRow();
}
});
Button delete = new Button("Delete row", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
deleteRow();
}
});
// gl.addComponent(new Label("0-0"), 0, 0);
// gl.addComponent(new Label("0-1"), 1, 0);
gl.addComponent(new Label("1-0"), 1, 0);
gl.addComponent(new Label("1-1"), 1, 1);
gl.addComponent(new Label("0,0-1,0"), 0, 0, 1, 0);
gl.addComponent(new Label("2,0-3,0"), 2, 0, 3, 0);
Label l = new Label("Large cell 0,1-2,2<br/>yadayada<br/>lorem ipsum");
l.setContentMode(ContentMode.HTML);
gl.addComponent(l, 0, 1, 2, 2);
gl.addComponent(new Label("3-1"), 3, 1);
gl.addComponent(new Label("3,2-3,3"), 3, 2, 3, 3);
gl.addComponent(tf, 0, 3);
gl.addComponent(insert, 1, 3);
gl.addComponent(delete, 2, 3);
gl.setStyleName("border");
w.addComponent(gl);
}
protected void deleteRow() {
int pos = Integer.parseInt(tf.getValue().toString());
gl.removeRow(pos);
}
protected void clearRow() {
int pos = Integer.parseInt(tf.getValue().toString());
for (int col = 0; col < gl.getColumns(); col++) {
try {
gl.removeComponent(col, pos);
} catch (Exception e) {
e.printStackTrace();
}
}
}
protected void insertRow() {
int pos = Integer.parseInt(tf.getValue().toString());
gl.insertRow(pos);
try {
TextField t = new TextField("", "Newly added row");
t.setWidth("100%");
gl.addComponent(t, 0, pos, 3, pos);
} catch (Exception e) {
// TODO: handle exception
}
}
}
|