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
|
package com.vaadin.tests.tickets;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Tree;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Reindeer;
public class Ticket1245 extends com.vaadin.Application.LegacyApplication {
TextField f = new TextField();
@Override
public void init() {
final LegacyWindow main = new LegacyWindow(getClass().getName()
.substring(getClass().getName().lastIndexOf(".") + 1));
setMainWindow(main);
main.addComponent(new TreeExample());
}
}
class TreeExample extends CustomComponent {
// Id for the caption property
private static final Object CAPTION_PROPERTY = "caption";
private static final String desc = "non-first tree in non-sized orderedlayout seems to be the problem";
Tree tree;
public TreeExample() {
final VerticalLayout main = new VerticalLayout();
setCompositionRoot(main);
// Panel w/ Tree
main.setStyleName(Reindeer.PANEL_LIGHT);
main.setWidth("200px");
// // Description, this is needed. Works in first slot
main.addComponent(new Label(desc));
// setting either width or height fixes the issue
// p.setWidth(500);
// p.setHeight(800);
// Tree with a few items
tree = new Tree();
tree.setImmediate(true);
// we'll use a property for caption instead of the item id ("value"),
// so that multiple items can have the same caption
tree.addContainerProperty(CAPTION_PROPERTY, String.class, "");
tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
tree.setItemCaptionPropertyId(CAPTION_PROPERTY);
for (int i = 1; i <= 3; i++) {
final Object id = addCaptionedItem("Section " + i, null);
tree.expandItem(id);
addCaptionedItem("Team A", id);
addCaptionedItem("Team B", id);
}
main.addComponent(tree);
}
/**
* Helper to add an item with specified caption and (optional) parent.
*
* @param caption
* The item caption
* @param parent
* The (optional) parent item id
* @return the created item's id
*/
private Object addCaptionedItem(String caption, Object parent) {
// add item, let tree decide id
final Object id = tree.addItem();
// get the created item
final Item item = tree.getItem(id);
// set our "caption" property
@SuppressWarnings("unchecked")
final Property<String> p = (Property<String>) item
.getItemProperty(CAPTION_PROPERTY);
p.setValue(caption);
if (parent != null) {
tree.setChildrenAllowed(parent, true);
tree.setParent(id, parent);
tree.setChildrenAllowed(id, false);
}
return id;
}
}
|