001: /*
002: Copyright (c) 2003 eInnovation Inc. All rights reserved
003:
004: This library is free software; you can redistribute it and/or modify it under the terms
005: of the GNU Lesser General Public License as published by the Free Software Foundation;
006: either version 2.1 of the License, or (at your option) any later version.
007:
008: This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
009: without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: See the GNU Lesser General Public License for more details.
011: */
012:
013: /*
014: * Created on May 29, 2003
015: */
016: package com.openedit.webui.tree;
017:
018: /**
019: * This is a placeholder for a future version
020: *
021: */
022: public abstract class HtmlTreeRenderer extends BaseTreeRenderer {
023: protected boolean expandingAll = false;
024:
025: public HtmlTreeRenderer(WebTree inWebTree) {
026: fieldWebTree = inWebTree;
027: }
028:
029: public HtmlTreeRenderer() {
030:
031: }
032:
033: public String renderAsString() {
034: StringBuffer js = new StringBuffer();
035:
036: // Ensure the root node is always expanded.
037: Object obj = getWebTree().getModel().getRoot();
038: expandNode(obj);
039:
040: js.append("<div class=\"dtree\" id='" + getWebTree().getName()
041: + "'>");
042: js.append(renderFolder(getWebTree().getModel().getRoot(), 0,
043: true)); //line levels and blank levels
044: js.append("</div>");
045: return js.toString();
046: }
047:
048: public String renderAsString(String inNodeId) {
049: StringBuffer js = new StringBuffer();
050: WebTreeModel model = getWebTree().getModel();
051: int levels = 0;
052: Object child = model.getChildById(inNodeId);
053: if (child != null) {
054: Object parent = model.getParent(child);
055: while (parent != null) {
056: levels++;
057: parent = model.getParent(parent);
058: }
059: js.append(renderFolder(child, levels, false)); //line levels and blank levels
060: }
061: return js.toString();
062: }
063:
064: protected String renderFolder(Object inNode, int level,
065: boolean entire) {
066: // Use null for our folder icon, and the JavaScript tree will substitute either folder.gif or
067: // folderopen.gif, depending on whether the node is open or closed.
068: StringBuffer js = new StringBuffer();
069: String id = getWebTree().getModel().getId(inNode);
070: String name = toName(inNode);
071: String path = toUrl(inNode);
072: // String post = "";
073: // if( isLast)
074: // {
075: // post = "bottom";
076: // }
077: String selected = "node";
078: String treeRow = "";
079: if (getSelectedNode() == inNode) {
080: selected = "nodeSel";
081: treeRow = "class='dTreeNodeSel' ";
082: }
083:
084: String icon = customIconSet(inNode);
085: if (icon == null) {
086: icon = "";
087: }
088:
089: boolean folder = !getWebTree().getModel().isLeaf(inNode);
090: if (folder) {
091: js.append("<div id='" + getWebTree().getName() + "treerow"
092: + id + "'>");
093: // if (entire)
094: // {
095: // js.append("<div style='padding-left: " + (1)*18 + "px;margin-left: "+ (-1)*18 + "px;'>");
096: // }
097: // else
098: // {
099: js.append("<div " + treeRow + " id='"
100: + getWebTree().getName() + "treeitem" + id
101: + "' style='padding-left: " + (level) * 18
102: + "px;' >");
103: // }
104: //indent(js,level);
105: boolean expanded = hasBeenExpanded(inNode);
106: boolean shouldexpand = false;
107: js.append("<a class='node' href='#" + path
108: + "' onclick=\"return " + getWebTree().getName()
109: + ".toggleNode('" + path + "','");
110: js.append(getWebTree().getId());
111: js.append("','" + id + "');\" >");
112:
113: if (expanded) {
114: //if( level > 0)
115: if (inNode != getWebTree().getModel().getRoot()) {
116: js
117: .append("<img alt='' src='"
118: + getHome()
119: + "/openedit/images/tree/down.gif' id='jpageTree"
120: + id + "' />");
121: }
122: js
123: .append("<img alt='' src='" + getHome()
124: + "/openedit/images/tree/" + icon
125: + "folderopen.gif' id='ipageTree" + id
126: + "' />");
127: } else //if ( hasChildren )
128: {
129: shouldexpand = true;
130: if (inNode != getWebTree().getModel().getRoot()) {
131: js
132: .append("<img alt='' src='"
133: + getHome()
134: + "/openedit/images/tree/right.gif' id='jpageTree"
135: + id + "' /><img alt='' src='"
136: + getHome()
137: + "/openedit/images/tree/" + icon
138: + "folder.gif' id='ipageTree" + id
139: + "' />");
140:
141: }
142: }
143: js.append("</a><a title='" + path + "' href='#" + path
144: + "' onclick=\"");
145: if (shouldexpand) {
146: js.append("return " + getWebTree().getName()
147: + ".jumpAndOpenNode('" + path + "','");
148: js.append(getWebTree().getId());
149: js.append("','" + id + "');\"");
150: } else {
151: js.append(" return " + getWebTree().getName()
152: + ".jumpToNode('" + path + "','" + id
153: + "');\" ");
154: //js.append(" return jumpAndOpenNode('" + path + "','" + id + "');\" ");
155: }
156: js.append(" id='" + getWebTree().getName() + "spageTree"
157: + id + "'>" + name + "</a>");
158: js.append("</div>\n");
159: if (expanded) {
160: int c = getWebTree().getModel().getChildCount(inNode);
161: for (int i = 0; i < c; i++) {
162: Object childNode = getWebTree().getModel()
163: .getChild(inNode, i);
164: js
165: .append(renderFolder(childNode, level + 1,
166: entire));
167: }
168: }
169: js.append("</div>\n");
170: //js.append("\n </div>\n");
171: } else {
172: // if (entire)
173: // {
174: // js.append("\n<div " + treeRow + "style='padding-left: " + (2)*18 + "px;' id='treerow" + id + "'>");
175: // }
176: // else {
177: js.append("\n<div " + treeRow + "style='padding-left: "
178: + (level + 1) * 18 + "px;' id='"
179: + getWebTree().getName() + "treeitem" + id + "'>");
180: // }
181: //indent(js,level+2);
182: js.append("<a title='" + path + "' href='#" + path
183: + "' onclick=\"return " + getWebTree().getName()
184: + ".jumpToNode('" + path + "','" + id + "');\" >");
185: js.append("<img src='" + getHome()
186: + "/openedit/images/tree/" + icon
187: + "page.gif' id='" + getWebTree().getName()
188: + "ipageTree" + id + "' alt='' />" + name
189: + "</a></div>");
190: }
191: return js.toString();
192: }
193:
194: public void indent(StringBuffer str, int level) {
195: str.append("<img src=\"" + getHome()
196: + "/openedit/images/tree/empty.gif\" width='" + (level)
197: * 11 + "' height='1' alt=\"\" />");
198: }
199:
200: }
|