1 33 34 package com.icesoft.faces.component.menubar; 35 36 import com.icesoft.faces.component.CSS_DEFAULT; 37 import com.icesoft.faces.component.ext.taglib.Util; 38 import com.icesoft.faces.context.effects.JavascriptContext; 39 import com.icesoft.faces.util.CoreUtils; 40 41 import javax.faces.component.NamingContainer; 42 import javax.faces.component.UICommand; 43 import javax.faces.component.UIComponent; 44 import javax.faces.context.FacesContext; 45 import javax.faces.el.ValueBinding; 46 import javax.faces.event.AbortProcessingException; 47 import javax.faces.event.FacesEvent; 48 49 50 78 public class MenuBar extends UICommand implements NamingContainer { 79 80 private static final String DEFAULT_IMAGEDIR = "/xmlhttp/css/xp/css-images/"; 82 85 public static final String ORIENTATION_VERTICAL = "vertical"; 86 89 public static final String ORIENTATION_HORIZONTAL = "horizontal"; 90 93 public static final String DEFAULT_ORIENTATION = ORIENTATION_HORIZONTAL; 94 97 public static final String ID_PREFIX = "menu-"; 98 99 private String imageDir; 100 private String orientation; private String style; 102 private String renderedOnUserRole = null; 103 private Boolean noIcons; 104 105 108 public MenuBar() { 109 JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS, 110 FacesContext.getCurrentInstance()); 111 } 112 113 119 public String getFamily() { 120 return "com.icesoft.faces.Menu"; 121 } 122 123 126 public String getComponentType() { 127 return "com.icesoft.faces.Menu"; 128 } 129 130 133 public String getRendererType() { 134 return "com.icesoft.faces.View"; 135 } 136 137 144 public String getNoIcons() { 145 146 if (noIcons != null) { 147 return noIcons.toString(); 148 } 149 ValueBinding vb = getValueBinding("noIcons"); 150 if (vb != null) { 151 return vb.getValue(getFacesContext()).toString(); 152 } 153 return String.valueOf(false); 154 } 155 156 163 public void setNoIcons(String b) { 164 noIcons = new Boolean (b); 165 } 166 167 172 public void setStyle(String style) { 173 this.style = style; 174 } 175 176 181 public String getStyle() { 182 if (style != null) { 183 return style; 184 } 185 ValueBinding vb = getValueBinding("style"); 186 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 187 } 188 189 191 196 public String getImageDir() { 197 if (imageDir != null) { 198 return imageDir; 199 } 200 ValueBinding vb = getValueBinding("imageDir"); 201 if (vb != null) { 202 return (String ) vb.getValue(getFacesContext()); 203 } 204 return CoreUtils.resolveResourceURL(getFacesContext(), DEFAULT_IMAGEDIR); 205 } 206 207 212 public void setImageDir(String imageDir) { 213 this.imageDir = imageDir; 214 } 215 216 221 public String getOrientation() { 222 if (orientation != null) { 223 return orientation; 224 } 225 ValueBinding vb = getValueBinding("orientation"); 226 if (vb != null) { 227 return (String ) vb.getValue(getFacesContext()); 228 } 229 return DEFAULT_ORIENTATION; 230 } 231 232 237 public void setOrientation(String orient) { 238 orientation = orient; 239 } 240 241 244 public void processDecodes(FacesContext context) { 245 if (context == null) { 246 throw new NullPointerException ("context"); 247 } 248 if (!isRendered()) { 249 return; 250 } 251 252 decodeRecursive(this, context); 253 try { 254 decode(context); 255 } catch (RuntimeException e) { 256 context.renderResponse(); 257 throw e; 258 } 259 } 260 261 265 private void decodeRecursive(UIComponent component, FacesContext context) { 266 for (int i = 0; i < component.getChildCount(); i++) { 267 UIComponent next = (UIComponent) component.getChildren().get(i); 268 next.processDecodes(context); 269 decodeRecursive(next, context); 270 } 271 } 272 273 276 public void queueEvent(FacesEvent event) { 277 super.queueEvent(event); 278 } 279 280 283 public void broadcast(FacesEvent event) throws AbortProcessingException { 284 super.broadcast(event); 285 return; 286 287 } 288 289 294 public void setRenderedOnUserRole(String renderedOnUserRole) { 295 this.renderedOnUserRole = renderedOnUserRole; 296 } 297 298 303 public String getRenderedOnUserRole() { 304 if (renderedOnUserRole != null) { 305 return renderedOnUserRole; 306 } 307 ValueBinding vb = getValueBinding("renderedOnUserRole"); 308 return vb != null ? (String ) vb.getValue(getFacesContext()) : null; 309 } 310 311 316 public boolean isRendered() { 317 if (!Util.isRenderedOnUserRole(this)) { 318 return false; 319 } 320 return super.isRendered(); 321 } 322 323 private String styleClass; 324 329 public void setStyleClass(String styleClass) { 330 this.styleClass = styleClass; 331 } 332 333 338 public String getStyleClass() { 339 String defaultStyle = CSS_DEFAULT.MENU_BAR_STYLE; 340 String userDefinedClass = styleClass; 341 if (MenuBar.ORIENTATION_VERTICAL.equalsIgnoreCase( 342 getOrientation())){ 343 defaultStyle+=CSS_DEFAULT.MENU_BAR_VERTICAL_SUFFIX_STYLE; 344 if (userDefinedClass != null) { 345 userDefinedClass+=CSS_DEFAULT.MENU_BAR_VERTICAL_SUFFIX_STYLE; 346 } 347 } 348 return Util.getQualifiedStyleClass(this, 349 userDefinedClass, 350 defaultStyle, 351 "styleClass"); 352 } 353 354 public String getItemStyleClass() { 355 return Util.getQualifiedStyleClass(this, 356 CSS_DEFAULT.MENU_BAR_ITEM_STYLE); 357 } 358 359 public String getItemLabelStyleClass() { 360 return Util.getQualifiedStyleClass(this, 361 CSS_DEFAULT.MENU_BAR_ITEM_LABEL_STYLE); 362 } 363 364 public String getItemImageStyleClass() { 365 return Util.getQualifiedStyleClass(this, 366 CSS_DEFAULT.MENU_BAR_ITEM_STYLE+ 367 CSS_DEFAULT.MENU_ITEM_IMAGE_STYLE); 368 } 369 370 public String getSubMenuStyleClass() { 371 return Util.getQualifiedStyleClass(this, 372 CSS_DEFAULT.MENU_BAR_SUB_MENU_STYLE); 373 } 374 375 public String getSubMenuIndicatorStyleClass() { 376 return Util.getQualifiedStyleClass(this, 377 CSS_DEFAULT.MENU_BAR_SUB_MENU_INDICATOR_STYLE); 378 } 379 } 380 381 | Popular Tags |