Author: nbelaevski
Date: 2007-10-31 21:37:44 -0400 (Wed, 31 Oct 2007)
New Revision: 3663
Added:
trunk/framework/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
trunk/samples/tree-demo/src/main/java/org/richfaces/SwingTreeNode.java
Modified:
trunk/framework/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java
trunk/samples/seamIntegration/
trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java
trunk/samples/tree-demo/src/main/webapp/pages/index.jsp
trunk/ui/tree/src/main/java/org/richfaces/component/CacheableTreeDataModel.java
trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
trunk/ui/tree/src/test/java/org/richfaces/component/TreeModelTest.java
Log:
http://jira.jboss.com/jira/browse/RF-864
Modified:
trunk/framework/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java 2007-11-01
01:04:03 UTC (rev 3662)
+++
trunk/framework/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -37,8 +37,6 @@
public abstract class AbstractTreeDataModel extends ExtendedDataModel {
public final static char SEPARATOR = NamingContainer.SEPARATOR_CHAR;
- private TreeNode wrappedData;
-
public final int getRowCount() {
return -1;
}
@@ -53,14 +51,6 @@
}
}
- public final Object getWrappedData() {
- return wrappedData;
- }
-
- public final void setWrappedData(Object data) {
- wrappedData = (TreeNode) data;
- }
-
public final void walk(FacesContext context, DataVisitor dataVisitor,
Range range, Object argument) throws IOException {
walk(context, dataVisitor, range, null, argument, false);
@@ -132,6 +122,6 @@
dataVisitor.process(context, treeRowKey, argument);
}
}
-
+
public abstract TreeNode getTreeNode();
}
Added: trunk/framework/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -0,0 +1,45 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model;
+
+/**
+ * Created 01.11.2007
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class ClassicTreeDataModel extends TreeDataModel<TreeNode> {
+
+ public ClassicTreeDataModel() {
+ super(TreeNode.class, TreeDataModelNodeAdaptor.classicTreeNodeAdaptor);
+ }
+
+ public TreeNode getTreeNode() {
+ if (isRowAvailable()) {
+ return locateTreeNode((TreeRowKey) getRowKey());
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2007-11-01
01:04:03 UTC (rev 3662)
+++
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -573,4 +573,14 @@
}
};
+
+ @Override
+ public Object getWrappedData() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ throw new UnsupportedOperationException();
+ }
}
Added: trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -0,0 +1,85 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.swing.tree.TreeNode;
+
+/**
+ * Created 01.11.2007
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class SwingTreeDataModel extends TreeDataModel<TreeNode> {
+
+ private TreeNode treeNode;
+
+ public SwingTreeDataModel() {
+ super(TreeNode.class, TreeDataModelNodeAdaptor.swingTreeNodeAdaptor);
+ }
+
+ @Override
+ protected TreeNode getData() {
+ return treeNode;
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ if (data != null) {
+ SwingTreeNodeImpl treeNodeImpl = new SwingTreeNodeImpl();
+
+ if (data instanceof Collection<?>) {
+ Collection<?> collection = (Collection<?>) data;
+
+ for (Iterator<?> iterator = collection.iterator(); iterator
+ .hasNext();) {
+ treeNodeImpl.addChild((TreeNode) iterator.next());
+ }
+ } else if (data.getClass().isArray()) {
+ Object[] nodes = (Object[]) data;
+ for (int i = 0; i < nodes.length; i++) {
+ treeNodeImpl.addChild((TreeNode) nodes[i]);
+ }
+ } else {
+ treeNodeImpl.addChild((TreeNode) data);
+ }
+
+ this.treeNode = treeNodeImpl;
+ } else {
+ this.treeNode = null;
+ }
+
+ super.setWrappedData(data);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.AbstractTreeDataModel#getTreeNode()
+ */
+ @Override
+ public org.richfaces.model.TreeNode getTreeNode() {
+ return null;
+ }
+
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -0,0 +1,98 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.tree.TreeNode;
+
+/**
+ * Created 01.11.2007
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class SwingTreeNodeImpl implements TreeNode {
+
+ private Vector<TreeNode> children = new Vector<TreeNode>();
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#children()
+ */
+ public Enumeration children() {
+ return children.elements();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getAllowsChildren()
+ */
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ public void setAllowsChildren(boolean allowsChildren) {
+ if (!allowsChildren) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getChildAt(int)
+ */
+ public TreeNode getChildAt(int childIndex) {
+ return children.get(childIndex);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getChildCount()
+ */
+ public int getChildCount() {
+ return children.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
+ */
+ public int getIndex(TreeNode node) {
+ return children.indexOf(node);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getParent()
+ */
+ public TreeNode getParent() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#isLeaf()
+ */
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ public void addChild(TreeNode node) {
+ children.add(node);
+ }
+
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java 2007-11-01
01:04:03 UTC (rev 3662)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -36,13 +36,32 @@
* @author Nick Belaevski - nbelaevski(a)exadel.com created 16.11.2006
*
*/
-public class TreeDataModel extends AbstractTreeDataModel {
+public abstract class TreeDataModel<T> extends AbstractTreeDataModel {
+
+ private Object wrappedData;
+ private Class<T> clazz;
+
private TreeRowKey currentRowKey;
private TreeRowKey oldRowKey;
- private TreeNode rowTreeData;
+ private T rowTreeData;
+ protected final TreeDataModelNodeAdaptor<T> nodeAdaptor;
+
+ public TreeDataModel(Class<T> clazz, TreeDataModelNodeAdaptor<T>
nodeAdaptor) {
+ this.clazz = clazz;
+ this.nodeAdaptor = nodeAdaptor;
+ }
+
+ public final Class<T> getClazz() {
+ return clazz;
+ }
+
+ public final TreeDataModelNodeAdaptor<T> getNodeAdaptor() {
+ return nodeAdaptor;
+ }
+
public Object getRowKey() {
return this.currentRowKey;
}
@@ -62,63 +81,65 @@
Range range, Object rowKey, Object argument, boolean last) throws IOException {
ListRowKey listRowKey = (ListRowKey) rowKey;
- TreeNode node = locateTreeNode(listRowKey);
+ T node = locateTreeNode(listRowKey);
if (node != null) {
TreeRange treeRange = (TreeRange) range;
if (treeRange == null || treeRange.processNode(listRowKey)) {
- if (node.getParent() != null) {
+ if (nodeAdaptor.getParent(node) != null) {
processElement(context, dataVisitor, argument, listRowKey, last);
}
if (treeRange == null || treeRange.processChildren(listRowKey)) {
- if (!node.isLeaf()) {
- Iterator children = node.getChildren();
+ if (!nodeAdaptor.isLeaf(node)) {
+ Iterator<Map.Entry<Object, T>> children =
nodeAdaptor.getChildren(node);
- Map.Entry childEntry = children.hasNext() ? (Map.Entry) children.next() : null;
- TreeNode childNode;
- Object identifier;
+ if (children != null) {
+ Map.Entry<Object, T> childEntry = children.hasNext() ? children.next() :
null;
+ T childNode;
+ Object identifier;
- if (childEntry != null) {
- childNode = (TreeNode) childEntry.getValue();
- identifier = childEntry.getKey();
- } else {
- childNode = null;
- identifier = null;
- }
-
- do {
- Map.Entry nextChildEntry = children.hasNext() ? (Map.Entry) children.next() :
null;
- TreeNode nextChildNode;
- Object nextIdentifier;
-
- if (nextChildEntry != null) {
- nextChildNode = (TreeNode) nextChildEntry.getValue();
- nextIdentifier = nextChildEntry.getKey();
+ if (childEntry != null) {
+ childNode = childEntry.getValue();
+ identifier = childEntry.getKey();
} else {
- nextChildNode = null;
- nextIdentifier = null;
+ childNode = null;
+ identifier = null;
}
- if (childNode != null) {
+ do {
+ Map.Entry<Object, T> nextChildEntry = children.hasNext() ? children.next()
: null;
+ T nextChildNode;
+ Object nextIdentifier;
- boolean isLast = nextChildNode == null;
+ if (nextChildEntry != null) {
+ nextChildNode = nextChildEntry.getValue();
+ nextIdentifier = nextChildEntry.getKey();
+ } else {
+ nextChildNode = null;
+ nextIdentifier = null;
+ }
- ListRowKey newRowKey;
- if (rowKey != null) {
- newRowKey = new ListRowKey(listRowKey, identifier);
- } else {
- newRowKey = new ListRowKey(identifier);
+ if (childNode != null) {
+
+ boolean isLast = nextChildNode == null;
+
+ ListRowKey newRowKey;
+ if (rowKey != null) {
+ newRowKey = new ListRowKey(listRowKey, identifier);
+ } else {
+ newRowKey = new ListRowKey(identifier);
+ }
+
+ this.doWalk(context, dataVisitor, range, newRowKey, argument, isLast);
}
- this.doWalk(context, dataVisitor, range, newRowKey, argument, isLast);
- }
-
- identifier = nextIdentifier;
- childNode = nextChildNode;
- } while (childNode != null);
+ identifier = nextIdentifier;
+ childNode = nextChildNode;
+ } while (childNode != null);
+ }
}
}
}
@@ -139,14 +160,14 @@
doWalk(context, dataVisitor, range, rowKey, argument, last);
}
- public TreeNode locateTreeNode(TreeRowKey rowKey) {
+ public T locateTreeNode(TreeRowKey rowKey) {
return locateTreeNode(rowKey, false);
}
- public TreeNode locateTreeNode(TreeRowKey rowKey, boolean allowCreate) {
+ public T locateTreeNode(TreeRowKey rowKey, boolean allowCreate) {
boolean useCached = (rowTreeData != null && rowKey != null &&
rowKey.equals(this.oldRowKey));
if (!useCached) {
- TreeNode rootNode = (TreeNode) getWrappedData();
+ T rootNode = getData();
if (rootNode != null) {
if (rowKey != null) {
@@ -162,7 +183,7 @@
for (int i = 0; i < oldRowKey.depth()
- commonPathLength; i++) {
- rowTreeData = rowTreeData.getParent();
+ rowTreeData = nodeAdaptor.getParent(rowTreeData);
}
} else {
commonPathLength = 0;
@@ -171,19 +192,18 @@
}
}
oldRowKey = rowKey;
- Iterator iterator = rowKey.getSubPathIterator(commonPathLength);
+ Iterator<?> iterator = rowKey.getSubPathIterator(commonPathLength);
while (iterator.hasNext()) {
//TODO nick - check rowTreeData for null
Object pathSegment = iterator.next();
- TreeNode childRowTreeData = rowTreeData.getChild(pathSegment);
+ T childRowTreeData = nodeAdaptor.getChild(rowTreeData, pathSegment);
if (childRowTreeData == null) {
if (!allowCreate) {
return null;
} else {
- childRowTreeData = new TreeNodeImpl();
- rowTreeData.addChild(pathSegment, childRowTreeData);
+ childRowTreeData = nodeAdaptor.addChild(rowTreeData, pathSegment);
}
}
@@ -200,7 +220,7 @@
}
public boolean isRowAvailable() {
- TreeNode data = locateTreeNode(this.currentRowKey);
+ T data = locateTreeNode(this.currentRowKey);
if (data != null) {
return true;
@@ -211,9 +231,9 @@
public Object getRowData() {
if (isRowAvailable()) {
- TreeNode treeNode = locateTreeNode(this.currentRowKey);
+ T treeNode = locateTreeNode(this.currentRowKey);
if (treeNode != null) {
- return treeNode.getData();
+ return nodeAdaptor.getRowData(treeNode);
}
return null;
@@ -226,9 +246,9 @@
public boolean isLeaf() {
if (isRowAvailable()) {
- TreeNode treeNode = locateTreeNode(this.currentRowKey);
+ T treeNode = locateTreeNode(this.currentRowKey);
if (treeNode != null) {
- return treeNode.isLeaf();
+ return nodeAdaptor.isLeaf(treeNode);
}
}
@@ -240,12 +260,17 @@
walk(context, visitor, range, key, argument, last);
}
- public TreeNode getTreeNode() {
- if (isRowAvailable()) {
- return locateTreeNode(this.currentRowKey);
- }
+ @Override
+ public Object getWrappedData() {
+ return wrappedData;
+ }
- throw new IllegalStateException(
- "No tree element available or row key not set!");
+ @Override
+ public void setWrappedData(Object data) {
+ this.wrappedData = data;
}
+
+ protected T getData() {
+ return clazz.cast(wrappedData);
+ }
}
Added:
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -0,0 +1,183 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.swing.tree.TreeNode;
+
+/**
+ * Created 01.11.2007
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public interface TreeDataModelNodeAdaptor<T> {
+ public T getParent(T node);
+
+ public boolean isLeaf(T node);
+
+ public T addChild(T node, Object key);
+
+ public T getChild(T node, Object key);
+
+ public Iterator<Map.Entry<Object, T>> getChildren(T node);
+
+ public Object getRowData(T node);
+
+ public void setRowData(T node, Object rowData);
+
+ public static final TreeDataModelNodeAdaptor<org.richfaces.model.TreeNode>
classicTreeNodeAdaptor =
+ new TreeDataModelNodeAdaptor<org.richfaces.model.TreeNode>() {
+
+ public org.richfaces.model.TreeNode addChild(org.richfaces.model.TreeNode node,
+ Object key) {
+ //TODO nick - review implementation usage inside interface
+ TreeNodeImpl impl = new TreeNodeImpl();
+ node.addChild(key, impl);
+
+ return impl;
+ }
+
+ public org.richfaces.model.TreeNode getChild(org.richfaces.model.TreeNode node, Object
key) {
+ return node.getChild(key);
+ }
+
+ public Iterator<Entry<Object, org.richfaces.model.TreeNode>> getChildren(
+ org.richfaces.model.TreeNode node) {
+ return node.getChildren();
+ }
+
+ public org.richfaces.model.TreeNode getParent(org.richfaces.model.TreeNode node) {
+ return node.getParent();
+ }
+
+ public Object getRowData(org.richfaces.model.TreeNode node) {
+ return node.getData();
+ }
+
+ public boolean isLeaf(org.richfaces.model.TreeNode node) {
+ return node.isLeaf();
+ }
+
+ public void setRowData(org.richfaces.model.TreeNode node,
+ Object rowData) {
+ node.setData(rowData);
+ }
+
+ };
+
+ public static final TreeDataModelNodeAdaptor<javax.swing.tree.TreeNode>
swingTreeNodeAdaptor =
+ new TreeDataModelNodeAdaptor<javax.swing.tree.TreeNode>() {
+
+ final class SwingNodeMapEntry implements Map.Entry<Object, TreeNode> {
+
+ private Object key;
+ private TreeNode child;
+
+ public SwingNodeMapEntry(int i, TreeNode child) {
+ this.key = Integer.valueOf(i);
+ this.child = child;
+ }
+
+ public Object getKey() {
+ return this.key;
+ }
+
+ public TreeNode getValue() {
+ return child;
+ }
+
+ public TreeNode setValue(TreeNode value) {
+ TreeNode node = this.child;
+ this.child = value;
+
+ return node;
+ }
+
+ };
+
+ public javax.swing.tree.TreeNode addChild(
+ javax.swing.tree.TreeNode node, Object key) {
+
+ throw new UnsupportedOperationException();
+ }
+
+ public javax.swing.tree.TreeNode getChild(
+ javax.swing.tree.TreeNode node, Object key) {
+
+ Integer intKey = (Integer) key;
+ return node.getChildAt(intKey.intValue());
+ }
+
+ public Iterator<Entry<Object, javax.swing.tree.TreeNode>> getChildren(
+ final javax.swing.tree.TreeNode node) {
+
+ if (node.getAllowsChildren()) {
+ return new Iterator<Entry<Object,javax.swing.tree.TreeNode>>() {
+
+ private final Enumeration<?> e = node.children();
+ private int counter = 0;
+
+ public boolean hasNext() {
+ return e.hasMoreElements();
+ }
+
+ public Entry<Object, javax.swing.tree.TreeNode> next() {
+ javax.swing.tree.TreeNode child = (javax.swing.tree.TreeNode) e.nextElement();
+ SwingNodeMapEntry entry = new SwingNodeMapEntry(counter++, child);
+ return entry;
+
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ }
+
+ return null;
+ }
+
+ public javax.swing.tree.TreeNode getParent(
+ javax.swing.tree.TreeNode node) {
+ return node.getParent();
+ }
+
+ public Object getRowData(javax.swing.tree.TreeNode node) {
+ return node;
+ }
+
+ public boolean isLeaf(javax.swing.tree.TreeNode node) {
+ return !node.getAllowsChildren() || node.isLeaf();
+ }
+
+ public void setRowData(TreeNode node, Object rowData) {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java 2007-11-01
01:04:03 UTC (rev 3662)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -55,7 +55,7 @@
* @return {@link Iterator} of {@link Map.Entry} instances containing {@link TreeNode}
as values
* and their identifiers as keys
*/
- public Iterator getChildren();
+ public Iterator<Map.Entry<Object, TreeNode>> getChildren();
/**
* find child by id
* @param id identifier of the child to find
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java 2007-11-01
01:04:03 UTC (rev 3662)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -31,6 +31,11 @@
*/
public abstract class TreeRowKey implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7318192501938658798L;
+
public static final char SEPARATOR_ESCAPE_CHAR = '_';
/**
@@ -44,7 +49,7 @@
* @param fromIndex
* @return subpath segments iterator
*/
- public abstract Iterator getSubPathIterator(int fromIndex);
+ public abstract Iterator<?> getSubPathIterator(int fromIndex);
/**
* getter for path string representation
@@ -73,7 +78,7 @@
* getter for path iterator
* @return path segments iterator
*/
- public abstract Iterator iterator();
+ public abstract Iterator<?> iterator();
/**
* returns this row key and otherRowKey argument row key common path segments count
Property changes on: trunk/samples/seamIntegration
___________________________________________________________________
Name: svn:ignore
+ target
.classpath
.project
.settings
Modified: trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java 2007-11-01 01:04:03 UTC
(rev 3662)
+++ trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java 2007-11-01 01:37:44 UTC
(rev 3663)
@@ -22,9 +22,12 @@
package org.richfaces;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.faces.FacesException;
import javax.faces.application.Application;
@@ -55,6 +58,8 @@
private TreeNode data;
+ private List<javax.swing.tree.TreeNode> swingTreeNodes;
+
private TreeNode selectedNode = null;
private Map selectedNodeChildren = new LinkedHashMap();
@@ -152,11 +157,38 @@
data1.addChild(id, child);
}
initData();
+
+ SwingTreeNode treeNode = convertToSwingTreeNode(this.data);
+ List<javax.swing.tree.TreeNode> list = new
ArrayList<javax.swing.tree.TreeNode>();
+ for (int i = 0; i < treeNode.getChildCount(); i++) {
+ list.add(treeNode.getChildAt(i));
+ }
+
+ this.swingTreeNodes = list;
}
+ private SwingTreeNode convertToSwingTreeNode(TreeNode treeNode) {
+ SwingTreeNode node = new SwingTreeNode(treeNode.getData());
+ if (treeNode.isLeaf()) {
+ node.setAllowsChildren(false);
+ } else {
+ Iterator<Entry<Object, TreeNode>> children = treeNode.getChildren();
+ while (children.hasNext()) {
+ TreeNode value = children.next().getValue();
+ node.addChild(convertToSwingTreeNode(value));
+ }
+ }
+
+ return node;
+ }
+
public TreeNode getData() {
return data;
}
+
+ public List<javax.swing.tree.TreeNode> getSwingTreeNodes() {
+ return swingTreeNodes;
+ }
public String getSwitchType() {
return switchType;
Added: trunk/samples/tree-demo/src/main/java/org/richfaces/SwingTreeNode.java
===================================================================
--- trunk/samples/tree-demo/src/main/java/org/richfaces/SwingTreeNode.java
(rev 0)
+++ trunk/samples/tree-demo/src/main/java/org/richfaces/SwingTreeNode.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -0,0 +1,132 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.tree.TreeNode;
+
+/**
+ * Created 01.11.2007
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class SwingTreeNode implements TreeNode {
+
+ private TreeNode parent;
+ private Vector<SwingTreeNode> children = new Vector<SwingTreeNode>();
+ private boolean allowsChildren = true;
+ private Object data;
+
+ public SwingTreeNode(Object data) {
+ super();
+ this.data = data;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#children()
+ */
+ public Enumeration children() {
+ if (getAllowsChildren()) {
+ return children.elements();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getAllowsChildren()
+ */
+ public boolean getAllowsChildren() {
+ return allowsChildren;
+ }
+
+ public void setAllowsChildren(boolean allowsChildren) {
+ this.allowsChildren = allowsChildren;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getChildAt(int)
+ */
+ public TreeNode getChildAt(int childIndex) {
+ if (getAllowsChildren()) {
+ return children.get(childIndex);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getChildCount()
+ */
+ public int getChildCount() {
+ return children.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
+ */
+ public int getIndex(TreeNode node) {
+ if (getAllowsChildren()) {
+ return children.indexOf(node);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getParent()
+ */
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#isLeaf()
+ */
+ public boolean isLeaf() {
+ if (getAllowsChildren()) {
+ return children.isEmpty();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public void addChild(SwingTreeNode node) {
+ if (getAllowsChildren()) {
+ node.setParent(this);
+ children.add(node);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object getData() {
+ return data;
+ }
+}
Modified: trunk/samples/tree-demo/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/samples/tree-demo/src/main/webapp/pages/index.jsp 2007-11-01 01:04:03 UTC (rev
3662)
+++ trunk/samples/tree-demo/src/main/webapp/pages/index.jsp 2007-11-01 01:37:44 UTC (rev
3663)
@@ -185,6 +185,21 @@
<br />
</f:verbatim>
+ <h:outputText value="Swing Tree:" />
+
+ <rich:tree id="swingTree" switchType="client"
value="#{bean.swingTreeNodes}" var="data"
+ preserveModel="none">
+
+ <rich:treeNode>
+ <h:outputText value="#{data.data}" />
+ </rich:treeNode>
+ </rich:tree>
+
+ <f:verbatim>
+ <br />
+ <br />
+ </f:verbatim>
+
<rich:tree id="testTree"
var="_data"
switchType="ajax"
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/CacheableTreeDataModel.java
===================================================================
---
trunk/ui/tree/src/main/java/org/richfaces/component/CacheableTreeDataModel.java 2007-11-01
01:04:03 UTC (rev 3662)
+++
trunk/ui/tree/src/main/java/org/richfaces/component/CacheableTreeDataModel.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -37,7 +37,7 @@
* @author Nick - mailto:nbelaevski@exadel.com created 08.01.2007
*
*/
-public class CacheableTreeDataModel extends TreeDataModel {
+public class CacheableTreeDataModel<T> extends TreeDataModel<T> {
private final class Visitor implements DataVisitor, LastElementAware {
private final DataVisitor visitor;
@@ -50,7 +50,7 @@
throws IOException {
TreeRowKey treeRowKey = (TreeRowKey) rowKey;
treeDataModel.setRowKey(treeRowKey);
- locateTreeNode(treeRowKey, true).setData(treeDataModel.getRowData());
+ nodeAdaptor.setRowData(locateTreeNode(treeRowKey, true), treeDataModel.getRowData());
if (visitor != null) {
visitor.process(context, rowKey, argument);
@@ -72,25 +72,25 @@
}
}
- private TreeDataModel treeDataModel;
+ private TreeDataModel<T> treeDataModel;
public boolean isLeaf() {
TreeRowKey rowKey = (TreeRowKey) getRowKey();
- TreeNode treeNode = locateTreeNode(rowKey);
- if (treeNode != null && !treeNode.isLeaf()) {
+ T treeNode = locateTreeNode(rowKey);
+ if (treeNode != null && !nodeAdaptor.isLeaf(treeNode)) {
return false;
}
treeNode = treeDataModel.locateTreeNode(rowKey);
if (treeNode != null) {
- return treeNode.isLeaf();
+ return nodeAdaptor.isLeaf(treeNode);
}
return false;
}
- public CacheableTreeDataModel(TreeDataModel model) {
- super();
+ public CacheableTreeDataModel(TreeDataModel<T> model) {
+ super(model.getClazz(), model.getNodeAdaptor());
setWrappedData(new TreeNodeImpl());
setTreeDataModel(model);
}
@@ -102,11 +102,11 @@
argument, last);
}
- public void setTreeDataModel(TreeDataModel treeDataModel) {
+ public void setTreeDataModel(TreeDataModel<T> treeDataModel) {
this.treeDataModel = treeDataModel;
}
- public TreeDataModel getTreeDataModel() {
+ public TreeDataModel<T> getTreeDataModel() {
return treeDataModel;
}
@@ -114,11 +114,11 @@
Range range, Object rowKey, Object argument, boolean last)
throws IOException {
- TreeNode cachedTreeNode = locateTreeNode((TreeRowKey) rowKey);
- TreeNode treeNode = treeDataModel.locateTreeNode((TreeRowKey) rowKey);
+ T cachedTreeNode = locateTreeNode((TreeRowKey) rowKey);
+ T treeNode = treeDataModel.locateTreeNode((TreeRowKey) rowKey);
if (treeNode != null) {
- if (cachedTreeNode == null || (cachedTreeNode.isLeaf() && !treeNode.isLeaf()))
{
+ if (cachedTreeNode == null || (nodeAdaptor.isLeaf(cachedTreeNode) &&
!nodeAdaptor.isLeaf(treeNode))) {
//fill cache
treeDataModel.walk(context, new Visitor(dataVisitor), range,
rowKey, argument, last);
@@ -128,10 +128,6 @@
}
}
- public void setRowData(Object object) {
- (locateTreeNode((TreeRowKey)getRowKey())).setData(object);
- }
-
public boolean isTransient() {
return true;
}
@@ -142,4 +138,10 @@
"ReplaceableTreeDataModel shouldn't be transient!");
}
}
+
+ @Override
+ public TreeNode getTreeNode() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-11-01 01:04:03
UTC (rev 3662)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-11-01 01:37:44
UTC (rev 3663)
@@ -22,9 +22,7 @@
package org.richfaces.component;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.faces.application.Application;
@@ -64,9 +62,10 @@
import org.richfaces.event.NodeSelectedListener;
import org.richfaces.event.TreeListenerEventsProducer;
import org.richfaces.model.AbstractTreeDataModel;
-import org.richfaces.model.ListRowKey;
+import org.richfaces.model.ClassicTreeDataModel;
import org.richfaces.model.StackingTreeModel;
import org.richfaces.model.StackingTreeModelProvider;
+import org.richfaces.model.SwingTreeDataModel;
import org.richfaces.model.TreeDataModel;
import org.richfaces.model.TreeModelVisualComponentProvider;
import org.richfaces.model.TreeNode;
@@ -511,14 +510,21 @@
private ExtendedDataModel createDataModel(boolean allowCached) {
Object value = this.getValue();
if (value != null) {
- TreeDataModel treeDataModel = new TreeDataModel();
- treeDataModel.setWrappedData(this.getValue());
-
- if (allowCached && PRESERVE_MODEL_REQUEST.equals(getPreserveModel())) {
- treeDataModel = new CacheableTreeDataModel(treeDataModel);
+ if (value instanceof TreeNode) {
+ TreeDataModel<TreeNode> treeDataModel = new ClassicTreeDataModel();
+ treeDataModel.setWrappedData(value);
+
+ if (allowCached && PRESERVE_MODEL_REQUEST.equals(getPreserveModel())) {
+ treeDataModel = new CacheableTreeDataModel<TreeNode>(treeDataModel);
+ }
+
+ return treeDataModel;
+ } else {
+ SwingTreeDataModel swingTreeDataModel = new SwingTreeDataModel();
+ swingTreeDataModel.setWrappedData(value);
+
+ return swingTreeDataModel;
}
-
- return treeDataModel;
} else {
//TODO implement request caching
StackingTreeModel stackingTreeModel = new VisualStackingTreeModel(null);
Modified: trunk/ui/tree/src/test/java/org/richfaces/component/TreeModelTest.java
===================================================================
--- trunk/ui/tree/src/test/java/org/richfaces/component/TreeModelTest.java 2007-11-01
01:04:03 UTC (rev 3662)
+++ trunk/ui/tree/src/test/java/org/richfaces/component/TreeModelTest.java 2007-11-01
01:37:44 UTC (rev 3663)
@@ -35,9 +35,9 @@
import org.richfaces.component.xml.XmlNodeData;
import org.richfaces.component.xml.XmlTreeDataBuilder;
import org.richfaces.model.AbstractTreeDataModel;
+import org.richfaces.model.ClassicTreeDataModel;
import org.richfaces.model.LastElementAware;
import org.richfaces.model.ListRowKey;
-import org.richfaces.model.TreeDataModel;
import org.richfaces.model.TreeNode;
import org.xml.sax.InputSource;
@@ -48,7 +48,7 @@
*/
public class TreeModelTest extends TestCase {
private TreeNode node = null;
- private AbstractTreeDataModel model = new TreeDataModel();
+ private AbstractTreeDataModel model = new ClassicTreeDataModel();
protected void setUp() throws Exception {
super.setUp();