Friday, 18 January
2008
Fri, 18 Jan
'08
1:20 p.m.
Author: konstantin.mishin
Date: 2008-01-18 14:20:34 -0500 (Fri, 18 Jan 2008)
New Revision: 5474
Added:
trunk/framework/api/src/main/java/org/richfaces/component/Filterable.java
trunk/framework/api/src/main/java/org/richfaces/model/Field.java
trunk/framework/api/src/main/java/org/richfaces/model/FilterField.java
trunk/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java
Removed:
trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java
trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java
trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java
trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java
Modified:
trunk/framework/api/src/main/java/org/richfaces/component/Column.java
trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java
trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java
trunk/framework/api/src/main/java/org/richfaces/model/SequenceDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
Log:
RF-1741
Modified: trunk/framework/api/src/main/java/org/richfaces/component/Column.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/component/Column.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/api/src/main/java/org/richfaces/component/Column.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -21,6 +21,8 @@
package org.richfaces.component;
+import org.richfaces.model.Ordering;
+
/**
* Marker interface for all components used as column in UIDataTable
* @author shura
@@ -59,4 +61,11 @@
public abstract void setSortExpression(String sortExpression);
public abstract String getSortExpression();
+ /**
+ * SortOrder is an enumeration of the possible sort orderings.
+ *
+ * @param sortOrder
+ */
+ public abstract void setSortOrder(Ordering sortOrder);
+ public abstract Ordering getSortOrder();
}
Added: trunk/framework/api/src/main/java/org/richfaces/component/Filterable.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/component/Filterable.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/component/Filterable.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.util.List;
+
+import org.richfaces.model.FilterField;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public interface Filterable {
+
+ public List<FilterField> getFilterFields();
+
+ public void setFilterFields(List<FilterField> filterFields);
+
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -3,16 +3,18 @@
*/
package org.richfaces.component;
-import org.richfaces.model.SortOrder2;
+import java.util.List;
+import org.richfaces.model.SortField2;
+
/**
* @author Maksim Kaszynski
*
*/
public interface Sortable2 {
- public SortOrder2 getSortOrder();
+ public List<SortField2> getSortFields();
- public void setSortOrder(SortOrder2 sortOrder);
+ public void setSortFields(List<SortField2> sortFields);
}
Added: trunk/framework/api/src/main/java/org/richfaces/model/Field.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/Field.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/Field.java 2008-01-18 19:20:34
UTC (rev 5474)
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.Serializable;
+
+import javax.el.ValueExpression;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public abstract class Field implements Serializable{
+
+ private static final long serialVersionUID = 7576046308828980778L;
+
+ private ValueExpression expression;
+
+ public Field(ValueExpression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Field other = (Field) obj;
+ if (expression == null) {
+ if (other.expression != null)
+ return false;
+ } else if
(!expression.getExpressionString().equals(other.expression.getExpressionString()))
+ return false;
+ return true;
+ }
+
+ public ValueExpression getExpression() {
+ return expression;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((expression == null) ? 0 : expression.hashCode());
+ return result;
+ }
+
+ public void setExpression(ValueExpression expression) {
+ this.expression = expression;
+ }
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/FilterField.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/FilterField.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/FilterField.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class FilterField extends Field{
+
+ private static final long serialVersionUID = -5453359866996963829L;
+
+ public FilterField(ValueExpression expression) {
+ super(expression);
+ }
+
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -6,5 +6,6 @@
*/
public enum Ordering {
ASCENDING {},
- DESCENDING {}
+ DESCENDING {},
+ UNSORTED {}
}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/SequenceDataModel.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/SequenceDataModel.java 2008-01-18
18:42:23 UTC (rev 5473)
+++
trunk/framework/api/src/main/java/org/richfaces/model/SequenceDataModel.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -76,7 +76,7 @@
* @see javax.faces.model.DataModel#getRowData()
*/
public Object getRowData() {
- return list != null ? list.get(key.intValue()) : null;
+ return (list != null && key != null) ? list.get(key.intValue()) : null;
}
/* (non-Javadoc)
@@ -97,7 +97,7 @@
* @see javax.faces.model.DataModel#isRowAvailable()
*/
public boolean isRowAvailable() {
- return list != null && list.size() > key.intValue();
+ return list != null && key != null && list.size() > key.intValue();
}
/* (non-Javadoc)
Modified: trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -3,48 +3,45 @@
*/
package org.richfaces.model;
-import java.io.Serializable;
-
import javax.el.ValueExpression;
/**
* @author Maksim Kaszynski
*
*/
-public class SortField2 implements Serializable{
+public class SortField2 extends Field{
- private static final long serialVersionUID = 2122437301428777493L;
+ private static final long serialVersionUID = 4578290842517554179L;
private Ordering ordering;
- private ValueExpression expression;
-
public SortField2(ValueExpression expression) {
- super();
- this.expression = expression;
+ super(expression);
}
public SortField2(ValueExpression expression, Ordering ordering) {
- super();
- this.expression = expression;
+ super(expression);
this.ordering = ordering;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((ordering == null) ? 0 : ordering.hashCode());
+ return result;
+ }
-
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
- if (obj == null)
+ if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
SortField2 other = (SortField2) obj;
- if (expression == null) {
- if (other.expression != null)
- return false;
- } else if
(!expression.getExpressionString().equals(other.expression.getExpressionString()))
- return false;
if (ordering == null) {
if (other.ordering != null)
return false;
@@ -52,27 +49,11 @@
return false;
return true;
}
- public ValueExpression getExpression() {
- return expression;
- }
+
public Ordering getOrdering() {
return ordering;
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result
- + ((expression == null) ? 0 : expression.hashCode());
- result = prime * result
- + ((ordering == null) ? 0 : ordering.hashCode());
- return result;
- }
- public void setExpression(ValueExpression expression) {
- this.expression = expression;
- }
-
public void setOrdering(Ordering ordering) {
this.ordering = ordering;
}
Deleted: trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -1,62 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import java.io.Serializable;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class SortOrder2 implements Serializable{
-
- private static final long serialVersionUID = -8464361988367479001L;
-
- private List<SortField2> fields = new LinkedList<SortField2>();
-
- public List<SortField2> getFields() {
- return fields;
- }
-
- public void setFields(List<SortField2> fields) {
- this.fields = fields;
- }
-
- public void addField(SortField2 field2) {
- fields.add(field2);
- }
-
- public boolean isEmpty() {
- return fields == null || fields.isEmpty();
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((fields == null) ? 0 : fields.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- SortOrder2 other = (SortOrder2) obj;
- if (fields == null) {
- if (other.fields != null)
- return false;
- } else if (!fields.equals(other.fields))
- return false;
- return true;
- }
-
-
-}
Added: trunk/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -0,0 +1,186 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+import org.ajax4jsf.model.SerializableDataModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+import org.richfaces.model.impl.expressive.ObjectWrapperFactory;
+import org.richfaces.model.impl.expressive.WrappedBeanComparator2;
+import org.richfaces.model.impl.expressive.WrappedBeanFilter;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ModifiableModel extends ExtendedDataModel{
+
+ private static final Log log = LogFactory.getLog(ModifiableModel.class);
+
+ private ExtendedDataModel delegate;
+
+ private ExtendedDataModel originalModel;
+
+ private ExtendedDataModel modifiedModel;
+
+ private String var;
+
+ private List<FilterField> filterFields;
+ private List<SortField2> sortFields;
+
+ public ModifiableModel(ExtendedDataModel originalModel, String var,
+ List<FilterField> filterFields, List<SortField2> sortFields) {
+ this.originalModel = originalModel;
+ delegate = originalModel;
+ this.var = var;
+ this.filterFields = filterFields;
+ this.sortFields = sortFields;
+ }
+
+ public void addDataModelListener(DataModelListener listener) {
+ originalModel.addDataModelListener(listener);
+ }
+
+ public DataModelListener[] getDataModelListeners() {
+ return originalModel.getDataModelListeners();
+ }
+
+ public int getRowCount() {
+ return delegate.getRowCount();
+ }
+
+ public Object getRowData() {
+ return delegate.getRowData();
+ }
+
+ public int getRowIndex() {
+ return delegate.getRowIndex();
+ }
+
+ public Object getRowKey() {
+ return delegate.getRowKey();
+ }
+
+ public SerializableDataModel getSerializableModel(Range range) {
+ return delegate.getSerializableModel(range);
+ }
+
+ public Object getWrappedData() {
+ return delegate.getWrappedData();
+ }
+
+ public boolean isRowAvailable() {
+ return delegate.isRowAvailable();
+ }
+
+ public void removeDataModelListener(DataModelListener listener) {
+ delegate.removeDataModelListener(listener);
+ }
+
+ public void setRowIndex(int rowIndex) {
+ delegate.setRowIndex(rowIndex);
+ }
+
+ public void setRowKey(Object key) {
+ delegate.setRowKey(key);
+ }
+
+ public void setWrappedData(Object data) {
+ delegate.setWrappedData(data);
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+
+ if (shouldSort() || shouldFilter()) {
+ if (modifiedModel == null) {
+ modifiedModel = new SequenceDataModel();
+ modifiedModel.setWrappedData(prepareCollection());
+ }
+ delegate = modifiedModel;
+ } else {
+ delegate = originalModel;
+ }
+
+ delegate.walk(context, visitor, range, argument);
+ }
+
+ private boolean shouldSort() {
+ return sortFields != null && !sortFields.isEmpty();
+ }
+
+ private boolean shouldFilter() {
+ return filterFields != null && !filterFields.isEmpty();
+ }
+
+ private List<?> prepareCollection() {
+ int rowCount = originalModel.getRowCount();
+ final List<Object> collection;
+
+ if (rowCount > 0) {
+ collection = new ArrayList<Object>(rowCount);
+ } else {
+ collection = new ArrayList<Object>();
+ }
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ try {
+
+ originalModel.walk(context, new DataVisitor() {
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ originalModel.setRowKey(rowKey);
+ if (originalModel.isRowAvailable()) {
+ collection.add(originalModel.getRowData());
+ }
+ }
+ }, new SequenceRange(0, -1),
+ null);
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ List<Object> modifedcollection = collection;
+
+ if (shouldFilter()) {
+ List <Object> filteredCollection = new ArrayList<Object>();
+ ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(
+ context, var, filterFields);
+ WrappedBeanFilter wrappedBeanFilter = new WrappedBeanFilter(filterFields);
+ wrapperFactory.wrapList(modifedcollection);
+ for (Object object : modifedcollection) {
+ if(wrappedBeanFilter.accept((JavaBeanWrapper)object)) {
+ filteredCollection.add(object);
+ }
+ }
+ modifedcollection = filteredCollection;
+ wrapperFactory.unwrapList(modifedcollection);
+ }
+
+ if (shouldSort()) {
+ ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(
+ context, var, sortFields);
+ WrappedBeanComparator2 wrappedBeanComparator = new WrappedBeanComparator2(
+ sortFields);
+ wrapperFactory.wrapList(modifedcollection);
+ Collections.sort(modifedcollection, wrappedBeanComparator);
+ wrapperFactory.unwrapList(modifedcollection);
+ }
+ return modifedcollection;
+
+ }
+}
Deleted: trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -1,111 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-import javax.faces.model.DataModelListener;
-
-import org.ajax4jsf.model.DataVisitor;
-import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.Range;
-import org.ajax4jsf.model.SerializableDataModel;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class SortableModel extends ExtendedDataModel{
-
- private ExtendedDataModel delegate;
-
- private ExtendedDataModel originalModel;
-
- private ExtendedDataModel modifiedModel;
-
- public SortableModel(ExtendedDataModel originalModel) {
- this.originalModel = originalModel;
- delegate = originalModel;
- }
-
- public void addDataModelListener(DataModelListener listener) {
- originalModel.addDataModelListener(listener);
- }
-
- public DataModelListener[] getDataModelListeners() {
- return originalModel.getDataModelListeners();
- }
-
- public int getRowCount() {
- return delegate.getRowCount();
- }
-
- public Object getRowData() {
- return delegate.getRowData();
- }
-
- public int getRowIndex() {
- return delegate.getRowIndex();
- }
-
- public Object getRowKey() {
- return delegate.getRowKey();
- }
-
- public SerializableDataModel getSerializableModel(Range range) {
- return delegate.getSerializableModel(range);
- }
-
- public Object getWrappedData() {
- return delegate.getWrappedData();
- }
-
- public boolean isRowAvailable() {
- return delegate.isRowAvailable();
- }
-
- public void removeDataModelListener(DataModelListener listener) {
- delegate.removeDataModelListener(listener);
- }
-
- public void setRowIndex(int rowIndex) {
- delegate.setRowIndex(rowIndex);
- }
-
- public void setRowKey(Object key) {
- delegate.setRowKey(key);
- }
-
- public void setWrappedData(Object data) {
- delegate.setWrappedData(data);
- }
-
- public void walk(FacesContext context, DataVisitor visitor, Range range,
- Object argument) throws IOException {
-
- if (shouldSort(range)) {
- if (modifiedModel == null) {
- modifiedModel = new SortedModel(originalModel,(SortableRange) range);
- }
- delegate = modifiedModel;
- } else {
- delegate = originalModel;
- }
-
- delegate.walk(context, visitor, range, argument);
- }
-
- private boolean shouldSort(Range range) {
- boolean result = false;
- if (range instanceof SortableRange) {
- SortableRange sortableRange = (SortableRange) range;
- SortOrder2 sortOrder = sortableRange.getSortOrder();
- if (sortOrder != null) {
- result = !sortOrder.isEmpty();
- }
- }
- return result;
- }
-}
Deleted: trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -1,31 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import org.ajax4jsf.model.SequenceRange;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class SortableRange extends SequenceRange {
-
- private SortOrder2 sortOrder;
- private String var;
-
- public SortableRange(int firstRow, int rows, String var, SortOrder2 sortOrder) {
- super(firstRow, rows);
- this.sortOrder = sortOrder;
- this.var = var;
- }
-
- public SortOrder2 getSortOrder() {
- return sortOrder;
- }
-
- public String getVar() {
- return var;
- }
-
-}
Deleted: trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java 2008-01-18
18:42:23 UTC (rev 5473)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -1,73 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.model.DataVisitor;
-import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.SequenceRange;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.richfaces.model.impl.expressive.ObjectWrapperFactory;
-import org.richfaces.model.impl.expressive.WrappedBeanComparator2;
-
-
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class SortedModel extends SequenceDataModel{
-
- private static final Log log = LogFactory.getLog(SortedModel.class);
-
- public SortedModel(ExtendedDataModel source, SortableRange range) {
- setWrappedData(prepareCollection(source, range));
- }
-
- private List<?> prepareCollection(final ExtendedDataModel source, final
SortableRange range) {
- int rowCount = source.getRowCount();
- final List<Object> collection;
-
- if (rowCount > 0) {
- collection = new ArrayList<Object>(rowCount);
- } else {
- collection = new ArrayList<Object>();
- }
-
- FacesContext context = FacesContext.getCurrentInstance();
- try {
-
- source.walk(context, new DataVisitor() {
- public void process(FacesContext context, Object rowKey,
- Object argument) throws IOException {
- source.setRowKey(rowKey);
- if (source.isRowAvailable()) {
- collection.add(source.getRowData());
- }
- }
- }, new SequenceRange(0, -1),
- null);
- } catch (IOException e) {
- log.error(e.getMessage(), e);
- }
-
- SortOrder2 sortOrder = range.getSortOrder();
- ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(context, range.getVar(),
sortOrder);
- WrappedBeanComparator2 wrappedBeanComparator = new WrappedBeanComparator2(sortOrder);
-
- wrapperFactory.wrapList(collection);
- Collections.sort(collection, wrappedBeanComparator);
- wrapperFactory.unwrapList(collection);
-
- return collection;
-
- }
-}
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java 2008-01-18
18:42:23 UTC (rev 5473)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -27,7 +27,7 @@
* @author Maksim Kaszynski
*
*/
-class JavaBeanWrapper {
+public class JavaBeanWrapper {
private Object wrappedObject;
private Map<String, Object> properties;
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2008-01-18
18:42:23 UTC (rev 5473)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -34,10 +34,9 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.util.ELUtils;
+import org.richfaces.model.Field;
import org.richfaces.model.SortField;
-import org.richfaces.model.SortField2;
import org.richfaces.model.SortOrder;
-import org.richfaces.model.SortOrder2;
/**
*
* class responsible for packaging objects with their properties evaluated using EL.
@@ -90,7 +89,7 @@
}
- public ObjectWrapperFactory(FacesContext context, final String var, SortOrder2
sortOrder) {
+ public ObjectWrapperFactory(FacesContext context, final String var, List<? extends
Field> sortOrder) {
this.context = context;
@@ -99,12 +98,10 @@
ELContext elContext = context.getELContext();
this.var = var;
- List<SortField2> fields = sortOrder.getFields();
+ expressions = new Expression[sortOrder.size()];
- expressions = new Expression[fields.size()];
-
int i = 0;
- for (SortField2 field : fields) {
+ for (Field field : sortOrder) {
ValueExpression valueExpression = field.getExpression();
Expression expression;
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java 2008-01-18
18:42:23 UTC (rev 5473)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -6,10 +6,9 @@
import javax.el.ValueExpression;
+import org.richfaces.model.Field;
import org.richfaces.model.Ordering;
-import org.richfaces.model.SortField;
import org.richfaces.model.SortField2;
-import org.richfaces.model.SortOrder2;
/**
* Comparator for {@link JavaBeanWrapper} objects.
@@ -20,11 +19,11 @@
*/
public final class WrappedBeanComparator2 implements Comparator<Object> {
- private final SortOrder2 sortOrder;
+ private final List<SortField2> sortFields;
- public WrappedBeanComparator2(SortOrder2 sortOrder) {
+ public WrappedBeanComparator2(List<SortField2> sortFields) {
super();
- this.sortOrder = sortOrder;
+ this.sortFields = sortFields;
}
public int compare(Object o1, Object o2) {
@@ -36,13 +35,11 @@
int result = 0;
- List<SortField2> fields = sortOrder.getFields();
-
- for (Iterator<SortField2> iterator = fields.iterator(); iterator.hasNext()
&& result == 0;) {
- SortField2 sortField2 = iterator.next();
- ValueExpression expression = sortField2.getExpression();
+ for (Iterator<SortField2> iterator = sortFields.iterator(); iterator.hasNext()
&& result == 0;) {
+ SortField2 field = iterator.next();
+ ValueExpression expression = field.getExpression();
String prop = expression.getExpressionString();
- Ordering ordering = sortField2.getOrdering();
+ Ordering ordering = field.getOrdering();
if (ordering != null) {
Object p1 = w1.getProperty(prop);
Object p2 = w2.getProperty(prop);
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java 2008-01-18
18:42:23 UTC (rev 5473)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java 2008-01-18
19:20:34 UTC (rev 5474)
@@ -3,14 +3,30 @@
*/
package org.richfaces.model.impl.expressive;
+import java.util.List;
+
+import org.richfaces.model.FilterField;
+
/**
* @author Maksim Kaszynski
*
*/
public class WrappedBeanFilter implements
org.richfaces.model.filter.Filter<JavaBeanWrapper>{
- public boolean accept(JavaBeanWrapper t) {
- // TODO Auto-generated method stub
- return false;
+ private final List<FilterField> filterFields;
+
+ public WrappedBeanFilter(List<FilterField> filterFields) {
+ this.filterFields = filterFields;
}
+
+ public boolean accept(JavaBeanWrapper wrapper) {
+ for (FilterField filterField : filterFields) {
+ Object property =
wrapper.getProperty(filterField.getExpression().getExpressionString());
+ if(!((Boolean)property).booleanValue()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
}