Author: nbelaevski
Date: 2010-12-02 20:31:15 -0500 (Thu, 02 Dec 2010)
New Revision: 20324
Added:
trunk/ui/common/ui/src/main/java/org/richfaces/convert/
trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/BaseTupleIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/DeclarativeTreeDataModelCompositeTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/IterableDataTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/MapDataTuplesIterator.java
Removed:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java
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/TreeDataVisitor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.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-9686'
Copied: trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java (from
rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java)
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java
(rev 0)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -0,0 +1,61 @@
+/*
+ * 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.convert;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class ConverterUtil {
+
+ private static final Converter STRING_CONVERTER = new Converter() {
+
+ public String getAsString(FacesContext context, UIComponent component, Object
value) {
+ if (value == null) {
+ return "";
+ }
+
+ return value.toString();
+ }
+
+ public Object getAsObject(FacesContext context, UIComponent component, String
value) {
+ if (Strings.isNullOrEmpty(value)) {
+ return null;
+ }
+
+ return value;
+ }
+ };
+
+ private ConverterUtil() {}
+
+ public static Converter stringConverter() {
+ return STRING_CONVERTER;
+ }
+
+}
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java
===================================================================
---
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -28,6 +28,7 @@
*/
public interface TreeDataVisitor {
+ //TODO make it possible to stop when visit complete
public void enterNode();
public void exitNode();
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -495,7 +495,7 @@
Object value = getValue();
if (value == null) {
- dataModel = new DeclarativeTreeDataModelImpl(this, getVar(),
getVariablesMap(getFacesContext()));
+ dataModel = new DeclarativeTreeDataModelImpl(this);
} else {
dataModel = new SwingTreeNodeDataModelImpl();
dataModel.setWrappedData(getValue());
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
(from rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -0,0 +1,167 @@
+/*
+ * 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 java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.DeclarativeModelKey;
+import org.richfaces.model.SequenceRowKey;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DeclarativeTreeDataModelWalker {
+
+ private static final Logger LOGGER = RichfacesLogger.COMPONENTS.getLogger();
+
+ private String var;
+
+ private FacesContext facesContext;
+
+ private UIComponent rootComponent;
+
+ private UIComponent currentComponent;
+
+ private Map<String, Object> contextMap;
+
+ private Object data;
+
+ public DeclarativeTreeDataModelWalker(AbstractTree rootComponent) {
+ super();
+
+ this.rootComponent = rootComponent;
+ this.facesContext = FacesContext.getCurrentInstance();
+ this.contextMap = rootComponent.getVariablesMap(facesContext);
+ this.var = rootComponent.getVar();
+ this.currentComponent = rootComponent;
+
+ }
+
+ protected UIComponent getChildModelComponent(String modelId) {
+ UIComponent modelComponent;
+
+ if (currentComponent instanceof TreeModelRecursiveAdaptor &&
modelId.equals(currentComponent.getId())) {
+ modelComponent = currentComponent;
+ } else {
+ modelComponent = Iterables.find(currentComponent.getChildren(),
ComponentPredicates.withId(modelId));
+ }
+
+ return modelComponent;
+ }
+
+ protected Object getNodes(UIComponent modelComponent) {
+ Object nodes = null;
+
+ if (modelComponent instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor recursiveAdaptor = (TreeModelRecursiveAdaptor)
modelComponent;
+
+ if (currentComponent.equals(modelComponent)) {
+ nodes = recursiveAdaptor.getNodes();
+ } else {
+ nodes = recursiveAdaptor.getRoots();
+ }
+ } else {
+ nodes = ((TreeModelAdaptor) modelComponent).getNodes();
+ }
+
+ return nodes;
+ }
+
+ protected FacesContext getFacesContext() {
+ return facesContext;
+ }
+
+ protected UIComponent getRootComponent() {
+ return rootComponent;
+ }
+
+ public UIComponent getCurrentComponent() {
+ return currentComponent;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void walk(SequenceRowKey key) {
+ Object initialContextValue = null;
+
+ if (var != null) {
+ initialContextValue = contextMap.remove(var);
+ }
+
+ try {
+ walkSimpleKeys(key.getSimpleKeys());
+ } finally {
+ if (var != null) {
+ try {
+ contextMap.put(var, initialContextValue);
+ } catch (Exception e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ protected DeclarativeModelKey convertKey(Object nodes, DeclarativeModelKey
declarativeModelKey) {
+ return declarativeModelKey;
+ }
+
+ protected Object getData(Object nodes, Object key) {
+ if (nodes instanceof Iterable<?>) {
+ Iterable<?> iterable = (Iterable<?>) nodes;
+ return Iterables.get(iterable, (Integer) key);
+ } else {
+ return ((Map<?, ?>) nodes).get(key);
+ }
+ }
+
+ protected void walkSimpleKeys(Object simpleKey) {
+ DeclarativeModelKey segment = (DeclarativeModelKey) simpleKey;
+
+ if (var != null) {
+ contextMap.put(var, this.data);
+ }
+
+ UIComponent modelComponent = getChildModelComponent(segment.getModelId());
+ Object nodes = getNodes(modelComponent);
+
+ this.currentComponent = modelComponent;
+ DeclarativeModelKey convertedKey = convertKey(nodes, segment);
+ this.data = getData(nodes, convertedKey.getModelKey());
+ }
+
+ protected void walkSimpleKeys(Object[] simpleKeys) {
+ for (Object simpleKey : simpleKeys) {
+ walkSimpleKeys(simpleKey);
+ }
+ }
+
+}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -21,18 +21,83 @@
*/
package org.richfaces.convert;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
import javax.faces.convert.IntegerConverter;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.DeclarativeTreeDataModelWalker;
import org.richfaces.model.DeclarativeModelKey;
+import org.richfaces.model.SequenceRowKey;
/**
* @author Nick Belaevski
*
*/
public class DeclarativeModelKeySequenceRowKeyConverter extends
SequenceRowKeyConverter<DeclarativeModelKey> {
+ private final class KeyConvertingWalker extends DeclarativeTreeDataModelWalker {
+
+ private final FacesContext context;
+
+ private DeclarativeModelKey[] convertedSimpleKeys;
+
+ private int keysIdx;
+
+ private KeyConvertingWalker(AbstractTree rootComponent, FacesContext context) {
+ super(rootComponent);
+ this.context = context;
+ }
+
+ @Override
+ protected DeclarativeModelKey convertKey(Object nodes, DeclarativeModelKey
declarativeModelKey) {
+ DeclarativeModelKey convertedKey;
+
+ if (nodes instanceof Iterable<?>) {
+ String modelKeyAsString = (String) declarativeModelKey.getModelKey();
+ Object modelKey = INTEGER_CONVERTER.getAsObject(context,
getRootComponent(), modelKeyAsString);
+ convertedKey = new DeclarativeModelKey(declarativeModelKey.getModelId(),
modelKey);
+ } else {
+ convertedKey = declarativeModelKey;
+ }
+
+ convertedSimpleKeys[keysIdx++] = convertedKey;
+
+ return super.convertKey(nodes, convertedKey);
+ }
+
+ @Override
+ public void walk(SequenceRowKey key) {
+ convertedSimpleKeys = new DeclarativeModelKey[key.getSimpleKeys().length];
+ keysIdx = 0;
+ super.walk(key);
+ }
+
+ public DeclarativeModelKey[] getConvertedSimpleKeys() {
+ return convertedSimpleKeys;
+ }
+ }
+
+ private static final Converter INTEGER_CONVERTER = new IntegerConverter();
+
public DeclarativeModelKeySequenceRowKeyConverter() {
- super(DeclarativeModelKey.class, new DeclarativeModelKeyConverter(new
IntegerConverter()));
+ super(DeclarativeModelKey.class, new
DeclarativeModelKeyConverter(ConverterUtil.stringConverter()));
}
+ @Override
+ public Object getAsObject(FacesContext context, UIComponent component, String value)
throws ConverterException {
+ SequenceRowKey key = (SequenceRowKey) super.getAsObject(context, component,
value);
+
+ if (key != null) {
+
+ KeyConvertingWalker walker = new KeyConvertingWalker((AbstractTree)
component, context);
+ walker.walk(key);
+
+ key = new SequenceRowKey((Object[]) walker.getConvertedSimpleKeys());
+ }
+
+ return key;
+ }
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -26,12 +26,13 @@
import javax.faces.convert.Converter;
import org.richfaces.convert.ObjectSequenceRowKeyConverter;
+import org.richfaces.model.iterators.ClassicTreeNodeTuplesIterator;
/**
* @author Nick Belaevski
*
*/
-public class ClassicTreeNodeDataModelImpl extends TreeSequenceKeyModel<TreeNode> {
+public class ClassicTreeNodeDataModelImpl extends
NodesTreeSequenceKeyModel<TreeNode> {
private static final Converter DEFAULT_CONVERTER = new
ObjectSequenceRowKeyConverter();
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -1,58 +0,0 @@
-/*
- * 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 com.google.common.collect.UnmodifiableIterator;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class ClassicTreeNodeTuplesIterator extends
UnmodifiableIterator<TreeDataModelTuple> {
-
- private TreeNode treeNode;
-
- private SequenceRowKey baseKey;
-
- private Iterator<Object> childrenKeysIterator = null;
-
- public ClassicTreeNodeTuplesIterator(TreeNode treeNode, SequenceRowKey baseKey) {
- super();
- this.treeNode = treeNode;
- this.baseKey = baseKey;
- this.childrenKeysIterator = treeNode.getChildrenKeysIterator();
- }
-
- public boolean hasNext() {
- return childrenKeysIterator.hasNext();
- }
-
- public TreeDataModelTuple next() {
- Object nextChildKey = childrenKeysIterator.next();
- Object rowKey = (baseKey != null ? baseKey.append(nextChildKey) : new
SequenceRowKey(nextChildKey));
-
- return new TreeDataModelTuple(rowKey, treeNode.getChild(nextChildKey));
- }
-
-}
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -1,94 +0,0 @@
-/*
- * 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 key;
-
- private Iterator<TreeDataModelTuple> iterator;
-
- public DeclarativeTreeDataModelCompositeTuplesIterator(UIComponent component,
SequenceRowKey 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-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -22,18 +22,16 @@
package org.richfaces.model;
import java.util.Iterator;
-import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.convert.Converter;
import org.richfaces.component.AbstractTree;
-import org.richfaces.component.ComponentPredicates;
+import org.richfaces.component.DeclarativeTreeDataModelWalker;
import org.richfaces.component.TreeModelAdaptor;
import org.richfaces.component.TreeModelRecursiveAdaptor;
import org.richfaces.convert.DeclarativeModelKeySequenceRowKeyConverter;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.iterators.DeclarativeTreeDataModelCompositeTuplesIterator;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
@@ -44,23 +42,15 @@
*/
public class DeclarativeTreeDataModelImpl extends TreeSequenceKeyModel<Object>
implements DeclarativeTreeModel<Object> {
- private static final Logger LOGGER = RichfacesLogger.MODEL.getLogger();
-
private static final Converter DEFAULT_CONVERTER = new
DeclarativeModelKeySequenceRowKeyConverter();
- private String var;
+ private AbstractTree tree;
- private Map<String, Object> contextMap;
-
- private UIComponent tree;
-
private UIComponent currentComponent;
- public DeclarativeTreeDataModelImpl(AbstractTree tree, String var, Map<String,
Object> contextMap) {
+ public DeclarativeTreeDataModelImpl(AbstractTree tree) {
this.tree = tree;
this.currentComponent = tree;
- this.var = var;
- this.contextMap = contextMap;
}
public UIComponent getCurrentComponent() {
@@ -96,64 +86,18 @@
@Override
protected void setupKey(SequenceRowKey key) {
- Object initialContextValue = null;
+ setRowKeyAndData(null, null);
+ this.currentComponent = tree;
- if (var != null) {
- initialContextValue = contextMap.remove(var);
- }
+ if (key != null) {
+ DeclarativeTreeDataModelWalker walker = new
DeclarativeTreeDataModelWalker(tree);
+ walker.walk(key);
- try {
- this.currentComponent = tree;
-
- super.setupKey(key);
- } finally {
- if (var != null) {
- try {
- contextMap.put(var, initialContextValue);
- } catch (Exception e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
+ setRowKeyAndData(key, walker.getData());
+ this.currentComponent = walker.getCurrentComponent();
}
}
- @Override
- protected Object setupChildContext(Object keyObject) {
- DeclarativeModelKey segment = (DeclarativeModelKey) keyObject;
- if (var != null) {
- contextMap.put(var, getData());
- }
-
- String modelId = segment.getModelId();
-
- UIComponent modelComponent;
-
- if (currentComponent instanceof TreeModelRecursiveAdaptor &&
modelId.equals(currentComponent.getId())) {
- modelComponent = currentComponent;
- } else {
- modelComponent = Iterables.find(currentComponent.getChildren(),
ComponentPredicates.withId(modelId));
- }
-
- Object nodes = null;
-
- if (modelComponent instanceof TreeModelRecursiveAdaptor) {
- TreeModelRecursiveAdaptor recursiveAdaptor = (TreeModelRecursiveAdaptor)
modelComponent;
-
- if (currentComponent.equals(modelComponent)) {
- nodes = recursiveAdaptor.getNodes();
- } else {
- nodes = recursiveAdaptor.getRoots();
- }
- } else {
- nodes = ((TreeModelAdaptor) modelComponent).getNodes();
- }
-
- Object data = Iterables.get((Iterable<?>) nodes, (Integer)
segment.getModelKey());
- this.currentComponent = modelComponent;
-
- return data;
- }
-
public TreeDataModelTuple createSnapshot() {
return new DeclarativeTreeDataModelTuple(getRowKey(), getData(),
getCurrentComponent());
}
@@ -161,7 +105,7 @@
public void restoreFromSnapshot(TreeDataModelTuple tuple) {
DeclarativeTreeDataModelTuple declarativeModelTuple =
(DeclarativeTreeDataModelTuple) tuple;
- super.restoreFromSnapshot(declarativeModelTuple);
+ setRowKeyAndData((SequenceRowKey) tuple.getRowKey(), tuple.getData());
this.currentComponent = declarativeModelTuple.getComponent();
}
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -1,60 +0,0 @@
-/*
- * 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;
-
-import com.google.common.collect.UnmodifiableIterator;
-
-final class DeclarativeTreeDataModelTuplesIterator extends
UnmodifiableIterator<TreeDataModelTuple> {
-
- private UIComponent component;
-
- private SequenceRowKey baseKey;
-
- private int counter = 0;
-
- private Iterator<?> dataIterator;
-
- public DeclarativeTreeDataModelTuplesIterator(UIComponent component, SequenceRowKey
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 newKey = (baseKey != null ? baseKey.append(key) : new
SequenceRowKey(key));
-
- return new DeclarativeTreeDataModelTuple(newKey, nextNode, component);
- }
-
- public boolean hasNext() {
- return dataIterator.hasNext();
- }
-
-}
\ No newline at end of file
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java
(from rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class NodesTreeSequenceKeyModel<V> extends
TreeSequenceKeyModel<V> {
+
+ private V rootNode;
+
+ protected V getRootNode() {
+ return rootNode;
+ }
+
+ protected void setRootNode(V rootNode) {
+ this.rootNode = rootNode;
+ }
+
+ protected void setupKey(SequenceRowKey key) {
+ setRowKeyAndData(null, rootNode);
+
+ if (key != null) {
+ V data = getRootNode();
+
+ for (Object simpleKey: key.getSimpleKeys()) {
+ data = setupChildContext(simpleKey);
+ setData(data);
+ }
+
+ setRowKeyAndData(key, data);
+ }
+ }
+
+ protected abstract V setupChildContext(Object segment);
+
+ public TreeDataModelTuple createSnapshot() {
+ return new TreeDataModelTuple(getRowKey(), getData());
+ }
+
+ public void restoreFromSnapshot(TreeDataModelTuple tuple) {
+ setRowKeyAndData((SequenceRowKey) tuple.getRowKey(), (V) tuple.getData());
+ }
+
+}
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-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -29,6 +29,7 @@
import javax.swing.tree.TreeNode;
import org.richfaces.convert.IntegerSequenceRowKeyConverter;
+import org.richfaces.model.iterators.IterableDataTuplesIterator;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
@@ -36,7 +37,7 @@
* @author Nick Belaevski
*
*/
-public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<TreeNode> {
+public class SwingTreeNodeDataModelImpl extends NodesTreeSequenceKeyModel<TreeNode>
{
private static final Converter DEFAULT_CONVERTER = new
IntegerSequenceRowKeyConverter();
@@ -78,7 +79,7 @@
public Iterator<TreeDataModelTuple> children() {
Iterator<TreeNode> children =
Iterators.forEnumeration((Enumeration<TreeNode>) getData().children());
- return new SwingTreeNodeTuplesIterator(getRowKey(), children);
+ return new IterableDataTuplesIterator(getRowKey(), children);
}
public boolean isLeaf() {
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java 2010-12-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -1,65 +0,0 @@
-/*
- * 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;
-
-import com.google.common.collect.UnmodifiableIterator;
-
-final class SwingTreeNodeTuplesIterator extends
UnmodifiableIterator<TreeDataModelTuple> {
-
- private SequenceRowKey baseKey;
-
- private Iterator<TreeNode> children;
-
- private int counter = 0;
-
- SwingTreeNodeTuplesIterator(SequenceRowKey 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 key;
-
- if (baseKey != null) {
- key = baseKey.append(getNextCounterValue());
- } else {
- key = new SequenceRowKey(getNextCounterValue());
- }
-
- return new TreeDataModelTuple(key, node);
- }
-
-}
\ 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-03
00:28:30 UTC (rev 20323)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -34,8 +34,6 @@
*/
public abstract class TreeSequenceKeyModel<V> extends ExtendedDataModel<V>
implements TreeDataModel<V> {
- private V rootNode;
-
private V data;
private SequenceRowKey rowKey;
@@ -52,10 +50,6 @@
}
}
- protected void resetRowKeyAndData() {
- setRowKeyAndData(null, rootNode);
- }
-
protected void setData(V data) {
this.data = data;
}
@@ -77,31 +71,8 @@
return data;
}
- protected void setupKey(SequenceRowKey key) {
- resetRowKeyAndData();
-
- if (key != null) {
- V data = getRootNode();
-
- for (Object simpleKey: key.getSimpleKeys()) {
- data = setupChildContext(simpleKey);
- setData(data);
- }
-
- setRowKeyAndData(key, data);
- }
- }
-
- protected abstract V setupChildContext(Object segment);
+ protected abstract void setupKey(SequenceRowKey key);
- protected V getRootNode() {
- return rootNode;
- }
-
- protected void setRootNode(V rootNode) {
- this.rootNode = rootNode;
- }
-
//TODO ExtendedDataModel legacy
@Override
public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) {
@@ -138,14 +109,6 @@
throw new UnsupportedOperationException();
}
- public TreeDataModelTuple createSnapshot() {
- return new TreeDataModelTuple(getRowKey(), getData());
- }
-
- public void restoreFromSnapshot(TreeDataModelTuple tuple) {
- setRowKeyAndData((SequenceRowKey) tuple.getRowKey(), (V) tuple.getData());
- }
-
public Object getParentRowKey(Object rowKey) {
SequenceRowKey key = getRowKey();
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/BaseTupleIterator.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/BaseTupleIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/BaseTupleIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -0,0 +1,119 @@
+/*
+ * 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.iterators;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.model.DeclarativeModelKey;
+import org.richfaces.model.DeclarativeTreeDataModelTuple;
+import org.richfaces.model.SequenceRowKey;
+import org.richfaces.model.TreeDataModelTuple;
+
+import com.google.common.collect.UnmodifiableIterator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class BaseTupleIterator extends
UnmodifiableIterator<TreeDataModelTuple> {
+
+ private SequenceRowKey baseKey;
+
+ private UIComponent component;
+
+ private Object rowKey;
+
+ private Object data;
+
+ public BaseTupleIterator(SequenceRowKey baseKey) {
+ this(baseKey, null);
+ }
+
+ public BaseTupleIterator(SequenceRowKey baseKey, UIComponent component) {
+ super();
+ this.baseKey = baseKey;
+ this.component = component;
+ }
+
+ protected abstract void proceedToNext();
+
+ protected UIComponent getComponent() {
+ return component;
+ }
+
+ protected SequenceRowKey getBaseKey() {
+ return baseKey;
+ }
+
+ protected void setKeyAndData(Object rowKey, Object data) {
+ this.rowKey = rowKey;
+ this.data = data;
+ }
+
+ protected Object getKey() {
+ return rowKey;
+ }
+
+ public final TreeDataModelTuple next() {
+ proceedToNext();
+
+ Object modelKey = getWrappedKey();
+ SequenceRowKey nextKey = getCompositeKey(modelKey);
+ return createTuple(nextKey);
+ }
+
+ protected TreeDataModelTuple createTuple(SequenceRowKey key) {
+ TreeDataModelTuple result;
+
+ if (component != null) {
+ result = new DeclarativeTreeDataModelTuple(key, data, component);
+ } else {
+ result = new TreeDataModelTuple(key, data);
+ }
+
+ return result;
+ }
+
+ protected Object getWrappedKey() {
+ Object modelKey;
+
+ if (getComponent() != null) {
+ modelKey = new DeclarativeModelKey(getComponent().getId(), getKey());
+ } else {
+ modelKey = getKey();
+ }
+
+ return modelKey;
+ }
+
+ protected SequenceRowKey getCompositeKey(Object modelKey) {
+ SequenceRowKey result;
+
+ if (getBaseKey() != null) {
+ result = getBaseKey().append(modelKey);
+ } else {
+ result = new SequenceRowKey(modelKey);
+ }
+
+ return result;
+ }
+}
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java
(from rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/ClassicTreeNodeTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -0,0 +1,59 @@
+/*
+ * 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.iterators;
+
+import java.util.Iterator;
+
+import org.richfaces.model.SequenceRowKey;
+import org.richfaces.model.TreeNode;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ClassicTreeNodeTuplesIterator extends BaseTupleIterator {
+
+ private TreeNode treeNode;
+
+ private SequenceRowKey baseKey;
+
+ private Iterator<Object> childrenKeysIterator = null;
+
+ public ClassicTreeNodeTuplesIterator(TreeNode treeNode, SequenceRowKey baseKey) {
+ super(baseKey);
+ this.treeNode = treeNode;
+ this.childrenKeysIterator = treeNode.getChildrenKeysIterator();
+ }
+
+ public boolean hasNext() {
+ return childrenKeysIterator.hasNext();
+ }
+
+ @Override
+ protected void proceedToNext() {
+ Object key = childrenKeysIterator.next();
+ TreeNode data = treeNode.getChild(key);
+
+ setKeyAndData(key, data);
+ }
+
+}
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/DeclarativeTreeDataModelCompositeTuplesIterator.java
(from rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/DeclarativeTreeDataModelCompositeTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/DeclarativeTreeDataModelCompositeTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -0,0 +1,114 @@
+/*
+ * 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.iterators;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.ComponentPredicates;
+import org.richfaces.component.TreeModelAdaptor;
+import org.richfaces.component.TreeModelRecursiveAdaptor;
+import org.richfaces.model.SequenceRowKey;
+import org.richfaces.model.TreeDataModelTuple;
+
+import com.google.common.collect.ForwardingIterator;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
+public class DeclarativeTreeDataModelCompositeTuplesIterator extends
ForwardingIterator<TreeDataModelTuple> {
+
+ private UIComponent component;
+
+ private SequenceRowKey key;
+
+ private Iterator<TreeDataModelTuple> iterator;
+
+ public DeclarativeTreeDataModelCompositeTuplesIterator(UIComponent component,
SequenceRowKey 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;
+
+ Object nodes = parentRecursiveAdaptor.getNodes();
+
+ Iterator<TreeDataModelTuple> tuplesIterator =
createTuplesIterator(component, nodes);
+ if (tuplesIterator != null) {
+ list.add(tuplesIterator);
+ }
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : Iterables.filter(component.getChildren(),
ComponentPredicates.isRendered())) {
+ Object nodes = null;
+
+ if (child instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor treeModelRecursiveAdaptor =
(TreeModelRecursiveAdaptor) child;
+
+ nodes = treeModelRecursiveAdaptor.getRoots();
+ } else if (child instanceof TreeModelAdaptor) {
+ TreeModelAdaptor treeModelAdaptor = (TreeModelAdaptor) child;
+
+ nodes = treeModelAdaptor.getNodes();
+ }
+
+ Iterator<TreeDataModelTuple> tuplesIterator =
createTuplesIterator(child, nodes);
+ if (tuplesIterator != null) {
+ list.add(tuplesIterator);
+ }
+ }
+ }
+
+ iterator = Iterators.concat(list.iterator());
+ }
+
+ return iterator;
+ }
+
+ private Iterator<TreeDataModelTuple> createTuplesIterator(UIComponent
component, Object nodes) {
+ if (nodes != null) {
+ if (nodes instanceof Iterable<?>) {
+ Iterable<?> iterable = (Iterable<?>) nodes;
+
+ return new IterableDataTuplesIterator(key, iterable.iterator(),
component);
+ } else if (nodes instanceof Map<?, ?>) {
+ Map<?, ?> map = (Map<?, ?>) nodes;
+
+ return new MapDataTuplesIterator(key, map, component);
+ }
+ }
+
+ return null;
+ }
+
+}
\ No newline at end of file
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/IterableDataTuplesIterator.java
(from rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/IterableDataTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/IterableDataTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -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.iterators;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.model.SequenceRowKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class IterableDataTuplesIterator extends BaseTupleIterator {
+
+ private Iterator<?> iterator;
+
+ private int counter = 0;
+
+ public IterableDataTuplesIterator(SequenceRowKey baseKey, Iterator<?> children)
{
+ this(baseKey, children, null);
+ }
+
+ public IterableDataTuplesIterator(SequenceRowKey baseKey, Iterator<?> children,
UIComponent component) {
+ super(baseKey, component);
+ this.iterator = children;
+ }
+
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ protected void proceedToNext() {
+ setKeyAndData(getNextCounterValue(), iterator.next());
+ }
+
+ private int getNextCounterValue() {
+ return counter++;
+ }
+
+}
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/MapDataTuplesIterator.java
(from rev 20320,
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/MapDataTuplesIterator.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/iterators/MapDataTuplesIterator.java 2010-12-03
01:31:15 UTC (rev 20324)
@@ -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.iterators;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.model.SequenceRowKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MapDataTuplesIterator extends BaseTupleIterator {
+
+ private Map<?, ?> dataMap;
+
+ private Iterator<?> keys;
+
+ public MapDataTuplesIterator(SequenceRowKey baseKey, Map<?, ?> dataMap) {
+ this(baseKey, dataMap, null);
+ }
+
+ public MapDataTuplesIterator(SequenceRowKey baseKey, Map<?, ?> dataMap,
UIComponent component) {
+ super(baseKey, component);
+
+ this.dataMap = dataMap;
+ this.keys = dataMap.keySet().iterator();
+ }
+
+ public boolean hasNext() {
+ return keys.hasNext();
+ }
+
+ @Override
+ protected void proceedToNext() {
+ Object key = keys.next();
+ setKeyAndData(key, dataMap.get(key));
+ }
+
+}