📄 htmltreerenderer.java
字号:
/* * $Id: HtmlTreeRenderer.java 6519 2006-01-17 08:17:22Z jonesde $ * * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.widget.html;import java.io.IOException;import java.io.Writer;import java.util.List;import java.util.Map;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.webapp.control.RequestHandler;import org.ofbiz.webapp.taglib.ContentUrlTag;import org.ofbiz.widget.screen.ScreenRenderer;import org.ofbiz.widget.screen.ScreenStringRenderer;import org.ofbiz.widget.tree.ModelTree;import org.ofbiz.widget.tree.TreeStringRenderer;/** * Widget Library - HTML Form Renderer implementation * * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 6519 $ * @since 3.1 */public class HtmlTreeRenderer implements TreeStringRenderer { ScreenStringRenderer screenStringRenderer = null; public static final String module = HtmlTreeRenderer.class.getName(); public HtmlTreeRenderer() {} public static String buildPathString(ModelTree modelTree, int depth) { StringBuffer buf = new StringBuffer(); for (int i=1; i <= depth; i++) { int idx = modelTree.getNodeIndexAtDepth(i); buf.append("."); buf.append(Integer.toString(idx + 1)); } return buf.toString(); } public void renderNodeBegin(Writer writer, Map context, ModelTree.ModelNode node, int depth, boolean isLast) throws IOException { String pathString = buildPathString(node.getModelTree(), depth); String currentNodeTrailPiped = null; List currentNodeTrail = node.getModelTree().getCurrentNodeTrail(); String staticNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); context.put("staticNodeTrailPiped", staticNodeTrailPiped); context.put("nodePathString", pathString); context.put("depth", Integer.toString(depth)); String style = node.getWrapStyle(context); if (UtilValidate.isNotEmpty(style)) { writer.write("<div"); writer.write(" class=\""); writer.write(style); writer.write("\""); writer.write(">"); } String pkName = node.getPkName(); String entityId = null; String entryName = node.getEntryName(); if (UtilValidate.isNotEmpty(entryName)) { Map map = (Map)context.get(entryName); entityId = (String)map.get(pkName); } else { entityId = (String) context.get(pkName); } boolean hasChildren = node.hasChildren(context); //Debug.logInfo("HtmlTreeExpandCollapseRenderer, hasChildren(1):" + hasChildren, module); // check to see if this node needs to be expanded. if (hasChildren && node.isExpandCollapse()) { String targetEntityId = null; List targetNodeTrail = node.getModelTree().getTrailList(); if (depth < targetNodeTrail.size()) { targetEntityId = (String)targetNodeTrail.get(depth); } //Debug.logInfo("HtmlTreeExpandCollapseRenderer, targetEntityId(1):" + targetEntityId, module); //Debug.logInfo("HtmlTreeExpandCollapseRenderer, depth(1):" + depth, module); ModelTree.ModelNode.Image expandCollapseImage = new ModelTree.ModelNode.Image(); expandCollapseImage.setBorder("0"); ModelTree.ModelNode.Link expandCollapseLink = new ModelTree.ModelNode.Link(); String expandCollapseStyle = UtilFormatOut.checkEmpty(node.getExpandCollapseStyle(), "expandcollapse"); expandCollapseLink.setStyle(expandCollapseStyle); expandCollapseLink.setImage(expandCollapseImage); //String currentNodeTrailCsv = (String)context.get("currentNodeTrailCsv"); int openDepth = node.getModelTree().getOpenDepth(); if (depth >= openDepth && (targetEntityId == null || !targetEntityId.equals(entityId))) { // Not on the trail if( node.showPeers(depth)) { context.put("processChildren", new Boolean(false)); //expandCollapseLink.setText(" + "); currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); context.put("currentNodeTrailPiped", currentNodeTrailPiped); //context.put("currentNodeTrailCsv", currentNodeTrailCsv); expandCollapseImage.setSrc("/images/expand.gif"); String target = node.getModelTree().getExpandCollapseRequest(context); String trailName = node.getModelTree().getTrailName(context); if (target.indexOf("?") < 0) target += "?"; else target += "&"; target += trailName + "=" + currentNodeTrailPiped; target += "#" + staticNodeTrailPiped; //expandCollapseLink.setTarget("/ViewOutline?docRootContentId=${docRootContentId}&targetNodeTrailCsv=${currentNodeTrailCsv}"); expandCollapseLink.setTarget(target); } } else { context.put("processChildren", new Boolean(true)); //expandCollapseLink.setText(" - "); String lastContentId = (String)currentNodeTrail.remove(currentNodeTrail.size() - 1); currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); if (currentNodeTrailPiped == null) currentNodeTrailPiped = ""; context.put("currentNodeTrailPiped", currentNodeTrailPiped); //context.put("currentNodeTrailCsv", currentNodeTrailCsv); expandCollapseImage.setSrc("/images/collapse.gif"); String target = node.getModelTree().getExpandCollapseRequest(context); String trailName = node.getModelTree().getTrailName(context); if (target.indexOf("?") < 0) target += "?"; else target += "&"; target += trailName + "=" + currentNodeTrailPiped; target += "#" + staticNodeTrailPiped; expandCollapseLink.setTarget(target); // add it so it can be remove in renderNodeEnd currentNodeTrail.add(lastContentId); currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); if (currentNodeTrailPiped == null) currentNodeTrailPiped = ""; context.put("currentNodeTrailPiped", currentNodeTrailPiped); } renderLink( writer, context, expandCollapseLink); } else if (!hasChildren){ writer.write(" "); context.put("processChildren", new Boolean(false)); //currentNodeTrail.add(contentId); } return; } public void renderNodeEnd(Writer writer, Map context, ModelTree.ModelNode node) throws IOException { String style = node.getWrapStyle(context); if (UtilValidate.isNotEmpty(style)) { writer.write("</div>"); } return; } public void renderLabel(Writer writer, Map context, ModelTree.ModelNode.Label label) throws IOException { // open tag writer.write("<span"); String id = label.getId(context); if (UtilValidate.isNotEmpty(id)) { writer.write(" id=\""); writer.write(id); writer.write("\""); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -