1 33 34 package com.icesoft.faces.component.outputprogress; 35 36 import com.icesoft.faces.component.CSS_DEFAULT; 37 import com.icesoft.faces.component.ext.taglib.Util; 38 import com.icesoft.faces.util.DOMUtils; 39 40 import org.w3c.dom.Element ; 41 import org.w3c.dom.Text ; 42 43 import javax.faces.component.UIComponentBase; 44 import javax.faces.context.FacesContext; 45 import javax.faces.el.ValueBinding; 46 47 58 public class OutputProgress extends UIComponentBase { 59 60 private final String DEFAULT_LABEL_POSITION = "embed"; 61 62 private String label = null; 63 64 private String labelPosition = null; 65 66 private String labelComplete = null; 67 68 private String styleClass = null; 69 70 private boolean labelPositionChanged = false; 71 72 private String style = null; 73 74 private Integer value = null; 75 76 private Text textNode = null; 77 78 private Element barNode = null; 79 80 private Boolean indeterminate = null; 81 82 private String renderedOnUserRole; 83 84 89 public String getFamily() { 90 return "com.icesoft.faces.Progress"; 91 } 92 93 98 public String getRendererType() { 99 return "com.icesoft.faces.Bar"; 100 } 101 102 106 public void setTextNode(Text textNode) { 107 this.textNode = textNode; 108 } 109 110 114 public Text getTextNode() { 115 return textNode; 116 } 117 118 122 public void setBarNode(Element barNode) { 123 this.barNode = barNode; 124 } 125 126 130 public Element getBarNode() { 131 return barNode; 132 } 133 134 138 public void setLabel(String label) { 139 this.label = label; 140 } 141 142 146 public void setLabelPosition(String labelPosition) { 147 this.labelPosition = labelPosition; 148 } 149 150 154 public void setLabelComplete(String labelComplete) { 155 this.labelComplete = labelComplete; 156 } 157 158 public String getStyle() { 159 if (style != null) { 160 return style; 161 } 162 ValueBinding vb = getValueBinding("style"); 163 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 164 } 165 166 170 public void setStyle(String style) { 171 this.style = style; 172 } 173 174 178 public void setValue(int value) { 179 this.value = new Integer (value); 180 } 181 182 186 public int getValue() { 187 if (value != null) { 188 return value.intValue(); 189 } 190 ValueBinding vb = getValueBinding("value"); 191 return vb != null ? ((Integer ) vb.getValue(getFacesContext())) 192 .intValue() : 0; 193 } 194 195 199 public String getLabel() { 200 if (label != null) { 201 return label; 202 } 203 ValueBinding vb = getValueBinding("label"); 204 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 205 } 206 207 public boolean getIndeterminate() { 208 if (indeterminate != null) { 209 return indeterminate.booleanValue(); 210 } 211 ValueBinding vb = getValueBinding("indeterminate"); 212 if (vb != null) { 213 return ((Boolean ) vb.getValue(getFacesContext())).booleanValue(); 214 } 215 return false; 216 } 217 218 public void setIndeterminate(boolean b) { 219 indeterminate = new Boolean (b); 220 } 221 222 226 public String getProgressLabel() { 227 if (getLabel() == null && getIndeterminate()) { 228 return "in progress..."; 229 } else if (getLabel() != null){ 230 return DOMUtils.escapeAnsi(getLabel()); 231 } else { 232 return getLabel(); 233 } 234 } 235 236 240 public String getLabelPosition() { 241 if (labelPosition != null) { 242 return labelPosition; 243 } 244 ValueBinding vb = getValueBinding("labelPosition"); 245 return vb != null ? (String ) vb.getValue(getFacesContext()) 246 : DEFAULT_LABEL_POSITION; 247 } 248 249 253 public String getLabelComplete() { 254 if (labelComplete != null) { 255 return labelComplete; 256 } 257 ValueBinding vb = getValueBinding("labelComplete"); 258 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 259 } 260 261 266 public String getProgressLabelComplete() { 267 if (getLabelComplete() == null && getIndeterminate()) { 268 return " "; 269 } else if (getLabelComplete() != null) { 270 return DOMUtils.escapeAnsi(getLabelComplete()); 271 } else { 272 return getLabelComplete(); 273 } 274 } 275 276 280 public void setStyleClass(String styleClass) { 281 this.styleClass = styleClass; 282 } 283 284 288 public String getStyleClass() { 289 return Util.getQualifiedStyleClass(this, 290 styleClass, 291 CSS_DEFAULT.OUTPUT_PROGRESS_BASE_CLASS, 292 "styleClass"); 293 } 294 295 public String getTextClass() { 296 return Util.getQualifiedStyleClass(this, 297 CSS_DEFAULT.OUTPUT_PROGRESS_TEXT_STYLE_CLASS); 298 } 299 300 public String getBackgroundClass() { 301 return Util.getQualifiedStyleClass(this, 302 CSS_DEFAULT.OUTPUT_PROGRESS_BG_STYLE_CLASS); 303 } 304 305 public String getFillClass() { 306 return Util.getQualifiedStyleClass(this, 307 CSS_DEFAULT.OUTPUT_PROGRESS_FILL_STYLE_CLASS); 308 } 309 310 public String getIndeterminateActiveClass() { 311 return Util.getQualifiedStyleClass(this, 312 CSS_DEFAULT.OUTPUT_PROGRESS_INDETERMINATE_ACTIVE_CLASS); 313 } 314 315 public String getIndeterminateInactiveClass() { 316 return Util.getQualifiedStyleClass(this, 317 CSS_DEFAULT.OUTPUT_PROGRESS_INDETERMINATE_INACTIVE_CLASS); 318 } 319 323 public boolean isRendered() { 324 if (!Util.isRenderedOnUserRole(this)) { 325 return false; 326 } 327 return super.isRendered(); 328 } 329 330 335 public Object saveState(FacesContext context) { 336 Object values[] = new Object [10]; 337 values[0] = super.saveState(context); 338 values[1] = label; 339 values[2] = labelPosition; 340 values[3] = labelComplete; 341 values[4] = new Boolean (labelPositionChanged); 342 values[5] = value; 343 values[6] = textNode; 344 values[7] = barNode; 345 values[8] = style; 346 values[9] = renderedOnUserRole; 347 return ((Object ) (values)); 348 } 349 350 355 public void restoreState(FacesContext context, Object state) { 356 Object values[] = (Object []) state; 357 super.restoreState(context, values[0]); 358 label = (String ) values[1]; 359 labelPosition = (String ) values[2]; 360 labelComplete = (String ) values[3]; 361 labelPositionChanged = ((Boolean ) values[4]).booleanValue(); 362 value = (Integer ) values[5]; 363 textNode = (Text ) values[6]; 364 barNode = (Element ) values[7]; 365 style = (String ) values[8]; 366 renderedOnUserRole = (String ) values[9]; 367 } 368 369 372 public void setRenderedOnUserRole(String renderedOnUserRole) { 373 this.renderedOnUserRole = renderedOnUserRole; 374 } 375 376 379 public String getRenderedOnUserRole() { 380 if (renderedOnUserRole != null) { 381 return renderedOnUserRole; 382 } 383 ValueBinding vb = getValueBinding("renderedOnUserRole"); 384 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 385 } 386 387 } 388 | Popular Tags |