Author: nbelaevski
Date: 2010-12-27 11:10:14 -0500 (Mon, 27 Dec 2010)
New Revision: 20813
Added:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelDataBean.java
Modified:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java
trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
Log:
https://issues.jboss.org/browse/RF-9987
Modified:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java 2010-12-27
15:50:27 UTC (rev 20812)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java 2010-12-27
16:10:14 UTC (rev 20813)
@@ -1,61 +1,45 @@
-/**
- *
+/*
+ * 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.demo.model.tree;
-import javax.faces.FacesException;
-import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.Unmarshaller.Listener;
+import javax.faces.bean.ViewScoped;
-import org.richfaces.demo.model.tree.adaptors.Entry;
-import org.richfaces.demo.model.tree.adaptors.Root;
-
/**
* @author Nick Belaevski
- * mailto:nbelaevski@exadel.com
- * created 25.07.2007
- *
+ *
*/
@ManagedBean
-@ApplicationScoped
+@ViewScoped
public class TreeModelBean {
-
- private Root root;
-
- private void initializeRoot() {
-
- try {
- JAXBContext context = JAXBContext.newInstance(Root.class);
- Unmarshaller unmarshaller = context.createUnmarshaller();
- unmarshaller.setListener(new Listener() {
- @Override
- public void afterUnmarshal(Object target, Object parent) {
- super.afterUnmarshal(target, parent);
-
- if (parent instanceof Entry) {
- ((Entry) target).setParent((Entry) parent);
- }
-
- }
- });
-
-
- root = (Root)
unmarshaller.unmarshal(TreeModelBean.class.getResource("tree-model-data.xml"));
- } catch (JAXBException e) {
- throw new FacesException(e.getMessage(), e);
- }
+
+ private boolean projectIsLeaf = false;
+
+ public boolean isProjectIsLeaf() {
+ return projectIsLeaf;
}
-
- public Root getRoot() {
- if (root == null) {
- initializeRoot();
- }
-
- return root;
- }
+ public void setProjectIsLeaf(boolean projectIsLeaf) {
+ this.projectIsLeaf = projectIsLeaf;
+ }
+
}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelDataBean.java
(from rev 20790,
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelDataBean.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelDataBean.java 2010-12-27
16:10:14 UTC (rev 20813)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.richfaces.demo.model.tree;
+
+import javax.faces.FacesException;
+import javax.faces.bean.ApplicationScoped;
+import javax.faces.bean.ManagedBean;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.Unmarshaller.Listener;
+
+import org.richfaces.demo.model.tree.adaptors.Entry;
+import org.richfaces.demo.model.tree.adaptors.Root;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 25.07.2007
+ *
+ */
+@ManagedBean
+@ApplicationScoped
+public class TreeModelDataBean {
+
+ private Root root;
+
+ private void initializeRoot() {
+
+ try {
+ JAXBContext context = JAXBContext.newInstance(Root.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ unmarshaller.setListener(new Listener() {
+ @Override
+ public void afterUnmarshal(Object target, Object parent) {
+ super.afterUnmarshal(target, parent);
+
+ if (parent instanceof Entry) {
+ ((Entry) target).setParent((Entry) parent);
+ }
+
+ }
+ });
+
+
+ root = (Root)
unmarshaller.unmarshal(TreeModelDataBean.class.getResource("tree-model-data.xml"));
+ } catch (JAXBException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+ }
+
+ public Root getRoot() {
+ if (root == null) {
+ initializeRoot();
+ }
+
+ return root;
+ }
+
+}
Modified: trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml 2010-12-27 15:50:27 UTC
(rev 20812)
+++ trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml 2010-12-27 16:10:14 UTC
(rev 20813)
@@ -16,13 +16,18 @@
<h:messages id="messages" />
</a4j:outputPanel>
+ <h:form>
+ Project is leaf:
+ <h:selectBooleanCheckbox value="#{treeModelBean.projectIsLeaf}"
onclick="submit()" />
+ </h:form>
+
<h:form id="form">
<it:tree id="tree" var="node" toggleType="ajax">
<it:treeNode>
<a4j:commandLink value="#{node}" action="#{node.processClick}"
/>
</it:treeNode>
- <it:treeModelAdaptor nodes="#{treeModelBean.root.projects}">
+ <it:treeModelAdaptor nodes="#{treeModelDataBean.root.projects}"
leaf="#{treeModelBean.projectIsLeaf}">
<it:treeNode iconExpanded="/images/folder_key.png"
iconCollapsed="/images/folder_key.png">
<a4j:commandLink value="#{node}"
action="#{node.processClick}" />
</it:treeNode>
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java 2010-12-27
15:50:27 UTC (rev 20812)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java 2010-12-27
16:10:14 UTC (rev 20813)
@@ -39,4 +39,6 @@
public void setRowKeyConverter(Converter converter);
+ public boolean isLeaf();
+
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java 2010-12-27
15:50:27 UTC (rev 20812)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java 2010-12-27
16:10:14 UTC (rev 20813)
@@ -38,7 +38,7 @@
public static final String COMPONENT_FAMILY =
"org.richfaces.TreeModelAdaptor";
private enum PropertyKeys {
- nodes
+ nodes, leaf
}
@Override
@@ -58,4 +58,12 @@
getStateHelper().put(PropertyKeys.nodes, nodes);
}
-}
+ public boolean isLeaf() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.leaf, false);
+ }
+
+ public void setLeaf(boolean leaf) {
+ getStateHelper().put(PropertyKeys.leaf, leaf);
+ }
+
+}
\ No newline at end of file
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java 2010-12-27
15:50:27 UTC (rev 20812)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java 2010-12-27
16:10:14 UTC (rev 20813)
@@ -38,7 +38,7 @@
public static final String COMPONENT_FAMILY =
"org.richfaces.TreeModelRecursiveAdaptor";
private enum PropertyKeys {
- roots, nodes
+ roots, nodes, leaf
}
@Override
@@ -70,4 +70,12 @@
return null;
}
+ public boolean isLeaf() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.leaf, false);
+ }
+
+ public void setLeaf(boolean leaf) {
+ getStateHelper().put(PropertyKeys.leaf, leaf);
+ }
+
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-27
15:50:27 UTC (rev 20812)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-27
16:10:14 UTC (rev 20813)
@@ -63,7 +63,14 @@
public boolean isLeaf() {
UIComponent currentComponent = getCurrentComponent();
- if (currentComponent instanceof TreeModelRecursiveAdaptor) {
+
+ TreeModelAdaptor adaptor = (TreeModelAdaptor) currentComponent;
+
+ if (adaptor.isLeaf()) {
+ return true;
+ }
+
+ if (adaptor instanceof TreeModelRecursiveAdaptor) {
return false;
}