[richfaces-svn-commits] JBoss Rich Faces SVN: r1350 - in trunk/richfaces-samples/tree-demo/src/main: webapp and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Jun 27 12:34:54 EDT 2007


Author: A.Skokov
Date: 2007-06-27 12:34:54 -0400 (Wed, 27 Jun 2007)
New Revision: 1350

Added:
   trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Library.java
   trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Organism.java
   trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Pathway.java
   trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/TreeBean.java
   trunk/richfaces-samples/tree-demo/src/main/webapp/pages/index2.jsp
Modified:
   trunk/richfaces-samples/tree-demo/src/main/webapp/WEB-INF/faces-config.xml
   trunk/richfaces-samples/tree-demo/src/main/webapp/index.jsp
Log:
http://jira.jboss.com/jira/browse/RF-295

Added: trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Library.java
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Library.java	                        (rev 0)
+++ trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Library.java	2007-06-27 16:34:54 UTC (rev 1350)
@@ -0,0 +1,117 @@
+package org.richfaces;
+
+import org.richfaces.component.TreeNode;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class Library implements TreeNode {
+
+    private Map pathways = null;
+    private Object state1;
+    //private Object state2;
+
+    private List listPathway;
+
+    public Library() {
+    }
+
+    public Library(List l) {
+        this.listPathway = l;
+    }
+
+    private Map getPathways() {
+        if (this.pathways == null) {
+            initData();
+        }
+        return this.pathways;
+    }
+
+    public void addPathway(Pathway pw) {
+        addChild(Long.toString(pw.getId()), pw);
+        pw.setParent(this);
+    }
+
+    public void addChild(Object identifier, TreeNode child) {
+        getPathways().put(identifier, child);
+    }
+
+    public TreeNode getChild(Object id) {
+        return (TreeNode) getPathways().get(id);
+    }
+
+    public Iterator getChildren() {
+        return getPathways().entrySet().iterator();
+    }
+
+    public Object getData() {
+        return this;
+    }
+
+    public TreeNode getParent() {
+        return null;
+    }
+
+    public boolean isLeaf() {
+        return getPathways().isEmpty();
+    }
+
+    public void removeChild(Object id) {
+        getPathways().remove(id);
+    }
+
+    public void setData(Object data) {
+    }
+
+    public void setParent(TreeNode parent) {
+    }
+
+    public String getType() {
+        return "library";
+    }
+
+
+    private long nextId = 0;
+
+    private long getNextId() {
+        return nextId++;
+    }
+
+
+    private Map pathCache = new HashMap();
+
+    private Pathway getPathwayByName(String name, Library library) {
+        Pathway pathway = (Pathway) pathCache.get(name);
+        if (pathway == null) {
+            pathway = new Pathway(getNextId());
+            pathway.setName(name);
+            pathCache.put(name, pathway);
+            library.addPathway(pathway);
+        }
+        return pathway;
+    }
+
+    private void initData() {
+        pathways = new HashMap();
+
+        for (int i = 0; i < 15; i++) {
+            Pathway path = getPathwayByName("PATH_" + i, this);
+            for (int j = 0; j < 20; j++) {
+                Organism org = new Organism(getNextId());
+                org.setName("ORG_" + i + "." + j);
+                path.addOrganism(org);
+            }
+        }
+
+    }
+
+    public Object getState1() {
+        return state1;
+    }
+
+    public void setState1(Object state1) {
+        this.state1 = state1;
+    }
+}
\ No newline at end of file

Added: trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Organism.java
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Organism.java	                        (rev 0)
+++ trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Organism.java	2007-06-27 16:34:54 UTC (rev 1350)
@@ -0,0 +1,75 @@
+package org.richfaces;
+
+import org.richfaces.component.TreeNode;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+
+public class Organism implements TreeNode {
+    private long id;
+    private String name;
+    private Pathway pathway;
+
+    public Organism(long id) {
+        this.id = id;
+    }
+
+    public void addChild(Object identifier, TreeNode child) {
+        throw new UnsupportedOperationException("Organisms do not have children");
+    }
+
+    public TreeNode getChild(Object id) {
+        throw new UnsupportedOperationException("Organisms do not have children");
+    }
+
+    public Iterator getChildren() {
+        // TODO: Fix me!
+        return new ArrayList().iterator(); // work around limitation for TreeNode
+    }
+
+    public Object getData() {
+        return this;
+    }
+
+    public TreeNode getParent() {
+        return pathway;
+    }
+
+    public boolean isLeaf() {
+        return true;
+    }
+
+    public void removeChild(Object id) {
+        throw new UnsupportedOperationException("Organisms do not have children");
+    }
+
+    public void setData(Object data) {
+    }
+
+    public void setParent(TreeNode parent) {
+        this.pathway = (Pathway) parent;
+    }
+
+    public Pathway getPathway() {
+        return pathway;
+    }
+
+    public void setPathway(Pathway artist) {
+        this.pathway = artist;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String title) {
+        this.name = title;
+    }
+
+    public long getId() {
+        return id;
+    }
+    public String getType() {
+        return "organism";
+    }
+}

