Author: nbelaevski
Date: 2010-10-31 13:00:29 -0400 (Sun, 31 Oct 2010)
New Revision: 19800
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeRange.java
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
Log:
https://jira.jboss.org/browse/RF-9315
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-31
16:27:50 UTC (rev 19799)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-31
17:00:29 UTC (rev 19800)
@@ -43,6 +43,7 @@
import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
import org.richfaces.application.MessageFactory;
import org.richfaces.application.ServiceTracker;
import org.richfaces.appplication.FacesMessages;
@@ -87,6 +88,16 @@
private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class TreeComponentState implements DataComponentState {
+ public Range getRange() {
+ return new TreeRange(getFacesContext(), AbstractTree.this);
+ }
+ }
+
private enum PropertyKeys {
expanded
}
@@ -121,6 +132,10 @@
}
public boolean isExpanded() {
+ if (getRowKey() == null) {
+ return true;
+ }
+
FacesContext context = getFacesContext();
Boolean localExpandedValue = getLocalExpandedValue(context);
if (localExpandedValue != null) {
@@ -149,9 +164,6 @@
return model;
}
- /* (non-Javadoc)
- * @see org.richfaces.component.UIDataAdaptor#createComponentState()
- */
@Override
protected DataComponentState createComponentState() {
// TODO Auto-generated method stub
@@ -278,4 +290,10 @@
protected Iterator<UIComponent> dataChildren() {
return Iterators.<UIComponent>concat(super.dataChildren(),
Iterators.singletonIterator(treeDecoderHelper));
}
+
+ @Override
+ public DataComponentState getComponentState() {
+ return new TreeComponentState();
+ }
+
}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeRange.java
===================================================================
--- sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeRange.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-10-31
17:00:29 UTC (rev 19800)
@@ -0,0 +1,57 @@
+/*
+ * 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.component;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.Range;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeRange implements Range {
+
+ private FacesContext facesContext;
+
+ private AbstractTree tree;
+
+ private boolean traverseAll;
+
+ public TreeRange(FacesContext facesContext, AbstractTree tree) {
+ super();
+ this.facesContext = facesContext;
+ this.tree = tree;
+
+ traverseAll = SwitchType.client == tree.getToggleMode();
+ }
+
+ public boolean processNodeChildren(Object rowKey) {
+ if (traverseAll) {
+ return true;
+ }
+
+ tree.setRowKey(facesContext, rowKey);
+ return tree.isExpanded();
+ }
+
+}
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java 2010-10-31
16:27:50 UTC (rev 19799)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java 2010-10-31
17:00:29 UTC (rev 19800)
@@ -32,6 +32,7 @@
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
+import org.richfaces.component.TreeRange;
import com.google.common.collect.Iterators;
@@ -43,21 +44,12 @@
private static final SequenceRowKey<Integer> EMPTY_SEQUENCE_ROW_KEY = new
SequenceRowKey<Integer>();
- private SwingTreeNodeImpl rootNode;
+ private SwingTreeNodeImpl<?> rootNode;
private TreeNode selectedNode;
private SequenceRowKey<Integer> selectedRowKey;
- private TreeNode walkNode;
-
- private SequenceRowKey<Integer> walkRowKey;
-
- private void setWalkContextData(TreeNode node, SequenceRowKey<Integer> key) {
- this.walkNode = node;
- this.walkRowKey = key;
- }
-
private Iterator<TreeNode> findChildren(SequenceRowKey<Integer>
compositeKey) {
TreeNode treeNode = findNode(compositeKey);
@@ -92,12 +84,7 @@
@Override
public void setRowKey(Object key) {
this.selectedRowKey = (SequenceRowKey<Integer>) key;
-
- if (walkRowKey != null && walkRowKey.equals(key)) {
- this.selectedNode = walkNode;
- } else {
- this.selectedNode = findNode(selectedRowKey);
- }
+ this.selectedNode = findNode(selectedRowKey);
}
@Override
@@ -173,8 +160,10 @@
DataVisitResult visitResult = visitor.process(context, object, argument);
if (visitResult == DataVisitResult.CONTINUE) {
- Iterator<Object> childrenIterator = getChildrenIterator(context,
object);
- walk(context, visitor, range, argument, childrenIterator);
+ if (((TreeRange) range).processNodeChildren(object)) {
+ Iterator<Object> childrenIterator =
getChildrenIterator(context, object);
+ walk(context, visitor, range, argument, childrenIterator);
+ }
}
}
}
@@ -186,8 +175,10 @@
public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) {
// TODO Auto-generated method stub
- Iterator<Object> iterator = getChildrenIterator(context, null);
- walk(context, visitor, range, argument, iterator);
+ if (((TreeRange) range).processNodeChildren(null)) {
+ Iterator<Object> iterator = getChildrenIterator(context, null);
+ walk(context, visitor, range, argument, iterator);
+ }
}
}