1 17 package org.alfresco.web.ui.common.component; 18 19 import java.io.IOException ; 20 21 import javax.faces.component.UIComponent; 22 import javax.faces.context.FacesContext; 23 import javax.faces.context.ResponseWriter; 24 import javax.faces.el.ValueBinding; 25 26 import org.alfresco.web.ui.common.Utils; 27 28 31 public class UIMenu extends SelfRenderingComponent 32 { 33 36 39 public String getFamily() 40 { 41 return "org.alfresco.faces.Controls"; 42 } 43 44 47 public void encodeBegin(FacesContext context) throws IOException 48 { 49 if (isRendered() == false) 50 { 51 return; 52 } 53 54 ResponseWriter out = context.getResponseWriter(); 55 56 String menuId = getNextMenuId(this, context); 58 out.write("<a HREF='#' onclick=\"javascript:_toggleMenu(event, '"); 59 out.write(menuId); 60 out.write("');return false;\""); 61 outputAttribute(out, getAttributes().get("style"), "style"); 62 outputAttribute(out, getAttributes().get("styleClass"), "class"); 63 outputAttribute(out, getTooltip(), "title"); 64 out.write('>'); 65 66 String label = getLabel(); 68 if (label != null) 69 { 70 out.write(Utils.encode(label)); 71 } 72 73 if (getAttributes().get("image") != null) 75 { 76 out.write(Utils.buildImageTag(context, (String )getAttributes().get("image"), null, "absmiddle")); 77 } 78 79 out.write("</a>"); 80 81 out.write("<br><div id='"); 83 out.write(menuId); 84 out.write("' style=\"position:absolute;display:none;padding-left:2px;\">"); 85 out.write("<table border=0 cellpadding=0"); 86 outputAttribute(out, getAttributes().get("itemSpacing"), "cellspacing"); 87 outputAttribute(out, getAttributes().get("menuStyle"), "style"); 88 outputAttribute(out, getAttributes().get("menuStyleClass"), "class"); 89 out.write(">"); 90 } 91 92 95 public void encodeEnd(FacesContext context) throws IOException 96 { 97 if (isRendered() == false) 98 { 99 return; 100 } 101 102 ResponseWriter out = context.getResponseWriter(); 103 104 out.write("</table></div>"); 106 } 107 108 111 public void restoreState(FacesContext context, Object state) 112 { 113 Object values[] = (Object [])state; 114 super.restoreState(context, values[0]); 116 this.label = (String )values[1]; 117 this.tooltip = (String )values[2]; 118 } 119 120 123 public Object saveState(FacesContext context) 124 { 125 Object values[] = new Object [3]; 126 values[0] = super.saveState(context); 128 values[1] = this.label; 129 values[2] = this.tooltip; 130 return values; 131 } 132 133 134 137 140 public String getLabel() 141 { 142 ValueBinding vb = getValueBinding("label"); 143 if (vb != null) 144 { 145 this.label = (String )vb.getValue(getFacesContext()); 146 } 147 return this.label; 148 } 149 150 153 public void setLabel(String label) 154 { 155 this.label = label; 156 } 157 158 161 public String getTooltip() 162 { 163 ValueBinding vb = getValueBinding("tooltip"); 164 if (vb != null) 165 { 166 this.tooltip = (String )vb.getValue(getFacesContext()); 167 } 168 return this.tooltip; 169 } 170 171 174 public void setTooltip(String tooltip) 175 { 176 this.tooltip = tooltip; 177 } 178 179 180 183 190 public static String getNextMenuId(UIComponent component, FacesContext context) 191 { 192 Integer val = (Integer )context.getExternalContext().getRequestMap().get(MENU_ID_KEY); 193 if (val == null) 194 { 195 val = Integer.valueOf(0); 196 } 197 198 String id = component.getClientId(context) + '_' + val.toString(); 200 201 val = Integer.valueOf( val.intValue() + 1 ); 203 context.getExternalContext().getRequestMap().put(MENU_ID_KEY, val); 204 205 return id; 206 } 207 208 209 212 private final static String MENU_ID_KEY = "__awc_menu_id"; 213 214 private String label; 215 216 private String tooltip; 217 } 218 | Popular Tags |