1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.widgets.field.layout.layouts; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
22 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.ClearBreak; |
23 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel; |
24 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; |
25 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
26 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
27 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement.LineNum; |
28 | |
|
29 | |
import com.google.gwt.user.client.ui.FlowPanel; |
30 | |
import com.google.gwt.user.client.ui.Widget; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class GroupFieldLayout extends FieldLayout{ |
43 | 0 | private SpanPanel top = new SpanPanel(); |
44 | 0 | private FlowPanel layout = new FlowPanel(); |
45 | 0 | private FlowPanel fieldContainer = new FlowPanel(); |
46 | 0 | private FlowPanel fieldsPanel = new FlowPanel(); |
47 | 0 | private SpanPanel buttonArea = new SpanPanel(); |
48 | 0 | private ValidationMessagePanel validationPanel = new ValidationMessagePanel(); |
49 | 0 | private List<FieldElement> currentLine = new ArrayList<FieldElement>(); |
50 | 0 | private int lineCount = 0; |
51 | 0 | public static enum ValidationLocation{NONE, TOP, RIGHT}; |
52 | |
private ValidationLocation loc; |
53 | 0 | private boolean lineHasTitles = false; |
54 | 0 | private boolean lineHasDescriptions = false; |
55 | |
|
56 | |
public GroupFieldLayout(){ |
57 | 0 | super(); |
58 | 0 | this.loc = ValidationLocation.RIGHT; |
59 | 0 | init(); |
60 | 0 | } |
61 | |
|
62 | |
public GroupFieldLayout(ValidationLocation loc){ |
63 | 0 | super(); |
64 | 0 | this.loc = loc; |
65 | 0 | init(); |
66 | 0 | } |
67 | |
|
68 | |
public GroupFieldLayout(SectionTitle title){ |
69 | 0 | super(); |
70 | 0 | this.loc = ValidationLocation.RIGHT; |
71 | 0 | this.setLayoutTitle(title); |
72 | 0 | init(); |
73 | 0 | } |
74 | |
|
75 | |
public GroupFieldLayout(SectionTitle title, ValidationLocation loc){ |
76 | 0 | super(); |
77 | 0 | this.loc = loc; |
78 | 0 | this.setLayoutTitle(title); |
79 | 0 | init(); |
80 | 0 | } |
81 | |
|
82 | |
private void init(){ |
83 | |
|
84 | 0 | this.instructions.setVisible(false); |
85 | 0 | layout.add(this.instructions); |
86 | 0 | layout.add(this.message); |
87 | 0 | if(loc == ValidationLocation.RIGHT){ |
88 | 0 | this.hasValidation = true; |
89 | 0 | fieldContainer.add(fieldsPanel); |
90 | 0 | fieldContainer.add(validationPanel); |
91 | 0 | layout.add(fieldContainer); |
92 | 0 | fieldContainer.setStyleName("ks-form-module-group"); |
93 | 0 | fieldContainer.addStyleName("clearfix"); |
94 | 0 | fieldsPanel.setStyleName("ks-form-module-fields"); |
95 | 0 | fieldsPanel.addStyleName("clearfix"); |
96 | 0 | validationPanel.setStyleName("ks-form-module-validation"); |
97 | |
} |
98 | 0 | else if(loc == ValidationLocation.TOP){ |
99 | 0 | this.hasValidation = true; |
100 | 0 | fieldContainer.add(validationPanel); |
101 | 0 | fieldContainer.add(fieldsPanel); |
102 | 0 | layout.add(fieldContainer); |
103 | 0 | fieldContainer.setStyleName("ks-form-module-group"); |
104 | 0 | fieldContainer.addStyleName("clearfix"); |
105 | 0 | fieldsPanel.setStyleName("ks-form-module-fields"); |
106 | 0 | fieldsPanel.addStyleName("clearfix"); |
107 | 0 | validationPanel.setStyleName("ks-form-module-validation"); |
108 | |
} |
109 | |
else{ |
110 | 0 | this.hasValidation = false; |
111 | 0 | fieldContainer.add(fieldsPanel); |
112 | 0 | layout.add(fieldContainer); |
113 | 0 | fieldContainer.setStyleName("ks-form-module-group"); |
114 | 0 | fieldContainer.addStyleName("clearfix"); |
115 | 0 | fieldsPanel.setStyleName("ks-form-module-fields"); |
116 | 0 | fieldsPanel.addStyleName("clearfix"); |
117 | |
} |
118 | |
|
119 | 0 | top.add(layout); |
120 | 0 | top.add(buttonArea); |
121 | 0 | this.add(top); |
122 | |
|
123 | 0 | } |
124 | |
|
125 | |
public void nextLine(){ |
126 | 0 | fieldsPanel.add(new ClearBreak()); |
127 | 0 | currentLine = new ArrayList<FieldElement>(); |
128 | |
|
129 | 0 | lineCount++; |
130 | 0 | lineHasTitles = false; |
131 | 0 | lineHasDescriptions = false; |
132 | 0 | } |
133 | |
|
134 | |
@Override |
135 | |
public void addFieldToLayout(FieldElement field) { |
136 | 0 | currentLine.add(field); |
137 | |
|
138 | 0 | if(field.getFieldName() != null && !field.getFieldName().equals("")){ |
139 | 0 | lineHasTitles = true; |
140 | |
} |
141 | |
|
142 | 0 | if(field.getInstructionText() != null && !field.getInstructionText().equals("")){ |
143 | 0 | lineHasDescriptions = true; |
144 | |
} |
145 | |
|
146 | 0 | for(FieldElement f: currentLine){ |
147 | 0 | if(lineHasTitles && lineHasDescriptions){ |
148 | 0 | f.setTitleDescLineHeight(LineNum.TRIPLE); |
149 | |
} |
150 | 0 | else if(lineHasTitles || lineHasDescriptions){ |
151 | 0 | f.setTitleDescLineHeight(LineNum.DOUBLE); |
152 | |
} |
153 | |
else{ |
154 | 0 | f.setTitleDescLineHeight(LineNum.SINGLE); |
155 | |
} |
156 | |
} |
157 | |
|
158 | 0 | fieldsPanel.add(field); |
159 | 0 | field.setValidationPanel(validationPanel); |
160 | 0 | field.setParentPanel(fieldContainer); |
161 | |
|
162 | 0 | } |
163 | |
|
164 | |
@Override |
165 | |
public void addLayoutToLayout(FieldLayout fieldLayout) { |
166 | 0 | layout.add(fieldLayout); |
167 | 0 | fieldLayout.setParentLayout(this); |
168 | 0 | } |
169 | |
|
170 | |
@Override |
171 | |
public void addWidgetToLayout(Widget widget) { |
172 | 0 | layout.add(widget); |
173 | |
|
174 | 0 | } |
175 | |
|
176 | |
@Override |
177 | |
public void removeFieldLayoutComponentFromLayout( |
178 | |
FieldLayoutComponent component) { |
179 | 0 | if(component instanceof FieldElement){ |
180 | 0 | fieldsPanel.remove((FieldElement)component); |
181 | |
} |
182 | 0 | else if(component instanceof FieldLayout){ |
183 | 0 | layout.remove((FieldLayout)component); |
184 | |
} |
185 | |
|
186 | 0 | } |
187 | |
|
188 | |
@Override |
189 | |
public void removeWidgetFromLayout(Widget widget) { |
190 | 0 | layout.remove(widget); |
191 | |
|
192 | 0 | } |
193 | |
|
194 | |
@Override |
195 | |
public void setLayoutTitle(SectionTitle layoutTitle) { |
196 | 0 | if(this.layoutTitle != null){ |
197 | 0 | layout.remove(this.layoutTitle); |
198 | |
} |
199 | 0 | this.layoutTitle = layoutTitle; |
200 | 0 | layout.insert(layoutTitle, 0); |
201 | 0 | layoutTitle.addStyleName("ks-layout-header"); |
202 | 0 | } |
203 | |
|
204 | |
@Override |
205 | |
public void addButtonLayoutToLayout(ButtonLayout buttonLayout) { |
206 | 0 | buttonArea.add(buttonLayout); |
207 | 0 | } |
208 | |
|
209 | |
} |