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.framework.databinding.layout;
35
36 import com.vaadin.ui.FormLayout;
37 import com.vaadin.ui.TabSheet;
38 import com.vaadin.ui.themes.ValoTheme;
39
40 import java.util.Map;
41
42 import org.apache.commons.lang3.StringUtils;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46 import com.vaadin.ui.Component;
47
48
49
50
51
52 public class TabbedLayoutProducer implements LayoutProducer<TabbedLayoutDefinition> {
53 private static final Logger log = LoggerFactory.getLogger(TabbedLayoutProducer.class);
54 @Override
55 public Component createLayout(TabbedLayoutDefinition definition, Map<String, Component> mappings) {
56 TabSheet tabSheetComponent = new TabSheet();
57 tabSheetComponent.addStyleName(ValoTheme.TABSHEET_FRAMED);
58 tabSheetComponent.setSizeFull();
59
60 if (definition.getTabs().size() == 1) {
61 tabSheetComponent.addStyleName("single-tab");
62 }
63
64 definition.getTabs().forEach(tabDefinition -> {
65 FormLayout formSection = new FormLayout();
66 formSection.setMargin(true);
67 formSection.setSizeFull();
68 tabDefinition.getFields().forEach(field -> {
69 final Component fieldComponent = mappings.get(field.getName());
70 if (fieldComponent != null) {
71 formSection.addComponent(fieldComponent);
72
73 } else {
74 log.warn(String.format("Could not retrieve component field named %s from mappings", field.getName()));
75 }
76 });
77 tabSheetComponent.addTab(formSection, StringUtils.defaultIfBlank(tabDefinition.getLabel(), tabDefinition.getName()));
78
79 });
80 return tabSheetComponent;
81 }
82 }