Author: ilya_shaikovsky
Date: 2010-11-02 06:59:22 -0400 (Tue, 02 Nov 2010)
New Revision: 19885
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDXmlDescriptor.java
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/NamedNode.java
Removed:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Artist.java
Modified:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDParser.java
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/SimpleTreeBean.java
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/CD.java
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Company.java
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Country.java
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/tree/samples/tree-sample.xhtml
Log:
https://jira.jboss.org/browse/RF-9611
Modified:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDParser.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDParser.java 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDParser.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -11,31 +11,30 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import org.richfaces.demo.tree.model.CD;
@ManagedBean(name="cdsParser")
@ApplicationScoped
public class CDParser {
- private List<CD> cdsList;
+ private List<CDXmlDescriptor> cdsList;
@XmlRootElement(name = "CATALOG")
private static final class CDsHolder {
- private List<CD> cds;
+ private List<CDXmlDescriptor> cds;
@XmlElement(name = "CD")
- public List<CD> getCds() {
+ public List<CDXmlDescriptor> getCds() {
return cds;
}
@SuppressWarnings("unused")
- public void setCds(List<CD> cds) {
+ public void setCds(List<CDXmlDescriptor> cds) {
this.cds = cds;
}
}
- public synchronized List<CD> getCdsList() {
+ public synchronized List<CDXmlDescriptor> getCdsList() {
if (cdsList == null) {
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
URL resource =
ccl.getResource("org/richfaces/demo/tree/CDCatalog.xml");
Copied:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDXmlDescriptor.java
(from rev 19883,
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/CD.java)
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDXmlDescriptor.java
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/CDXmlDescriptor.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -0,0 +1,69 @@
+package org.richfaces.demo.tree;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlElement;
+
+public class CDXmlDescriptor implements Serializable {
+ private String artist;
+ private String title;
+ private String country;
+ private String company;
+ private float price;
+ private int year;
+
+ @XmlElement(name = "ARTIST")
+ public String getArtist() {
+ return artist;
+ }
+
+ public void setArtist(String artist) {
+ this.artist = artist;
+ }
+
+ @XmlElement(name = "TITLE")
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @XmlElement(name = "COUNTRY")
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ @XmlElement(name = "COMPANY")
+ public String getCompany() {
+ return company;
+ }
+
+ public void setCompany(String company) {
+ this.company = company;
+ }
+
+ @XmlElement(name = "PRICE")
+ public float getPrice() {
+ return price;
+ }
+
+ public void setPrice(float price) {
+ this.price = price;
+ }
+
+ @XmlElement(name = "YEAR")
+ public int getYear() {
+ return year;
+ }
+
+ public void setYear(int year) {
+ this.year = year;
+ }
+
+}
Modified:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/SimpleTreeBean.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/SimpleTreeBean.java 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/SimpleTreeBean.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -22,14 +22,20 @@
package org.richfaces.demo.tree;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
+import javax.swing.tree.TreeNode;
import org.richfaces.demo.tree.model.CD;
+import org.richfaces.demo.tree.model.Company;
+import org.richfaces.demo.tree.model.Country;
/**
* @author Ilya Shaikovsky
@@ -39,20 +45,62 @@
@SessionScoped
public class SimpleTreeBean implements Serializable {
@ManagedProperty(value = "#{cdsParser.cdsList}")
- private List<CD> cds;
+ private List<CDXmlDescriptor> cdXmlDescriptors;
+ private List<TreeNode> rootNodes = new ArrayList<TreeNode>();
+ private Map<String, Country> countriesCache = new HashMap<String,
Country>();
+ private Map<String, Company> companiesCache = new HashMap<String,
Company>();
+
@PostConstruct
public void init() {
-// for (CD cd : cds) {
-//
-// }
+ for (CDXmlDescriptor current : cdXmlDescriptors) {
+ String countryName = current.getCountry();
+ String companyName = current.getCompany();
+ Country country = getCountryByName(current);
+ Company company = getCompanyByName(current, country);
+ CD cd = new CD(current.getTitle(), current.getArtist(), company,
current.getPrice(), current.getYear());
+ company.getCds().add(cd);
+ }
}
- public List<CD> getCds() {
- return cds;
+ private Country getCountryByName(CDXmlDescriptor descriptor) {
+ String countryName = descriptor.getCountry();
+ Country country = countriesCache.get(countryName);
+ if (country == null) {
+ country = new Country();
+ country.setName(countryName);
+ countriesCache.put(countryName, country);
+ rootNodes.add(country);
+ }
+ return country;
}
- public void setCds(List<CD> cds) {
- this.cds = cds;
+ private Company getCompanyByName(CDXmlDescriptor descriptor, Country country) {
+ String companyName = descriptor.getCompany();
+ Company company = companiesCache.get(companyName);
+ if (company == null) {
+ company = new Company();
+ company.setName(companyName);
+ company.setParent(country);
+ country.getCompanies().add(company);
+ companiesCache.put(companyName, company);
+ }
+ return company;
}
+ public List<CDXmlDescriptor> getCdXmlDescriptors() {
+ return cdXmlDescriptors;
+ }
+
+ public void setCdXmlDescriptors(List<CDXmlDescriptor> cdXmlDescriptors) {
+ this.cdXmlDescriptors = cdXmlDescriptors;
+ }
+
+ public List<TreeNode> getRootNodes() {
+ return rootNodes;
+ }
+
+ public void setRootNodes(List<TreeNode> rootNodes) {
+ this.rootNodes = rootNodes;
+ }
+
}
Deleted:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Artist.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Artist.java 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Artist.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -1,44 +0,0 @@
-package org.richfaces.demo.tree.model;
-
-import java.util.Enumeration;
-
-import javax.swing.tree.TreeNode;
-
-public class Artist implements TreeNode{
-
- public TreeNode getChildAt(int childIndex) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int getChildCount() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public TreeNode getParent() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int getIndex(TreeNode node) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public boolean getAllowsChildren() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isLeaf() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public Enumeration children() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
Modified:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/CD.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/CD.java 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/CD.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -1,18 +1,67 @@
package org.richfaces.demo.tree.model;
-import java.io.Serializable;
+import java.util.Enumeration;
-import javax.xml.bind.annotation.XmlElement;
+import javax.swing.tree.TreeNode;
-public class CD implements Serializable {
+public class CD extends NamedNode implements TreeNode {
+ private Company company;
private String artist;
private String title;
- private String country;
- private String company;
private float price;
private int year;
- @XmlElement(name = "ARTIST")
+ public CD() {
+ this.setType("cd");
+ }
+
+ public CD(String title, String artist, Company company, float price, int year) {
+ super();
+ this.setType("cd");
+ this.company = company;
+ this.artist = artist;
+ this.title = title;
+ this.price = price;
+ this.year = year;
+ }
+
+ public TreeNode getChildAt(int childIndex) {
+ return null;
+ }
+
+ public int getChildCount() {
+ return 0;
+ }
+
+ public TreeNode getParent() {
+ return company;
+ }
+
+ public int getIndex(TreeNode node) {
+ return 0;
+ }
+
+ public boolean getAllowsChildren() {
+ return false;
+ }
+
+ public boolean isLeaf() {
+ return true;
+ }
+
+ public Enumeration<TreeNode> children() {
+ return new Enumeration<TreeNode>() {
+
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ public TreeNode nextElement() {
+ return null;
+ }
+ };
+ }
+
public String getArtist() {
return artist;
}
@@ -21,7 +70,6 @@
this.artist = artist;
}
- @XmlElement(name = "TITLE")
public String getTitle() {
return title;
}
@@ -30,25 +78,6 @@
this.title = title;
}
- @XmlElement(name = "COUNTRY")
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- @XmlElement(name = "COMPANY")
- public String getCompany() {
- return company;
- }
-
- public void setCompany(String company) {
- this.company = company;
- }
-
- @XmlElement(name = "PRICE")
public float getPrice() {
return price;
}
@@ -57,7 +86,6 @@
this.price = price;
}
- @XmlElement(name = "YEAR")
public int getYear() {
return year;
}
@@ -65,5 +93,4 @@
public void setYear(int year) {
this.year = year;
}
-
}
Modified:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Company.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Company.java 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Company.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -1,44 +1,72 @@
package org.richfaces.demo.tree.model;
+import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.List;
import javax.swing.tree.TreeNode;
-public class Company implements TreeNode{
+import com.google.common.collect.Iterators;
+public class Company extends NamedNode implements TreeNode {
+ private String name;
+ private List<CD> cds = new ArrayList<CD>();
+ private Country country;
+
+ public Company() {
+ this.setType("company");
+ }
+
public TreeNode getChildAt(int childIndex) {
- // TODO Auto-generated method stub
- return null;
+ return cds.get(childIndex);
}
public int getChildCount() {
- // TODO Auto-generated method stub
- return 0;
+ return cds.size();
}
public TreeNode getParent() {
- // TODO Auto-generated method stub
- return null;
+ return country;
}
+ public void setParent(Country country) {
+ this.country = country;
+ }
+
public int getIndex(TreeNode node) {
- // TODO Auto-generated method stub
- return 0;
+ return cds.indexOf(node);
}
public boolean getAllowsChildren() {
- // TODO Auto-generated method stub
- return false;
+ return true;
}
public boolean isLeaf() {
- // TODO Auto-generated method stub
- return false;
+ return cds.isEmpty();
}
public Enumeration children() {
- // TODO Auto-generated method stub
- return null;
+ return Iterators.asEnumeration(cds.iterator());
}
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+ public List<CD> getCds() {
+ return cds;
+ }
+
}
Modified:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Country.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Country.java 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/Country.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -8,10 +8,15 @@
import com.google.common.collect.Iterators;
-public class Country implements TreeNode {
+public class Country extends NamedNode implements TreeNode {
+
private String name;
private List<Company> companies = new ArrayList<Company>();
+ public Country() {
+ this.setType("country");
+ }
+
public TreeNode getChildAt(int childIndex) {
return companies.get(childIndex);
}
@@ -40,4 +45,16 @@
return Iterators.asEnumeration(companies.iterator());
}
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<Company> getCompanies() {
+ return companies;
+ }
+
}
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/NamedNode.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/NamedNode.java
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/model/NamedNode.java 2010-11-02
10:59:22 UTC (rev 19885)
@@ -0,0 +1,13 @@
+package org.richfaces.demo.tree.model;
+
+public class NamedNode {
+ private String type;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+}
Modified:
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-11-02
10:59:22 UTC (rev 19885)
@@ -290,7 +290,7 @@
</demo>
</demos>
</group>
- <!-- group>
+ <group>
<name>Trees</name>
<demos>
<demo new="true">
@@ -304,7 +304,7 @@
</samples>
</demo>
</demos>
- </group-->
+ </group>
<group>
<name>Output/Panels</name>
<demos>
Modified:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/tree/samples/tree-sample.xhtml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/tree/samples/tree-sample.xhtml 2010-11-02
09:53:35 UTC (rev 19884)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/tree/samples/tree-sample.xhtml 2010-11-02
10:59:22 UTC (rev 19885)
@@ -6,21 +6,21 @@
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form id="form">
- <a4j:repeat value="#{treeBean.cds}"
var="cd">#{cd.artist}</a4j:repeat>
- <ui:remove>
- <rich:tree id="tree" nodeType="#{node.parent == null ?
'rootNode': 'childNode'}" var="node"
value="#{treeBean.rootNodes}"
- selectionType="#{treeBean.selectionType}"
toggleType="#{treeBean.toggleType}">
- <rich:treeNode type="rootNode">
- <h:panelGroup id="rootNodeGroup">
- Root node: #{node.data} -
- </h:panelGroup>
+ <rich:tree id="tree" nodeType="#{node.type}"
var="node"
+ value="#{treeBean.rootNodes}" toggleType="client">
+ <rich:treeNode type="country">
+ #{node.name}
</rich:treeNode>
- <rich:treeNode type="childNode">
- <h:panelGroup id="childNodeGroup">
- #{node.data} -
- </h:panelGroup>
+ <rich:treeNode type="company">
+ #{node.name}
</rich:treeNode>
- </rich:tree>
- </ui:remove>
- </h:form>
+ <rich:treeNode type="cd">
+ #{node.artist}:#{node.title}
+ </rich:treeNode>
+ <rich:treeNode>
+ node not found for some reason
+ </rich:treeNode>
+ </rich:tree>
+
+ </h:form>
</ui:composition>
\ No newline at end of file