Added: trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Pathway.java
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Pathway.java	                        (rev 0)
+++ trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Pathway.java	2007-06-27 16:34:54 UTC (rev 1350)
@@ -0,0 +1,83 @@
+package org.richfaces;
+
+import org.richfaces.component.TreeNode;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
+
+public class Pathway implements TreeNode {
+
+    private long id;
+    private Map organisms = new HashMap();
+    private String name;
+    private Library library;
+
+
+    public Pathway(long id) {
+        this.id = id;
+    }
+
+    public void addOrganism(Organism org) {
+        addChild(Long.toString(org.getId()), org);
+        org.setParent(this);
+    }
+
+    public void addChild(Object identifier, TreeNode child) {
+        organisms.put(identifier, child);
+    }
+
+    public TreeNode getChild(Object id) {
+        return (TreeNode) organisms.get(id);
+    }
+
+    public Iterator getChildren() {
+        return organisms.entrySet().iterator();
+    }
+
+    public Object getData() {
+        return this;
+    }
+
+    public TreeNode getParent() {
+        return library;
+    }
+
+    public boolean isLeaf() {
+        return organisms.isEmpty();
+    }
+
+    public void removeChild(Object id) {
+        organisms.remove(id);
+    }
+
+    public void setData(Object data) {
+    }
+
+    public void setParent(TreeNode parent) {
+        library = (Library) parent;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Library getLibrary() {
+        return library;
+    }
+
+    public void setLibrary(Library library) {
+        this.library = library;
+    }
+    public String getType() {
+        return "pathway";
+    }
+}
\ No newline at end of file

Added: trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/TreeBean.java
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/TreeBean.java	                        (rev 0)
+++ trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/TreeBean.java	2007-06-27 16:34:54 UTC (rev 1350)
@@ -0,0 +1,7 @@
+package org.richfaces;
+
+public class TreeBean {
+    public Object getPathwayTree() {
+        return new Library();
+    }
+}

Modified: trunk/richfaces-samples/tree-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/webapp/WEB-INF/faces-config.xml	2007-06-27 16:33:47 UTC (rev 1349)
+++ trunk/richfaces-samples/tree-demo/src/main/webapp/WEB-INF/faces-config.xml	2007-06-27 16:34:54 UTC (rev 1350)
@@ -7,6 +7,11 @@
   <managed-bean-class>org.richfaces.Bean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>
+<managed-bean>
+ <managed-bean-name>pathwayBean</managed-bean-name>
+ <managed-bean-class>org.richfaces.TreeBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+</managed-bean>
  <managed-bean>
   <managed-bean-name>skinBean</managed-bean-name>
   <managed-bean-class>org.richfaces.SkinBean</managed-bean-class>

Modified: trunk/richfaces-samples/tree-demo/src/main/webapp/index.jsp
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/webapp/index.jsp	2007-06-27 16:33:47 UTC (rev 1349)
+++ trunk/richfaces-samples/tree-demo/src/main/webapp/index.jsp	2007-06-27 16:34:54 UTC (rev 1350)
@@ -2,6 +2,6 @@
 <html>
 <head></head>
 	<body>
-		<jsp:forward page="/pages/index.jsf" />
+		<jsp:forward page="/pages/index2.jsf" />
 	</body>
 </html>
\ No newline at end of file

Added: trunk/richfaces-samples/tree-demo/src/main/webapp/pages/index2.jsp
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/webapp/pages/index2.jsp	                        (rev 0)
+++ trunk/richfaces-samples/tree-demo/src/main/webapp/pages/index2.jsp	2007-06-27 16:34:54 UTC (rev 1350)
@@ -0,0 +1,36 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j" %>
+<%@ taglib uri="http://richfaces.ajax4jsf.org/tree" prefix="rich" %>
+<html>
+<head>
+    <title></title>
+</head>
+
+<body>
+<f:view>
+
+<h:form>
+
+    <rich:tree switchType="client" style="width:300px"
+               value="#{pathwayBean.pathwayTree}" var="item"
+               nodeFace="#{item.type}">
+        <rich:treeNode type="library">
+            <h:outputText value="#{item.type}"/>
+        </rich:treeNode>
+        <rich:treeNode type="pathway">
+            <h:outputText value="#{item.name}"/>
+        </rich:treeNode>
+        <rich:treeNode type="organism">
+            <h:outputText value="#{item.name}"/>
+        </rich:treeNode>
+    </rich:tree>
+
+</h:form>
+
+<a4j:log hotkey="O"/>
+
+</f:view>
+</body>
+</html>




More information about the richfaces-svn-commits mailing list