Author: nbelaevski
Date: 2010-12-27 08:37:38 -0500 (Mon, 27 Dec 2010)
New Revision: 20809
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java
Removed:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java
Modified:
trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
Log:
https://issues.jboss.org/browse/RF-10047
https://issues.jboss.org/browse/RF-10038
https://issues.jboss.org/browse/RF-9995
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-12-27
13:36:30 UTC (rev 20808)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -1298,7 +1298,7 @@
return dataVisitor.getVisitResult();
} else {
- return visitComponents(dataChildren(), visitContext, callback);
+ return visitComponents(getFacetsAndChildren(), visitContext, callback);
}
}
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java 2010-12-27
13:36:30 UTC (rev 20808)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/convert/ConverterUtil.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -24,6 +24,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
+import javax.faces.convert.IntegerConverter;
import com.google.common.base.Strings;
@@ -33,8 +34,7 @@
*/
public final class ConverterUtil {
- private static final Converter STRING_CONVERTER = new Converter() {
-
+ public static final class StringConverter implements Converter {
public String getAsString(FacesContext context, UIComponent component, Object
value) {
if (value == null) {
return "";
@@ -42,7 +42,7 @@
return value.toString();
}
-
+
public Object getAsObject(FacesContext context, UIComponent component, String
value) {
if (Strings.isNullOrEmpty(value)) {
return null;
@@ -50,12 +50,20 @@
return value;
}
- };
+ }
+
+ private static final Converter STRING_CONVERTER = new StringConverter();
+ private static final Converter INTEGER_CONVERTER = new IntegerConverter();
+
private ConverterUtil() {}
public static Converter stringConverter() {
return STRING_CONVERTER;
}
+
+ public static Converter integerConverter() {
+ return INTEGER_CONVERTER;
+ }
}
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-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -22,9 +22,11 @@
package org.richfaces.component;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import javax.el.ELContext;
import javax.el.ELException;
@@ -38,6 +40,7 @@
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
@@ -65,6 +68,7 @@
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.event.TreeToggleListener;
import org.richfaces.event.TreeToggleSource;
+import org.richfaces.model.DeclarativeModelKey;
import org.richfaces.model.DeclarativeTreeDataModelImpl;
import org.richfaces.model.DeclarativeTreeModel;
import org.richfaces.model.SwingTreeNodeDataModelImpl;
@@ -77,6 +81,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
+import com.google.common.collect.Maps;
/**
* @author Nick Belaevski
@@ -102,6 +107,10 @@
public static final String DEFAULT_TREE_NODE_FACET_NAME = DEFAULT_TREE_NODE_ID;
+ private static final String COMPONENT_FOR_MODEL_UNAVAILABLE = "Component is not
available for model {0}";
+
+ private static final String CONVERTER_FOR_MODEL_UNAVAILABLE = "Row key converter
is not available for model {0}";
+
private static final class MatchingTreeNodePredicate implements
Predicate<UIComponent> {
private String type;
@@ -141,6 +150,8 @@
private transient UIComponent currentComponent = this;
+ private transient Map<String, UIComponent> declatariveModelsMap = null;
+
public AbstractTree() {
setKeepSaved(true);
setRendererType("org.richfaces.TreeRenderer");
@@ -552,7 +563,9 @@
@Override
protected void resetDataModel() {
super.resetDataModel();
+
treeRange = null;
+ declatariveModelsMap = null;
}
public TreeDataModelTuple createSnapshot() {
@@ -570,4 +583,65 @@
super.restoreChildState(facesContext);
}
+ protected UIComponent findDeclarativeModel(String modelId) {
+ if (declatariveModelsMap == null) {
+ declatariveModelsMap = Maps.newHashMap();
+ }
+
+ UIComponent adaptor = declatariveModelsMap.get(modelId);
+ if (adaptor == null) {
+ adaptor = findComponent(modelId);
+ if (adaptor != null) {
+ declatariveModelsMap.put(modelId, adaptor);
+ }
+ }
+
+ if (adaptor == null) {
+ throw new
IllegalStateException(MessageFormat.format(COMPONENT_FOR_MODEL_UNAVAILABLE, modelId));
+ }
+
+ return adaptor;
+ }
+
+ public String convertDeclarativeKeyToString(FacesContext context, DeclarativeModelKey
declarativeKey) throws ConverterException {
+ try {
+ UIComponent component = findDeclarativeModel(declarativeKey.getModelId());
+
+ TreeModelAdaptor adaptor = (TreeModelAdaptor) component;
+
+ Converter rowKeyConverter = adaptor.getRowKeyConverter();
+ if (rowKeyConverter == null) {
+ throw new
ConverterException(MessageFormat.format(CONVERTER_FOR_MODEL_UNAVAILABLE,
declarativeKey.getModelId()));
+ }
+
+ return rowKeyConverter.getAsString(context, (UIComponent) adaptor,
declarativeKey.getModelKey());
+ } catch (ConverterException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ConverterException(e.getMessage(), e);
+ }
+ }
+
+ public DeclarativeModelKey convertDeclarativeKeyFromString(FacesContext context,
String modelId,
+ String modelKeyAsString) throws ConverterException {
+
+ try {
+ UIComponent component = findDeclarativeModel(modelId);
+
+ TreeModelAdaptor adaptor = (TreeModelAdaptor) component;
+
+ Converter rowKeyConverter = adaptor.getRowKeyConverter();
+ if (rowKeyConverter == null) {
+ throw new
ConverterException(MessageFormat.format(CONVERTER_FOR_MODEL_UNAVAILABLE, modelId));
+ }
+
+ Object modelKey = rowKeyConverter.getAsObject(context, (UIComponent) adaptor,
modelKeyAsString);
+ return new DeclarativeModelKey(modelId, modelKey);
+ } catch (ConverterException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ConverterException(e.getMessage(), e);
+ }
+ }
+
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java 2010-12-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -21,19 +21,149 @@
*/
package org.richfaces.component;
+import java.util.Map;
+
+import javax.el.ValueExpression;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.component.StateHelper;
+import javax.faces.component.StateHolder;
import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.convert.ConverterUtil;
/**
* @author Nick Belaevski
*
*/
-@JsfComponent(type = AbstractTreeModelAdaptor.COMPONENT_TYPE,
- tag = @Tag(name = "treeModelAdaptor"))
-public abstract class AbstractTreeModelAdaptor extends UIComponentBase implements
TreeModelAdaptor {
+public abstract class AbstractTreeModelAdaptor extends UIComponentBase {
- public static final String COMPONENT_TYPE =
"org.richfaces.TreeModelAdaptor";
+ private enum PropertyKeys {
+ rowKeyConverter, rowKeyConverterSet
+ }
+ private Converter rowKeyConverter;
+
+ public Converter getRowKeyConverter() {
+ if (this.rowKeyConverter != null) {
+ return this.rowKeyConverter;
+ }
+
+ ValueExpression converterExpression =
getValueExpression(PropertyKeys.rowKeyConverter.toString());
+ if (converterExpression != null) {
+ return (Converter)
converterExpression.getValue(getFacesContext().getELContext());
+ } else {
+ return null;
+ }
+ }
+
+ public void setRowKeyConverter(Converter converter) {
+ StateHelper stateHelper = getStateHelper();
+ if (initialStateMarked()) {
+ stateHelper.put(PropertyKeys.rowKeyConverterSet, Boolean.TRUE);
+ }
+
+ this.rowKeyConverter = converter;
+ }
+
+ protected void memoizeDefaultRowKeyConverter(Object value) {
+ if (isSetRowKeyConverter()) {
+ return;
+ }
+
+ if (value instanceof Iterable<?>) {
+ setRowKeyConverter(ConverterUtil.integerConverter());
+ } else if (value instanceof Map<?, ?>) {
+ setRowKeyConverter(ConverterUtil.stringConverter());
+ }
+ }
+
+ private boolean isSetRowKeyConverter() {
+ return isSetLocalRowKeyConverter() ||
getValueExpression(PropertyKeys.rowKeyConverter.toString()) != null;
+ }
+
+ private boolean isSetLocalRowKeyConverter() {
+ Boolean value = (Boolean) getStateHelper().get(PropertyKeys.rowKeyConverterSet);
+ return Boolean.TRUE.equals(value);
+ }
+
+ @Override
+ public void markInitialState() {
+ super.markInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).markInitialState();
+ }
+ }
+
+ @Override
+ public void clearInitialState() {
+ super.clearInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).clearInitialState();
+ }
+ }
+
+ @Override
+ public void restoreState(FacesContext context, Object stateObject) {
+ Object[] state = (Object[]) stateObject;
+
+ super.restoreState(context, state[0]);
+
+ boolean converterHasPartialState = Boolean.TRUE.equals(state[1]);
+ Object savedConverterState = state[2];
+
+ if (converterHasPartialState) {
+ ((StateHolder) rowKeyConverter).restoreState(context, savedConverterState);
+ } else {
+ rowKeyConverter = (Converter) UIComponentBase.restoreAttachedState(context,
savedConverterState);
+ }
+ }
+
+ @Override
+ public Object saveState(FacesContext context) {
+ Object parentState = super.saveState(context);
+
+ Object converterState = null;
+ boolean nullDelta = true;
+
+ boolean converterHasPartialState = false;
+
+ if (initialStateMarked()) {
+ if (!isSetLocalRowKeyConverter() && rowKeyConverter != null
&& rowKeyConverter instanceof PartialStateHolder) {
+ // Delta
+ StateHolder holder = (StateHolder) rowKeyConverter;
+ if (!holder.isTransient()) {
+ Object attachedState = holder.saveState(context);
+ if (attachedState != null) {
+ nullDelta = false;
+ converterState = attachedState;
+ }
+ converterHasPartialState = true;
+ } else {
+ converterState = null;
+ }
+ } else if (isSetLocalRowKeyConverter() || rowKeyConverter != null) {
+ // Full
+ converterState = saveAttachedState(context, rowKeyConverter);
+ nullDelta = false;
+ }
+
+ if (parentState == null && nullDelta) {
+ // No values
+ return null;
+ }
+ } else {
+ converterState = saveAttachedState(context, rowKeyConverter);
+ }
+
+ return new Object[] {
+ parentState,
+ converterHasPartialState,
+ converterState
+ };
+ }
+
}
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java 2010-12-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -1,43 +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.component;
-
-import javax.faces.component.UIComponentBase;
-
-import org.richfaces.cdk.annotations.Attribute;
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.Tag;
-
-/**
- * @author Nick Belaevski
- *
- */
-@JsfComponent(type = AbstractTreeModelRecursiveAdaptor.COMPONENT_TYPE,
- tag = @Tag(name = "treeModelRecursiveAdaptor"))
-public abstract class AbstractTreeModelRecursiveAdaptor extends UIComponentBase
implements TreeModelRecursiveAdaptor {
-
- public static final String COMPONENT_TYPE =
"org.richfaces.TreeModelRecursiveAdaptor";
-
- @Attribute(defaultValue = "first")
- public abstract String getRecursionOrder();
-
-}
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-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -66,7 +66,7 @@
}
- private void setupChildModelContext(String modelId) {
+ private void setupModelComponentContext(String modelId) {
if (currentComponent instanceof TreeModelRecursiveAdaptor &&
modelId.equals(currentComponent.getId())) {
//currentComponent already set
modelData = ((TreeModelRecursiveAdaptor) currentComponent).getNodes();
@@ -80,6 +80,15 @@
}
}
+ private void setupDataModelContext(Object key) {
+ if (modelData instanceof Iterable<?>) {
+ Iterable<?> iterable = (Iterable<?>) modelData;
+ data = Iterables.get(iterable, (Integer) key);
+ } else {
+ data = ((Map<?, ?>) modelData).get(key);
+ }
+ }
+
protected FacesContext getFacesContext() {
return facesContext;
}
@@ -104,7 +113,15 @@
}
try {
- walkSimpleKeys(key.getSimpleKeys());
+ for (Object simpleKey : key.getSimpleKeys()) {
+ DeclarativeModelKey declarativeKey = (DeclarativeModelKey) simpleKey;
+ if (var != null) {
+ contextMap.put(var, data);
+ }
+
+ setupModelComponentContext(declarativeKey.getModelId());
+ setupDataModelContext(declarativeKey.getModelKey());
+ }
} finally {
if (var != null) {
try {
@@ -116,35 +133,4 @@
}
}
- 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 walkSimpleKey(DeclarativeModelKey segment) {
- if (var != null) {
- contextMap.put(var, data);
- }
-
- setupChildModelContext(segment.getModelId());
-
- DeclarativeModelKey convertedKey = convertKey(modelData, segment);
- data = getData(modelData, convertedKey.getModelKey());
- }
-
- protected void walkSimpleKeys(Object[] simpleKeys) {
- for (Object simpleKey : simpleKeys) {
- DeclarativeModelKey declarativeKey = (DeclarativeModelKey) simpleKey;
- walkSimpleKey(declarativeKey);
- }
- }
-
}
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
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -21,12 +21,20 @@
*/
package org.richfaces.component;
+import javax.faces.convert.Converter;
+
+import org.richfaces.cdk.annotations.Attribute;
+
/**
* @author Nick Belaevski
*
*/
public interface TreeModelAdaptor {
+ @Attribute
public Object getNodes();
+ @Attribute
+ public Converter getRowKeyConverter();
+
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java 2010-12-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -21,12 +21,15 @@
*/
package org.richfaces.component;
+import org.richfaces.cdk.annotations.Attribute;
+
/**
* @author Nick Belaevski
*
*/
public interface TreeModelRecursiveAdaptor extends TreeModelAdaptor {
+ @Attribute
public Object getRoots();
public String getRecursionOrder();
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -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.component;
+
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(type = UITreeModelAdaptor.COMPONENT_TYPE,
+ family = UITreeModelAdaptor.COMPONENT_FAMILY,
+ tag = @Tag(name = "treeModelAdaptor"))
+public class UITreeModelAdaptor extends AbstractTreeModelAdaptor implements
TreeModelAdaptor {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.TreeModelAdaptor";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.TreeModelAdaptor";
+
+ private enum PropertyKeys {
+ nodes
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public Object getNodes() {
+ Object nodes = getStateHelper().eval(PropertyKeys.nodes);
+
+ memoizeDefaultRowKeyConverter(nodes);
+
+ return nodes;
+ }
+
+ public void setNodes(Object nodes) {
+ getStateHelper().put(PropertyKeys.nodes, nodes);
+ }
+
+}
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/UITreeModelRecursiveAdaptor.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -0,0 +1,73 @@
+/*
+ * 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 org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(type = UITreeModelRecursiveAdaptor.COMPONENT_TYPE,
+ family = UITreeModelRecursiveAdaptor.COMPONENT_FAMILY,
+ tag = @Tag(name = "treeModelRecursiveAdaptor"))
+public class UITreeModelRecursiveAdaptor extends AbstractTreeModelAdaptor implements
TreeModelRecursiveAdaptor {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.TreeModelRecursiveAdaptor";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.TreeModelRecursiveAdaptor";
+
+ private enum PropertyKeys {
+ roots, nodes
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public Object getRoots() {
+ Object roots = getStateHelper().eval(PropertyKeys.roots);
+
+ memoizeDefaultRowKeyConverter(roots);
+
+ return roots;
+ }
+
+ public void setRoots(Object roots) {
+ getStateHelper().put(PropertyKeys.roots, roots);
+ }
+
+ public Object getNodes() {
+ return getStateHelper().eval(PropertyKeys.nodes);
+ }
+
+ public void setNodes(Object nodes) {
+ getStateHelper().put(PropertyKeys.nodes, nodes);
+ }
+
+ public String getRecursionOrder() {
+ return null;
+ }
+
+}
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-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -21,85 +21,85 @@
*/
package org.richfaces.convert;
+import static org.richfaces.convert.SequenceRowKeyConverter.SEPARATOR_SPLITTER;
+import static org.richfaces.convert.TreeConverterUtil.escape;
+import static org.richfaces.convert.TreeConverterUtil.unescape;
+import static org.richfaces.model.TreeDataModel.SEPARATOR_CHAR;
+
+import java.util.Iterator;
+import java.util.List;
+
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;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
/**
* @author Nick Belaevski
*
*/
-public class DeclarativeModelSequenceKeyConverter extends
SequenceRowKeyConverter<DeclarativeModelKey> {
+public class DeclarativeModelSequenceKeyConverter implements Converter {
- private final class KeyConvertingWalker extends DeclarativeTreeDataModelWalker {
+ public static final String CONVERTER_ID =
"org.richfaces.DeclarativeModelSequenceKeyConverter";
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value)
throws ConverterException {
+ if (Strings.isNullOrEmpty(value)) {
+ return null;
+ }
+
+ Iterator<String> split = SEPARATOR_SPLITTER.split(value).iterator();
- private final FacesContext context;
-
- private DeclarativeModelKey[] convertedSimpleKeys;
-
- private int keysIdx;
+ AbstractTree tree = (AbstractTree) component;
- private KeyConvertingWalker(FacesContext context, AbstractTree rootComponent) {
- super(context, rootComponent);
- this.context = context;
- }
-
- @Override
- protected DeclarativeModelKey convertKey(Object nodes, DeclarativeModelKey
declarativeModelKey) {
- DeclarativeModelKey convertedKey;
+ List<DeclarativeModelKey> declarativeKeys = Lists.newArrayList();
+
+ while (split.hasNext()) {
+ String modelId = unescape(split.next());
+ String modelKeyAsString = unescape(split.next());
- 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;
+ DeclarativeModelKey declarativeKey =
tree.convertDeclarativeKeyFromString(context, modelId, modelKeyAsString);
- return super.convertKey(nodes, convertedKey);
+ declarativeKeys.add(declarativeKey);
}
- @Override
- public void walk(SequenceRowKey key) {
- convertedSimpleKeys = new DeclarativeModelKey[key.getSimpleKeys().length];
- keysIdx = 0;
- super.walk(key);
- }
+ return new SequenceRowKey((Object[]) declarativeKeys.toArray(new
DeclarativeModelKey[declarativeKeys.size()]));
+ }
- public DeclarativeModelKey[] getConvertedSimpleKeys() {
- return convertedSimpleKeys;
+ public String getAsString(FacesContext context, UIComponent component, Object value)
{
+ if (value == null) {
+ return "";
}
- }
-
- public static final String CONVERTER_ID =
"org.richfaces.DeclarativeModelSequenceKeyConverter";
-
- private static final Converter INTEGER_CONVERTER = new IntegerConverter();
-
- public DeclarativeModelSequenceKeyConverter() {
- 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) {
+ SequenceRowKey sequenceRowKey = (SequenceRowKey) value;
+
+ Object[] declarativeKeys = sequenceRowKey.getSimpleKeys();
+ AbstractTree tree = (AbstractTree) component;
+
+ StringBuilder result = new StringBuilder();
+
+ for (Object declarativeKeyObject : declarativeKeys) {
+ DeclarativeModelKey declarativeKey = (DeclarativeModelKey)
declarativeKeyObject;
+ String modelId = escape(declarativeKey.getModelId());
- KeyConvertingWalker walker = new KeyConvertingWalker(context, (AbstractTree)
component);
- walker.walk(key);
+ String modelKeyAsString = escape(tree.convertDeclarativeKeyToString(context,
declarativeKey));
- key = new SequenceRowKey((Object[]) walker.getConvertedSimpleKeys());
+ if (result.length() != 0) {
+ result.append(SEPARATOR_CHAR);
+ }
+
+ result.append(modelId);
+
+ result.append(SEPARATOR_CHAR);
+ result.append(modelKeyAsString);
}
- return key;
+ return result.toString();
}
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java 2010-12-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -21,7 +21,6 @@
*/
package org.richfaces.convert;
-import javax.faces.convert.IntegerConverter;
/**
* @author Nick Belaevski
@@ -32,7 +31,7 @@
public static final String CONVERTER_ID =
"org.richfaces.IntegerSequenceRowKeyConverter";
public IntegerSequenceRowKeyConverter() {
- super(Integer.class, new IntegerConverter());
+ super(Integer.class, ConverterUtil.integerConverter());
}
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java 2010-12-27
13:36:30 UTC (rev 20808)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java 2010-12-27
13:37:38 UTC (rev 20809)
@@ -1,12 +1,14 @@
package org.richfaces.convert;
+import static org.richfaces.model.TreeDataModel.SEPARATOR_CHAR;
+
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
-import static org.richfaces.model.TreeDataModel.*;
+
import org.richfaces.model.SequenceRowKey;
import com.google.common.base.Splitter;
@@ -21,7 +23,7 @@
public class SequenceRowKeyConverter<T> implements Converter {
- private static final Splitter DOT_SPLITTER = Splitter.on(SEPARATOR_CHAR);
+ static final Splitter SEPARATOR_SPLITTER = Splitter.on(SEPARATOR_CHAR);
private Class<T> clazz;
@@ -38,7 +40,7 @@
return null;
}
- Iterable<String> split = DOT_SPLITTER.split(value);
+ Iterable<String> split = SEPARATOR_SPLITTER.split(value);
List<T> keysList = Lists.<T>newArrayList();
for (String s: split) {