Author: nbelaevski
Date: 2009-04-08 12:06:25 -0400 (Wed, 08 Apr 2009)
New Revision: 13440
Modified:
trunk/ui/treeModel/src/main/config/component/recursiveTreeNodesAdaptor.xml
trunk/ui/treeModel/src/main/java/org/richfaces/component/UIRecursiveTreeNodesAdaptor.java
Log:
https://jira.jboss.org/jira/browse/RF-6639
Modified: trunk/ui/treeModel/src/main/config/component/recursiveTreeNodesAdaptor.xml
===================================================================
--- trunk/ui/treeModel/src/main/config/component/recursiveTreeNodesAdaptor.xml 2009-04-08
16:05:05 UTC (rev 13439)
+++ trunk/ui/treeModel/src/main/config/component/recursiveTreeNodesAdaptor.xml 2009-04-08
16:06:25 UTC (rev 13440)
@@ -83,5 +83,9 @@
</description>
<defaultvalue>true</defaultvalue>
</property>
+ <property>
+ <name>recursionOrder</name>
+ <classname>java.lang.String</classname>
+ </property>
</component>
</components>
Modified:
trunk/ui/treeModel/src/main/java/org/richfaces/component/UIRecursiveTreeNodesAdaptor.java
===================================================================
---
trunk/ui/treeModel/src/main/java/org/richfaces/component/UIRecursiveTreeNodesAdaptor.java 2009-04-08
16:05:05 UTC (rev 13439)
+++
trunk/ui/treeModel/src/main/java/org/richfaces/component/UIRecursiveTreeNodesAdaptor.java 2009-04-08
16:06:25 UTC (rev 13440)
@@ -20,7 +20,9 @@
*/
package org.richfaces.component;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.apache.commons.collections.iterators.IteratorChain;
import org.richfaces.model.StackingTreeModel;
@@ -34,6 +36,10 @@
*/
public abstract class UIRecursiveTreeNodesAdaptor extends UITreeNodesAdaptor {
+ protected static final String FIRST = "first";
+
+ protected static final String LAST = "last";
+
public static final String COMPONENT_TYPE =
"org.richfaces.RecursiveTreeNodesAdaptor";
public static final String COMPONENT_FAMILY =
"org.richfaces.RecursiveTreeNodesAdaptor";
@@ -47,6 +53,9 @@
public abstract boolean isIncludedRoot();
public abstract void setIncludedRoot(boolean active);
+ public abstract String getRecursionOrder();
+ public abstract void setRecursionOrder(String recursionOrder);
+
protected boolean includeNode() {
return isIncluded() && isIncludedRoot();
}
@@ -58,9 +67,7 @@
public abstract String getVar();
public abstract void setVar(String var);
- public StackingTreeModel getStackingModel() {
- StackingTreeModel stackingModel = super.getStackingModel();
-
+ protected StackingTreeModel createRecursiveModel() {
StackingTreeModel recursiveModel = new VisualStackingTreeModel(getId(), getVar(), new
StackingTreeModelDataProvider() {
public Object getData() {
@@ -78,7 +85,7 @@
return model;
}
- public Iterator getModelsIterator() {
+ public Iterator<StackingTreeModel> getModelsIterator() {
IteratorChain chain = new IteratorChain();
chain.addIterator(super.getModelsIterator());
chain.addIterator(this.getParent().getModelsIterator());
@@ -94,9 +101,43 @@
return UIRecursiveTreeNodesAdaptor.this.isIncluded() &&
UIRecursiveTreeNodesAdaptor.this.isIncludedNode();
}
};
- stackingModel.addStackingModel(recursiveModel);
- return stackingModel;
+ return recursiveModel;
}
+ @Override
+ protected void addChildModels(StackingTreeModel model,
+ List<StackingTreeModel> childModels) {
+
+ String recursionOrder = getRecursionOrder();
+ if (recursionOrder == null) {
+ recursionOrder = LAST;
+ }
+
+ List<StackingTreeModel> newModelsList = new
ArrayList<StackingTreeModel>(childModels.size() + 1);
+ boolean recursiveModelInserted = false;
+
+ for (StackingTreeModel childModel : childModels) {
+ newModelsList.add(childModel);
+
+ if (recursionOrder.equals(childModel.getId())) {
+ recursiveModelInserted = true;
+ newModelsList.add(createRecursiveModel());
+ }
+ }
+
+ if (!recursiveModelInserted) {
+ if (LAST.equals(recursionOrder)) {
+ newModelsList.add(createRecursiveModel());
+ } else if (FIRST.equals(recursionOrder)) {
+ newModelsList.add(0, createRecursiveModel());
+ } else {
+ throw new IllegalArgumentException("Recursion order: [" + recursionOrder +
+ "] cannot be processed by component " +
this.getClientId(getFacesContext()) + "!");
+ }
+ }
+
+ super.addChildModels(model, newModelsList);
+ }
+
}