Author: lfryc(a)redhat.com
Date: 2010-11-03 10:27:36 -0400 (Wed, 03 Nov 2010)
New Revision: 19913
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeBean.java
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichTreeBean.properties
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/list.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
Log:
added rich:tree simple sample (RF-9457)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-11-03
14:25:46 UTC (rev 19912)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-11-03
14:27:36 UTC (rev 19913)
@@ -140,6 +140,7 @@
components.put("richToggleControl", "Rich Toggle Control");
components.put("richTogglePanel", "Rich Toggle Panel");
components.put("richTogglePanelItem", "Rich Toggle Panel
Item");
+ components.put("richTree", "Rich Tree");
}
private void createSkinList() {
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeBean.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeBean.java 2010-11-03
14:27:36 UTC (rev 19913)
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.bean;
+
+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.ViewScoped;
+import javax.swing.tree.TreeNode;
+
+import org.richfaces.component.UITree;
+import org.richfaces.tests.metamer.Attributes;
+import org.richfaces.tests.metamer.model.tree.CompactDisc;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Managed bean for rich:list.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+@ManagedBean(name = "richTreeBean")
+@ViewScoped
+public class RichTreeBean implements Serializable {
+
+ private static final long serialVersionUID = 4008175400649809L;
+ private static Logger logger;
+ private Attributes attributes;
+ private List<TreeNode> root = new ArrayList<TreeNode>();
+
+ @ManagedProperty(value = "#{model}")
+ private Model model;
+
+ private Map<String, Country> countriesCache = new HashMap<String,
Country>();
+ private Map<String, Company> companiesCache = new HashMap<String,
Company>();
+
+ /**
+ * Initializes the managed bean.
+ */
+ @PostConstruct
+ public void init() {
+ logger = LoggerFactory.getLogger(getClass());
+ logger.debug("initializing bean " + getClass().getName());
+
+ attributes = Attributes.getUIComponentAttributes(UITree.class, getClass(),
false);
+ attributes.get("rendered").setValue(true);
+ attributes.get("toggleType").setValue("ajax");
+ attributes.get("selectionType").setValue("ajax");
+
+ for (CompactDiscXmlDescriptor descriptor : model.getCompactDiscs()) {
+ createCompactDisc(descriptor);
+ }
+ }
+
+ public Attributes getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Attributes attributes) {
+ 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);
+ return cd;
+ }
+
+ 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);
+ }
+ return company;
+ }
+
+ 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);
+ root.add(country);
+ }
+ return country;
+ }
+
+ public void setModel(Model model) {
+ this.model = model;
+ }
+
+ public List<TreeNode> getRoot() {
+ return root;
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichTreeBean.properties
===================================================================
---
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichTreeBean.properties
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichTreeBean.properties 2010-11-03
14:27:36 UTC (rev 19913)
@@ -0,0 +1,7 @@
+attr.toggleType.ajax=ajax
+attr.toggleType.client=client
+attr.toggleType.server=server
+attr.toggleType.null=
+attr.selectionType.client=client
+attr.selectionType.ajax=ajax
+attr.selectionType.null=
\ No newline at end of file
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/list.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/list.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/list.xhtml 2010-11-03
14:27:36 UTC (rev 19913)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, 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.
+ -->
+
+ <ui:composition template="/templates/list.xhtml">
+
+ <ui:define name="pageTitle">Rich Tree</ui:define>
+
+ <ui:define name="links">
+
+ <metamer:testPageLink id="simple" outcome="simple"
value="Simple">
+ The simple sample of <b>rich:tree</b> usage including all its
attributes.
+ </metamer:testPageLink>
+
+ </ui:define>
+
+ </ui:composition>
+
+</html>
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml 2010-11-03
14:27:36 UTC (rev 19913)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
+
xmlns:rich="http://richfaces.org/rich">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+ <rich:tree id="tree"
+ nodeType="#{node.type}"
+ var="node"
+ value="#{richTreeBean.root}"
+
+ toggleType="#{richTreeBean.attributes['toggleType'].value}"
+ selectionType="#{richTreeBean.attributes['selectionType'].value}"
+ rendered="#{richTreeBean.attributes['rendered'].value}">
+
+ <rich:treeNode type="country">
+ #{node.name}
+ </rich:treeNode>
+
+ <rich:treeNode type="company"
icon="/images/tree/disc.gif">
+ #{node.name}
+ </rich:treeNode>
+
+ <rich:treeNode type="cd" icon="/images/tree/song.gif">
+ #{node.artist} - #{node.title}
+ </rich:treeNode>
+ </rich:tree>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richTreeBean.attributes}"
id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file