You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2006/10/09 16:13:42 UTC
svn commit: r454386 - in /myfaces/tobago/trunk:
theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script...
Author: lofwyr
Date: Mon Oct 9 07:13:42 2006
New Revision: 454386
URL: http://svn.apache.org/viewvc?view=rev&rev=454386
Log:
clean up java script creation of the tree in tree.js
add samples
Modified:
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java
myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js
myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tree.jsp
myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/treeListBox.jsp
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java?view=diff&rev=454386&r1=454385&r2=454386
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java Mon Oct 9 07:13:42 2006
@@ -47,6 +47,7 @@
private static final Log LOG = LogFactory.getLog(TreeListboxRenderer.class);
+ @Override
public void encodeBeginTobago(
FacesContext facesContext, UIComponent component) throws IOException {
@@ -83,7 +84,7 @@
writer.endElement(HtmlConstants.INPUT);
- final Set<DefaultMutableTreeNode> selection = tree.getState().getSelection();
+ Set<DefaultMutableTreeNode> selection = tree.getState().getSelection();
value = new StringBuffer(";");
for (DefaultMutableTreeNode node : selection) {
value.append(nodeStateId(facesContext, tree.findUITreeNode(root, node)));
@@ -96,18 +97,21 @@
writer.writeAttribute(HtmlAttributes.VALUE, value, null);
writer.endElement(HtmlConstants.INPUT);
- String script = createJavascript(facesContext, clientId, root);
+ String scriptText = createJavascript(facesContext, clientId, root);
- final String[] scripts = {"script/tree.js"};
- ComponentUtil.findPage(tree).getScriptFiles().add(scripts[0]);
+ String[] scripts = {"script/tree.js"};
+ List<String> scriptFiles = ComponentUtil.findPage(tree).getScriptFiles();
+ for (String script : scripts) {
+ scriptFiles.add(script);
+ }
if (!TobagoConfig.getInstance(facesContext).isAjaxEnabled()) {
HtmlRendererUtil.startJavascript(writer);
- writer.writeText(script, null);
+ writer.writeText(scriptText, null);
HtmlRendererUtil.endJavascript(writer);
} else {
HtmlRendererUtil.writeScriptLoader(facesContext, scripts,
- new String[] {script.replaceAll("\n", " ")});
+ new String[] {scriptText.replaceAll("\n", " ")});
}
}
@@ -194,6 +198,7 @@
//
// }
+ @Override
public void encodeEndTobago(FacesContext facesContext,
UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java?view=diff&rev=454386&r1=454385&r2=454386
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java Mon Oct 9 07:13:42 2006
@@ -183,13 +183,8 @@
writer.writeText(" var ", null);
writer.writeText(jsClientId, null);
- writer.writeText(" = new ", null);
- if (component.getChildCount() == 0) {
- writer.writeText("TreeNode", null);
- } else {
- writer.writeText("TreeFolder", null);
- }
- writer.writeText("('", null);
+ writer.writeText(" = new TreeNode('", null);
+ // label
Object name = treeNode.getAttributes().get(ATTR_NAME);
if (LOG.isDebugEnabled()) {
debuging += name + " : ";
@@ -200,8 +195,14 @@
LOG.warn("name = null");
}
writer.writeText("','", null);
+
+ // id
writer.writeText(clientId, null);
writer.writeText("',", null);
+
+ // is folder
+ writer.writeText(component.getChildCount() > 0, null);
+ writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowIcons()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowJunctions()), null);
@@ -251,22 +252,35 @@
}
writer.writeText(",", null);
writer.writeText(Boolean.toString(treeState.isMarked(node)), null);
- if (component.getChildCount() > 0) {
- writer.writeText(",", null);
- boolean expanded = treeState.isExpanded(node);
- writer.writeText(Boolean.toString(expanded), null);
- if (LOG.isDebugEnabled()) {
- debuging += expanded ? "E" : "-";
- }
+ writer.writeText(",", null);
+ // expanded
+ boolean expanded = treeState.isExpanded(node);
+ writer.writeText(Boolean.toString(expanded), null);
+ if (LOG.isDebugEnabled()) {
+ debuging += expanded ? "E" : "-";
}
writer.writeText(",", null);
- writer.writeText(Boolean.toString(root.isRequired()), null);
+ // required
+ writer.writeText(Boolean.toString(root.isRequired()), null);
writer.writeText(",", null);
+
+ // disabled
writer.writeText(ComponentUtil.getBooleanAttribute(treeNode, ATTR_DISABLED), null);
- writer.writeText(",treeResourcesHelp);\n", null);
+ // resources
+ writer.writeText(",treeResourcesHelp", null);
+ writer.writeText(",", null);
+
+ // action (not implemented)
+ writer.writeText("null", null);
+ writer.writeText(",", null);
+
+ // parent
+ writer.writeText(jsParentClientId != null ? jsParentClientId : "null", null);
+ writer.writeText(");\n", null);
+/*
if (jsParentClientId != null) { // if not the root node
writer.writeText(" ", null);
writer.writeText(jsParentClientId, null);
@@ -274,6 +288,7 @@
writer.writeText(jsClientId, null);
writer.writeText(");\n", null);
}
+*/
if (LOG.isDebugEnabled()) {
LOG.debug(debuging);
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java?view=diff&rev=454386&r1=454385&r2=454386
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java Mon Oct 9 07:13:42 2006
@@ -21,8 +21,6 @@
* $Id$
*/
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MUTABLE;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
import org.apache.myfaces.tobago.component.ComponentUtil;
@@ -33,9 +31,9 @@
import org.apache.myfaces.tobago.model.TreeState;
import org.apache.myfaces.tobago.renderkit.RenderUtil;
import org.apache.myfaces.tobago.renderkit.RendererBase;
-import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
-import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
+import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import javax.faces.component.NamingContainer;
@@ -43,14 +41,14 @@
import javax.faces.context.FacesContext;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.List;
import java.util.StringTokenizer;
public class TreeRenderer extends RendererBase {
-
- private static final Log LOG = LogFactory.getLog(TreeRenderer.class);
-
- // tree resources (TREE_IMAGES)
+ /**
+ * Resources to display the tree.
+ */
private static final String[] TREE_IMAGES = {
"openfoldericon.gif",
"foldericon.gif",
@@ -71,6 +69,7 @@
};
+ @Override
public void decode(FacesContext facesContext, UIComponent component) {
if (ComponentUtil.isOutputOnly(component)) {
return;
@@ -103,6 +102,7 @@
: clientId.replace(NamingContainer.SEPARATOR_CHAR, '_');
}
+ @Override
public void encodeEndTobago(FacesContext facesContext,
UIComponent component) throws IOException {
@@ -173,21 +173,23 @@
writer.endElement(HtmlConstants.TABLE);
// writer.endElement(HtmlConstants.DIV);
+ String[] scriptTexts = createJavascript(facesContext, clientId, root);
- String[] script = createJavascript(facesContext, clientId, root);
-
- final String[] scripts = {"script/tree.js"};
- ComponentUtil.findPage(tree).getScriptFiles().add(scripts[0]);
+ String[] scripts = {"script/tree.js"};
+ List<String> scriptFiles = ComponentUtil.findPage(tree).getScriptFiles();
+ for (String script : scripts) {
+ scriptFiles.add(script);
+ }
if (!TobagoConfig.getInstance(facesContext).isAjaxEnabled()) {
HtmlRendererUtil.startJavascript(writer);
- for (String s : script) {
- writer.writeText(s, null);
+ for (String scriptText : scriptTexts) {
+ writer.writeText(scriptText, null);
writer.writeText('\n', null);
}
HtmlRendererUtil.endJavascript(writer);
} else {
- HtmlRendererUtil.writeScriptLoader(facesContext, scripts, script);
+ HtmlRendererUtil.writeScriptLoader(facesContext, scripts, scriptTexts);
}
writer.endElement(HtmlConstants.DIV);
@@ -201,11 +203,12 @@
sb.append("{\n");
sb.append(" var treeResourcesHelp = new Object();\n");
- for (int i = 0; i < TREE_IMAGES.length; i++) {
+ for (String images : TREE_IMAGES) {
sb.append(" treeResourcesHelp[\"");
- sb.append(TREE_IMAGES[i]);
+ sb.append(images);
sb.append("\"] = \"");
- sb.append(ResourceManagerUtil.getImageWithPath(facesContext, "image/" + TREE_IMAGES[i]));
+ sb.append(ResourceManagerUtil.getImageWithPath(facesContext,
+ "image/" + images));
sb.append("\";\n");
}
sb.append(" \n treeResourcesHelp.getImage = function (name) {\n");
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js?view=diff&rev=454386&r1=454385&r2=454386
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js Mon Oct 9 07:13:42 2006
@@ -19,10 +19,7 @@
var content = document.getElementById(node.id + "-cont");
if (content) {
var selectState = document.getElementById(treeHiddenId + '-selectState');
- var icon;
- //if (! selectState) { // why this if ?? {
- icon = document.getElementById(node.id + '-icon');
- //}
+ var icon = document.getElementById(node.id + '-icon');
var junction = document.getElementById(node.id + '-junction');
var hidden = document.getElementById(treeHiddenId);
if (content.style.display == 'none') {
@@ -296,13 +293,16 @@
}
};
-function TreeNode(label, id, hideIcons, hideJunctions, hideRootJunction,
+function TreeNode(label, id, isFolder,
+ hideIcons, hideJunctions, hideRootJunction,
hideRoot, treeHiddenId, selectable, mutable,
- formId, selected, marked, required, disabled, treeResources,
- action, parent, icon) {
+ formId, selected, marked,
+ expanded, required, disabled, treeResources,
+ action, parent, icon, openIcon) {
this.label = label;
this.id = id;
Tobago.treeNodes[id] = this;
+ this.isFolder = isFolder
this.hideIcons = hideIcons || false;
this.hideJunctions = hideJunctions || false;
this.hideRootJunction = hideRootJunction || false;
@@ -313,11 +313,15 @@
this.formId = formId;
this.selected = selected;
this.marked = marked;
+ this.expanded = expanded;
this.required = required;
this.disabled = disabled;
this.treeResources = treeResources;
this.action = action;
- this.icon = icon;
+ this.icon = icon
+ || treeResources.getImage("foldericon.gif");
+ this.openIcon = openIcon
+ || treeResources.getImage("openfoldericon.gif");
this.childNodes = [];
// FIXME: page:form
this.onclick
@@ -332,189 +336,53 @@
this.onfocus = "storeMarker(this.parentNode, '" + treeHiddenId + "')";
// this.ondblclick = "toggle(this.parentNode, '" + treeHiddenId + "')";
- var hidden = document.getElementById(treeHiddenId);
- var iconOnClick = '';
- var markIcon = '';
- var markIconOnClick = '';
- if (selectable) {
- if (selected) {
- markIcon = treeResources.getImage("checked" + (this.disabled ? "Disabled" : "") + ".gif");
- } else {
- markIcon = treeResources.getImage("unchecked" + (this.disabled ? "Disabled" : "") + ".gif");
- }
- if (!this.disabled) {
- markIconOnClick
- = 'onclick="toggleSelect(this.parentNode, \'' + treeHiddenId
- + '\', \'' + treeResources.getImage("unchecked.gif")
- + '\', \'' + treeResources.getImage("checked.gif")
- + '\')"';
- }
- }
- if (marked) {
- storeMarker(this, treeHiddenId);
- }
-
- this.add = function (node) {
- };
-
- this.toString = function (depth, last) { // merge with folder...
- var str = '';
- str += '<div id="' + this.id + '" class="tree-item">'; // XXX or mark this?!
- str += this.indent(depth, last);
- if (! this.hideJunctions
- && ! (this.hideRootJunction && this.hideRoot && depth == 1)) {
- str += '<img class="tree-junction" id="' + this.id
- + '-junction" src="' + ((last)
- ? treeResources.getImage("L.gif")
- : treeResources.getImage("T.gif"))
- + '" alt="">';
- } else if (( !this.hideRoot && depth >0 ) || (this.hideRoot && depth > 1)) {
- str += '<img class="tree-junction" id="' + this.id
- + '-junction" src="' + treeResources.getImage("blank.gif")
- + '" alt="">';
- }
- if (! this.hideIcons) {
- str += '<img class="tree-icon" id="' + this.id
-// + '-icon" src="' + this.icon + '" ' + iconOnClick + ' alt="">';
- + '-icon" src="' + treeResources.getImage("new.gif") + '" ' + iconOnClick + ' alt="">';
- }
- if (selectable) {
- str += '<img class="tree-icon" id="' + this.id
- + '-markIcon" src="' + markIcon + '" ' + markIconOnClick + ' alt="">';
- }
- var itemStyle = "tree-item-label";
- if (this.disabled) {
- itemStyle += " tree-item-label-disabled";
- }
- if (this.marked) {
- itemStyle += " tree-item-marker";
- }
- if (this.action && !this.disabled) {
- str += '<a class="' + itemStyle + '" href="' + this.action + '" id="'
- + this.id + '-anchor">' + this.label + '</a>';
- } else {
- // TODO: mozilla shoud use href="javascript:;" and ie href="#"
- str += '<a class="' + itemStyle + '"';
- if (!this.disabled) {
- str += ' href="#"' + ' onclick="' + this.onclick + '"'
- + ' onfocus="' + this.onfocus + '"';
- }
- str += '>'
- + this.label + '</a>';
- }
- str += '</div>';
- return str;
- };
-
- // is the node the last child of its paranet?
- this.isLast = function() {
- if (!this.parentNode) return true;
- var siblings = this.parentNode.childNodes;
- if (siblings.length == 0) return true;
- return (this == siblings[siblings.length-1]);
- };
-
- this.indent = function(depth, last) {
- if (!depth) depth = 0;
- var str = "";
- var node = this;
- while (node.parentNode) {
- node = node.parentNode;
- if((!node.parentNode && (node.hideRootJunction || node.hideRoot))
- || (node.parentNode && !node.parentNode.parentNode
- && node.hideRootJunction && node.hideRoot)) {
- break;
- }
- str = '<img class="tree-junction" src="'
- + ((node.isLast() || node.hideJunctions)
- ? treeResources.getImage("blank.gif")
- : treeResources.getImage("I.gif")) + '" alt="">' + str;
- }
- return str;
- };
-
- this.initSelection = function() {
- if (this.selected) {
- var selectState = document.getElementById(treeHiddenId + '-selectState');
- if (selectState) {
- selectState.value = selectState.value + nodeStateId(this) + ";";
- }
- }
- };
-
- if (parent) {
- parent.add(this);
- }
-
- this.hasChildren = function() {
- return (this.childNodes && this.childNodes.length > 0);
- }
-}
-
-function TreeFolder(label, id, hideIcons, hideJunctions, hideRootJunction,
- hideRoot, treeHiddenId, selectable, mutable, formId, selected, marked,
- expanded, required, disabled, treeResources, action, parent, icon, openIcon) {
- this.base = TreeNode;
- this.base(label, id, hideIcons, hideJunctions, hideRootJunction,
- hideRoot, treeHiddenId, selectable, mutable, formId, selected, marked,
- required, disabled, treeResources, action, parent, icon);
- this.open = false;
- this.expanded = expanded;
-
+ var hidden = document.getElementById(this.treeHiddenId);
if (this.expanded) {
- var hidden = document.getElementById(this.treeHiddenId);
+ hidden = document.getElementById(this.treeHiddenId);
var regex = new RegExp(";" + nodeStateId(this) + ";");
if (! hidden.value.match(regex)) {
hidden.value = hidden.value + nodeStateId(this) + ";" ;
}
}
- this.icon = icon
- || treeResources.getImage("foldericon.gif");
- this.openIcon = openIcon
- || treeResources.getImage("openfoldericon.gif");
-
this.add = function (node) {
node.parentNode = this;
this.childNodes[this.childNodes.length] = node;
return node;
};
- this.toString = function (depth, last) {
- if (!depth) depth = 0;
- var hidden = document.getElementById(this.treeHiddenId);
-// var isOpen
-// = hidden.value.indexOf(";" + nodeStateId(this) + ";", 0) > -1
-// || depth == 0 && this.hideRoot; // don't close a hidden root!
- var str = '';
- var iconOnClickFunction = '';
- var actualIcon = '';
- var markIcon = '';
- var markIconOnClickFunction = '';
- if (selectable) {
- if (selectable.match(/LeafOnly$/)) {
- markIcon = treeResources.getImage("1x1.gif");
+ var iconOnClickFunction = '';
+ var markIcon = '';
+ var markIconOnClickFunction = '';
+ if (selectable) {
+ if (selectable.match(/LeafOnly$/) && isFolder) {
+ markIcon = treeResources.getImage("1x1.gif");
+ } else {
+ if (selected) {
+ markIcon = treeResources.getImage("checked" + (this.disabled ? "Disabled" : "") + ".gif");
} else {
- if (selected) {
- markIcon = treeResources.getImage("checked" + this.disabled ? "Disabled" : "" + ".gif");
- } else {
- markIcon = treeResources.getImage("unchecked" + this.disabled ? "Disabled" : "" + ".gif");
- }
- if (!this.disabled) {
- markIconOnClickFunction
- = 'onclick="toggleSelect(this.parentNode, \'' + treeHiddenId
+ markIcon = treeResources.getImage("unchecked" + (this.disabled ? "Disabled" : "") + ".gif");
+ }
+ if (!this.disabled) {
+ markIconOnClickFunction
+ = 'onclick="toggleSelect(this.parentNode, \'' + treeHiddenId
+ '\', \'' + treeResources.getImage("unchecked.gif")
+ '\', \'' + treeResources.getImage("checked.gif")
+ '\')"';
- }
}
}
+ }
+ if (marked) {
+ storeMarker(this, treeHiddenId);
+ }
- actualIcon = (this.expanded ? this.openIcon : this.icon) ;
- iconOnClickFunction = "toggle";
+ var actualIcon = (this.expanded ? this.openIcon : this.icon) ;
+ this.toString = function (depth, last) {
+ if (!depth) depth = 0;
+ var str = '';
if (! this.hideRoot || depth > 0) {
str += '<div id="' + this.id + '" class="tree-item">';
str += this.indent(depth, last);
@@ -531,8 +399,8 @@
: ((depth == 0)
? treeResources.getImage("Rplus.gif")
: (last)
- ? treeResources.getImage("Lplus.gif")
- : treeResources.getImage("Tplus.gif"))
+ ? treeResources.getImage(isFolder ? "Lplus.gif" : "L.gif")
+ : treeResources.getImage(isFolder ? "Tplus.gif" : "T.gif"))
)
+ '" onclick="toggle(this.parentNode, \'' + treeHiddenId
+ '\', \'' + treeResources.getImage("openfoldericon.gif")
@@ -543,33 +411,37 @@
str += '<img class="tree-junction" id="' + this.id
+ '-junction" src="' + treeResources.getImage("blank.gif")
+ '" alt="">';
- }
+ }
if (! this.hideIcons) {
- str += '<img class="tree-icon" id="' + this.id
- + '-icon" src="' + actualIcon + '"'
- + ' onclick="' + iconOnClickFunction + '(this.parentNode, \'' + treeHiddenId
- + '\', \'' + treeResources.getImage("openfoldericon.gif")
- + '\', \'' + treeResources.getImage("foldericon.gif")
- + '\')"'
- + ' alt="">';
+ if (isFolder) {
+ str += '<img class="tree-icon" id="' + this.id
+ + '-icon" src="' + actualIcon + '"'
+ + ' onclick="' + iconOnClickFunction + '(this.parentNode, \'' + treeHiddenId
+ + '\', \'' + treeResources.getImage("openfoldericon.gif")
+ + '\', \'' + treeResources.getImage("foldericon.gif")
+ + '\')"'
+ + ' alt="">';
+ } else {
+ str += '<img class="tree-icon" id="' + this.id
+ + '-icon" src="' + treeResources.getImage("new.gif") + '" ' + iconOnClickFunction + ' alt="">';
+ }
}
if (selectable) {
str += '<img class="tree-icon" id="' + this.id
+ '-markIcon" src="' + markIcon + '" ' + markIconOnClickFunction + ' alt="">';
}
- var itemStyle = "tree-folder-label";
-
+ var itemStyle = isFolder ? "tree-folder-label" : "tree-item-label";
if (this.disabled) {
- itemStyle += " tree-folder-label-disabled";
+ itemStyle += isFolder ? " tree-folder-label-disabled" : " tree-item-label-disabled";
}
if (this.marked) {
itemStyle += " tree-item-marker";
}
if (this.action && !this.disabled) {
str += '<a class="' + itemStyle + '" href="' + this.action + '" id="'
- + this.id + '-anchor">' + this.label + '</a>';
+ + this.id + '-anchor">' + this.label + '</a>';
} else {
- // TODO: mozilla shoud use href="javascript:;" and ie href="#"
+ // TODO: mozilla shoud use href="javascript:;" and ie href="#"
str += '<a class="' + itemStyle + '"';
if (!this.disabled) {
str += ' href="#"' + ' onclick="' + this.onclick + '"'
@@ -580,36 +452,70 @@
}
str += '</div>';
}
- str += '<div id="' + this.id
- + '-cont" class="tree-container" style="display: '
- + (this.expanded ? 'block' : 'none') + ';">';
- for (var i=0; i<this.childNodes.length; ++i) {
- var lastChild = i+1 == this.childNodes.length;
- var n = this.childNodes[i];
- str += n.toString(depth+1, lastChild);
+ if (isFolder) {
+ str += '<div id="' + this.id
+ + '-cont" class="tree-container" style="display: '
+ + (this.expanded ? 'block' : 'none') + ';">';
+ for (var i=0; i<this.childNodes.length; ++i) {
+ var lastChild = i+1 == this.childNodes.length;
+ var n = this.childNodes[i];
+ str += n.toString(depth+1, lastChild);
+ }
+ str += '</div>';
}
- str += '</div>';
return str;
};
+ // is the node the last child of its paranet?
+ this.isLast = function() {
+ if (!this.parentNode) return true;
+ var siblings = this.parentNode.childNodes;
+ if (siblings.length == 0) return true;
+ return (this == siblings[siblings.length-1]);
+ };
+ this.indent = function(depth, last) {
+ if (!depth) depth = 0;
+ var str = "";
+ var node = this;
+ while (node.parentNode) {
+ node = node.parentNode;
+ if((!node.parentNode && (node.hideRootJunction || node.hideRoot))
+ || (node.parentNode && !node.parentNode.parentNode
+ && node.hideRootJunction && node.hideRoot)) {
+ break;
+ }
+ str = '<img class="tree-junction" src="'
+ + ((node.isLast() || node.hideJunctions)
+ ? treeResources.getImage("blank.gif")
+ : treeResources.getImage("I.gif")) + '" alt="">' + str;
+ }
+ return str;
+ };
this.initSelection = function() {
if (this.selected) {
var selectState = document.getElementById(this.treeHiddenId + '-selectState');
if (selectState) {
- selectState.value = selectState.value + nodeStateId(this) + ";" ;
+ selectState.value = selectState.value + nodeStateId(this) + ";";
}
}
-
- for (var i=0; i<this.childNodes.length; ++i) {
- this.childNodes[i].initSelection();
+ if (this.childNodes) {
+ for (var i=0; i<this.childNodes.length; i++) {
+ this.childNodes[i].initSelection();
+ }
}
};
-}
-TreeFolder.prototype = new TreeNode;
+ if (parent) {
+ parent.add(this);
+ }
+
+ this.hasChildren = function() {
+ return (this.childNodes && this.childNodes.length > 0);
+ }
+}
// ////////////////////////////////////////////////// listTree
Modified: myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tree.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tree.jsp?view=diff&rev=454386&r1=454385&r2=454386
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tree.jsp (original)
+++ myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tree.jsp Mon Oct 9 07:13:42 2006
@@ -1,6 +1,3 @@
-<%@ page import="javax.swing.tree.DefaultMutableTreeNode" %>
-<%@ page import="javax.swing.tree.MutableTreeNode" %>
-<%@ page import="org.apache.myfaces.tobago.model.TreeState" %>
<%--
* Copyright 2002-2005 The Apache Software Foundation.
*
@@ -17,6 +14,9 @@
* limitations under the License.
--%>
+<%@ page import="javax.swing.tree.DefaultMutableTreeNode" %>
+<%@ page import="org.apache.myfaces.tobago.model.TreeState" %>
+
<%
DefaultMutableTreeNode tree;
TreeState treeState;
@@ -42,8 +42,8 @@
treeState.addExpandState(temp);
treeState.addSelection(temp2);
treeState.setMarker(music);
-request.setAttribute("tree", tree);
-request.setAttribute("treeState", treeState);
+ session.setAttribute("tree", tree);
+ session.setAttribute("treeState", treeState);
%>
<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
@@ -55,7 +55,8 @@
<jsp:body>
<tc:panel>
<f:facet name="layout">
- <tc:gridLayout rows="150px;1*" />
+ <%--<tc:gridLayout rows="300px;1*" />--%>
+ <tc:gridLayout rows="200px;300px;1*" />
</f:facet>
<tc:tree state="#{treeState}" value="#{tree}" id="screenshotTree"
idReference="userObject"
@@ -66,9 +67,16 @@
showRoot="true"
selectable="single"
mutable="false"
- >
- </tc:tree>
+ />
+ <tc:tree state="#{treeState}" value="#{tree}"
+ idReference="userObject"
+ nameReference="userObject"
+ showIcons="false"
+ showJunctions="false"
+ showRootJunction="false"
+ showRoot="false"
+ />
<tc:cell/>
Modified: myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/treeListBox.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/treeListBox.jsp?view=diff&rev=454386&r1=454385&r2=454386
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/treeListBox.jsp (original)
+++ myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/treeListBox.jsp Mon Oct 9 07:13:42 2006
@@ -13,4 +13,59 @@
* See the License for the specific language governing permissions and
* limitations under the License.
--%>
-todo
+
+<%@ page import="javax.swing.tree.DefaultMutableTreeNode" %>
+<%@ page import="org.apache.myfaces.tobago.model.TreeState" %>
+
+<%
+ DefaultMutableTreeNode tree;
+ TreeState treeState;
+
+ tree = new DefaultMutableTreeNode("Category");
+ tree.insert(new DefaultMutableTreeNode("Sports"), 0);
+ tree.insert(new DefaultMutableTreeNode("Movies"), 0);
+ DefaultMutableTreeNode music = new DefaultMutableTreeNode("Music");
+ tree.insert(music, 0);
+ tree.insert(new DefaultMutableTreeNode("Games"), 0);
+ DefaultMutableTreeNode temp = new DefaultMutableTreeNode("Science");
+ temp.insert(
+ new DefaultMutableTreeNode("Geography"), 0);
+ temp.insert(
+ new DefaultMutableTreeNode("Mathematics"), 0);
+ DefaultMutableTreeNode temp2 = new DefaultMutableTreeNode("Astronomy");
+ temp2.insert(new DefaultMutableTreeNode("Education"), 0);
+ temp2.insert(new DefaultMutableTreeNode("Pictures"), 0);
+ temp.insert(temp2, 2);
+ tree.insert(temp, 2);
+ treeState = new TreeState();
+ treeState.addExpandState(tree);
+ treeState.addExpandState(temp);
+ treeState.addSelection(temp2);
+ treeState.setMarker(music);
+ session.setAttribute("tree", tree);
+ session.setAttribute("treeState", treeState);
+%>
+
+<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib tagdir="/WEB-INF/tags/layout" prefix="layout" %>
+
+<layout:screenshot>
+ <f:subview id="tree">
+ <jsp:body>
+ <tc:panel>
+ <f:facet name="layout">
+ <tc:gridLayout rows="300px;1*" />
+ </f:facet>
+ <tc:treeListbox state="#{treeState}" value="#{tree}"
+ idReference="userObject"
+ nameReference="userObject"/>
+
+ <tc:cell/>
+
+ </tc:panel>
+
+ </jsp:body>
+ </f:subview>
+</layout:screenshot>
+