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 2010/06/09 21:32:50 UTC
svn commit: r953127 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/m...
Author: lofwyr
Date: Wed Jun 9 19:32:49 2010
New Revision: 953127
URL: http://svn.apache.org/viewvc?rev=953127&view=rev
Log:
TOBAGO-377: new tree implementation
- removing value attribute from tc:treeNode, because the only senseful value was #{node} where "node" is the value of the "var" attribute of the parent tc:treeData component
- fixing rendering of nodes inside of a tc:treeData: icons and junctions was displayed incorrect
- fixing icons, when showJunctions="false"
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeNodeTagDeclaration.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.jsp
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/tree.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-ajax.jsp
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-editor.jsp
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-menu.jsp
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-normal.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-state.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/navigation.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/tc/treeListbox/treeListbox.xhtml
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java Wed Jun 9 19:32:49 2010
@@ -17,14 +17,14 @@ package org.apache.myfaces.tobago.intern
* limitations under the License.
*/
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.myfaces.tobago.component.SupportsMarkup;
import org.apache.myfaces.tobago.component.TreeModelBuilder;
import org.apache.myfaces.tobago.event.TreeExpansionEvent;
import org.apache.myfaces.tobago.event.TreeExpansionListener;
import org.apache.myfaces.tobago.model.MixedTreeModel;
import org.apache.myfaces.tobago.model.TreePath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -46,11 +46,6 @@ public abstract class AbstractUITreeNode
private List<Boolean> junctions;
private boolean hasNextSibling;
- @Override
- public boolean getRendersChildren() {
- return true;
- }
-
public void buildTreeModelBegin(FacesContext facesContext, MixedTreeModel model) {
model.beginBuildNode(this);
setDepth(computeDepth(this));
@@ -91,55 +86,48 @@ public abstract class AbstractUITreeNode
mixedModel.onEncodeEnd();
}
- private int computeDepth(UIComponent node) {
+ private int computeDepth(UIComponent component) {
int depth = 0;
- while (node != null) {
+ while (component != null) {
depth++;
- if (node instanceof AbstractUITree) {
+ if (component instanceof AbstractUITree) {
return depth;
}
- if (node instanceof AbstractUITreeData) {
- Object dataTree = ((AbstractUITreeData) node).getValue();
+ if (component instanceof AbstractUITreeData) {
+ Object dataTree = ((AbstractUITreeData) component).getValue();
// todo: make independent from impl.
if (dataTree instanceof DefaultMutableTreeNode) {
- return ((DefaultMutableTreeNode) dataTree).getDepth();
+ return ((DefaultMutableTreeNode) dataTree).getDepth(); // XXX expensive
}
LOG.warn("Tree type not supported");
}
- node = node.getParent();
+ component = component.getParent();
}
throw new RuntimeException("Not inside of a UITree");
}
private boolean computeFolder() {
- if (isInData()) {
- Object value = getValue();
- // todo: make independent from impl.
- if (value instanceof DefaultMutableTreeNode) {
- return !((DefaultMutableTreeNode) value).isLeaf();
- }
- LOG.warn("Tree type not supported");
- return true;
+ DefaultMutableTreeNode node = getDataNode();
+ if (node != null) {
+ return !node.isLeaf();
} else {
- return getChildCount() != 0;
+ for (UIComponent child : getChildren()) {
+ if ((child instanceof AbstractUITreeNode || child instanceof AbstractUITreeData) && child.isRendered()) {
+ return true;
+ }
+ }
+ return false;
}
}
private boolean computeHasNextSibling() {
- if (isInData()) {
- Object value = getValue();
- // todo: make independent from impl.
- if (value instanceof DefaultMutableTreeNode) {
-
- DefaultMutableTreeNode tree = (DefaultMutableTreeNode) value;
- if (tree.isRoot()) {
- return hasSiblingAfter(getParent().getParent(), getParent());
- } else {
- return tree.getNextSibling() != null;
- }
+ DefaultMutableTreeNode node = getDataNode();
+ if (node != null) {
+ if (node.isRoot()) {
+ return hasSiblingAfter(getParent().getParent(), getParent());
+ } else {
+ return node.getNextSibling() != null;
}
- LOG.warn("Tree type not supported");
- return false;
} else {
return hasSiblingAfter(getParent(), this);
}
@@ -159,31 +147,39 @@ public abstract class AbstractUITreeNode
return false;
}
- private boolean isInData() {
+ /**
+ * Finds the value of the current node via the var attribute of the tree data.
+ * Returns null if it will be called not inside of {@link AbstractUITreeData}
+ */
+ // todo: make independent from impl.: DefaultMutableTreeNode
+ private DefaultMutableTreeNode getDataNode() {
UIComponent component = this;
while (component != null) {
if (component instanceof AbstractUITreeData) {
- return true;
+ final AbstractUITreeData data = (AbstractUITreeData) component;
+ final Object currentNode
+ = FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(data.getVar());
+ return (DefaultMutableTreeNode) currentNode;
} else if (component instanceof AbstractUITree) {
- return false;
+ return null;
}
component = component.getParent();
}
- return false;
+ return null;
}
@Override
public Object getValue() {
- DefaultMutableTreeNode value = (DefaultMutableTreeNode) super.getValue();
- if (value == null) { // XXX: hack!
- value = new DefaultMutableTreeNode();
- value.setUserObject(System.identityHashCode(value));
- setValue(value);
- if (LOG.isInfoEnabled()) {
- LOG.info("Created temporary Node: " + value.getUserObject());
- }
- }
- return value;
+ LOG.error("XXXXXXXXXXX should not be called!!!!!!!!!!!!");
+ return super.getValue();
+ }
+
+ /**
+ * Returns the level of the tree node inside of the virtual tree. The root node has level 0.
+ * The children of the root note have level 1, and so on.
+ */
+ public int getLevel() {
+ return path.getLength() - 1;
}
public String nodeStateId(FacesContext facesContext) {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeNodeTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeNodeTagDeclaration.java?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeNodeTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeNodeTagDeclaration.java Wed Jun 9 19:32:49 2010
@@ -32,7 +32,6 @@ import org.apache.myfaces.tobago.interna
import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasMarkup;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasTip;
-import org.apache.myfaces.tobago.internal.taglib.declaration.HasValue;
import org.apache.myfaces.tobago.internal.taglib.declaration.IsDisabled;
/**
@@ -53,7 +52,7 @@ import org.apache.myfaces.tobago.interna
facets = {
@Facet(name = Facets.ADDENDUM, description = "Displays an additional component to a node.")})
public interface TreeNodeTagDeclaration
- extends HasIdBindingAndRendered, HasLabel, HasValue, HasMarkup, HasTip, HasImage, IsDisabled,
+ extends HasIdBindingAndRendered, HasLabel, HasMarkup, HasTip, HasImage, IsDisabled,
AbstractCommandTagDeclaration {
/**
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java Wed Jun 9 19:32:49 2010
@@ -54,6 +54,10 @@ public class TreePath implements Seriali
return path;
}
+ public int getLength() {
+ return path.length;
+ }
+
public String getPathString() {
StringBuffer buffer = new StringBuffer();
for (int item : path) {
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.jsp?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.jsp (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.jsp Wed Jun 9 19:32:49 2010
@@ -28,7 +28,6 @@
<tc:treeNode label="#{node.userObject.title}"
action="#{node.userObject.action}"
immediate="true"
- value="#{node}"
expanded="true"/>
</tc:treeData>
</tc:treeMenu>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.xhtml?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/navigation.xhtml Wed Jun 9 19:32:49 2010
@@ -33,7 +33,6 @@
<tc:treeNode label="#{node.userObject.title}"
action="#{node.userObject.action}"
immediate="true"
- value="#{node}"
expanded="true"/>
</tc:treeData>
</tc:treeMenu>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/tree.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/tree.xhtml?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/tree.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/tree.xhtml Wed Jun 9 19:32:49 2010
@@ -48,7 +48,6 @@
<tc:treeNode label="#{node.userObject.name}"
id="template"
expanded="true"
- value="#{node}"
image="image/feather.png"/>
<!--
todo: tree editor
@@ -103,7 +102,6 @@
<tc:treeNode label="#{node.userObject.name}"
id="template"
expanded="true"
- value="#{node}"
image="image/feather.png"/>
</tc:treeData>
</tc:treeMenu>
@@ -127,7 +125,6 @@
<tc:treeNode label="#{node.userObject.name}"
id="template"
expanded="true"
- value="#{node}"
image="image/feather.png"/>
</tc:treeData>
</tc:treeListbox>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-ajax.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-ajax.jsp?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-ajax.jsp (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-ajax.jsp Wed Jun 9 19:32:49 2010
@@ -48,8 +48,7 @@
markup="#{node.userObject.markup}"
tip="#{node.userObject.tip}"
action="#{node.userObject.action}"
- disabled="#{node.userObject.disabled}"
- value="#{node}"/>
+ disabled="#{node.userObject.disabled}"/>
</tc:treeData>
<tc:treeNode label="2 Action 1" action="#{controller.action1}" id="action1"/>
<tc:treeNode label="3 Action 2" action="#{controller.action2}" id="action2"/>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-editor.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-editor.jsp?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-editor.jsp (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-editor.jsp Wed Jun 9 19:32:49 2010
@@ -41,7 +41,7 @@
<tc:treeNode label="#{node.userObject.name}" id="template"
markup="#{node.userObject.markup}"
tip="#{node.userObject.tip}"
- action="#{node.userObject.action}" value="#{node}"/>
+ action="#{node.userObject.action}"/>
</tc:treeData>
</tc:treeNode>
</tc:tree>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-menu.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-menu.jsp?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-menu.jsp (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-menu.jsp Wed Jun 9 19:32:49 2010
@@ -35,8 +35,7 @@
markup="#{node.userObject.markup}"
tip="#{node.userObject.tip}"
action="#{node.userObject.action}"
- disabled="#{node.userObject.disabled}"
- value="#{node}"/>
+ disabled="#{node.userObject.disabled}"/>
</tc:treeData>
<tc:treeNode label="2 Action 1" action="#{treeController.action1}" id="action1"/>
<tc:treeNode label="3 Action 2" action="#{treeController.action2}" id="action2"/>
@@ -59,8 +58,7 @@
markup="#{node.userObject.markup}"
tip="#{node.userObject.tip}"
action="#{node.userObject.action}"
- disabled="#{node.userObject.disabled}"
- value="#{node}"/>
+ disabled="#{node.userObject.disabled}"/>
</tc:treeData>
</tc:treeMenu>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-normal.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-normal.xhtml?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-normal.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-normal.xhtml Wed Jun 9 19:32:49 2010
@@ -44,7 +44,6 @@
tip="#{node.userObject.tip}"
action="#{node.userObject.action}"
disabled="#{node.userObject.disabled}"
- value="#{node}"
image="image/feather.png"
treeExpansionListener="#{node.userObject.expansionListener}"/>
</tc:treeData>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-state.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-state.xhtml?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-state.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-state.xhtml Wed Jun 9 19:32:49 2010
@@ -44,7 +44,6 @@
tip="#{node.userObject.tip}"
action="#{node.userObject.action}"
disabled="#{node.userObject.disabled}"
- value="#{node}"
image="image/feather.png"/>
</tc:treeData>
<tc:treeNode label="2 Action 1" action="#{treeController.action1}" id="action1">
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/navigation.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/navigation.xhtml?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/navigation.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/navigation.xhtml Wed Jun 9 19:32:49 2010
@@ -46,7 +46,7 @@
<tc:button action="#{clientConfig.submit}" label="OK"/>
</tc:panel>
- <tc:tree showJunctions="true">
+ <tc:tree showJunctions="true" showIcons="true">
<tc:treeData value="#{browser.tree}" var="node">
<tc:treeNode link="#{node.resource}" label="#{node.label}" target="page:content"/>
</tc:treeData>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/tc/treeListbox/treeListbox.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/tc/treeListbox/treeListbox.xhtml?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/tc/treeListbox/treeListbox.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/tc/treeListbox/treeListbox.xhtml Wed Jun 9 19:32:49 2010
@@ -31,7 +31,6 @@
<tc:treeNode label="#{node.userObject.name}"
id="template"
expanded="true"
- value="#{node}"
image="image/feather.png"/>
</tc:treeData>
</tc:treeListbox>
Modified: myfaces/tobago/trunk/tobago-theme/tobago-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/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java?rev=953127&r1=953126&r2=953127&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java Wed Jun 9 19:32:49 2010
@@ -128,7 +128,8 @@ public class TreeNodeRenderer extends Co
if (level > 0) { // root will not rendered as an option
writer.startElement(HtmlConstants.OPTION, null);
- writer.writeAttribute(HtmlAttributes.VALUE, node.getValue().toString(), true); // XXX converter?
+// todo: define where to store the selection of a tree, node.getValue() seems not to be a god place.
+// writer.writeAttribute(HtmlAttributes.VALUE, node.getValue().toString(), true); // XXX converter?
writer.writeIdAttribute(id);
writer.writeAttribute(HtmlAttributes.SELECTED, expanded);
writer.writeText("(" + level + ") " + node.getLabel());
@@ -186,34 +187,38 @@ public class TreeNodeRenderer extends Co
public void encodeBeginMenuAndNormal(FacesContext facesContext, UITreeNode node, AbstractUITree tree, boolean isMenu)
throws IOException {
- String treeId = tree.getClientId(facesContext);
- boolean folder = node.isFolder();
- boolean marked = node.isMarked();
- String id = node.getClientId(facesContext);
- int depth = node.getDepth();
- boolean hasNextSibling = node.isHasNextSibling();
- List<Boolean> junctions = node.getJunctions();
-
- boolean expanded = isExpanded(tree, node);
- boolean showIcons = false;
- boolean showJunctions = false;
- boolean showRootJunction = false;
+ final String treeId = tree.getClientId(facesContext);
+ final boolean folder = node.isFolder();
+ final boolean marked = node.isMarked();
+ final String id = node.getClientId(facesContext);
+ final int level = node.getLevel();
+ final boolean hasNextSibling = node.isHasNextSibling();
+ final List<Boolean> junctions = node.getJunctions();
+
+ final boolean expanded = isExpanded(tree, node);
+ final boolean showRoot = tree.isShowRoot();
+ final boolean showIcons;
+ final boolean showJunctions;
+ final boolean showRootJunction;
if (tree instanceof UITree) {
showIcons = ((UITree) tree).isShowIcons();
showJunctions = ((UITree) tree).isShowJunctions();
showRootJunction = ((UITree) tree).isShowRootJunction();
+ } else { // UITreeMenu
+ showIcons = false;
+ showJunctions = false;
+ showRootJunction = false;
}
- boolean showRoot = tree.isShowRoot();
if (!showRoot && junctions.size() > 0) {
junctions.remove(0);
}
String source;
- String openSource = null;
- String closedSource;
+ final String openSource;
+ final String closedSource;
- String image = ComponentUtils.getStringAttribute(node, "image");
+ final String image = ComponentUtils.getStringAttribute(node, "image");
if (image != null) { // application image
closedSource = ResourceManagerUtils.getImageWithPath(facesContext, image);
} else { // theme image
@@ -228,6 +233,7 @@ public class TreeNodeRenderer extends Co
}
source = expanded ? openSource : closedSource;
} else {
+ openSource = null;
if (image != null) { // application image
source = ResourceManagerUtils.getImageWithPath(facesContext,
ResourceUtils.addPostfixToFilename(image, "leaf"), true);
@@ -242,7 +248,7 @@ public class TreeNodeRenderer extends Co
CommandRendererHelper helper = new CommandRendererHelper(facesContext, node, CommandRendererHelper.Tag.ANCHOR);
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
- if (showRoot || depth != 0) {
+ if (showRoot || level != 0) {
writer.startElement(HtmlConstants.DIV, null);
// div id
@@ -266,7 +272,7 @@ public class TreeNodeRenderer extends Co
// div style (width)
Style style = new Style(facesContext, tree);
String widthString;
- if (style != null && style.getWidth() != null) {
+ if (style.getWidth() != null) {
widthString = "width: " + Integer.toString(style.getWidth().getPixel() - 22); // fixme: 4 + 18 for scrollbar
} else {
widthString = "100%";
@@ -281,10 +287,10 @@ public class TreeNodeRenderer extends Co
encodeMenuIcon(facesContext, writer, treeId, id, expanded, node);
}
- encodeIndent(facesContext, writer, isMenu, junctions);
+ encodeIndent(facesContext, writer, isMenu, showJunctions, junctions);
encodeTreeJunction(facesContext, writer, id, treeId, showJunctions, showRootJunction, showRoot, expanded,
- folder, depth, hasNextSibling, openSource, closedSource);
+ folder, level, hasNextSibling, openSource, closedSource);
encodeTreeIcons(writer, id, treeId, showIcons, folder, source, openSource, closedSource);
@@ -339,7 +345,8 @@ public class TreeNodeRenderer extends Co
}
private void encodeIndent(
- FacesContext facesContext, TobagoResponseWriter writer, boolean menuMode, List<Boolean> junctions)
+ final FacesContext facesContext, final TobagoResponseWriter writer, final boolean menuMode,
+ final boolean showJunctions, final List<Boolean> junctions)
throws IOException {
String blank = ResourceManagerUtils.getImageWithPath(facesContext, "image/blank.gif");
@@ -348,7 +355,7 @@ public class TreeNodeRenderer extends Co
for (Boolean junction : junctions) {
writer.startElement(HtmlConstants.IMG, null);
writer.writeClassAttribute("tobago-treeNode-junction");
- if (junction && !menuMode) {
+ if (junction && !menuMode && showJunctions) {
writer.writeAttribute("src", perpendicular, true);
} else {
writer.writeAttribute("src", blank, true);
@@ -360,20 +367,20 @@ public class TreeNodeRenderer extends Co
private void encodeTreeJunction(
FacesContext facesContext, TobagoResponseWriter writer, String id, String treeId,
boolean showJunctions, boolean showRootJunction, boolean showRoot, boolean expanded, boolean folder,
- int depth, boolean hasNextSibling, String openSource, String closedSource)
+ int level, boolean hasNextSibling, String openSource, String closedSource)
throws IOException {
if (!(!showJunctions
- || !showRootJunction && depth == 0
- || !showRootJunction && !showRoot && depth == 1)) {
+ || !showRootJunction && level == 0
+ || !showRootJunction && !showRoot && level == 1)) {
writer.startElement(HtmlConstants.IMG, null);
writer.writeClassAttribute("tobago-treeNode-junction");
writer.writeIdAttribute(id + "-junction");
String gif = folder && expanded
- ? (depth == 0
+ ? (level == 0
? "Rminus.gif"
: (hasNextSibling ? "Tminus.gif" : "Lminus.gif"))
- : ((depth == 0)
+ : ((level == 0)
? "Rplus.gif"
: (hasNextSibling)
? (folder ? "Tplus.gif" : "T.gif")
@@ -386,7 +393,7 @@ public class TreeNodeRenderer extends Co
writer.writeAttribute("onclick", createOnclickForToggle(treeId, openSource, closedSource), true);
}
writer.writeAttribute("alt", "", false);
-// } else if (( !this.hideRoot && depth >0 ) || (this.hideRoot && depth > 1)) {
+// } else if (( !this.hideRoot && level >0 ) || (this.hideRoot && level > 1)) {
// str += '<img class="tree-junction" id="' + this.id
// + '-junction" src="' + this.treeResources.getImage("blank.gif")
// + '" alt="">';