Author: nbelaevski
Date: 2010-12-01 11:55:03 -0500 (Wed, 01 Dec 2010)
New Revision: 20272
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java
Modified:
trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
Log:
Merge branch 'RF-9680' into HEAD
Conflicts:
ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
===================================================================
---
trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2010-12-01
16:51:58 UTC (rev 20271)
+++
trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -22,15 +22,17 @@
package org.richfaces.model;
import java.io.Serializable;
-import java.util.ArrayList;
+import java.util.Collection;
import java.util.Enumeration;
-import java.util.List;
import javax.swing.tree.TreeNode;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
/**
* @author Nick Belaevski
@@ -44,17 +46,28 @@
private T data;
- private List<TreeNode> children = new ArrayList<TreeNode>();
+ private Collection<TreeNode> children;
+ private boolean allowUpdateParents = true;
+
public SwingTreeNodeImpl() {
+ this(null);
}
- public SwingTreeNodeImpl(List<TreeNode> children) {
- this.children = children;
+ void setAllowUpdateParents(boolean allowUpdateParents) {
+ this.allowUpdateParents = allowUpdateParents;
}
+
+ public SwingTreeNodeImpl(Collection<TreeNode> children) {
+ this.children = wrapNull(children);
+ }
+ private static Collection<TreeNode> wrapNull(Collection<TreeNode> src) {
+ return src != null ? src : Lists.<TreeNode>newArrayList();
+ }
+
public TreeNode getChildAt(int childIndex) {
- return children.get(childIndex);
+ return Iterables.get(children, childIndex);
}
public int getChildCount() {
@@ -70,14 +83,26 @@
}
public int getIndex(TreeNode node) {
- return children.indexOf(node);
+ return Iterables.indexOf(children, Predicates.equalTo(node));
}
public void addChild(TreeNode node) {
- ((SwingTreeNodeImpl<?>) node).setParent(this);
children.add(node);
+ if (allowUpdateParents && node instanceof SwingTreeNodeImpl<?>) {
+ SwingTreeNodeImpl<?> treeNodeImpl = (SwingTreeNodeImpl<?>) node;
+ treeNodeImpl.setParent(this);
+ }
}
+ public void removeChild(TreeNode node) {
+ if (children.remove(node)) {
+ if (allowUpdateParents && node instanceof SwingTreeNodeImpl<?>)
{
+ SwingTreeNodeImpl<?> treeNodeImpl = (SwingTreeNodeImpl<?>)
node;
+ treeNodeImpl.setParent(null);
+ }
+ }
+ }
+
public boolean getAllowsChildren() {
return true;
}
@@ -98,7 +123,7 @@
this.data = data;
}
- public List<TreeNode> getChildrenList() {
+ public Collection<TreeNode> getChildrenList() {
return children;
}
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -0,0 +1,94 @@
+/*
+ * 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.model;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.ComponentPredicates;
+import org.richfaces.component.TreeModelAdaptor;
+import org.richfaces.component.TreeModelRecursiveAdaptor;
+
+import com.google.common.collect.ForwardingIterator;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
+final class DeclarativeTreeDataModelCompositeTuplesIterator extends
ForwardingIterator<TreeDataModelTuple> {
+
+ private UIComponent component;
+
+ private SequenceRowKey<DeclarativeModelKey> key;
+
+ private Iterator<TreeDataModelTuple> iterator;
+
+ public DeclarativeTreeDataModelCompositeTuplesIterator(UIComponent component,
SequenceRowKey<DeclarativeModelKey> key) {
+ super();
+ this.component = component;
+ this.key = key;
+ }
+
+ @Override
+ protected Iterator<TreeDataModelTuple> delegate() {
+ if (iterator == null) {
+ List<Iterator<TreeDataModelTuple>> list = Lists.newArrayList();
+
+ if (component instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor parentRecursiveAdaptor =
(TreeModelRecursiveAdaptor) component;
+
+ Collection<?> nodes = (Collection<?>)
parentRecursiveAdaptor.getNodes();
+
+ if (nodes != null) {
+ list.add(new DeclarativeTreeDataModelTuplesIterator(component, key,
nodes.iterator()));
+ }
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : Iterables.filter(component.getChildren(),
ComponentPredicates.isRendered())) {
+ Collection<?> nodes = null;
+
+ if (child instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor treeModelRecursiveAdaptor =
(TreeModelRecursiveAdaptor) child;
+
+ nodes = (Collection<?>)
treeModelRecursiveAdaptor.getRoots();
+ } else if (child instanceof TreeModelAdaptor) {
+ TreeModelAdaptor treeModelAdaptor = (TreeModelAdaptor) child;
+
+ nodes = (Collection<?>) treeModelAdaptor.getNodes();
+ }
+
+ if (nodes != null) {
+ list.add(new DeclarativeTreeDataModelTuplesIterator(child, key,
nodes.iterator()));
+ }
+ }
+ }
+
+ iterator = Iterators.concat(list.iterator());
+ }
+
+ return iterator;
+ }
+
+}
\ No newline at end of file
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-01
16:51:58 UTC (rev 20271)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -21,9 +21,9 @@
*/
package org.richfaces.model;
-import java.util.Collection;
+import static com.google.common.base.Objects.firstNonNull;
+
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.faces.component.UIComponent;
@@ -36,10 +36,7 @@
import org.richfaces.log.RichfacesLogger;
import com.google.common.base.Predicates;
-import com.google.common.collect.ForwardingIterator;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
/**
* @author Nick Belaevski
@@ -48,108 +45,17 @@
public class DeclarativeTreeDataModelImpl extends
TreeSequenceKeyModel<DeclarativeModelKey, Object> implements
DeclarativeTreeModel<Object> {
private static final Logger LOGGER = RichfacesLogger.MODEL.getLogger();
-
- private final class DeclarativeModelIterator implements
Iterator<TreeDataModelTuple> {
-
- private UIComponent component;
- private SequenceRowKey<DeclarativeModelKey> baseKey;
-
- private int counter = 0;
-
- private Iterator<?> nodesIterator;
-
- public DeclarativeModelIterator(UIComponent component,
SequenceRowKey<DeclarativeModelKey> baseKey, Iterator<?> nodesIterator) {
- super();
- this.component = component;
- this.baseKey = baseKey;
- this.nodesIterator = nodesIterator;
- }
+ private static final SequenceRowKey<DeclarativeModelKey> EMPTY_KEY = new
SequenceRowKey<DeclarativeModelKey>();
- public TreeDataModelTuple next() {
- Object nextNode = nodesIterator.next();
- DeclarativeModelKey key = new DeclarativeModelKey(component.getId(),
counter++);
-
- SequenceRowKey<DeclarativeModelKey> newKey = baseKey.append(key);
-
- return new DeclarativeTreeDataModelTuple(newKey, nextNode, component);
- }
-
- public boolean hasNext() {
- return nodesIterator.hasNext();
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- }
-
- private final class DeclarativeModelCompositeIterator extends
ForwardingIterator<TreeDataModelTuple> {
-
- private UIComponent component;
-
- private SequenceRowKey<DeclarativeModelKey> key;
-
- private Iterator<TreeDataModelTuple> iterator;
-
- public DeclarativeModelCompositeIterator(UIComponent component,
SequenceRowKey<DeclarativeModelKey> key) {
- super();
- this.component = component;
- this.key = key;
- }
-
- @Override
- protected Iterator<TreeDataModelTuple> delegate() {
- if (iterator == null) {
- List<Iterator<TreeDataModelTuple>> list =
Lists.newArrayList();
-
- if (component instanceof TreeModelRecursiveAdaptor) {
- TreeModelRecursiveAdaptor parentRecursiveAdaptor =
(TreeModelRecursiveAdaptor) component;
-
- Collection<?> nodes = (Collection<?>)
parentRecursiveAdaptor.getNodes();
-
- if (nodes != null) {
- list.add(new DeclarativeModelIterator(component, key,
nodes.iterator()));
- }
- }
-
- if (component.getChildCount() > 0) {
- for (UIComponent child : Iterables.filter(component.getChildren(),
ComponentPredicates.isRendered())) {
- Collection<?> nodes = null;
-
- if (child instanceof TreeModelRecursiveAdaptor) {
- TreeModelRecursiveAdaptor treeModelRecursiveAdaptor =
(TreeModelRecursiveAdaptor) child;
-
- nodes = (Collection<?>)
treeModelRecursiveAdaptor.getRoots();
- } else if (child instanceof TreeModelAdaptor) {
- TreeModelAdaptor treeModelAdaptor = (TreeModelAdaptor)
child;
-
- nodes = (Collection<?>) treeModelAdaptor.getNodes();
- }
-
- if (nodes != null) {
- list.add(new DeclarativeModelIterator(child, key,
nodes.iterator()));
- }
- }
- }
-
- iterator = Iterators.concat(list.iterator());
- }
-
- return iterator;
- }
-
- }
-
private String var;
-
+
private Map<String, Object> contextMap;
-
+
private UIComponent tree;
-
+
private UIComponent currentComponent;
-
+
public DeclarativeTreeDataModelImpl(AbstractTree tree, String var, Map<String,
Object> contextMap) {
super();
this.tree = tree;
@@ -162,11 +68,8 @@
return currentComponent;
}
- protected void setCurrentComponent(UIComponent currentComponent) {
- this.currentComponent = currentComponent;
- }
-
public boolean isLeaf() {
+ UIComponent currentComponent = getCurrentComponent();
if (currentComponent instanceof TreeModelRecursiveAdaptor) {
return false;
}
@@ -174,20 +77,16 @@
if (currentComponent.getChildCount() == 0) {
return true;
}
-
+
return Iterables.contains(currentComponent.getChildren(),
Predicates.instanceOf(TreeModelAdaptor.class));
}
public Iterator<TreeDataModelTuple> children() {
- return new DeclarativeModelCompositeIterator(currentComponent, safeGetRowKey());
+ return new DeclarativeTreeDataModelCompositeTuplesIterator(currentComponent,
safeGetRowKey());
}
- /* (non-Javadoc)
- * @see org.richfaces.model.TreeDataModel#getParentRowKey(java.lang.Object)
- */
public Object getParentRowKey(Object rowKey) {
- // TODO Auto-generated method stub
- return null;
+ return safeGetRowKey().getParent();
}
@Override
@@ -207,7 +106,7 @@
if (var != null) {
initialContextValue = contextMap.remove(var);
}
-
+
try {
this.currentComponent = tree;
@@ -222,11 +121,11 @@
}
}
}
-
+
@Override
protected void walkNext(DeclarativeModelKey segment) {
String modelId = segment.getModelId();
-
+
UIComponent modelComponent;
if (currentComponent instanceof TreeModelRecursiveAdaptor &&
modelId.equals(currentComponent.getId())) {
@@ -236,10 +135,10 @@
}
Object nodes = null;
-
+
if (modelComponent instanceof TreeModelRecursiveAdaptor) {
TreeModelRecursiveAdaptor recursiveAdaptor = (TreeModelRecursiveAdaptor)
modelComponent;
-
+
if (currentComponent.equals(modelComponent)) {
nodes = recursiveAdaptor.getNodes();
} else {
@@ -251,13 +150,17 @@
Object data = Iterables.get((Iterable<?>) nodes, (Integer)
segment.getModelKey());
setRowKeyAndData(safeGetRowKey().append(segment), data);
- setCurrentComponent(modelComponent);
-
+ this.currentComponent = modelComponent;
+
if (var != null) {
contextMap.put(var, data);
}
}
+ private SequenceRowKey<DeclarativeModelKey> safeGetRowKey() {
+ return firstNonNull(getRowKey(), EMPTY_KEY);
+ }
+
public TreeDataModelTuple createSnapshot() {
return new DeclarativeTreeDataModelTuple(getRowKey(), getData(),
getCurrentComponent());
}
@@ -266,7 +169,7 @@
DeclarativeTreeDataModelTuple declarativeModelTuple =
(DeclarativeTreeDataModelTuple) tuple;
super.restoreFromSnapshot(declarativeModelTuple);
- setCurrentComponent(declarativeModelTuple.getComponent());
+ this.currentComponent = declarativeModelTuple.getComponent();
}
-
+
}
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -0,0 +1,62 @@
+/*
+ * 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.model;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+final class DeclarativeTreeDataModelTuplesIterator implements
Iterator<TreeDataModelTuple> {
+
+ private UIComponent component;
+
+ private SequenceRowKey<DeclarativeModelKey> baseKey;
+
+ private int counter = 0;
+
+ private Iterator<?> dataIterator;
+
+ public DeclarativeTreeDataModelTuplesIterator(UIComponent component,
SequenceRowKey<DeclarativeModelKey> baseKey, Iterator<?> dataIterator) {
+ super();
+ this.component = component;
+ this.baseKey = baseKey;
+ this.dataIterator = dataIterator;
+ }
+
+ public TreeDataModelTuple next() {
+ Object nextNode = dataIterator.next();
+ DeclarativeModelKey key = new DeclarativeModelKey(component.getId(), counter++);
+
+ SequenceRowKey<DeclarativeModelKey> newKey = baseKey.append(key);
+
+ return new DeclarativeTreeDataModelTuple(newKey, nextNode, component);
+ }
+
+ public boolean hasNext() {
+ return dataIterator.hasNext();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-12-01
16:51:58 UTC (rev 20271)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -21,147 +21,58 @@
*/
package org.richfaces.model;
+import static com.google.common.base.Objects.firstNonNull;
+
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
-import java.util.NoSuchElementException;
import javax.swing.tree.TreeNode;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
-
+import com.google.common.collect.Lists;
/**
* @author Nick Belaevski
*
*/
public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<Integer,
TreeNode> {
- private final class SwingTreeNodeRowKeyIterator implements
Iterator<TreeDataModelTuple> {
+ private static final SequenceRowKey<Integer> EMPTY_KEY = new
SequenceRowKey<Integer>();
+
+ private boolean asksAllowsChildren = false;
+
+ private Object wrappedData;
- private SequenceRowKey<Integer> baseKey;
+ private TreeNode createFakeRootNode(Object wrappedData) {
+ Collection<TreeNode> nodes;
- private Iterator<TreeNode> children;
-
- private int counter = 0;
-
- private SwingTreeNodeRowKeyIterator(SequenceRowKey<Integer> baseKey,
Iterator<TreeNode> children) {
- this.baseKey = baseKey;
- this.children = children;
+ if (wrappedData instanceof Collection<?>) {
+ nodes = (Collection<TreeNode>) wrappedData;
+ } else if (wrappedData instanceof TreeNode) {
+ nodes = Lists.newArrayList((TreeNode) wrappedData);
+ } else if (wrappedData == null) {
+ nodes = null;
+ } else {
+ throw new IllegalArgumentException(String.valueOf(wrappedData));
}
-
- private int getNextCounterValue() {
- return counter++;
- }
- public boolean hasNext() {
- return children.hasNext();
- }
-
- public TreeDataModelTuple next() {
- TreeNode node = children.next();
-
- SequenceRowKey<Integer> key;
-
- if (baseKey != null) {
- key = baseKey.append(getNextCounterValue());
- } else {
- key = new SequenceRowKey<Integer>(getNextCounterValue());
- }
-
- return new TreeDataModelTuple(key, node);
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
+ SwingTreeNodeImpl<?> treeNodeImpl = new
SwingTreeNodeImpl<Object>(nodes);
+ treeNodeImpl.setAllowUpdateParents(false);
+ return treeNodeImpl;
}
-
- private final class FakeRootNode implements TreeNode {
-
- private Collection<TreeNode> wrappedData;
-
- public FakeRootNode(Collection<TreeNode> wrappedData) {
- super();
- this.wrappedData = wrappedData;
- }
-
- public boolean isLeaf() {
- return !wrappedData.isEmpty();
- }
-
- public TreeNode getParent() {
- return null;
- }
-
- public int getIndex(TreeNode node) {
- if (wrappedData == null) {
- return -1;
- }
-
- return Iterables.indexOf(wrappedData, Predicates.equalTo(node));
- }
-
- public int getChildCount() {
- if (wrappedData == null) {
- return 0;
- }
-
- return wrappedData.size();
- }
-
- public TreeNode getChildAt(int childIndex) {
- if (wrappedData == null) {
- throw new NoSuchElementException(String.valueOf(childIndex));
- }
-
- return Iterables.get(wrappedData, childIndex);
- }
-
- public boolean getAllowsChildren() {
- return true;
- }
-
- public Enumeration<?> children() {
- if (wrappedData == null) {
- return Iterators.asEnumeration(Iterators.emptyIterator());
- }
-
- return Iterators.asEnumeration(wrappedData.iterator());
- }
-
- public Collection<TreeNode> getWrappedData() {
- return wrappedData;
- }
- }
-
- private boolean asksAllowsChildren = false;
- private Iterator<TreeNode> safeGetChildren(TreeNode treeNode) {
- if (treeNode == null) {
- return Iterators.emptyIterator();
- }
-
- return Iterators.forEnumeration((Enumeration<TreeNode>)
treeNode.children());
- }
-
-
public Object getParentRowKey(Object rowKey) {
throw new UnsupportedOperationException();
}
public void setWrappedData(Object data) {
- setRootNode(new FakeRootNode((Collection<TreeNode>) data));
+ this.wrappedData = data;
+
+ setRootNode(createFakeRootNode(data));
}
- public Collection<TreeNode> getWrappedData() {
- FakeRootNode rootNode = (FakeRootNode) getRootNode();
- if (rootNode == null) {
- return null;
- }
- return rootNode.getWrappedData();
+ public Object getWrappedData() {
+ return wrappedData;
}
protected TreeNode findChild(TreeNode parent, Integer simpleKey) {
@@ -169,7 +80,8 @@
}
public Iterator<TreeDataModelTuple> children() {
- return new SwingTreeNodeRowKeyIterator(getRowKey(), safeGetChildren(getData()));
+ Iterator<TreeNode> children =
Iterators.forEnumeration((Enumeration<TreeNode>) getData().children());
+ return new SwingTreeNodeTuplesIterator(getRowKey(), children);
}
public boolean isLeaf() {
@@ -187,4 +99,8 @@
//TODO - optimize - remove partial keys creation
setRowKeyAndData(safeGetRowKey().append(segment), child);
}
+
+ private SequenceRowKey<Integer> safeGetRowKey() {
+ return firstNonNull(getRowKey(), EMPTY_KEY);
+ }
}
\ No newline at end of file
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -0,0 +1,67 @@
+/*
+ * 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.model;
+
+import java.util.Iterator;
+
+import javax.swing.tree.TreeNode;
+
+final class SwingTreeNodeTuplesIterator implements Iterator<TreeDataModelTuple> {
+
+ private SequenceRowKey<Integer> baseKey;
+
+ private Iterator<TreeNode> children;
+
+ private int counter = 0;
+
+ SwingTreeNodeTuplesIterator(SequenceRowKey<Integer> baseKey,
Iterator<TreeNode> children) {
+ this.baseKey = baseKey;
+ this.children = children;
+ }
+
+ private int getNextCounterValue() {
+ return counter++;
+ }
+
+ public boolean hasNext() {
+ return children.hasNext();
+ }
+
+ public TreeDataModelTuple next() {
+ TreeNode node = children.next();
+
+ SequenceRowKey<Integer> key;
+
+ if (baseKey != null) {
+ key = baseKey.append(getNextCounterValue());
+ } else {
+ key = new SequenceRowKey<Integer>(getNextCounterValue());
+ }
+
+ return new TreeDataModelTuple(key, node);
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-12-01
16:51:58 UTC (rev 20271)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-12-01
16:55:03 UTC (rev 20272)
@@ -34,8 +34,6 @@
*/
public abstract class TreeSequenceKeyModel<K, V> extends ExtendedDataModel<V>
implements TreeDataModel<V> {
- private final SequenceRowKey<K> emptyKey = new SequenceRowKey<K>();
-
private V rootNode;
private V data;
@@ -46,16 +44,6 @@
return rowKey;
}
- protected SequenceRowKey<K> safeGetRowKey() {
- SequenceRowKey<K> key = getRowKey();
-
- if (key == null) {
- key = emptyKey;
- }
-
- return key;
- }
-
public void setRowKey(Object rowKey) {
if (this.rowKey == null || !this.rowKey.equals(rowKey)) {
walkKey((SequenceRowKey<K>) rowKey);