1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22 import org.kuali.rice.krad.uif.CssConstants;
23 import org.kuali.rice.krad.uif.CssConstants.Padding;
24 import org.kuali.rice.krad.uif.UifConstants.Orientation;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.container.Container;
27 import org.kuali.rice.krad.uif.view.View;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 @BeanTags({@BeanTag(name = "boxLayout-bean", parent = "Uif-BoxLayoutBase"),
48 @BeanTag(name = "horizontalBoxLayout-bean", parent = "Uif-HorizontalBoxLayout"),
49 @BeanTag(name = "verticalBoxLayout-bean", parent = "Uif-VerticalBoxLayout")})
50 public class BoxLayoutManager extends LayoutManagerBase {
51 private static final long serialVersionUID = 4467342272983290044L;
52
53 private Orientation orientation;
54 private String padding;
55
56 private String itemStyle;
57 private List<String> itemStyleClasses;
58
59 public BoxLayoutManager() {
60 super();
61
62 itemStyle = "";
63 orientation = Orientation.HORIZONTAL;
64 itemStyleClasses = new ArrayList<String>();
65 }
66
67
68
69
70
71
72
73 @Override
74 public void performFinalize(View view, Object model, Container container) {
75 super.performFinalize(view, model, container);
76
77 if (StringUtils.isBlank(itemStyle)) {
78 itemStyle = "";
79 }
80
81 if (StringUtils.isNotEmpty(padding)) {
82 if (orientation.equals(Orientation.VERTICAL)) {
83
84
85 itemStyle += CssConstants.getCssStyle(Padding.PADDING_BOTTOM, padding);
86 } else {
87
88 itemStyle += CssConstants.getCssStyle(Padding.PADDING_RIGHT, padding);
89 }
90 }
91
92
93 this.addStyleClass("clearfix");
94
95 for (Component c : container.getItems()) {
96 if (c != null) {
97
98 List<String> styleClasses = c.getCssClasses();
99 if (styleClasses == null) {
100 styleClasses = new ArrayList<String>();
101 }
102
103 if (orientation.equals(Orientation.HORIZONTAL)) {
104 styleClasses.add("uif-boxLayoutHorizontalItem");
105 styleClasses.addAll(this.getItemStyleClasses());
106 } else {
107 styleClasses.add("uif-boxLayoutVerticalItem");
108 styleClasses.addAll(this.getItemStyleClasses());
109 styleClasses.add("clearfix");
110 }
111 c.setCssClasses(styleClasses);
112
113 if (c.getStyle() != null && !c.getStyle().endsWith(";")) {
114 c.appendToStyle(";" + this.getItemStyle());
115 } else {
116 c.appendToStyle(this.getItemStyle());
117 }
118 }
119 }
120 }
121
122
123
124
125
126
127
128 @BeanTagAttribute(name = "orientation", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
129 public Orientation getOrientation() {
130 return this.orientation;
131 }
132
133
134
135
136
137
138 public void setOrientation(Orientation orientation) {
139 this.orientation = orientation;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153 @BeanTagAttribute(name = "padding")
154 public String getPadding() {
155 return this.padding;
156 }
157
158
159
160
161
162
163 public void setPadding(String padding) {
164 this.padding = padding;
165 }
166
167
168
169
170
171
172
173
174 @BeanTagAttribute(name = "itemStyle")
175 public String getItemStyle() {
176 return this.itemStyle;
177 }
178
179
180
181
182
183
184 public void setItemStyle(String itemStyle) {
185 this.itemStyle = itemStyle;
186 }
187
188
189
190
191
192
193 @BeanTagAttribute(name = "itemStyleClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
194 public List<String> getItemStyleClasses() {
195 return itemStyleClasses;
196 }
197
198
199
200
201
202
203 public void setItemStyleClasses(List<String> itemStyleClasses) {
204 this.itemStyleClasses = itemStyleClasses;
205 }
206
207
208
209
210
211
212
213 public String getItemStyleClassesAsString() {
214 if (itemStyleClasses != null) {
215 return StringUtils.join(itemStyleClasses, " ");
216 }
217
218 return "";
219 }
220
221
222
223
224 @Override
225 protected <T> void copyProperties(T layout) {
226 super.copyProperties(layout);
227 BoxLayoutManager boxLayoutManagerCopy = (BoxLayoutManager) layout;
228 boxLayoutManagerCopy.setPadding(this.padding);
229 boxLayoutManagerCopy.setItemStyle(this.itemStyle);
230 boxLayoutManagerCopy.setOrientation(this.orientation);
231
232 if (itemStyleClasses != null) {
233 boxLayoutManagerCopy.setItemStyleClasses(new ArrayList<String>(itemStyleClasses));
234 }
235 }
236 }