Author: nbelaevski
Date: 2007-09-12 15:26:06 -0400 (Wed, 12 Sep 2007)
New Revision: 2916
Added:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemBean.java
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemNode.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/examples/
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/examples/recursiveAdaptor.xhtml
Modified:
trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/usage.xhtml
Log:
Demo for recursiveTreeNodesAdaptor added
Added:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemBean.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemBean.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemBean.java 2007-09-12
19:26:06 UTC (rev 2916)
@@ -0,0 +1,16 @@
+package org.richfaces.treemodeladaptor;
+
+
+public class FileSystemBean {
+ private static String SRC_PATH = "/WEB-INF/src";
+
+ private FileSystemNode[] srcRoots;
+
+ public synchronized FileSystemNode[] getSourceRoots() {
+ if (srcRoots == null) {
+ srcRoots = new FileSystemNode(SRC_PATH).getNodes();
+ }
+
+ return srcRoots;
+ }
+}
Added:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemNode.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemNode.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/treemodeladaptor/FileSystemNode.java 2007-09-12
19:26:06 UTC (rev 2916)
@@ -0,0 +1,55 @@
+package org.richfaces.treemodeladaptor;
+
+import java.util.Set;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+public class FileSystemNode {
+ private String path;
+
+ private static FileSystemNode[] CHILDREN_ABSENT = new FileSystemNode[0];
+
+ private FileSystemNode[] children;
+
+ private String shortPath;
+
+ public FileSystemNode(String path) {
+ this.path = path;
+ int idx = path.lastIndexOf('/');
+ if (idx != -1) {
+ shortPath = path.substring(idx + 1);
+ } else {
+ shortPath = path;
+ }
+ }
+
+ public synchronized FileSystemNode[] getNodes() {
+ if (children == null) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Set resourcePaths = externalContext.getResourcePaths(this.path);
+ if (resourcePaths != null) {
+ Object[] nodes = (Object[]) resourcePaths.toArray();
+ children = new FileSystemNode[nodes.length];
+
+ for (int i = 0; i < nodes.length; i++) {
+ String nodePath = nodes[i].toString();
+ if (nodePath.endsWith("/")) {
+ nodePath = nodePath.substring(0, nodePath.length() - 1);
+ }
+ children[i] = new FileSystemNode(nodePath);
+ }
+ } else {
+ children = CHILDREN_ABSENT;
+ }
+ }
+
+ return children;
+ }
+
+ public String toString() {
+ return shortPath;
+ }
+
+}
\ No newline at end of file
Modified: trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2007-09-12
18:47:30 UTC (rev 2915)
+++ trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2007-09-12
19:26:06 UTC (rev 2916)
@@ -159,6 +159,11 @@
<value>Paint 2D</value>
</managed-property>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>fileSystemBean</managed-bean-name>
+
<managed-bean-class>org.richfaces.treemodeladaptor.FileSystemBean</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
<managed-bean>
<managed-bean-name>simpleTreeBean</managed-bean-name>
<managed-bean-class>org.richfaces.demo.tree.SimpleTreeBean</managed-bean-class>
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/examples/recursiveAdaptor.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/examples/recursiveAdaptor.xhtml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/examples/recursiveAdaptor.xhtml 2007-09-12
19:26:06 UTC (rev 2916)
@@ -0,0 +1,14 @@
+<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+
+ <h:form>
+ <rich:tree style="width:300px" switchType="ajax">
+ <rich:recursiveTreeNodesAdaptor roots="#{fileSystemBean.sourceRoots}"
var="item" nodes="#{item.nodes}" />
+ </rich:tree>
+ </h:form>
+
+</ui:composition>
\ No newline at end of file
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/usage.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/usage.xhtml 2007-09-12
18:47:30 UTC (rev 2915)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/treeNodesAdaptor/usage.xhtml 2007-09-12
19:26:06 UTC (rev 2916)
@@ -20,6 +20,32 @@
the second "nodes" is used on another recursion levels (the second level
and deeper).
</p>
+ <h:panelGroup rendered="#{not empty fileSystemBean.sourceRoots}">
+ <div class="sample-container" >
+ <ui:include
src="/richfaces/treeNodesAdaptor/examples/recursiveAdaptor.xhtml"/>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath"
value="/richfaces/treeNodesAdaptor/examples/recursiveAdaptor.xhtml"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath"
value="/WEB-INF/src/org/richfaces/treemodeladaptor/FileSystemBean.java"/>
+ <ui:param name="openlabel" value="View FileSystemBean.java
Source" />
+ <ui:param name="sourcetype" value="java" />
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath"
value="/WEB-INF/src/org/richfaces/treemodeladaptor/FileSystemNode.java"/>
+ <ui:param name="openlabel" value="View FileSystemNode.java
Source" />
+ <ui:param name="sourcetype" value="java" />
+ </ui:include>
+ </div>
+ </h:panelGroup>
+ <f:verbatim rendered="#{empty fileSystemBean.sourceRoots}">
+ The information for this demo is generated and incorporated in the
richfaces-demo.war
+ file with Maven process. Demo artifacts are located under /WEB-INF/src
folder.<br/>
+ As soon as you read this text, you have no such folder in your run-time enviroment
+ right now.<br />
+ If you use Jetty to run, use 'mvn jetty:run-war' command.
+ </f:verbatim>
+
<p>Model adaptor components can be nested without any limitations. The
following code-snippet
shows an example of using Nodes Adapter along with rich:tree</p>
<div class="sample-container">