Author: lfryc(a)redhat.com
Date: 2010-12-14 09:09:22 -0500 (Tue, 14 Dec 2010)
New Revision: 20555
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml
Log:
rich:tree - adaptors - support for Map in model and recursive model(RF-9698)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java 2010-12-14
13:31:25 UTC (rev 20554)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java 2010-12-14
14:09:22 UTC (rev 20555)
@@ -25,6 +25,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
@@ -50,7 +51,8 @@
private static final long serialVersionUID = 4008175400649809L;
private static Logger logger;
private Attributes attributes;
- private boolean leafChildrenNullable = true;
+ private AtomicReference<Boolean> leafChildrenNullable = new
AtomicReference<Boolean>(true);
+ private boolean useMapModel;
private transient List<RecursiveNode> rootNodes;
/*
@@ -103,10 +105,18 @@
}
public boolean isLeafChildrenNullable() {
- return leafChildrenNullable;
+ return leafChildrenNullable.get();
}
public void setLeafChildrenNullable(boolean leafChildrenNullable) {
- this.leafChildrenNullable = leafChildrenNullable;
+ this.leafChildrenNullable.set(leafChildrenNullable);
}
+
+ public boolean isUseMapModel() {
+ return useMapModel;
+ }
+
+ public void setUseMapModel(boolean useMapModel) {
+ this.useMapModel = useMapModel;
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java 2010-12-14
13:31:25 UTC (rev 20554)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java 2010-12-14
14:09:22 UTC (rev 20555)
@@ -21,8 +21,11 @@
*******************************************************************************/
package org.richfaces.tests.metamer.model.treeAdaptor;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -31,18 +34,22 @@
public class ModelNode extends Node {
private static final int BS = 3;
+ private static final int KS = 4;
List<B> bs;
+ Map<K, V> map;
List<RecursiveNode> rs;
public ModelNode() {
- super(null, true, null);
+ super(null, null, null);
}
-
- protected ModelNode(Node parent, boolean nullable,
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
+
+ protected ModelNode(Node parent, AtomicReference<Boolean> nullable,
+ Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
super(parent, nullable, lazyLoadingListenerReference);
}
- public static ModelNode getInstance(Node parent, boolean nullable,
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
+ public static ModelNode getInstance(Node parent, AtomicReference<Boolean>
nullable,
+ Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
return lazyLoadingChecker(new ModelNode(parent, nullable,
lazyLoadingListenerReference));
}
@@ -64,6 +71,16 @@
return bs;
}
+ public Map<K, V> getMap() {
+ if (map == null) {
+ map = new LinkedHashMap<K, V>();
+ for (int i = 0; i < KS; i++) {
+ map.put(new K(i), new V(i));
+ }
+ }
+ return map;
+ }
+
public List<RecursiveNode> getRecursive() {
if (rs == null) {
rs = RecursiveNode.createChildren(this, nullable, null);
@@ -88,19 +105,33 @@
return ModelNode.this.getLabel() + "-B-" + number;
}
}
-
- @Override
- public String toString() {
- return getLabel();
+
+ public class K {
+ int number;
+
+ public K(int number) {
+ this.number = number;
+ }
+
+ public String getLabel() {
+ return ModelNode.this.getLabel() + "-K-" + number;
+ }
}
- private RecursiveNode getParentRecursive() {
- for (Node predecessor : getPredecessorsFromRoot()) {
- if (predecessor instanceof RecursiveNode) {
- return (RecursiveNode) predecessor;
- }
+ public class V {
+ int number;
+
+ public V(int number) {
+ this.number = number;
}
- return null;
+
+ public String getLabel() {
+ return ModelNode.this.getLabel() + "-V-" + number;
+ }
}
+ @Override
+ public String toString() {
+ return getLabel();
+ }
}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java 2010-12-14
13:31:25 UTC (rev 20554)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java 2010-12-14
14:09:22 UTC (rev 20555)
@@ -23,6 +23,7 @@
import java.util.Deque;
import java.util.LinkedList;
+import java.util.concurrent.atomic.AtomicReference;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -30,11 +31,12 @@
*/
public abstract class Node {
Node parent;
- boolean nullable;
+ AtomicReference<Boolean> nullable;
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference = new
NodeReference();
- protected Node(Node parent, boolean nullable,
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
+ protected Node(Node parent, AtomicReference<Boolean> nullable,
+ Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
this.parent = parent;
this.nullable = nullable;
if (lazyLoadingListenerReference != null) {
@@ -74,11 +76,11 @@
}
public abstract String getLabel();
-
+
public Reference<LazyLoadingListener<Node>>
getLazyLoadingListenerReference() {
return lazyLoadingListenerReference;
}
-
+
public void setLazyLoadingListener(Reference<LazyLoadingListener<Node>>
lazyLoadingListener) {
this.lazyLoadingListenerReference = lazyLoadingListener;
}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java 2010-12-14
13:31:25 UTC (rev 20554)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java 2010-12-14
14:09:22 UTC (rev 20555)
@@ -21,8 +21,14 @@
*******************************************************************************/
package org.richfaces.tests.metamer.model.treeAdaptor;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -32,21 +38,25 @@
private static final int CHILDREN = 4;
private static final int LEVELS = 2;
private static final List<RecursiveNode> EMPTY_LIST = new
LinkedList<RecursiveNode>();
+ private static final Map<Integer, RecursiveNode> EMPTY_MAP = new
HashMap<Integer, RecursiveNode>();
int number;
List<RecursiveNode> children = null;
+ NodeMap nodeMap = new NodeMap();
ModelNode model;
public RecursiveNode() {
- super(null, true, null);
+ super(null, null, null);
}
-
- protected RecursiveNode(Node parent, boolean nullable, int number,
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
+
+ protected RecursiveNode(Node parent, AtomicReference<Boolean> nullable, int
number,
+ Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
super(parent, nullable, lazyLoadingListenerReference);
this.number = number;
}
- public static RecursiveNode getInstance(Node parent, boolean nullable, int number,
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
+ public static RecursiveNode getInstance(Node parent, AtomicReference<Boolean>
nullable, int number,
+ Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
return lazyLoadingChecker(new RecursiveNode(parent, nullable, number,
lazyLoadingListenerReference));
}
@@ -58,9 +68,9 @@
return getRecursionLevel() >= LEVELS + (isOddBranch() ? 0 : 1);
}
- public List<RecursiveNode> getRecursive() {
+ public List<RecursiveNode> getRecursiveList() {
if (isLeaf()) {
- return getEmpty();
+ return getEmptyList();
}
if (children == null) {
children = createChildren(this, nullable, null);
@@ -68,10 +78,21 @@
return children;
}
- private List<RecursiveNode> getEmpty() {
- return nullable ? null : EMPTY_LIST;
+ public Map<Integer, RecursiveNode> getRecursiveMap() {
+ if (isLeaf()) {
+ return getEmptyMap();
+ }
+ return nodeMap;
}
+ private List<RecursiveNode> getEmptyList() {
+ return nullable.get() ? null : EMPTY_LIST;
+ }
+
+ private Map<Integer, RecursiveNode> getEmptyMap() {
+ return nullable.get() ? null : EMPTY_MAP;
+ }
+
public String getLabel() {
String parentLabel = (isRoot() ? "" : parent.getLabel() +
"-") + "R-";
String recursionLabel = (isRecursionRoot() ? parentLabel : parent.getLabel() +
".") + number;
@@ -100,7 +121,8 @@
}
}
- public static List<RecursiveNode> createChildren(Node parent, boolean nullable,
Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
+ public static List<RecursiveNode> createChildren(Node parent,
AtomicReference<Boolean> nullable,
+ Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
List<RecursiveNode> children = new LinkedList<RecursiveNode>();
for (int i = 0; i < CHILDREN; i++) {
RecursiveNode node = RecursiveNode.getInstance(parent, nullable, i,
lazyLoadingListenerReference);
@@ -131,4 +153,107 @@
public String toString() {
return getLabel();
}
+
+ public class NodeMap implements Map<Integer, RecursiveNode> {
+
+ @Override
+ public int size() {
+ return getRecursiveList().size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return getRecursiveList().isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public RecursiveNode get(Object key) {
+ if (key instanceof Integer) {
+ return getRecursiveList().get((Integer) key);
+ }
+ throw new IllegalStateException("there is no value for the key
'" + key + "' (type "
+ + key.getClass().getName() + ")");
+ }
+
+ @Override
+ public RecursiveNode put(Integer key, RecursiveNode value) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public RecursiveNode remove(Object key) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public void putAll(Map<? extends Integer, ? extends RecursiveNode> m) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public Set<Integer> keySet() {
+ HashSet<Integer> set = new HashSet<Integer>();
+ for (int i = 0; i < getRecursiveList().size(); i++) {
+ set.add(i);
+ }
+ return set;
+ }
+
+ @Override
+ public Collection<RecursiveNode> values() {
+ return getRecursiveList();
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<Integer, RecursiveNode>> entrySet() {
+ HashSet<Map.Entry<Integer, RecursiveNode>> set = new
HashSet<Map.Entry<Integer, RecursiveNode>>();
+ int i = 0;
+ for (RecursiveNode node : getRecursiveList()) {
+ set.add(new MapEntry(i++, node));
+ }
+ return set;
+ }
+
+ }
+
+ public class MapEntry implements Map.Entry<Integer, RecursiveNode> {
+
+ int key;
+ RecursiveNode node;
+
+ public MapEntry(int key, RecursiveNode node) {
+ this.key = key;
+ this.node = node;
+ }
+
+ @Override
+ public Integer getKey() {
+ return key;
+ }
+
+ @Override
+ public RecursiveNode getValue() {
+ return node;
+ }
+
+ @Override
+ public RecursiveNode setValue(RecursiveNode value) {
+ throw new UnsupportedOperationException("not supported");
+ }
+ }
}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml 2010-12-14
13:31:25 UTC (rev 20554)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml 2010-12-14
14:09:22 UTC (rev 20555)
@@ -77,7 +77,7 @@
<rich:treeModelRecursiveAdaptor
roots="#{richTreeModelRecursiveAdaptorBean.rootNodes}"
- nodes="#{node.recursive}"
+ nodes="#{richTreeModelRecursiveAdaptorBean.useMapModel ?
node.recursiveMap : node.recursiveList}"
recursionOrder="#{richTreeModelRecursiveAdaptorBean.attributes['recursionOrder'].value}"
@@ -93,7 +93,17 @@
</rich:treeNode>
</rich:treeModelAdaptor>
- <rich:treeModelRecursiveAdaptor
roots="#{node.model.recursive}" nodes="#{node.recursive}"
rendered="#{richTreeModelRecursiveAdaptorBean.attributes['rendered'].value}">
+ <rich:treeModelAdaptor nodes="#{node.model.map}"
rendered="#{richTreeModelAdaptorBean.attributes['rendered'].value}">
+ <rich:treeNode>
+ #{node.label}
+ </rich:treeNode>
+ </rich:treeModelAdaptor>
+
+ <rich:treeModelRecursiveAdaptor
+ roots="#{node.model.recursive}"
+ nodes="#{richTreeModelRecursiveAdaptorBean.useMapModel ?
node.recursiveMap : node.recursiveList}"
+
rendered="#{richTreeModelRecursiveAdaptorBean.attributes['rendered'].value}">
+
<rich:treeNode
rendered="#{richTreeNodeBean.attributes['rendered'].value || node.number !=
1}">
#{node.label}
</rich:treeNode>
@@ -106,11 +116,24 @@
<ui:define name="outOfTemplateAfter">
<h:panelGrid id="selectionOutput" columns="2">
- <h:outputLabel value="Selection: " />
+ <h:outputLabel value="Selection:" />
<h:outputText value="#{richTreeBean.selection}" />
<h:outputLabel value="Lazy Initialized:" />
<h:outputText
value="#{richTreeModelRecursiveAdaptorBean.lazyInitializedNodes}" />
+
+ <h:outputLabel value="Recursive Leaf Children Nullable:" />
+ <h:selectBooleanCheckbox
value="#{richTreeModelRecursiveAdaptorBean.leafChildrenNullable}">
+ <a4j:ajax render="commonGrid" />
+ </h:selectBooleanCheckbox>
+
+ <h:outputLabel value="Recursive Model Representation:" />
+ <h:selectOneRadio
value="#{richTreeModelRecursiveAdaptorBean.useMapModel}">
+ <f:selectItem itemLabel="List<RecursiveNode>"
itemValue="false" />
+ <f:selectItem itemLabel="Map<Integer,
RecursiveNode>" itemValue="true" />
+
+ <a4j:ajax render="commonGrid" />
+ </h:selectOneRadio>
</h:panelGrid>
<a4j:outputPanel>