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 package info.magnolia.ui.vaadin.layout;
35
36 import java.util.ArrayList;
37 import java.util.Iterator;
38 import java.util.List;
39
40 import org.apache.commons.lang3.StringUtils;
41
42 import com.vaadin.shared.ui.ContentMode;
43 import com.vaadin.ui.Component;
44 import com.vaadin.ui.CssLayout;
45 import com.vaadin.ui.Label;
46 import com.vaadin.ui.VerticalLayout;
47
48
49
50
51 public class SmallAppLayout extends VerticalLayout {
52
53 private final CssLayout sectionsLayout = new CssLayout();
54
55 private final CssLayout descriptionLayout = new CssLayout();
56 private final Label description = new Label();
57
58 public SmallAppLayout() {
59 addStyleName("smallapp");
60 setSizeFull();
61 setSpacing(false);
62 setMargin(false);
63
64 description.addStyleName("smallapp-description");
65 description.setContentMode(ContentMode.HTML);
66 descriptionLayout.addStyleName("smallapp-description-layout");
67 descriptionLayout.setVisible(false);
68 descriptionLayout.addComponent(description);
69
70 sectionsLayout.addStyleName("smallapp-sections");
71 sectionsLayout.setSizeFull();
72
73 addComponents(descriptionLayout, sectionsLayout);
74 setExpandRatio(descriptionLayout, 0f);
75 setExpandRatio(sectionsLayout, 1f);
76 }
77
78 @Override
79 public String getDescription() {
80 return description.getValue();
81 }
82
83 @Override
84 public void setDescription(String description) {
85 this.description.setValue(description);
86 this.descriptionLayout.setVisible(StringUtils.isNoneBlank(description));
87 }
88
89 public List<Component> getSections() {
90 Iterator<Component> it = sectionsLayout.iterator();
91 List<Component> sections = new ArrayList<>();
92 while (it.hasNext()) {
93 sections.add(it.next());
94 }
95 return sections;
96 }
97
98
99
100
101 public void addSection(Component section, String sectionTitle) {
102 section.setCaption(sectionTitle);
103 addSection(section);
104 }
105
106
107
108
109 public void addSection(Component section) {
110 section.addStyleName("smallapp-section");
111 sectionsLayout.addComponent(section);
112 }
113
114 public void removeSection(Component section) {
115 sectionsLayout.removeComponent(section);
116 }
117 }