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 (orientation.equals(Orientation.HORIZONTAL)) {
100 styleClasses.add("uif-boxLayoutHorizontalItem");
101 styleClasses.addAll(this.getItemStyleClasses());
102 } else {
103 styleClasses.add("uif-boxLayoutVerticalItem");
104 styleClasses.addAll(this.getItemStyleClasses());
105 styleClasses.add("clearfix");
106 }
107 c.setCssClasses(styleClasses);
108
109 if (c.getStyle() != null && !c.getStyle().endsWith(";")) {
110 c.appendToStyle(";" + this.getItemStyle());
111 } else {
112 c.appendToStyle(this.getItemStyle());
113 }
114 }
115 }
116 }
117
118
119
120
121
122
123
124 @BeanTagAttribute(name = "orientation", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
125 public Orientation getOrientation() {
126 return this.orientation;
127 }
128
129
130
131
132
133
134 public void setOrientation(Orientation orientation) {
135 this.orientation = orientation;
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149 @BeanTagAttribute(name = "padding")
150 public String getPadding() {
151 return this.padding;
152 }
153
154
155
156
157
158
159 public void setPadding(String padding) {
160 this.padding = padding;
161 }
162
163
164
165
166
167
168
169
170 @BeanTagAttribute(name = "itemStyle")
171 public String getItemStyle() {
172 return this.itemStyle;
173 }
174
175
176
177
178
179
180 public void setItemStyle(String itemStyle) {
181 this.itemStyle = itemStyle;
182 }
183
184
185
186
187
188
189 @BeanTagAttribute(name = "itemStyleClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
190 public List<String> getItemStyleClasses() {
191 return itemStyleClasses;
192 }
193
194
195
196
197
198
199 public void setItemStyleClasses(List<String> itemStyleClasses) {
200 this.itemStyleClasses = itemStyleClasses;
201 }
202
203
204
205
206
207
208
209 public String getItemStyleClassesAsString() {
210 if (itemStyleClasses != null) {
211 return StringUtils.join(itemStyleClasses, " ");
212 }
213
214 return "";
215 }
216
217
218
219
220 @Override
221 protected <T> void copyProperties(T layout) {
222 super.copyProperties(layout);
223 BoxLayoutManager boxLayoutManagerCopy = (BoxLayoutManager) layout;
224 boxLayoutManagerCopy.setPadding(this.getPadding());
225 boxLayoutManagerCopy.setItemStyle(this.getItemStyle());
226 boxLayoutManagerCopy.setOrientation(this.getOrientation());
227
228 if(itemStyleClasses != null) {
229 boxLayoutManagerCopy.setItemStyleClasses(new ArrayList<String>(itemStyleClasses));
230 }
231 }
232 }