Author: nbelaevski
Date: 2011-03-10 09:34:20 -0500 (Thu, 10 Mar 2011)
New Revision: 22132
Added:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/DataHolderTreeNodeImpl.java
Modified:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java
Log:
https://issues.jboss.org/browse/RF-9718
Reviewed by Ilya
Modified:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
===================================================================
---
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2011-03-10
13:59:47 UTC (rev 22131)
+++
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2011-03-10
14:34:20 UTC (rev 22132)
@@ -22,32 +22,39 @@
package org.richfaces.demo;
-import org.richfaces.component.AbstractTree;
-import org.richfaces.component.AbstractTreeNode;
-import org.richfaces.component.SwitchType;
-import org.richfaces.event.TreeSelectionChangeEvent;
-import org.richfaces.event.TreeSelectionChangeListener;
-import org.richfaces.event.TreeToggleEvent;
-import org.richfaces.event.TreeToggleListener;
-import org.richfaces.log.LogFactory;
-import org.richfaces.log.Logger;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.IntegerConverter;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.FacesEvent;
import javax.swing.tree.TreeNode;
-import java.io.Serializable;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.SwitchType;
+import org.richfaces.convert.SequenceRowKeyConverter;
+import org.richfaces.demo.model.tree.DataHolderTreeNodeImpl;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
+import org.richfaces.log.LogFactory;
+import org.richfaces.log.Logger;
+import org.richfaces.model.SwingTreeNodeImpl;
+import org.richfaces.model.TreeNodeImpl;
+
/**
* @author Nick Belaevski
*
@@ -99,6 +106,8 @@
private static final Logger LOGGER = LogFactory.getLogger(TreeBean.class);
+ private static final Converter INTEGER_SEQUENCE_KEY_CONVERTER = new
SequenceRowKeyConverter<Integer>(Integer.class, new IntegerConverter());
+
private List<TreeNode> rootNodes;
private List<TreeNode> lazyRootNodes;
@@ -118,6 +127,8 @@
private ToggleActionListenerImpl toggleActionListenerImpl = new
ToggleActionListenerImpl();
private SelectionChangeActionListenerImpl selectionChangeActionListener;
+ private org.richfaces.model.TreeNode classicTreeNode;
+
private static Object staticGetNodeData() {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().evaluateExpressionGet(facesContext,
"#{node}", Object.class);
@@ -146,6 +157,28 @@
return result;
}
+ private org.richfaces.model.TreeNode createClassicNode(TreeNode node) {
+ TreeNodeImpl result = new DataHolderTreeNodeImpl(node.isLeaf(),
((SwingTreeNodeImpl<?>) node).getData());
+
+ for (int i = 0; i < node.getChildCount(); i++) {
+ result.addChild(i, createClassicNode(node.getChildAt(i)));
+ }
+
+ return result;
+ }
+
+ private org.richfaces.model.TreeNode createRootClassicNode(List<TreeNode>
nodes) {
+ TreeNodeImpl rootNode = new TreeNodeImpl();
+
+ int key = 0;
+
+ for (TreeNode node : nodes) {
+ rootNode.addChild(key++, createClassicNode(node));
+ }
+
+ return rootNode;
+ }
+
@PostConstruct
public void init() {
try {
@@ -153,6 +186,7 @@
parser.parse(TreeBean.class.getResource("plants.xml"));
rootNodes = parser.getRootNodes();
lazyRootNodes = createLazyNodes(rootNodes);
+ classicTreeNode = createRootClassicNode(rootNodes);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
@@ -166,6 +200,10 @@
return lazyRootNodes;
}
+ public org.richfaces.model.TreeNode getClassicTreeNode() {
+ return classicTreeNode;
+ }
+
public SwitchType[] getTypes() {
return SwitchType.values();
}
@@ -264,4 +302,9 @@
public void setSelectionChangeActionListener(SelectionChangeActionListenerImpl
selectionChangeActionListener) {
this.selectionChangeActionListener = selectionChangeActionListener;
}
+
+ public Converter getIntegerSequenceKeyConveter() {
+ return INTEGER_SEQUENCE_KEY_CONVERTER;
+ }
+
}
Added:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/DataHolderTreeNodeImpl.java
===================================================================
---
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/DataHolderTreeNodeImpl.java
(rev 0)
+++
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/DataHolderTreeNodeImpl.java 2011-03-10
14:34:20 UTC (rev 22132)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.model.tree;
+
+import org.richfaces.model.TreeNodeImpl;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DataHolderTreeNodeImpl extends TreeNodeImpl {
+
+ private Object data;
+
+ public DataHolderTreeNodeImpl(boolean leaf, Object data) {
+ super(leaf);
+ this.data = data;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + " >> " + data;
+ }
+}
Modified: branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml
===================================================================
--- branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml 2011-03-10 13:59:47
UTC (rev 22131)
+++ branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml 2011-03-10 14:34:20
UTC (rev 22132)
@@ -131,6 +131,18 @@
</it:treeNode>
</it:tree>
+ org.richfaces.model.TreeNode support:
+ <it:tree value="#{treeBean.classicTreeNode}" var="node"
+ selectionType="#{treeBean.selectionType}"
toggleType="#{treeBean.toggleType}"
+ rowKeyConverter="#{treeBean.integerSequenceKeyConveter}">
+ <it:treeNode>
+ #{node.data} -
+ <h:commandLink value="link"
action="#{treeBean.clickNode}">
+ <f:ajax render=":messages" />
+ </h:commandLink>
+ </it:treeNode>
+ </it:tree>
+
<h:commandLink value="Re-render">
<f:ajax render=":form:tree" execute="@all" />
</h:commandLink>
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2011-03-10
13:59:47 UTC (rev 22131)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2011-03-10
14:34:20 UTC (rev 22132)
@@ -49,9 +49,9 @@
import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
+import org.richfaces.application.FacesMessages;
import org.richfaces.application.MessageFactory;
import org.richfaces.application.ServiceTracker;
-import org.richfaces.application.FacesMessages;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
@@ -66,6 +66,7 @@
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.event.TreeToggleListener;
import org.richfaces.event.TreeToggleSource;
+import org.richfaces.model.ClassicTreeNodeDataModelImpl;
import org.richfaces.model.DeclarativeModelKey;
import org.richfaces.model.DeclarativeTreeDataModelImpl;
import org.richfaces.model.DeclarativeTreeModel;
@@ -73,6 +74,7 @@
import org.richfaces.model.TreeDataModel;
import org.richfaces.model.TreeDataModelTuple;
import org.richfaces.model.TreeDataVisitor;
+import org.richfaces.model.TreeNode;
import org.richfaces.renderkit.MetaComponentRenderer;
import com.google.common.base.Predicate;
@@ -473,9 +475,12 @@
Object value = getValue();
if (value == null) {
dataModel = new DeclarativeTreeDataModelImpl(this);
+ } else if (value instanceof TreeNode) {
+ dataModel = new ClassicTreeNodeDataModelImpl();
+ dataModel.setWrappedData(value);
} else {
dataModel = new SwingTreeNodeDataModelImpl();
- dataModel.setWrappedData(getValue());
+ dataModel.setWrappedData(value);
}
return dataModel;
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java 2011-03-10
13:59:47 UTC (rev 22131)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java 2011-03-10
14:34:20 UTC (rev 22132)
@@ -36,8 +36,6 @@
private static final Converter DEFAULT_CONVERTER = new
StringSequenceRowKeyConverter();
- private TreeNode rootNode;
-
public boolean isLeaf() {
return getData().isLeaf();
}
@@ -53,12 +51,12 @@
@Override
public Object getWrappedData() {
- return rootNode;
+ return getRootNode();
}
@Override
public void setWrappedData(Object data) {
- this.rootNode = (TreeNode) data;
+ setRootNode((TreeNode) data);
}
public Converter getRowKeyConverter() {
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java 2011-03-10
13:59:47 UTC (rev 22131)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java 2011-03-10
14:34:20 UTC (rev 22132)
@@ -34,8 +34,6 @@
private TreeNode treeNode;
- private SequenceRowKey baseKey;
-
private Iterator<Object> childrenKeysIterator = null;
public ClassicTreeNodeTuplesIterator(TreeNode treeNode, SequenceRowKey baseKey) {