1 7 package fr.improve.struts.taglib.layout.util; 8 9 import javax.servlet.ServletContext ; 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.jsp.JspException ; 12 13 import org.apache.struts.Globals; 14 15 import fr.improve.struts.taglib.layout.menu.MenuAction; 16 import fr.improve.struts.taglib.layout.menu.MenuComponent; 17 import fr.improve.struts.taglib.layout.skin.Skin; 18 import fr.improve.struts.taglib.layout.treeview.TreeItemInfo; 19 import fr.improve.struts.taglib.layout.treeview.TreeViewTag; 20 21 26 public class BasicTreeview implements TreeviewInterface { 27 protected static String VERTICAL_TREE = "treeLine.gif"; 28 protected static String CLOSE_NODE = "treeNodeClose.gif"; 29 protected static String LAST_CLOSE_NODE = "treeNodeCloseLast.gif"; 30 protected static String OPEN_NODE = "treeNodeOpen.gif"; 31 protected static String LAST_OPEN_NODE = "treeNodeOpenLast.gif"; 32 protected static String LAST_ITEM = "treeItemLast.gif"; 33 protected static String ITEM = "treeItem.gif"; 34 35 38 protected void startLink(StringBuffer buffer, HttpServletRequest in_request, ServletContext in_servletcontext, String in_styleClass, String in_link, String in_target, String in_bundle, String in_tooltip) throws JspException { 39 buffer.append("<a HREF=\""); 40 String lc_link = in_link; 41 if (in_target==null && !LayoutUtils.getSkin(in_request.getSession()).getFollowLinkIfFormChanged()) { 42 StringBuffer lc_newLink = new StringBuffer ("javascript:checkFormChange('"); 45 lc_newLink.append(in_link); 46 lc_newLink.append("','"); 47 lc_newLink.append(LayoutUtils.getLabel(in_request, in_servletcontext, Globals.MESSAGES_KEY, "layout.dataLost", null, false)); 48 lc_newLink.append("')"); 49 lc_newLink.append("\" onMouseOver=\"status='"); 50 lc_newLink.append(in_link); 51 lc_newLink.append("';return true;\" onMouseOut=\"status='';return true;"); 52 lc_link = lc_newLink.toString(); 53 } 54 buffer.append(lc_link); 55 buffer.append("\""); 56 if (in_styleClass!=null && in_styleClass.length()!=0) { 57 buffer.append(" class=\""); 58 buffer.append(in_styleClass); 59 buffer.append("\""); 60 } 61 if (in_target!=null && in_target.length()!=0) { 62 buffer.append(" target=\""); 63 buffer.append(in_target); 64 buffer.append("\""); 65 } 66 if (in_tooltip!=null && in_tooltip.length()!=0) { 67 String lc_tooltip = LayoutUtils.getLabel(in_request, in_servletcontext,in_bundle, in_tooltip, null, false); 68 buffer.append(" title=\""); 69 buffer.append(lc_tooltip); 70 buffer.append("\" alt=\""); 71 buffer.append(lc_tooltip); 72 buffer.append("\""); 73 } 74 buffer.append(">"); 75 } 76 77 80 protected void endLink(StringBuffer buffer) { 81 buffer.append("</a>"); 82 } 83 84 87 protected void renderLabel(StringBuffer buffer, HttpServletRequest in_request, ServletContext in_servletcontext, String in_bundle, String key) throws JspException { 88 buffer.append(LayoutUtils.getLabel(in_request, in_servletcontext,in_bundle, key, null, false)); 89 } 90 91 94 public void renderLabel(StringBuffer buffer, HttpServletRequest in_request, ServletContext in_servletcontext, TreeItemInfo in_info, MenuComponent in_item) throws JspException { 95 String lc_link = in_item.getLocation(); 96 if (lc_link!=null && lc_link.length()!=0) { 97 startLink(buffer, in_request, in_servletcontext, in_info.styleClass, lc_link, in_item.getTarget(), in_info.bundle, in_item.getToolTip()); 98 } 99 renderLabel(buffer, in_request, in_servletcontext, in_info.bundle, in_item.getTitle()); 100 if (lc_link!=null && lc_link.length()!=0) { 101 endLink(buffer); 102 } 103 } 104 105 public void renderImage(StringBuffer buffer, HttpServletRequest in_request, TreeItemInfo in_info, MenuComponent in_item) { 107 if (in_item.getImage()!=null) { 108 if (in_info.hasSubMenus) { 109 buffer.append("<a HREF=\""); 111 if (!in_info.useIndirection) { 112 buffer.append("javascript://\""); 113 } else { 114 buffer.append(in_request.getContextPath()); 115 buffer.append("/"); 116 buffer.append(LayoutUtils.getSkin(in_request.getSession()).getProperty(Skin.TREEVIEW_ACTION, TreeViewTag.DEFAULT_TREEVIEW_ACTION)); 117 buffer.append("?open="); 118 buffer.append(in_info.path); 119 buffer.append("&bundle="); 120 buffer.append(in_info.bundle); 121 buffer.append("&name="); 122 buffer.append(in_info.name); 123 buffer.append("&class="); 124 buffer.append(in_info.styleClass); 125 buffer.append("\" id=\"treeViewNode"); 126 buffer.append(in_info.path); 127 buffer.append("\""); 128 } 129 130 buffer.append(" onclick=\"return changeTreeAndSubtrees('"); 131 132 133 buffer.append(in_info.path); 136 buffer.append("');"); 137 buffer.append("\" target=\"treeFrame\">"); 138 } 139 140 buffer.append("<img SRC=\""); 142 buffer.append(in_info.imageDirectory); 143 buffer.append("/"); 144 buffer.append(in_item.getImage()); 145 buffer.append("\" border=\"0\">"); 146 147 if (in_info.hasSubMenus) { 148 buffer.append("</a> "); 150 } 151 } 152 } 153 154 public void endLabel(StringBuffer buffer) { 155 buffer.append("</td>"); 156 } 157 158 public void startLabel(StringBuffer buffer, String in_styleClass, String onclick, String style) { 159 buffer.append("<td"); 161 if (in_styleClass!=null && in_styleClass.length()!=0) { 162 buffer.append(" class=\""); 163 buffer.append(in_styleClass); 164 buffer.append("\""); 165 } 166 if (style!=null) { 167 buffer.append(" style=\""); 168 buffer.append(style); 169 buffer.append("\""); 170 } 171 if (onclick!=null) { 172 buffer.append(" onclick=\""); 173 buffer.append(onclick); 174 buffer.append("\""); 175 } 176 buffer.append(">"); 177 } 178 179 public void endRow(StringBuffer buffer) { 180 buffer.append("</tr>"); 182 } 183 184 public int endSubMenu(StringBuffer buffer, HttpServletRequest in_request, ServletContext in_servletcontext, int lc_numberOfMenusPrinted, MenuComponent currentMenu, TreeItemInfo in_info) throws JspException { 185 buffer.append("</tr>"); 186 buffer.append("<tr><td valign=\"top\" colspan=\"2\" id=\"treeView" + in_info.path + "\""); 187 if (in_info.isClosed) { 188 buffer.append(" style=\"display:none;\""); 189 } 190 buffer.append(">"); 191 if (!in_info.useIndirection) { 192 buffer.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"); 193 lc_numberOfMenusPrinted += TreeViewTag.doPrintMenu(buffer, currentMenu.getMenuComponents(), in_request, in_servletcontext, in_info.bundle, in_info.path, in_info.name, in_info.styleClass); 194 buffer.append("</table>"); 195 } 196 buffer.append("</td></tr>"); 197 buffer.append("</table></td>"); 198 return lc_numberOfMenusPrinted; 199 } 200 201 public void startSubMenu(StringBuffer buffer) { 202 buffer.append("<td valign=\"top\" colspan=\"2\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr>"); 203 } 204 205 209 public void renderIcon(StringBuffer buffer, TreeItemInfo in_info, MenuComponent in_item) { 210 buffer.append("<td width=\"1\">"); 211 220 buffer.append("</td>"); 221 } 222 223 226 public void renderTree(StringBuffer buffer, HttpServletRequest in_request, TreeItemInfo in_info) { 227 228 buffer.append("<td valign=\"top\" height=\"100%\""); 229 230 if (!in_info.isLast) { 232 buffer.append(" style=\"background-image: url("); 233 buffer.append(in_info.imageDirectory); 234 buffer.append("/"); 235 buffer.append(VERTICAL_TREE); 236 buffer.append("); background-repeat: repeat-y; \""); 237 } 238 239 buffer.append(" width=\""); 240 buffer.append(16); 241 buffer.append("\">"); 242 243 if (in_info.hasSubMenus) { 245 String lc_closeImage; 246 String lc_openImage; 247 if (in_info.isLast) { 248 lc_closeImage = LAST_CLOSE_NODE; 249 lc_openImage = LAST_OPEN_NODE; 250 } else { 251 lc_closeImage = CLOSE_NODE; 252 lc_openImage = OPEN_NODE; 253 } 254 startTreeUrl(buffer, in_request, in_info, lc_closeImage, lc_openImage); 255 renderTreeImage(buffer, in_info, lc_closeImage, lc_openImage, 16, 22); 256 endTreeUrl(buffer); 257 } else { 258 buffer.append("<img SRC=\""); 259 buffer.append(in_info.imageDirectory); 260 buffer.append("/"); 261 if (in_info.isLast) { 262 buffer.append(LAST_ITEM); 264 } else { 265 buffer.append(ITEM); 267 } 268 buffer.append("\" border=\"0\" width=\"16\" height=\"22\">"); 269 } 270 271 buffer.append("</td>"); 272 } 274 275 protected void renderTreeImage(StringBuffer buffer, TreeItemInfo in_info, String lc_closeImage, String lc_openImage, int in_width, int in_height) { 276 buffer.append("<img SRC=\""); 277 buffer.append(in_info.imageDirectory); 278 buffer.append("/"); 279 buffer.append(in_info.isClosed ? lc_closeImage : lc_openImage); 280 buffer.append("\" id=\"treeViewImage"); 281 buffer.append(in_info.path); 282 buffer.append("\" border=\"0\" width=\""); 283 buffer.append(in_width); 284 buffer.append("\" height=\""); 285 buffer.append(in_height); 286 buffer.append("\" align=\"middle\">"); 287 } 288 289 protected void endTreeUrl(StringBuffer buffer) { 290 buffer.append("</a>"); 291 } 292 293 protected void startTreeUrl(StringBuffer buffer, HttpServletRequest in_request, TreeItemInfo in_info, String lc_closeImage, String lc_openImage) { 294 buffer.append("<a HREF=\""); 295 if (!in_info.useIndirection) { 296 buffer.append("javascript://\" onclick=\"return changeTree('"); 297 } else { 298 buffer.append(in_request.getContextPath()); 299 buffer.append("/"); 300 buffer.append(LayoutUtils.getSkin(in_request.getSession()).getProperty(Skin.TREEVIEW_ACTION, TreeViewTag.DEFAULT_TREEVIEW_ACTION)); 301 buffer.append("?open="); 302 buffer.append(in_info.path); 303 buffer.append("&bundle="); 304 buffer.append(in_info.bundle); 305 buffer.append("&name="); 306 buffer.append(in_info.name); 307 buffer.append("&class="); 308 buffer.append(in_info.styleClass); 309 buffer.append("\" id=\"treeViewNode"); 310 buffer.append(in_info.path); 311 buffer.append("\" onclick=\"return changeTree('"); 312 } 313 buffer.append(in_info.path); 314 buffer.append("','"); 315 buffer.append(in_info.imageDirectory); 316 buffer.append("/"); 317 buffer.append(lc_openImage); 318 buffer.append("','"); 319 buffer.append(in_info.imageDirectory); 320 buffer.append("/"); 321 buffer.append(lc_closeImage); 322 buffer.append("');"); 323 buffer.append("\" target=\"treeFrame\">"); 324 } 325 326 327 330 public void startRow(StringBuffer buffer) { 331 buffer.append("<tr>"); 332 } 333 334 338 public String computeStyleClass(String in_styleClass) { 339 String lc_newStyleClass = in_styleClass; 340 if (in_styleClass.length()!=0) { 341 char lc_lastChar = in_styleClass.charAt(in_styleClass.length()-1); 342 if (Character.isDigit(lc_lastChar)) { 343 lc_newStyleClass = lc_newStyleClass.substring(0, lc_newStyleClass.length()-1) + (char)(lc_lastChar+1); 345 } 346 } 347 return lc_newStyleClass; 348 } 349 350 public void renderActions(StringBuffer buffer, HttpServletRequest in_request, ServletContext in_context, TreeItemInfo in_info, MenuComponent in_item) throws JspException { 351 MenuAction[] lc_actions = in_item.getMenuAction(); 352 buffer.append("<td align=\"right\" nowrap>"); 353 int i; 354 for (i = 0; i < lc_actions.length; i++) { 355 MenuAction lc_menuAction = lc_actions[i]; 356 String lc_href = lc_menuAction.getHref(); 357 if (lc_href!=null) { 358 String lc_computedHref = lc_href; 359 if (lc_computedHref.indexOf('?')==-1) { 360 lc_computedHref = lc_computedHref + "?path=" + in_info.path; 361 } 362 startLink(buffer, in_request, in_context, null, lc_computedHref, lc_menuAction.getTarget(), in_info.bundle, null); 363 } 364 buffer.append("<img SRC=\""); 365 buffer.append(in_info.imageDirectory); 366 buffer.append("/"); 367 buffer.append(lc_menuAction.getImgSrc()); 368 buffer.append("\" align=\"middle\" border=\"0\">"); 369 if (lc_href!=null) { 370 endLink(buffer); 371 } 372 } 373 buffer.append("</td>"); 374 } 375 376 } 377 | Popular Tags |