Author: nbelaevski
Date: 2010-12-16 17:32:17 -0500 (Thu, 16 Dec 2010)
New Revision: 20629
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
Log:
DeclarativeTreeDataModelWalker refactoring
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java 2010-12-16
21:35:18 UTC (rev 20628)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java 2010-12-16
22:32:17 UTC (rev 20629)
@@ -51,47 +51,33 @@
private Map<String, Object> contextMap;
+ private Object modelData;
+
private Object data;
- public DeclarativeTreeDataModelWalker(AbstractTree rootComponent) {
+ public DeclarativeTreeDataModelWalker(FacesContext facesContext, AbstractTree
rootComponent) {
super();
this.rootComponent = rootComponent;
- this.facesContext = FacesContext.getCurrentInstance();
+ this.facesContext = facesContext;
this.contextMap = rootComponent.getVariablesMap(facesContext);
this.var = rootComponent.getVar();
this.currentComponent = rootComponent;
}
- protected UIComponent getChildModelComponent(String modelId) {
- UIComponent modelComponent;
-
+ private void setupChildModelContext(String modelId) {
if (currentComponent instanceof TreeModelRecursiveAdaptor &&
modelId.equals(currentComponent.getId())) {
- modelComponent = currentComponent;
+ //currentComponent already set
+ modelData = ((TreeModelRecursiveAdaptor) currentComponent).getNodes();
} 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();
+ currentComponent = Iterables.find(currentComponent.getChildren(),
ComponentPredicates.withId(modelId));
+ if (currentComponent instanceof TreeModelRecursiveAdaptor) {
+ modelData = ((TreeModelRecursiveAdaptor) currentComponent).getRoots();
} else {
- nodes = recursiveAdaptor.getRoots();
+ modelData = ((TreeModelAdaptor) currentComponent).getNodes();
}
- } else {
- nodes = ((TreeModelAdaptor) modelComponent).getNodes();
}
-
- return nodes;
}
protected FacesContext getFacesContext() {
@@ -143,24 +129,21 @@
}
}
- protected void walkSimpleKeys(Object simpleKey) {
- DeclarativeModelKey segment = (DeclarativeModelKey) simpleKey;
-
+ protected void walkSimpleKey(DeclarativeModelKey segment) {
if (var != null) {
- contextMap.put(var, this.data);
+ contextMap.put(var, data);
}
- UIComponent modelComponent = getChildModelComponent(segment.getModelId());
- Object nodes = getNodes(modelComponent);
-
- this.currentComponent = modelComponent;
- DeclarativeModelKey convertedKey = convertKey(nodes, segment);
- this.data = getData(nodes, convertedKey.getModelKey());
+ setupChildModelContext(segment.getModelId());
+
+ DeclarativeModelKey convertedKey = convertKey(modelData, segment);
+ data = getData(modelData, convertedKey.getModelKey());
}
protected void walkSimpleKeys(Object[] simpleKeys) {
for (Object simpleKey : simpleKeys) {
- walkSimpleKeys(simpleKey);
+ DeclarativeModelKey declarativeKey = (DeclarativeModelKey) simpleKey;
+ walkSimpleKey(declarativeKey);
}
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java 2010-12-16
21:35:18 UTC (rev 20628)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java 2010-12-16
22:32:17 UTC (rev 20629)
@@ -45,8 +45,8 @@
private int keysIdx;
- private KeyConvertingWalker(AbstractTree rootComponent, FacesContext context) {
- super(rootComponent);
+ private KeyConvertingWalker(FacesContext context, AbstractTree rootComponent) {
+ super(context, rootComponent);
this.context = context;
}
@@ -93,7 +93,7 @@
if (key != null) {
- KeyConvertingWalker walker = new KeyConvertingWalker((AbstractTree)
component, context);
+ KeyConvertingWalker walker = new KeyConvertingWalker(context, (AbstractTree)
component);
walker.walk(key);
key = new SequenceRowKey((Object[]) walker.getConvertedSimpleKeys());
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-16
21:35:18 UTC (rev 20628)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-16
22:32:17 UTC (rev 20629)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.richfaces.component.AbstractTree;
@@ -90,7 +91,7 @@
this.currentComponent = tree;
if (key != null) {
- DeclarativeTreeDataModelWalker walker = new
DeclarativeTreeDataModelWalker(tree);
+ DeclarativeTreeDataModelWalker walker = new
DeclarativeTreeDataModelWalker(FacesContext.getCurrentInstance(), tree);
walker.walk(key);
setRowKeyAndData(key, walker.getData());
Show replies by date