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.form;
35
36 import info.magnolia.ui.vaadin.gwt.client.form.formsection.connector.FormSectionState;
37 import info.magnolia.ui.vaadin.gwt.client.form.rpc.FormSectionClientRpc;
38
39 import java.util.Iterator;
40 import java.util.LinkedList;
41 import java.util.List;
42
43 import com.vaadin.shared.Connector;
44 import com.vaadin.ui.AbstractLayout;
45 import com.vaadin.ui.Component;
46 import com.vaadin.v7.ui.AbstractField;
47
48
49
50
51 public class FormSection extends AbstractLayout {
52
53 private final List<Component> components = new LinkedList<Component>();
54
55 private String name;
56
57 public FormSection() {
58 addStyleName("v-form-layout");
59 }
60
61 @Override
62 protected FormSectionState getState() {
63 return (FormSectionState) super.getState();
64 }
65
66 @Override
67 protected FormSectionState getState(boolean markAsDirty) {
68 return (FormSectionState) super.getState(markAsDirty);
69 }
70
71 public void setComponentHelpDescription(Component c, String description) {
72 if (components.contains(c)) {
73 getState().helpDescriptions.put(c, description);
74 } else {
75 throw new IllegalArgumentException("Layout doesn't contain this component.");
76 }
77 }
78
79 @Override
80 public void addComponent(Component c) {
81 super.addComponent(c);
82 components.add(c);
83 c.addStyleName("v-form-field");
84 markAsDirty();
85 }
86
87 @Override
88 public void removeComponent(Component c) {
89 super.removeComponent(c);
90 components.remove(c);
91 markAsDirty();
92 }
93
94 @Override
95 public void replaceComponent(Component oldComponent, Component newComponent) {
96 }
97
98 @Override
99 public Iterator<Component> iterator() {
100 return components.iterator();
101 }
102
103 public void setValidationVisible(boolean isVisible) {
104 getState().isValidationVisible = isVisible;
105 }
106
107 @Override
108 public int getComponentCount() {
109 return components.size();
110 }
111
112 public Component getNextProblematicField(Connector currentFocused) {
113 int startIndex = components.indexOf(currentFocused) + 1;
114 while (startIndex < components.size()) {
115 Component c = components.get(startIndex++);
116 if (c instanceof AbstractField && !((AbstractField<?>) c).isValid()) {
117 return c;
118 }
119 }
120 return null;
121 }
122
123 public void focusField(Component field) {
124 getRpcProxy(FormSectionClientRpc.class).focus(field);
125 }
126
127 public String getName() {
128 return name;
129 }
130
131 public void setName(String name) {
132 this.name = name;
133 }
134
135 public List<Component> getComponents() {
136 return this.components;
137 }
138 }