Author: nbelaevski
Date: 2010-11-01 11:04:54 -0400 (Mon, 01 Nov 2010)
New Revision: 19837
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
Log:
https://jira.jboss.org/browse/RF-9315
- added support for different node types
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-01
15:02:46 UTC (rev 19836)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-01
15:04:54 UTC (rev 19837)
@@ -88,12 +88,33 @@
public static final String SELECTION_META_COMPONENT_ID = "selection";
- private static final Predicate<UIComponent> RENDERED_UITREE_NODE = new
Predicate<UIComponent>() {
+ private static final class MatchingTreeNodePredicate implements
Predicate<UIComponent> {
+
+ private String type;
+
+ public MatchingTreeNodePredicate(String type) {
+ super();
+ this.type = type;
+ }
+
public boolean apply(UIComponent input) {
- return (input instanceof AbstractTreeNode) && input.isRendered();
- };
+ if (!(input instanceof AbstractTreeNode)) {
+ return false;
+ }
+
+ if (!input.isRendered()) {
+ return false;
+ }
+
+ String nodeType = ((AbstractTreeNode) input).getType();
+ if (type == null && nodeType == null) {
+ return true;
+ }
+
+ return type != null && type.equals(nodeType);
+ }
};
-
+
private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
/**
@@ -131,6 +152,8 @@
@Attribute(defaultValue = "SwitchType.client")
public abstract SwitchType getSelectionType();
+ public abstract String getNodeType();
+
public Collection<Object> getSelection() {
@SuppressWarnings("unchecked")
Collection<Object> selection = (Collection<Object>)
getStateHelper().eval(PropertyKeys.selection);
@@ -220,7 +243,9 @@
return null;
}
- Iterator<UIComponent> iterator = Iterators.filter(getChildren().iterator(),
RENDERED_UITREE_NODE);
+ Iterator<UIComponent> iterator = Iterators.filter(getChildren().iterator(),
+ new MatchingTreeNodePredicate(getNodeType()));
+
if (iterator.hasNext()) {
return (AbstractTreeNode) iterator.next();
}
@@ -348,7 +373,13 @@
@Override
protected Iterator<UIComponent> dataChildren() {
- return Iterators.<UIComponent>concat(super.dataChildren(),
Iterators.singletonIterator(treeDecoderHelper));
+ AbstractTreeNode treeNodeComponent = getTreeNodeComponent();
+ if (treeNodeComponent != null) {
+ return
Iterators.<UIComponent>concat(Iterators.<UIComponent>singletonIterator(treeNodeComponent),
+ Iterators.singletonIterator(treeDecoderHelper));
+ } else {
+ return Iterators.<UIComponent>singletonIterator(treeDecoderHelper);
+ }
}
@Override
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-01
15:02:46 UTC (rev 19836)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-01
15:04:54 UTC (rev 19837)
@@ -61,6 +61,8 @@
@Attribute(defaultValue = "findTreeComponent().isImmediate()")
public abstract boolean isImmediate();
+ public abstract String getType();
+
protected AbstractTree findTreeComponent() {
UIComponent c = this;
while (c != null && !(c instanceof AbstractTree)) {
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-01
15:02:46 UTC (rev 19836)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-01
15:04:54 UTC (rev 19837)
@@ -268,6 +268,11 @@
AbstractTree tree = (AbstractTree) component;
AbstractTreeNode treeNode = tree.getTreeNodeComponent();
+
+ if (treeNode == null) {
+ return;
+ }
+
boolean expanded = Boolean.valueOf(newToggleState);
if (tree.isExpanded() ^ expanded) {
new TreeToggleEvent(treeNode, expanded).queue();