Author: jpapouse
Date: 2011-11-24 10:54:29 -0500 (Thu, 24 Nov 2011)
New Revision: 23001
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/CompactDisc.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Labeled.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/State.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/RichFacesTreeNode.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/SwingTreeNode.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContent.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContentFactory.java
Removed:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDisc.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Company.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Country.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/NamedNode.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTreeBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Company.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDiscXmlDescriptor.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/rf-10994.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreePhases.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSimple.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
Log:
RFPL-981: preparing environment for using other models than javax.swing.tree.TreeNode
(rich:tree)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTreeBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTreeBean.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTreeBean.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -24,10 +24,14 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
@@ -39,11 +43,15 @@
import org.richfaces.tests.metamer.Attributes;
import org.richfaces.tests.metamer.bean.Model;
import org.richfaces.tests.metamer.bean.RichBean;
-import org.richfaces.tests.metamer.model.tree.CompactDisc;
+import org.richfaces.tests.metamer.model.CompactDisc;
+import org.richfaces.tests.metamer.model.Company;
+import org.richfaces.tests.metamer.model.Labeled;
+import org.richfaces.tests.metamer.model.State;
import org.richfaces.tests.metamer.model.tree.CompactDiscXmlDescriptor;
-import org.richfaces.tests.metamer.model.tree.Company;
-import org.richfaces.tests.metamer.model.tree.Country;
-import org.richfaces.tests.metamer.model.tree.NamedNode;
+import org.richfaces.tests.metamer.model.tree.RichFacesTreeNode;
+import org.richfaces.tests.metamer.model.tree.SwingTreeNode;
+import org.richfaces.tests.metamer.model.tree.TreeNodeWithContent;
+import org.richfaces.tests.metamer.model.tree.TreeNodeWithContentFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,20 +67,27 @@
private static Logger logger;
private Attributes attributes;
- private List<NamedNode> root = new ArrayList<NamedNode>();
+ private List<RichFacesTreeNode<Labeled>> richfacesTreeNodeRoot;
+ private List<SwingTreeNode<Labeled>> swingTreeNodeRoot;
private Collection<? extends Serializable> selection;
// FIXME: @ManagedProperty(value = "#{model}")
// private Model model;
+ private Map<State, Set<Company>> companiesCache;
+ private Map<Company, Set<CompactDisc>> cdCache;
- private Map<String, Country> countriesCache = new HashMap<String,
Country>();
- private Map<String, Company> companiesCache = new HashMap<String,
Company>();
-
private boolean testLoadingFacet = false;
private boolean delayedRender = false;
- private Map<NamedNode, Boolean> expanded = new HashMap<NamedNode,
Boolean>();
+ private Map<TreeNodeWithContent<Labeled>, Boolean> expanded = new
HashMap<TreeNodeWithContent<Labeled>, Boolean>();
+ private Comparator<Labeled> labeledComparator = new Comparator<Labeled>()
{
+ @Override
+ public int compare(Labeled o1, Labeled o2) {
+ return o1.getLabel().compareTo(o2.getLabel());
+ }
+ };
+
/**
* Initializes the managed bean.
*/
@@ -95,9 +110,18 @@
attributes.remove("stateVar");
attributes.remove("nodeType");
+ // build cache
+ companiesCache = new TreeMap<State,
Set<Company>>(labeledComparator);
+ cdCache = new HashMap<Company, Set<CompactDisc>>();
for (CompactDiscXmlDescriptor descriptor : Model.unmarshallCompactDiscs()) {
createCompactDisc(descriptor);
}
+ // build trees
+ List<SwingTreeNode<Labeled>> swingTreeNodelist =
(List<SwingTreeNode<Labeled>>) (List<?>)
buldTree(SwingTreeNode.createFactory());
+ swingTreeNodeRoot = swingTreeNodelist;
+ List<RichFacesTreeNode<Labeled>> richfacesTreeNodeList =
(List<RichFacesTreeNode<Labeled>>) (List<?>)
buldTree(RichFacesTreeNode.createFactory());
+ richfacesTreeNodeRoot = richfacesTreeNodeList;
+
}
public Attributes getAttributes() {
@@ -108,54 +132,19 @@
this.attributes = attributes;
}
- private CompactDisc createCompactDisc(CompactDiscXmlDescriptor descriptor) {
- final Company company = findOrCreateCompany(descriptor);
-
- CompactDisc cd = new CompactDisc(descriptor.getTitle(), descriptor.getArtist(),
company, descriptor.getPrice(),
- descriptor.getYear());
- company.getCds().add(cd);
- expanded.put(cd, false);
- return cd;
+
+ public void processDragging(DropEvent dropEvent) {
+ RichBean.logToPage("* dropListener");
}
- private Company findOrCreateCompany(CompactDiscXmlDescriptor descriptor) {
- final Country country = findOrCreateCountry(descriptor);
-
- 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);
- expanded.put(company, false);
- }
- return company;
+ public List<RichFacesTreeNode<Labeled>> getRichFacesTreeNodeRoot() {
+ return richfacesTreeNodeRoot;
}
-
- private Country findOrCreateCountry(CompactDiscXmlDescriptor descriptor) {
- String countryName = descriptor.getCountry();
- Country country = countriesCache.get(countryName);
- if (country == null) {
- country = new Country();
- country.setName(countryName);
- countriesCache.put(countryName, country);
- expanded.put(country, false);
- root.add(country);
- }
- return country;
- }
- public void processDragging(DropEvent dropEvent) {
- RichBean.logToPage("* dropListener");
+ public List<SwingTreeNode<Labeled>> getSwingTreeNodeRoot() {
+ return swingTreeNodeRoot;
}
- public List<NamedNode> getRoot() {
-
- return root;
- }
-
public Collection<? extends Serializable> getSelection() {
return selection;
}
@@ -190,19 +179,67 @@
}
}
- public Map<NamedNode, Boolean> getExpanded() {
+ public Map<TreeNodeWithContent<Labeled>, Boolean> getExpanded() {
return expanded;
}
public void expandAll() {
- for (Entry<NamedNode, Boolean> entry : expanded.entrySet()) {
+ for (Entry<TreeNodeWithContent<Labeled>, Boolean> entry :
expanded.entrySet()) {
entry.setValue(true);
}
}
public void collapseAll() {
- for (Entry<NamedNode, Boolean> entry : expanded.entrySet()) {
+ for (Entry<TreeNodeWithContent<Labeled>, Boolean> entry :
expanded.entrySet()) {
entry.setValue(false);
}
}
+
+ private List<TreeNodeWithContent<Labeled>>
buldTree(TreeNodeWithContentFactory<TreeNodeWithContent<Labeled>>
treeNodeFactory) {
+ List<TreeNodeWithContent<Labeled>> firstLevelNodes = new
ArrayList<TreeNodeWithContent<Labeled>>();
+ for(State state : companiesCache.keySet()) {
+ TreeNodeWithContent<Labeled> stateTreeNode =
treeNodeFactory.createTreeNode(null, state);
+ stateTreeNode.setType("country");
+ for(Company company : companiesCache.get(state)) {
+ TreeNodeWithContent<Labeled> companyTreeNode =
treeNodeFactory.createTreeNode(stateTreeNode, company);
+ companyTreeNode.setType("company");
+ for (CompactDisc cd : cdCache.get(company)) {
+ TreeNodeWithContent<Labeled> cdTreeNode =
treeNodeFactory.createTreeNode(companyTreeNode, cd);
+ cdTreeNode.setType("cd");
+ expanded.put(cdTreeNode, false);
+ }
+ expanded.put(companyTreeNode, false);
+ }
+ expanded.put(stateTreeNode, false);
+ firstLevelNodes.add(stateTreeNode);
+ }
+ return firstLevelNodes;
+ }
+
+ private CompactDisc createCompactDisc(CompactDiscXmlDescriptor descriptor) {
+ final Company company = findOrCreateCompany(descriptor);
+ CompactDisc cd = new CompactDisc(descriptor.getTitle(), descriptor.getArtist());
+ cdCache.get(company).add(cd);
+ return cd;
+ }
+
+ private Company findOrCreateCompany(CompactDiscXmlDescriptor descriptor) {
+ final State country = findOrCreateCountry(descriptor);
+ Company company = new Company(descriptor.getCompany());
+ if (!cdCache.containsKey(company)) {
+ cdCache.put(company, new TreeSet<CompactDisc>(labeledComparator));
+ companiesCache.get(country).add(company);
+ }
+ return company;
+ }
+
+ private State findOrCreateCountry(CompactDiscXmlDescriptor descriptor) {
+ String countryName = descriptor.getCountry();
+ State country = new State();
+ country.setName(countryName);
+ if (!companiesCache.containsKey(country)) {
+ companiesCache.put(country, new TreeSet<Company>(labeledComparator));
+ }
+ return country;
+ }
}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/CompactDisc.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/CompactDisc.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/CompactDisc.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-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.tests.metamer.model;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class CompactDisc implements Labeled, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private String artist;
+ private String title;
+
+ public CompactDisc(String title, String artist) {
+ this.artist = artist;
+ this.title = title;
+ }
+
+ @Override
+ public String getLabel() {
+ return artist + " - " + title;
+ }
+
+ public String getArtist() {
+ return artist;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setArtist(String artist) {
+ this.artist = artist;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @Override
+ public String toString() {
+ return "CompactDisc [artist=" + artist + ", title=" + title +
"]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((artist == null) ? 0 : artist.hashCode());
+ result = prime * result + ((title == null) ? 0 : title.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CompactDisc other = (CompactDisc) obj;
+ if (artist == null) {
+ if (other.artist != null)
+ return false;
+ } else if (!artist.equals(other.artist))
+ return false;
+ if (title == null) {
+ if (other.title != null)
+ return false;
+ } else if (!title.equals(other.title))
+ return false;
+ return true;
+ }
+
+
+}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Company.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Company.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Company.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -33,7 +33,7 @@
* @version $Revision$
*/
@XmlRootElement(name = "company")
-public class Company implements Serializable {
+public class Company implements Labeled, Serializable {
private static final long serialVersionUID = -1L;
private String name;
@@ -93,5 +93,14 @@
public int hashCode() {
return 31 + 17 * name.hashCode();
}
+
+ public String getLabel() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return "Company [name=" + name + "]";
+ }
}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Labeled.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Labeled.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/Labeled.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-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.tests.metamer.model;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public interface Labeled {
+
+ String getLabel();
+
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/State.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/State.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/State.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-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.tests.metamer.model;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class State implements Labeled, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private String name;
+
+ @Override
+ public String getLabel() {
+ return name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return "Country [name=" + name + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ State other = (State) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+}
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDisc.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDisc.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDisc.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -1,104 +0,0 @@
-package org.richfaces.tests.metamer.model.tree;
-
-import java.util.Enumeration;
-
-import javax.swing.tree.TreeNode;
-
-public class CompactDisc extends NamedNode {
-
- private static final long serialVersionUID = 1L;
-
- private Company company;
- private String artist;
- private String title;
- private float price;
- private int year;
-
- public CompactDisc() {
- this.setType("cd");
- }
-
- public CompactDisc(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;
- }
-
- public void setArtist(String artist) {
- this.artist = artist;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-
- public int getYear() {
- return year;
- }
-
- public void setYear(int year) {
- this.year = year;
- }
-
- @Override
- public String toString() {
- return "CompactDisc [artist=" + artist + ", title=" + title +
"]";
- }
-}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDiscXmlDescriptor.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDiscXmlDescriptor.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/CompactDiscXmlDescriptor.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -5,6 +5,8 @@
import javax.xml.bind.annotation.XmlElement;
public class CompactDiscXmlDescriptor implements Serializable {
+
+ private static final long serialVersionUID = 1L;
private String artist;
private String title;
private String country;
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Company.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Company.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Company.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -1,80 +0,0 @@
-package org.richfaces.tests.metamer.model.tree;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.swing.tree.TreeNode;
-
-import com.google.common.collect.Iterators;
-
-public class Company extends NamedNode {
-
- private static final long serialVersionUID = 1L;
-
- private String name;
- private List<CompactDisc> compactDiscs = new ArrayList<CompactDisc>();
-
- private Country country;
-
- public Company() {
- this.setType("company");
- }
-
- public TreeNode getChildAt(int childIndex) {
- return compactDiscs.get(childIndex);
- }
-
- public int getChildCount() {
- return compactDiscs.size();
- }
-
- public TreeNode getParent() {
- return country;
- }
-
- public void setParent(Country country) {
- this.country = country;
- }
-
- public int getIndex(TreeNode node) {
- return compactDiscs.indexOf(node);
- }
-
- public boolean getAllowsChildren() {
- return true;
- }
-
- public boolean isLeaf() {
- return compactDiscs.isEmpty();
- }
-
- public Enumeration children() {
- return Iterators.asEnumeration(compactDiscs.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<CompactDisc> getCds() {
- return compactDiscs;
- }
-
- @Override
- public String toString() {
- return "Company [name=" + name + "]";
- }
-}
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Country.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Country.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/Country.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -1,66 +0,0 @@
-package org.richfaces.tests.metamer.model.tree;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.swing.tree.TreeNode;
-
-import com.google.common.collect.Iterators;
-
-public class Country extends NamedNode {
-
- private static final long serialVersionUID = 1L;
-
- private String name;
- private List<Company> companies = new ArrayList<Company>();
-
- public Country() {
- this.setType("country");
- }
-
- public TreeNode getChildAt(int childIndex) {
- return companies.get(childIndex);
- }
-
- public int getChildCount() {
- return companies.size();
- }
-
- public TreeNode getParent() {
- return null;
- }
-
- public int getIndex(TreeNode node) {
- return companies.indexOf(node);
- }
-
- public boolean getAllowsChildren() {
- return true;
- }
-
- public boolean isLeaf() {
- return companies.isEmpty();
- }
-
- public Enumeration<Company> children() {
- return Iterators.asEnumeration(companies.iterator());
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public List<Company> getCompanies() {
- return companies;
- }
-
- @Override
- public String toString() {
- return "Country [name=" + name + "]";
- }
-}
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/NamedNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/NamedNode.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/NamedNode.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -1,20 +0,0 @@
-package org.richfaces.tests.metamer.model.tree;
-
-import java.io.Serializable;
-
-import javax.swing.tree.TreeNode;
-
-public abstract class NamedNode implements TreeNode, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/RichFacesTreeNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/RichFacesTreeNode.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/RichFacesTreeNode.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-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.tests.metamer.model.tree;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.richfaces.model.TreeNode;
+import org.richfaces.tests.metamer.model.Labeled;
+import org.richfaces.tests.metamer.model.tree.TreeNodeWithContent;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class RichFacesTreeNode<Content extends Labeled> implements TreeNode,
TreeNodeWithContent<Content>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private Map<Object, TreeNode> children = new HashMap<Object,
TreeNode>();
+ private List<Object> keys = new ArrayList<Object>();
+ private Content content;
+ private String type;
+
+ @Override
+ public void addChild(Object key, TreeNode child) {
+ children.put(key, child);
+ keys.add(key);
+ }
+
+ @Override
+ public Content getContent() {
+ return content;
+ }
+
+ @Override
+ public TreeNode getChild(Object key) {
+ return children.get(key);
+ }
+
+ @Override
+ public Iterator<Object> getChildrenKeysIterator() {
+ return children.keySet().iterator();
+ }
+
+ @Override
+ public int indexOf(Object key) {
+ return keys.indexOf(key);
+ }
+
+ @Override
+ public void insertChild(int index, Object key, TreeNode child) {
+ addChild(key, child);
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ @Override
+ public void removeChild(Object key) {
+ children.remove(key);
+ keys.remove(key);
+ }
+
+ @Override
+ public void setContent(Content content) {
+ this.content = content;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return content == null ? super.toString() : content.toString();
+ }
+
+ public static TreeNodeWithContentFactory<TreeNodeWithContent<Labeled>>
createFactory() {
+ return new TreeNodeWithContentFactory<TreeNodeWithContent<Labeled>>()
{
+ @Override
+ public RichFacesTreeNode<Labeled>
createTreeNode(TreeNodeWithContent<Labeled> parent, Labeled content) {
+ RichFacesTreeNode<Labeled> treeNode = new
RichFacesTreeNode<Labeled>();
+ if (parent != null) {
+ RichFacesTreeNode<Labeled> castedParent =
(RichFacesTreeNode<Labeled>) parent;
+ castedParent.addChild(treeNode.getContent(), treeNode);
+ }
+ return treeNode;
+ }
+ };
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/SwingTreeNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/SwingTreeNode.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/SwingTreeNode.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,106 @@
+package org.richfaces.tests.metamer.model.tree;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.swing.tree.TreeNode;
+
+import org.richfaces.tests.metamer.model.Labeled;
+
+import com.google.common.collect.Iterators;
+
+public class SwingTreeNode<Content extends Labeled> implements TreeNode,
TreeNodeWithContent<Content>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private Content content;
+ private List<TreeNode> children = new ArrayList<TreeNode>();
+ private TreeNode parent;
+ private String type;
+
+ public void addChild(TreeNode child) {
+ children.add(child);
+ }
+
+ @Override
+ public Content getContent() {
+ return content;
+ }
+
+ @Override
+ public void setContent(Content content) {
+ this.content = content;
+ }
+
+ @Override
+ public Enumeration<TreeNode> children() {
+ return Iterators.asEnumeration(children.iterator());
+ }
+
+ @Override
+ public boolean getAllowsChildren() {
+ return isLeaf();
+ }
+
+ @Override
+ public TreeNode getChildAt(int childIndex) {
+ return children.get(childIndex);
+ }
+
+ @Override
+ public int getChildCount() {
+ return children.size();
+ }
+
+ @Override
+ public int getIndex(TreeNode node) {
+ return children.indexOf(node);
+ }
+
+ @Override
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public static TreeNodeWithContentFactory<TreeNodeWithContent<Labeled>>
createFactory() {
+ return new TreeNodeWithContentFactory<TreeNodeWithContent<Labeled>>()
{
+ @Override
+ public SwingTreeNode<Labeled>
createTreeNode(TreeNodeWithContent<Labeled> parent, Labeled content) {
+ SwingTreeNode<Labeled> treeNode = new
SwingTreeNode<Labeled>();
+ treeNode.setContent(content);
+ if (parent != null) {
+ SwingTreeNode<Labeled> castedParent =
(SwingTreeNode<Labeled>) parent;
+ castedParent.addChild(treeNode);
+ treeNode.setParent(castedParent);
+ }
+ return treeNode;
+ }
+ };
+ }
+
+ @Override
+ public String toString() {
+ return content == null ? super.toString() : content.toString();
+ }
+
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContent.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContent.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContent.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-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.tests.metamer.model.tree;
+
+import org.richfaces.tests.metamer.model.Labeled;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public interface TreeNodeWithContent<Content extends Labeled> {
+
+ Content getContent();
+
+ String getType();
+
+ void setContent(Content content);
+
+ void setType(String type);
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContentFactory.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContentFactory.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/tree/TreeNodeWithContentFactory.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-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.tests.metamer.model.tree;
+
+import org.richfaces.tests.metamer.model.Labeled;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public interface TreeNodeWithContentFactory<TreeNode extends
TreeNodeWithContent<Labeled>> {
+
+ TreeNode createTreeNode(TreeNode parent, Labeled content);
+}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/rf-10994.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/rf-10994.xhtml 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/rf-10994.xhtml 2011-11-24
15:54:29 UTC (rev 23001)
@@ -58,25 +58,25 @@
<rich:dragIndicator id="indicator" />
<p>
- <rich:tree value="#{richTreeBean.root}"
nodeType="#{node.type}" var="node">
+ <rich:tree value="#{richTreeBean.swingTreeNodeRoot}"
nodeType="#{node.type}" var="node">
<rich:treeNode type="country" title="Country node type"
expanded="#{richTreeBean.expanded[node]}" >
<a4j:outputPanel layout="block">
<rich:dropTarget acceptedTypes="file"
dropListener="#{richTreeBean.processDragging}" />
- <h:outputText value="#{node.name}" />
+ <h:outputText value="#{node.content.label}"
/>
</a4j:outputPanel>
</rich:treeNode>
<rich:treeNode type="company" title="Company node type"
expanded="#{richTreeBean.expanded[node]}" >
<a4j:outputPanel layout="block">
<rich:dragSource type="file"
dragIndicator="indicator" />
- <h:outputText value="#{node.name}" />
+ <h:outputText value="#{node.content.label}" />
</a4j:outputPanel>
</rich:treeNode>
<rich:treeNode type="cd" title="CD node type"
expanded="#{richTreeBean.expanded[node]}" >
<a4j:outputPanel layout="block">
- <h:outputText value="#{node.artist} -
#{node.title}" />
+ <h:outputText value="#{node.content.label}"
/>
</a4j:outputPanel>
</rich:treeNode>
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml 2011-11-24
15:54:29 UTC (rev 23001)
@@ -46,7 +46,7 @@
<rich:tree id="richTree"
nodeType="#{node.type}"
var="node"
- value="#{richTreeBean.root}"
+ value="#{richTreeBean.swingTreeNodeRoot}"
selection="#{richTreeBean.selection}"
selectionChangeListener="#{richTreeListenerBean.processSelectionChange}"
toggleListener="#{richTreeListenerBean.processToggle}"
@@ -125,7 +125,7 @@
<f:facet name="handleLoading">
<h:graphicImage
value="/resources/images/loading.gif"
rendered="#{richTreeBean.testLoadingFacet}" />
</f:facet>
- #{node.name}
+ #{node.content.label}
</rich:treeNode>
<rich:treeNode type="company"
@@ -161,7 +161,7 @@
<h:graphicImage
value="/resources/images/loading.gif"
rendered="#{richTreeBean.testLoadingFacet}" />
</f:facet>
- #{node.name}
+ #{node.content.label}
</rich:treeNode>
<rich:treeNode type="cd"
@@ -193,7 +193,7 @@
styleClass="#{richTreeNodeBean.attributes[2]['styleClass'].value}"
title="#{richTreeNodeBean.attributes[2]['title'].value}"
- #{node.artist} - #{node.title}
+ #{node.content.label}
</rich:treeNode>
</rich:tree>
</p>
@@ -206,7 +206,7 @@
<rich:tree id="richTreeDefaultNodes"
var="node"
- value="#{richTreeBean.root}"
+ value="#{richTreeBean.swingTreeNodeRoot}"
dir="#{richTreeBean.attributes['dir'].value}"
lang="#{richTreeBean.attributes['lang'].value}"
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreePhases.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreePhases.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreePhases.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -57,8 +57,8 @@
@Test
public void testPhasesSelection() {
- tree.getNode(2).expand();
- tree.getNode(2).getNode(3).select();
+ tree.getNode(4).expand();
+ tree.getNode(4).getNode(3).select();
phaseInfo.assertPhases(PhaseId.ANY_PHASE);
phaseInfo.assertListener(PhaseId.APPLY_REQUEST_VALUES, "selection change
listener invoked");
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -51,8 +51,8 @@
@Use(field = "selectionPaths", value = "")
public class TestTreeSelection extends AbstractMetamerTest {
- protected Integer[][] selectionPaths = new Integer[][] {{2, 3}, {3, 4}, {4, 1, 1},
{4}, {4, 1},
- {1, 5 }, {2, 3, 3 } };
+ protected Integer[][] selectionPaths = new Integer[][] {{4, 3}, {1, 4}, {2, 1, 1},
{2}, {2, 1},
+ {3, 5 }, {4, 10, 3 } };
protected TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
protected TreeNodeModel treeNode;
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSimple.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSimple.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -359,8 +359,8 @@
XHRHalter xhrHalter = null;
- for (int index : new int[] { 2, 3 }) {
- treeNode = (index == 2) ? tree.getNode(index) : treeNode.getNode(index);
+ for (int index : new int[] { 1, 2 }) {
+ treeNode = (index == 1) ? tree.getNode(index) : treeNode.getNode(index);
assertFalse(treeNode.getHandleLoading().isVisible());
assertTrue(treeNode.getHandle().isCollapsed());
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-11-24
14:50:12 UTC (rev 23000)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-11-24
15:54:29 UTC (rev 23001)
@@ -46,7 +46,7 @@
private static final int TOP_LEVEL_NODES = 4;
- protected int[][] paths = new int[][] {{3, 2, 1 }, {2, 4, 1 }};
+ protected int[][] paths = new int[][] {{1, 2, 1 }, {4, 4, 1 }};
@Inject
@Use(enumeration = true)