1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.element;
17
18 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
21 import org.kuali.rice.krad.uif.CssConstants;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.util.LifecycleElement;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28
29
30
31
32
33 @BeanTags({@BeanTag(name = "progressBar-bean", parent = "Uif-ProgressBar"),
34 @BeanTag(name = "progressBarVertical-bean", parent = "Uif-ProgressBar-Vertical")})
35 public class ProgressBar extends ContentElementBase {
36 private static final long serialVersionUID = -2643777398164666573L;
37
38 private Integer percentComplete;
39
40 private List<Integer> segmentPercentages;
41 private List<String> segmentSizes;
42 private List<String> segmentClasses;
43
44 private boolean vertical;
45
46 public ProgressBar() {
47 segmentSizes = new ArrayList<String>();
48 segmentClasses = new ArrayList<String>();
49 this.setRole(UifConstants.AriaRoles.PROGRESS_BAR);
50 }
51
52
53
54
55
56
57 @Override
58 public void performFinalize(Object model, LifecycleElement parent) {
59 super.performFinalize(model, parent);
60
61
62 String cssDimension = CssConstants.WIDTH;
63 if (vertical) {
64 cssDimension = CssConstants.HEIGHT;
65 }
66
67 boolean explicitlySetSizes = segmentPercentages != null && !getSegmentPercentages().isEmpty();
68
69
70 if (!explicitlySetSizes && percentComplete != null) {
71 segmentClasses = new ArrayList<String>();
72
73
74 segmentSizes.add(cssDimension + percentComplete + "%");
75 segmentClasses.add(
76 CssConstants.ProgressBar.PROGRESS_BAR + " " + CssConstants.ProgressBar.SUCCESS_PROGRESS_BAR);
77
78 this.setTitle(percentComplete.toString() + "%");
79
80
81 this.addAriaAttribute(UifConstants.AriaAttributes.VALUE_MIN, "0");
82 this.addAriaAttribute(UifConstants.AriaAttributes.VALUE_MAX, "100");
83 this.addAriaAttribute(UifConstants.AriaAttributes.VALUE_NOW, percentComplete.toString());
84 } else if (explicitlySetSizes && !(this instanceof StepProgressBar)) {
85 if (segmentClasses == null || segmentClasses.size() != segmentPercentages.size()) {
86 throw new RuntimeException(
87 "If segmentPercentages are set on a base ProgressBar type, segmentClasses must "
88 + "also be explicitly set and contain the same number of items");
89 }
90
91
92 percentComplete = 0;
93 for (int index = 0; index < segmentPercentages.size(); index++) {
94 segmentSizes.add(cssDimension + segmentPercentages.get(index) + "%");
95 percentComplete = percentComplete + segmentPercentages.get(index);
96 }
97
98
99 this.addAriaAttribute(UifConstants.AriaAttributes.VALUE_MIN, "0");
100 this.addAriaAttribute(UifConstants.AriaAttributes.VALUE_MAX, "100");
101 this.addAriaAttribute(UifConstants.AriaAttributes.VALUE_NOW, percentComplete.toString());
102 }
103
104 }
105
106
107
108
109
110
111 @BeanTagAttribute(name = "percentComplete")
112 public Integer getPercentComplete() {
113 return percentComplete;
114 }
115
116
117
118
119 public void setPercentComplete(Integer percentComplete) {
120 this.percentComplete = percentComplete;
121 }
122
123
124
125
126
127
128
129
130
131
132 @BeanTagAttribute(name = "segmentClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
133 public List<String> getSegmentClasses() {
134 return segmentClasses;
135 }
136
137
138
139
140 public void setSegmentClasses(List<String> segmentClasses) {
141 this.segmentClasses = segmentClasses;
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156 @BeanTagAttribute(name = "segmentPercentages", type = BeanTagAttribute.AttributeType.LISTVALUE)
157 public List<Integer> getSegmentPercentages() {
158 return segmentPercentages;
159 }
160
161
162
163
164 public void setSegmentPercentages(List<String> segmentPercentages) {
165
166 if (this.segmentPercentages == null) {
167 this.segmentPercentages = new ArrayList<Integer>();
168 }
169
170 for (String percentage : segmentPercentages) {
171 this.segmentPercentages.add(new Integer(percentage));
172 }
173 }
174
175
176
177
178
179
180
181 public List<String> getSegmentSizes() {
182 return segmentSizes;
183 }
184
185
186
187
188
189
190
191 @BeanTagAttribute(name = "vertical")
192 public boolean isVertical() {
193 return vertical;
194 }
195
196
197
198
199 public void setVertical(boolean vertical) {
200 this.vertical = vertical;
201 }
202
203 }