Author: maksimkaszynski
Date: 2008-01-09 05:34:40 -0500 (Wed, 09 Jan 2008)
New Revision: 5210
Added:
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
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/Expression.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/NullExpression.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/SimplePropertyExpression.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/TestObj.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
trunk/ui/dataTable/src/main/config/resources/
trunk/ui/dataTable/src/main/config/resources/resources-config.xml
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconBasic.java
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortAsc.java
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortDesc.java
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/data-table.js
Removed:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ValueBindingExpression.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasic.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortAsc.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortDesc.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java
trunk/sandbox/samples/sortingFilteringDemo/pom.xml
trunk/sandbox/samples/sortingFilteringDemo/src/main/webapp/pages/index.jsp
trunk/sandbox/ui/sortableHeader/pom.xml
trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/css/table.xcss
trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx
trunk/ui/scrollableDataTable/pom.xml
trunk/ui/scrollableDataTable/src/main/config/resources/resources-config.xml
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSplit.java
trunk/ui/scrollableDataTable/src/main/resources/org/richfaces/renderkit/html/css/scrollable-data-table.xcss
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java
Log:
http://jira.jboss.com/jira/browse/RF-1736
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -5,7 +5,6 @@
import java.sql.ResultSet;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import javax.faces.context.FacesContext;
@@ -36,26 +35,6 @@
public Range getRange() {
return new SequenceRange(getFirst(),getRows());
}
-
- public boolean isTransient() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void restoreState(FacesContext arg0, Object arg1) {
- // TODO Auto-generated method stub
-
- }
-
- public Object saveState(FacesContext arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void setTransient(boolean arg0) {
- // TODO Auto-generated method stub
-
- }
};
}
Added: trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,112 @@
+/**
+ *
+ */
+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;
+ SortOrder sortOrder = sortableRange.getSortOrder();
+ if (sortOrder != null) {
+ SortField[] fields = sortOrder.getFields();
+ result = fields != null && fields.length > 0;
+ }
+ }
+ return result;
+ }
+}
Added: trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,31 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import org.ajax4jsf.model.SequenceRange;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortableRange extends SequenceRange {
+
+ private SortOrder sortOrder;
+ private String var;
+
+ public SortableRange(int firstRow, int rows, String var, SortOrder sortOrder) {
+ super(firstRow, rows);
+ this.sortOrder = sortOrder;
+ this.var = var;
+ }
+
+ public SortOrder getSortOrder() {
+ return sortOrder;
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+}
Added: trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,73 @@
+/**
+ *
+ */
+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.WrappedBeanComparator;
+
+
+
+/**
+ * @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);
+ }
+
+ SortOrder sortOrder = range.getSortOrder();
+ ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(context, range.getVar(),
sortOrder);
+ WrappedBeanComparator wrappedBeanComparator = new
WrappedBeanComparator(sortOrder.getFields());
+
+ wrapperFactory.wrapList(collection);
+ Collections.sort(collection, wrappedBeanComparator);
+ wrapperFactory.unwrapList(collection);
+
+ return collection;
+
+ }
+}
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/Expression.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/Expression.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/Expression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,50 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+/**
+ * Base interface for expressions (Literal, EL, or empty)
+ * @author Maksim Kaszynski
+ *
+ */
+abstract class Expression {
+ /**
+ * this is expression string
+ */
+ private String expressionString;
+
+ public Expression(String n) {
+ expressionString = n;
+ }
+
+ /**
+ *
+ * @param base
+ * @return result of expression evaluation
+ */
+ public abstract Object evaluate(Object base);
+
+ public String getExpressionString() {
+ return expressionString;
+ }
+
+}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,46 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.Map;
+/**
+ * Object used in sorting - contains of base object, and its properties evaluated with
EL
+ * @author Maksim Kaszynski
+ *
+ */
+class JavaBeanWrapper {
+ private Object wrappedObject;
+ private Map<String, Object> properties;
+
+ public JavaBeanWrapper(Object o, Map<String, Object> props) {
+ wrappedObject = o;
+ properties = props;
+ }
+
+ public Object getProperty(String expression) {
+ return properties.get(expression);
+ }
+
+ public Object getWrappedObject() {
+ return wrappedObject;
+ }
+}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/NullExpression.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/NullExpression.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/NullExpression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,18 @@
+package org.richfaces.model.impl.expressive;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+final class NullExpression extends Expression {
+ /**
+ * @param n
+ */
+ NullExpression(String n) {
+ super(n);
+ }
+
+ public Object evaluate(Object base) {
+ return null;
+ }
+}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,146 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.faces.application.Application;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.util.ELUtils;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+/**
+ *
+ * class responsible for packaging objects with their properties evaluated using EL.
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public class ObjectWrapperFactory {
+
+ interface ObjectConvertor{
+ public Object convert(Object o);
+ }
+
+ private Expression [] expressions;
+ private FacesContext context;
+ private String var;
+ private ValueExpression varValue;
+
+ public ObjectWrapperFactory(FacesContext context, final String var, SortOrder sortOrder)
{
+
+ this.context = context;
+
+ Application application = context.getApplication();
+ ELResolver resolver = application.getELResolver();
+ ELContext elContext = context.getELContext();
+ this.var = var;
+
+ SortField[] sortFields = sortOrder.getFields();
+
+ expressions = new Expression[sortFields.length];
+
+ for (int i = 0; i < sortFields.length; i++) {
+ final SortField field = sortFields[i];
+ final String name = field.getName();
+
+ if (ELUtils.isValueReference(name)) {
+
+ expressions[i] = new ValueBindingExpression(context, name, var);
+
+ } else if (name.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
+
+ expressions[i] = new NullExpression(name);
+
+ } else {
+
+ expressions[i] = new SimplePropertyExpression(name, elContext, resolver);
+ }
+ }
+
+
+
+ }
+
+ void convertList (List<? super Object> list, ObjectConvertor c) {
+ int l = list.size();
+
+ for (int i = 0; i < l; i++) {
+ Object o = list.get(i);
+ list.set(i, c.convert(o));
+ }
+ }
+
+ public List<? super Object> unwrapList(List<Object> list) {
+
+ convertList(list, new ObjectConvertor() {
+ public Object convert(Object o) {
+ return unwrapObject(o);
+ }
+ });
+
+ ELContext elContext = context.getELContext();
+ VariableMapper mapper = elContext.getVariableMapper();
+ mapper.setVariable(var, varValue);
+
+ return list;
+ }
+
+ public Object unwrapObject(Object wrapper) {
+ return ((JavaBeanWrapper) wrapper).getWrappedObject();
+ }
+
+ public List<Object> wrapList(List<Object> list) {
+ ELContext elContext = context.getELContext();
+ VariableMapper mapper = elContext.getVariableMapper();
+ varValue = mapper.resolveVariable(var);
+
+ convertList(list, new ObjectConvertor() {
+ public Object convert(Object o) {
+ return wrapObject(o);
+ }
+ });
+
+ return list;
+ }
+
+ public JavaBeanWrapper wrapObject(Object o) {
+ Map<String, Object> props = new HashMap<String, Object>();
+ for (int i = 0; i < expressions.length; i++) {
+ Expression expression = expressions[i];
+
+ props.put(expression.getExpressionString(), expression.evaluate(o));
+ }
+
+ return new JavaBeanWrapper(o, props);
+
+ }
+
+}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/SimplePropertyExpression.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/SimplePropertyExpression.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/SimplePropertyExpression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,40 @@
+package org.richfaces.model.impl.expressive;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+
+/**
+ * Expression evaluated by applying application
+ * property resolver to the base object
+ * @author Maksim Kaszynski
+ *
+ */
+final class SimplePropertyExpression extends Expression {
+ /**
+ *
+ */
+ private final ELResolver resolver;
+ private final ELContext context;
+
+ /**
+ * @param n
+ * @param resolver
+ */
+ SimplePropertyExpression(String n, ELContext context, ELResolver resolver) {
+ super(n);
+ this.resolver = resolver;
+ this.context = context;
+ }
+
+ public Object evaluate(Object base) {
+ Object o = null;
+ try {
+ return resolver.getValue(context, base, getExpressionString());
+ } catch (ELException e) {
+
+ }
+
+ return o;
+ }
+}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ValueBindingExpression.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,45 @@
+package org.richfaces.model.impl.expressive;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.faces.context.FacesContext;
+
+/**
+ *
+ * Expression evaluated by invoking EL-expression in context of base object
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+final class ValueBindingExpression extends Expression {
+
+ private ELContext context;
+ private String var;
+ private ValueExpression valueExpression;
+ private VariableMapper mapper;
+ private ExpressionFactory factory;
+ /**
+ * @param n
+ * @param application
+ * @param requestMap
+ * @param expressionString
+ * @param context
+ * @param var
+ */
+ ValueBindingExpression(FacesContext faces, String expressionString, String var) {
+ super(expressionString);
+ this.context = faces.getELContext();
+ this.var = var;
+ ExpressionFactory expressionFactory = faces.getApplication().getExpressionFactory();
+ valueExpression = expressionFactory.createValueExpression(context, expressionString,
Object.class);
+ mapper = context.getVariableMapper();
+ factory = expressionFactory;
+ }
+
+ public Object evaluate(Object base) {
+ mapper.setVariable(var, factory.createValueExpression(base, Object.class));
+ return valueExpression.getValue(context);
+ }
+}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,61 @@
+package org.richfaces.model.impl.expressive;
+
+import java.util.Comparator;
+
+import org.richfaces.model.SortField;
+
+/**
+ * Comparator for {@link JavaBeanWrapper} objects.
+ * Compares them using {@link SortField} sequence.
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public final class WrappedBeanComparator implements Comparator<Object> {
+ /**
+ *
+ */
+ private final SortField[] fields;
+
+ /**
+ * @param fields
+ */
+ public WrappedBeanComparator(SortField[] fields) {
+ this.fields = fields;
+ }
+
+ public int compare(Object o1, Object o2) {
+ return compare((JavaBeanWrapper) o1, (JavaBeanWrapper) o2);
+ }
+
+ @SuppressWarnings("unchecked")
+ private int compare(JavaBeanWrapper w1, JavaBeanWrapper w2) {
+
+ int result = 0;
+
+ for (int i = 0; i < fields.length && result == 0; i++) {
+
+ String prop = fields[i].getName();
+ Boolean asc = fields[i].getAscending();
+
+ Object p1 = w1.getProperty(prop);
+ Object p2 = w2.getProperty(prop);
+
+ if (p1 != null) {
+ if (p1 instanceof Comparable && p2 != null) {
+ result = ((Comparable<Object>) p1).compareTo(p2);
+ } else {
+ result = 1;
+ }
+ }
+
+ if (asc != null && !asc.booleanValue()) {
+ result = -result;
+ }
+
+ }
+
+
+ return result;
+ }
+}
\ No newline at end of file
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java)
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,78 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaBeanWrapperTest extends TestCase {
+
+
+ private JavaBeanWrapper wrapper;
+ final Boolean test = Boolean.TRUE;
+ final Map props = Collections.singletonMap("true", test);
+ /**
+ * @param name
+ */
+ public JavaBeanWrapperTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ wrapper = new JavaBeanWrapper(test, props);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ wrapper = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.JavaBeanWrapper#getProperty(java.lang.String)}.
+ */
+ public void testGetProperty() {
+ assertEquals(test, wrapper.getProperty("true"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.JavaBeanWrapper#getWrappedObject()}.
+ */
+ public void testGetWrappedObject() {
+ assertEquals(test, wrapper.getWrappedObject());
+ }
+
+}
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java)
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,66 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import org.richfaces.model.impl.expressive.Expression;
+import org.richfaces.model.impl.expressive.NullExpression;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class NullExpressionTest extends TestCase {
+
+
+ private Expression expression;
+
+ /**
+ * @param name
+ */
+ public NullExpressionTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ expression = new NullExpression("_id2");
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ expression = null;
+ }
+
+ public void testEvaluate() {
+ Object o = new Object();
+ assertNull(expression.evaluate(o));
+ }
+
+}
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java)
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,200 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+import org.richfaces.model.impl.expressive.ObjectWrapperFactory;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ObjectWrapperFactoryTest extends AbstractAjax4JsfTestCase {
+
+
+ /**
+ *
+ */
+ SortField [] sortFields;
+ SortOrder sortOrder;
+ private ObjectWrapperFactory factory;
+ private String var = "abc";
+
+ public ObjectWrapperFactoryTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ sortFields = new SortField[3];
+ sortFields[0] = new SortField("_id1", 0, Boolean.TRUE);
+ sortFields[1] = new SortField("name", 1, Boolean.FALSE);
+ sortFields[2] = new SortField("#{" +var + ".name}", 2,
Boolean.TRUE);
+ sortOrder = new SortOrder(sortFields);
+
+ factory = new ObjectWrapperFactory(facesContext, var, sortOrder);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ sortFields = null;
+ sortOrder = null;
+ factory = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#convertList(java.util.List,
org.richfaces.model.impl.expressive.ObjectWrapperFactory.ObjectConvertor)}.
+ */
+ public final void testConvertList() {
+
+
+ List objects = new ArrayList();
+ objects.add(Boolean.TRUE);
+ int size = objects.size();
+ factory.convertList(objects, new ObjectWrapperFactory.ObjectConvertor() {
+ public Object convert(Object o ) {
+
+ return new Boolean(!((Boolean) o).booleanValue());
+ }
+ });
+
+ assertEquals(size, objects.size());
+ assertEquals(Boolean.FALSE, objects.get(0));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#unwrapList(java.util.List)}.
+ */
+ public final void testUnwrapList() {
+ List objects = new ArrayList(10);
+ int [] ints = new int[10];
+ Random random = new Random();
+ for(int i = 0; i < 10; i++) {
+ ints[i] = random.nextInt();
+ objects.add(new TestObj(String.valueOf(ints[i])));
+ }
+
+ List l1 = factory.wrapList(objects);
+ List l2 = factory.unwrapList(l1);
+
+ assertSame(objects, l1);
+ assertSame(objects, l2);
+ assertEquals(10, l2.size());
+
+ for(int i = 0; i < 10; i++) {
+ TestObj t = (TestObj) l2.get(i);
+ assertEquals(String.valueOf(ints[i]), t.getName());
+ }
+
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#unwrapObject(java.lang.Object)}.
+ */
+ public final void testUnwrapObject() {
+
+ TestObj t = new TestObj("20");
+
+ JavaBeanWrapper wrapper = new JavaBeanWrapper(t, new HashMap());
+
+ Object wrapped = factory.unwrapObject(wrapper);
+
+ assertSame(t, wrapped);
+
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#wrapList(java.util.List)}.
+ */
+ public final void testWrapList() {
+ List objects = new ArrayList(10);
+ int [] ints = new int[10];
+ Random random = new Random();
+ for(int i = 0; i < 10; i++) {
+ ints[i] = random.nextInt();
+ objects.add(new TestObj(String.valueOf(ints[i])));
+ }
+
+ List l1 = factory.wrapList(objects);
+
+ assertSame(objects, l1);
+ assertEquals(10, l1.size());
+
+ for(int i = 0; i < 10; i++) {
+ JavaBeanWrapper wrapper = (JavaBeanWrapper) l1.get(i);
+ TestObj t = (TestObj) wrapper.getWrappedObject();
+
+ String string = String.valueOf(ints[i]);
+
+ assertEquals(string, t.getName());
+
+ Object prop1 = wrapper.getProperty("name");
+ //Object prop2 = wrapper.getProperty("#{abc.name}");
+
+ assertNotNull(prop1);
+ //assertNotNull(prop2);
+ assertEquals(string, prop1);
+ //assertEquals(string, prop2);
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#wrapObject(java.lang.Object)}.
+ */
+ public final void testWrapObject() {
+ TestObj t = new TestObj("20");
+
+
+
+ JavaBeanWrapper wrapper = factory.wrapObject(t);
+
+ Object wrapped = wrapper.getWrappedObject();
+
+ assertSame(t, wrapped);
+
+ Object prop1 = wrapper.getProperty("name");
+ //Object prop2 = wrapper.getProperty("#{abc.name}");
+
+ assertNotNull(prop1);
+ //assertNotNull(prop2);
+ assertEquals("20", prop1);
+ //assertEquals("20", prop2);
+
+
+ }
+
+}
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java)
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,76 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.model.impl.expressive.SimplePropertyExpression;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimplePropertyExpressionTest extends AbstractAjax4JsfTestCase {
+
+ final static String property = "name";
+ private SimplePropertyExpression expression;
+
+ /**
+ * @param name
+ */
+ public SimplePropertyExpressionTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ expression = new SimplePropertyExpression("name",
facesContext.getELContext(), application.getELResolver());
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ expression = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.SimplePropertyExpression#evaluate(java.lang.Object)}.
+ */
+ public final void testEvaluate() {
+ TestObj testObj = new TestObj("aaaa");
+ Object prop = expression.evaluate(testObj);
+ assertNotNull(prop);
+ assertEquals("aaaa", prop);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.Expression#getExpressionString()}.
+ */
+ public final void testGetExpressionString() {
+ assertEquals(property, expression.getExpressionString());
+ }
+
+}
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/TestObj.java (from
rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/TestObj.java)
===================================================================
--- trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/TestObj.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/TestObj.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,46 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+public class TestObj {
+ private String name;
+
+ /**
+ *
+ */
+ public TestObj() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public TestObj(String name) {
+ this.name = name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java)
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,74 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.model.impl.expressive.ValueBindingExpression;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ValueBindingExpressionTest extends AbstractAjax4JsfTestCase {
+
+ private ValueBindingExpression expression;
+ static final String var = "obj";
+ static final String el = "#{" + var + ".name}";
+
+ public ValueBindingExpressionTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ expression = new ValueBindingExpression(facesContext, el, var);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ expression = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ValueBindingExpression#evaluate(java.lang.Object)}.
+ */
+ public final void testEvaluate() {
+ TestObj testObj = new TestObj("aaaa");
+ Object prop = expression.evaluate(testObj);
+ //assertNotNull(prop);
+ //assertEquals("aaaa", prop);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.Expression#getExpressionString()}.
+ */
+ public final void testGetExpressionString() {
+ assertEquals(el, expression.getExpressionString());
+ }
+
+}
Copied:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
(from rev 5082,
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java)
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,102 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.richfaces.model.SortField;
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+import org.richfaces.model.impl.expressive.WrappedBeanComparator;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class WrappedBeanComparatorTest extends TestCase {
+
+ private SortField[] sortFields;
+ private WrappedBeanComparator comparator;
+
+ private static final int [][] testData = {{0,0}, {0,1}, {1, 0}, {1, 1} };
+
+ private JavaBeanWrapper [] testWrapers;
+
+ public WrappedBeanComparatorTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ sortFields = new SortField[2];
+ sortFields[0] = new SortField("a", 1, Boolean.FALSE);
+ sortFields[1] = new SortField("b", 2, Boolean.TRUE);
+
+
+ comparator = new WrappedBeanComparator(sortFields);
+
+ testWrapers = new JavaBeanWrapper[testData.length];
+ for(int i = 0; i < testData.length; i++) {
+ testWrapers[i] = w(testData[i]);
+ }
+
+ }
+
+ private JavaBeanWrapper w(int [] ints) {
+ Map m = new HashMap();
+ m.put("a", new Integer(ints[0]));
+ m.put("b", new Integer(ints[1]));
+
+ return new JavaBeanWrapper(m, m);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ sortFields = null;
+ comparator = null;
+ testWrapers = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.WrappedBeanComparator#compare(java.lang.Object,
java.lang.Object)}.
+ */
+ public final void testCompare() {
+
+ assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+ assertTrue(comparator.compare(w(new int[] {1, 1}), w(new int [] {0, 0})) < 0);
+ assertTrue(comparator.compare(w(new int[] {0, 0}), w(new int [] {0, 1})) < 0);
+ assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 0})) == 0);
+ //assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+ //assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+
+ }
+
+}
Modified: trunk/sandbox/samples/sortingFilteringDemo/pom.xml
===================================================================
--- trunk/sandbox/samples/sortingFilteringDemo/pom.xml 2008-01-09 10:23:38 UTC (rev 5209)
+++ trunk/sandbox/samples/sortingFilteringDemo/pom.xml 2008-01-09 10:34:40 UTC (rev 5210)
@@ -19,5 +19,15 @@
<artifactId>sortableHeader</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>core</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>dataTable</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/sandbox/samples/sortingFilteringDemo/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/sandbox/samples/sortingFilteringDemo/src/main/webapp/pages/index.jsp 2008-01-09
10:23:38 UTC (rev 5209)
+++ trunk/sandbox/samples/sortingFilteringDemo/src/main/webapp/pages/index.jsp 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,12 +1,22 @@
<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/dataTable"
prefix="dt" %>
+<%@ taglib
uri="http://richfaces.org/a4j" prefix="a4j" %>
<html>
<head>
<title></title>
</head>
<body>
<f:view>
-
+ <dt:dataTable value="" >
+ <dt:column sortable="true" sortExpression="">
+ <f:facet name="header">
+ <h:outputText value=""></h:outputText>
+ </f:facet>
+ </dt:column>
+ <dt:column sortable="">
+ </dt:column>
+ </dt:dataTable>
</f:view>
</body>
</html>
Modified: trunk/sandbox/ui/sortableHeader/pom.xml
===================================================================
--- trunk/sandbox/ui/sortableHeader/pom.xml 2008-01-09 10:23:38 UTC (rev 5209)
+++ trunk/sandbox/ui/sortableHeader/pom.xml 2008-01-09 10:34:40 UTC (rev 5210)
@@ -37,5 +37,10 @@
<artifactId>core</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>dataTable</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added: trunk/ui/dataTable/src/main/config/resources/resources-config.xml
===================================================================
--- trunk/ui/dataTable/src/main/config/resources/resources-config.xml
(rev 0)
+++ trunk/ui/dataTable/src/main/config/resources/resources-config.xml 2008-01-09 10:34:40
UTC (rev 5210)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resource-config>
+ <resource
class="org.richfaces.renderkit.html.iconimages.DataTableIconSortAsc">
+ <name>org.richfaces.renderkit.html.iconimages.DataTableIconSortAsc</name>
+ </resource>
+ <resource
class="org.richfaces.renderkit.html.iconimages.DataTableIconSortDesc">
+ <name>org.richfaces.renderkit.html.iconimages.DataTableIconSortDesc</name>
+ </resource>
+</resource-config>
Modified: trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java 2008-01-09
10:23:38 UTC (rev 5209)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -28,16 +28,21 @@
import org.ajax4jsf.component.AjaxSupport;
import org.ajax4jsf.component.SequenceDataAdaptor;
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain;
+import org.richfaces.model.SortableModel;
+import org.richfaces.model.SortableRange;
/**
* JSF component class
*
*/
-public abstract class UIDataTable extends SequenceDataAdaptor {
+public abstract class UIDataTable extends SequenceDataAdaptor implements Sortable {
/**
* @author shura
@@ -88,7 +93,8 @@
*
* @see org.ajax4jsf.ajax.repeat.UIDataAdaptor#dataChildren()
*/
- public Iterator dataChildren() {
+ @SuppressWarnings("unchecked")
+ public Iterator<UIComponent> dataChildren() {
IteratorChain dataChildren = new IteratorChain();
dataChildren.addIterator(new FilterIterator(getFacets().values()
.iterator(), isAjaxSupport));
@@ -119,13 +125,14 @@
*
* @see org.ajax4jsf.ajax.repeat.UIDataAdaptor#fixedChildren()
*/
- public Iterator fixedChildren() {
+ @SuppressWarnings("unchecked")
+ public Iterator<UIComponent> fixedChildren() {
// Iterate over facets, non-column childrens and column's facets.
IteratorChain fixedChildren = new IteratorChain(getFacets().values().iterator());
fixedChildren.addIterator(new FilterIterator(getChildren().iterator(),
isNotColumn));
// Append all columns facets.
- for (Iterator iter = columns(); iter.hasNext();) {
+ for (Iterator<UIComponent> iter = columns(); iter.hasNext();) {
UIComponent column = (UIComponent) iter.next();
if (column.isRendered()) {
fixedChildren.addIterator(column.getFacets().values()
@@ -140,12 +147,27 @@
return fixedChildren;
}
- public Iterator columns() {
+ @SuppressWarnings("unchecked")
+ public Iterator<UIComponent> columns() {
return new FilterIterator(getChildren().iterator(), isColumn);
}
-
+
public static final String COMPONENT_TYPE = "org.richfaces.DataTable";
public static final String COMPONENT_FAMILY = "org.richfaces.DataTable";
+ @Override
+ protected ExtendedDataModel createDataModel() {
+ ExtendedDataModel dataModel = super.createDataModel();
+ return new SortableModel(dataModel);
+ }
+
+ @Override
+ protected DataComponentState createComponentState() {
+ return new DataComponentState() {
+ public Range getRange() {
+ return new SortableRange(getFirst(), getRows(), getVar(), getSortOrder());
+ }
+ };
+ }
}
\ No newline at end of file
Modified:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -29,6 +29,9 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.component.UIDataAdaptor;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
@@ -36,6 +39,8 @@
import org.richfaces.component.Row;
import org.richfaces.component.UIDataTable;
+import com.sun.org.apache.xpath.internal.compiler.OpCodes;
+
/**
* @author shura
*
@@ -141,11 +146,28 @@
columnHeaderClass);
writer.writeAttribute("scope", "col", null);
getUtils().encodeAttribute(context, column, "colspan");
+
+ if (column instanceof Column) {
+ Column col = (Column) column;
+ String clientId = column.getClientId(context) + facetName;
+ writer.writeAttribute("id", clientId, null);
+ if (col.isSortable()) {
+ String sortExpression = col.getSortExpression();
+ JSFunction function = new JSFunction("new RichFaces.SortControl");
+ function.addParameter(clientId);
+ function.addParameter(((UIDataAdaptor)column.getParent()).getBaseClientId(context));
+ function.addParameter(new JSReference(sortExpression));
+ function.addParameter(column.getClientId(context));
+ getUtils().writeScript(context, column, function.toScript());
+ }
+ }
+
UIComponent facet = column.getFacet(facetName);
if (facet != null) {
renderChild(context, facet);
}
+
writer.endElement(element);
}
}
@@ -382,4 +404,21 @@
}
return count;
}
+
+ public void encodeScriptIfNecessary(FacesContext context, UIDataTable component) throws
IOException {
+ boolean shouldRender = false;
+ Iterator<UIComponent> columns = component.columns();
+ while(columns.hasNext() && !shouldRender) {
+ UIComponent next = columns.next();
+ shouldRender = (next instanceof Column) && ((Column)next).isSortable();
+ }
+ if (shouldRender) {
+ JSFunction function = new JSFunction("new RichFaces.DataTable");
+ function.addParameter(component.getBaseClientId(context));
+ ScriptOptions scriptOptions = new ScriptOptions(component);
+ scriptOptions.addOption("sortMode", new JSFunction("new
RichFaces.SortMode.Single"));
+ function.addParameter(scriptOptions);
+ getUtils().writeScript(context, component, function.toScript());
+ }
+ }
}
\ No newline at end of file
Added:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconBasic.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconBasic.java
(rev 0)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconBasic.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,82 @@
+package org.richfaces.renderkit.html.iconimages;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.util.Date;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.resource.GifRenderer;
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.ajax4jsf.resource.Java2Dresource;
+import org.ajax4jsf.resource.ResourceContext;
+import org.ajax4jsf.util.HtmlColor;
+import org.ajax4jsf.util.Zipper;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+
+public abstract class DataTableIconBasic extends Java2Dresource {
+
+ public DataTableIconBasic() {
+ setRenderer(new GifRenderer());
+ setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
+ }
+
+ public Dimension getDimensions(FacesContext facesContext, Object data) {
+ return calculateDimensions();
+ }
+ protected Dimension getDimensions(ResourceContext resourceContext) {
+ return calculateDimensions();
+ }
+
+ protected Object deserializeData(byte[] objectArray) {
+ if (objectArray == null) {
+ return null;
+ }
+
+ Object [] stored = new Object[2];
+ stored[0] = new Color(Zipper.unzip(objectArray, 0));
+ stored[1] = new Color(Zipper.unzip(objectArray, 3));
+
+ return stored;
+ }
+
+ public abstract Dimension calculateDimensions();
+
+
+ protected Object getDataToStore(FacesContext context, Object data) {
+ Skin skin = SkinFactory.getInstance().getSkin(context);
+ Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(context);
+
+ Color col = null;
+
+ String skinParameter = "headerTextColor";
+ String headerTextColor = (String) skin.getParameter(context, skinParameter);
+ if (null == headerTextColor || "".equals(headerTextColor))
+ headerTextColor = (String) defaultSkin.getParameter(context, skinParameter);
+
+ if (headerTextColor == null) {
+ return null;
+ }
+
+ col = HtmlColor.decode(headerTextColor);
+
+ byte[] ret = new byte[6];
+ Zipper.zip(ret, col.getRGB(), 0);
+
+ skinParameter = "headerBackgroundColor";
+ String headerBackgroundColor = (String) skin.getParameter(context, skinParameter);
+ if (null == headerBackgroundColor || "".equals(headerBackgroundColor))
+ headerBackgroundColor = (String) defaultSkin.getParameter(context, skinParameter);
+
+ if (headerBackgroundColor == null) {
+ return null;
+ }
+
+ col = HtmlColor.decode(headerBackgroundColor);
+
+ Zipper.zip(ret, col.getRGB(), 3);
+
+ return ret;
+ }
+}
Added:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortAsc.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortAsc.java
(rev 0)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortAsc.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,33 @@
+package org.richfaces.renderkit.html.iconimages;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.GeneralPath;
+
+import org.ajax4jsf.resource.ResourceContext;
+
+public class DataTableIconSortAsc extends DataTableIconBasic {
+
+ public Dimension calculateDimensions() {
+ return new Dimension(13, 4);
+ }
+
+ protected void paint(ResourceContext context, Graphics2D g2d) {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
+ GeneralPath path = new GeneralPath();
+
+ path.moveTo(1,4);
+ path.lineTo(4,0);
+ path.lineTo(8,4);
+ path.closePath();
+ Object [] data = (Object[]) restoreData(context);
+ Color col = (Color)data[0];
+
+ g2d.setColor(col);
+ g2d.fill(path);
+ }
+}
Added:
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortDesc.java
===================================================================
---
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortDesc.java
(rev 0)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/html/iconimages/DataTableIconSortDesc.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,33 @@
+package org.richfaces.renderkit.html.iconimages;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.GeneralPath;
+
+import org.ajax4jsf.resource.ResourceContext;
+
+public class DataTableIconSortDesc extends DataTableIconBasic {
+
+ public Dimension calculateDimensions() {
+ return new Dimension(13, 4);
+ }
+
+ protected void paint(ResourceContext context, Graphics2D g2d) {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
+ GeneralPath path = new GeneralPath();
+
+ path.moveTo(1,0);
+ path.lineTo(4,4);
+ path.lineTo(8,0);
+ path.closePath();
+ Object [] data = (Object[]) restoreData(context);
+ Color col = (Color)data[0];
+
+ g2d.setColor(col);
+ g2d.fill(path);
+ }
+}
Modified:
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/css/table.xcss
===================================================================
---
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/css/table.xcss 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/css/table.xcss 2008-01-09
10:34:40 UTC (rev 5210)
@@ -191,4 +191,16 @@
<u:style name="text-align" value="left"/>
</u:selector>
+<u:selector name=".rich-sort-asc">
+ <u:style name="background-image">
+ <f:resource
f:key="org.richfaces.renderkit.html.iconimages.DataTableIconSortAsc"/>
+ </u:style>
+</u:selector>
+<u:selector name=".rich-sort-desc">
+ <u:style name="background-image">
+ <f:resource
f:key="org.richfaces.renderkit.html.iconimages.DataTableIconSortDesc"/>
+ </u:style>
+</u:selector>
+
+
</f:template>
Added:
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/data-table.js
===================================================================
---
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/data-table.js
(rev 0)
+++
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/data-table.js 2008-01-09
10:34:40 UTC (rev 5210)
@@ -0,0 +1,269 @@
+if (!window.RichFaces) var RichFaces = {};
+
+
+
+RichFaces.SortController = function() {
+ var controlsByTable = {};
+
+ return {
+ registerControl : function(control) {
+ var tableId = control.tableId;
+ var sortExpression = control.sortExpression;
+ var controlId = control.id;
+ var columnId = control.columnId;
+
+ var byTable = controlsByTable[tableId];
+ if (!byTable) {
+ byTable = {columns: {}, expressions : {}};
+ controlsByTable[tableId] = byTable;
+ }
+ var byExpression;
+ if (sortExpression) {
+ byExpression = byTable.expressions[sortExpression];
+ if (!byExpression) {
+ byExpression = {};
+ byTable.expressions[sortExpression] = byExpression;
+ }
+ } else if (columnId) {
+ byExpression = byTable.columns[columnId];
+ if (!byExpression) {
+ byExpression = {};
+ byTable.columns[columnId] = byExpression;
+ }
+ }
+ var byId = byExpression[controlId];
+ if (byId) {
+ //TODO: delete controls already registered??
+ } else {
+ byExpression[controlId] = control;
+ }
+ },
+
+ controlsByTable : function(tableId) {
+ var map = controlsByTable[tableId] || {expressions: {}, columns :{}};
+ var result = [];
+ ['expressions', 'columns'].each(
+ function(part) {
+ var parts = map[part];
+ if (parts) {
+ $H(parts).values().each(
+ function(x) {
+ result = result.concat($H(x).values());
+ }
+ );
+ }
+
+ }
+ );
+ return result.uniq();
+ },
+ controls : function(tableId, sortExpression, columnId) {
+ var map = controlsByTable[tableId] || {expressions: {}, columns :{}};
+ var array;
+ if (typeof sortExpression != 'undefined') {
+ array = $H(map.expressions[sortExpression]).values();
+ }
+ if (typeof columnId != 'undefined') {
+ var a = $H(map.columns[columnId]).values();
+ if (array) {
+ array = array.concat(a).uniq();
+ } else {
+ array = a;
+ }
+ }
+ return array;
+
+ }
+ };
+}();
+
+
+RichFaces.SortControl = Class.create({
+ initialize : function(id, tableId, sortExpression, columnId) {
+ this.id = id;
+ this.tableId = tableId;
+ this.columnId = columnId;
+ this.sortExpression = sortExpression;
+ this.onclick = this.invoke.bindAsEventListener(this);
+
+ var element = $(this.id);
+ element.observe("click", this.onclick);
+ element.setStyle({cursor: "pointer"});
+
+ RichFaces.SortController.registerControl(this);
+
+ },
+ displaySortedAscending : function() {
+ $(this.id)
+ .removeClassName("rich-sort-desc")
+ .addClassName("rich-sort-asc");
+ },
+ displaySortedDescending : function() {
+ $(this.id)
+ .removeClassName("rich-sort-asc")
+ .addClassName("rich-sort-desc");
+ },
+ displayNotSortedAtAll : function() {
+ $(this.id)
+ .removeClassName("rich-sort-desc")
+ .removeClassName("rich-sort-asc");
+ },
+ invoke : function(event) {
+ var sortExpression;
+
+ if (this.sortExpression) {
+ sortExpression = this.sortExpression;
+ } else {
+ var cell = Event.findElement(event, "th,td");
+ if (cell) {
+ sortExpression = cell.cellIndex;
+ }
+ }
+ if (typeof sortExpression != 'undefined') {
+ $(this.tableId).component.changeSorting(new RichFaces.SortOrder([new
RichFaces.SortField(sortExpression)]), this.columnId);
+ }
+ }
+});
+
+RichFaces.SortOrder = Class.create({
+ initialize : function(fields) {
+ this.fieldz = fields || [];
+ },
+ fields : function() {
+ return this.fieldz;
+ }
+});
+
+
+
+
+RichFaces.SortField = function(sortExpression, asc) {
+ this.sortExpression = sortExpression;
+ this.asc = asc;
+};
+
+RichFaces.SortMode = Class.create({
+ merge : function(oldSortOrder, newSortOrder) {
+ return oldSortOrder;
+ }
+});
+
+/**
+ * Basically toggle any existing
+ */
+RichFaces.SortMode.Single = Class.create(RichFaces.SortMode, {
+ merge : function(oldSortOrder, newSortOrder) {
+ var newFields = newSortOrder.fields();
+ var oldFields = oldSortOrder.fields();
+ var expr;
+ var asc;
+ if (oldFields.length > 0) {
+ expr = oldFields[0].sortExpression;
+ asc = oldFields[0].asc;
+ }
+ if (newFields.length > 0) {
+ var xpr = newFields[0].sortExpression;
+ if (xpr == expr) {
+ asc = !asc;
+ } else {
+ expr = xpr;
+ asc = true;
+ }
+ }
+ oldSortOrder = new RichFaces.SortOrder([new RichFaces.SortField(expr, asc)]);
+ return oldSortOrder;
+ }
+});
+
+
+RichFaces.DataTable = Class.create({
+ initialize : function(id, options) {
+ var table = $(id);
+ table.component = this;
+
+ this.sortMode = options.sortMode || new RichFaces.SortMode();
+ this.id = id;
+ this.sortOrder = options.sortOrder || new RichFaces.SortOrder();
+ this._compare = this.compare.bind(this);
+ },
+ /**
+ * Call this method to sort the table
+ * @param sortOrder - new sortOrder
+ * @param force if true, new sortOrder will completely replace previous one, otherwise
sortOrders are merged using sortMode
+ */
+ changeSorting : function(sortOrder, columnId, force){
+ if (force) {
+ this.sortOrder = sortOrder;
+ } else {
+ this.sortOrder = this.sortMode.merge(this.sortOrder, sortOrder);
+ }
+ this.sort();
+ var tableId = this.id;
+
+ var cbt = $A(RichFaces.SortController.controlsByTable(tableId));
+ cbt.each(
+ function(control) {
+ control.displayNotSortedAtAll();
+ }
+ );
+ $A(this.sortOrder.fields()).each(
+ function(field) {
+ var ctrls =
+ RichFaces.SortController.controls(tableId, field.sortExpression, columnId);
+ $A(ctrls).each(function(control) {
+ if (field.asc) {
+ control.displaySortedAscending();
+ } else {
+ control.displaySortedDescending();
+ }
+ });
+ }
+ );
+ },
+
+ sort : function() {
+ var table = $(this.id);
+ var tbody = table.tBodies[0];
+ if (tbody) {
+ var newTbody = tbody.cloneNode(false);
+ var newCollection = $A(tbody.rows).clone();
+ newCollection.sort(this._compare);
+ for(var i = 0; i < newCollection.length; i++) {
+ newTbody.appendChild(newCollection[i]);
+ }
+ tbody.parentNode.replaceChild(newTbody, tbody);
+ }
+
+ },
+ compare : function(row1, row2) {
+ var fields = this.sortOrder.fields();
+ var result = 0;
+ for(var i = 0; i < fields.length && result == 0; i++) {
+ var field = fields[i];
+ var expression = field.sortExpression;
+ if (typeof (expression) == 'function') {
+ result = expression(row1, row2);
+ } else if (typeof (expression) == 'number') {
+ var c1 = row1.cells[expression];
+ var c2 = row2.cells[expression];
+ if (c1) {
+ c1 = c1.innerHTML.stripTags();
+
+ }
+ if (c2) {
+ c2 = c2.innerHTML.stripTags();
+ }
+
+ result = ((c1 == c2) ? 0 : ((c1 < c2) ? -1 : 1));
+ }
+
+ if (field.asc == false) {
+ result = -result;
+ }
+
+ }
+ return result;
+
+
+ }
+});
\ No newline at end of file
Modified: trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx
===================================================================
--- trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx 2008-01-09
10:23:38 UTC (rev 5209)
+++ trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx 2008-01-09
10:34:40 UTC (rev 5210)
@@ -13,7 +13,7 @@
component="org.richfaces.component.UIDataTable"
<h:styles>css/table.xcss</h:styles>
-
+ <h:scripts>new
org.ajax4jsf.javascript.PrototypeScript(),scripts/data-table.js</h:scripts>
<f:clientid var="clientId"/>
<table id="#{clientId}"
class="dr-table rich-table #{component.attributes['styleClass']}"
style="#{component.attributes['style']}"
@@ -29,4 +29,5 @@
</vcp:body>
</tbody>
</table>
+ <f:call name="encodeScriptIfNecessary"/>
</f:root>
\ No newline at end of file
Modified: trunk/ui/scrollableDataTable/pom.xml
===================================================================
--- trunk/ui/scrollableDataTable/pom.xml 2008-01-09 10:23:38 UTC (rev 5209)
+++ trunk/ui/scrollableDataTable/pom.xml 2008-01-09 10:34:40 UTC (rev 5210)
@@ -77,7 +77,6 @@
<groupId>org.richfaces.ui</groupId>
<artifactId>dataTable</artifactId>
<version>3.2.0-SNAPSHOT</version>
- <scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/ui/scrollableDataTable/src/main/config/resources/resources-config.xml
===================================================================
--- trunk/ui/scrollableDataTable/src/main/config/resources/resources-config.xml 2008-01-09
10:23:38 UTC (rev 5209)
+++ trunk/ui/scrollableDataTable/src/main/config/resources/resources-config.xml 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<resource-config>
- <resource
class="org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSortAsc">
- <name>org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSortAsc</name>
+ <resource
class="org.richfaces.renderkit.html.iconimages.DataTableIconSortAsc">
+ <name>org.richfaces.renderkit.html.iconimages.DataTableIconSortAsc</name>
</resource>
- <resource
class="org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSortDesc">
- <name>org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSortDesc</name>
+ <resource
class="org.richfaces.renderkit.html.iconimages.DataTableIconSortDesc">
+ <name>org.richfaces.renderkit.html.iconimages.DataTableIconSortDesc</name>
</resource>
<resource
class="org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSplit">
<name>org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSplit</name>
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -32,6 +32,8 @@
import org.richfaces.model.ScrollableTableDataModel;
import org.richfaces.model.SortField;
import org.richfaces.model.SortOrder;
+import org.richfaces.model.impl.expressive.ObjectWrapperFactory;
+import org.richfaces.model.impl.expressive.WrappedBeanComparator;
/**
* @author Maksim Kaszynski
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/Expression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,50 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-/**
- * Base interface for expressions (Literal, EL, or empty)
- * @author Maksim Kaszynski
- *
- */
-abstract class Expression {
- /**
- * this is expression string
- */
- private String expressionString;
-
- public Expression(String n) {
- expressionString = n;
- }
-
- /**
- *
- * @param base
- * @return result of expression evaluation
- */
- public abstract Object evaluate(Object base);
-
- public String getExpressionString() {
- return expressionString;
- }
-
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/JavaBeanWrapper.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,46 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import java.util.Map;
-/**
- * Object used in sorting - contains of base object, and its properties evaluated with
EL
- * @author Maksim Kaszynski
- *
- */
-class JavaBeanWrapper {
- private Object wrappedObject;
- private Map properties;
-
- public JavaBeanWrapper(Object o, Map props) {
- wrappedObject = o;
- properties = props;
- }
-
- public Object getProperty(String expression) {
- return properties.get(expression);
- }
-
- public Object getWrappedObject() {
- return wrappedObject;
- }
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/NullExpression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,18 +0,0 @@
-package org.richfaces.model.internal;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-final class NullExpression extends Expression {
- /**
- * @param n
- */
- NullExpression(String n) {
- super(n);
- }
-
- public Object evaluate(Object base) {
- return null;
- }
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ObjectWrapperFactory.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,144 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.application.Application;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import javax.faces.el.PropertyResolver;
-
-import org.ajax4jsf.util.ELUtils;
-import org.richfaces.model.SortField;
-import org.richfaces.model.SortOrder;
-/**
- *
- * class responsible for packaging objects with their properties evaluated using EL.
- *
- * @author Maksim Kaszynski
- *
- */
-class ObjectWrapperFactory {
-
- interface ObjectConvertor {
- public Object convert(Object o);
- }
-
- private Expression [] expressions;
- private FacesContext context;
- private String var;
- private Object varValue;
-
- public ObjectWrapperFactory(FacesContext context, final String var, SortOrder sortOrder)
{
-
- this.context = context;
-
- Application application = context.getApplication();
- PropertyResolver resolver = application.getPropertyResolver();
-
- this.var = var;
-
- SortField[] sortFields = sortOrder.getFields();
-
- expressions = new Expression[sortFields.length];
-
- for (int i = 0; i < sortFields.length; i++) {
- final SortField field = sortFields[i];
- final String name = field.getName();
-
- if (ELUtils.isValueReference(name)) {
-
- expressions[i] = new ValueBindingExpression(context, name, var);
-
- } else if (name.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
-
- expressions[i] = new NullExpression(name);
-
- } else {
-
- expressions[i] = new SimplePropertyExpression(name, resolver);
- }
- }
-
-
-
- }
-
- void convertList(List list, ObjectConvertor c) {
- int l = list.size();
-
- for (int i = 0; i < l; i++) {
- Object o = list.get(i);
- list.set(i, c.convert(o));
- }
- }
-
- public List unwrapList(List list) {
-
- convertList(list, new ObjectConvertor() {
- public Object convert(Object o) {
- return unwrapObject(o);
- }
- });
-
- if (varValue != null){
- context.getExternalContext().getRequestMap().put(var, varValue);
- } else {
- context.getExternalContext().getRequestMap().remove(var);
- }
-
- return list;
- }
-
- public Object unwrapObject(Object wrapper) {
- return ((JavaBeanWrapper) wrapper).getWrappedObject();
- }
-
- public List wrapList(List list) {
-
- varValue = context.getExternalContext().getRequestMap().get(var);
-
- convertList(list, new ObjectConvertor() {
- public Object convert(Object o) {
- return wrapObject(o);
- }
- });
-
- return list;
- }
-
- public JavaBeanWrapper wrapObject(Object o) {
- Map props = new HashMap();
- for (int i = 0; i < expressions.length; i++) {
- Expression expression = expressions[i];
-
- props.put(expression.getExpressionString(), expression.evaluate(o));
- }
-
- return new JavaBeanWrapper(o, props);
-
- }
-
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/SimplePropertyExpression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,37 +0,0 @@
-package org.richfaces.model.internal;
-
-import javax.faces.el.EvaluationException;
-import javax.faces.el.PropertyResolver;
-
-/**
- * Expression evaluated by applying application
- * property resolver to the base object
- * @author Maksim Kaszynski
- *
- */
-final class SimplePropertyExpression extends Expression {
- /**
- *
- */
- private final PropertyResolver resolver;
-
- /**
- * @param n
- * @param resolver
- */
- SimplePropertyExpression(String n, PropertyResolver resolver) {
- super(n);
- this.resolver = resolver;
- }
-
- public Object evaluate(Object base) {
- Object o = null;
- try {
- return resolver.getValue(base, getExpressionString());
- } catch (EvaluationException e) {
-
- }
-
- return o;
- }
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ValueBindingExpression.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ValueBindingExpression.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ValueBindingExpression.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,42 +0,0 @@
-package org.richfaces.model.internal;
-
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-
-/**
- *
- * Expression evaluated by invoking EL-expression in context of base object
- *
- * @author Maksim Kaszynski
- *
- */
-final class ValueBindingExpression extends Expression {
- private final FacesContext context;
-
- private Map requestMap;
- private String var;
- private ValueBinding binding;
-
- /**
- * @param n
- * @param application
- * @param requestMap
- * @param expressionString
- * @param context
- * @param var
- */
- ValueBindingExpression(FacesContext context, String expressionString, String var) {
- super(expressionString);
- this.context = context;
- this.var = var;
- binding = context.getApplication().createValueBinding(expressionString);
- requestMap = context.getExternalContext().getRequestMap();
- }
-
- public Object evaluate(Object base) {
- requestMap.put(var, base);
- return binding.getValue(context);
- }
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/WrappedBeanComparator.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,54 +0,0 @@
-package org.richfaces.model.internal;
-
-import java.util.Comparator;
-
-import org.richfaces.model.SortField;
-
-/**
- * Comparator for {@link JavaBeanWrapper} objects.
- * Compares them using {@link SortField} sequence.
- *
- * @author Maksim Kaszynski
- *
- */
-final class WrappedBeanComparator implements Comparator {
- /**
- *
- */
- private final SortField[] fields;
-
- /**
- * @param fields
- */
- WrappedBeanComparator(SortField[] fields) {
- this.fields = fields;
- }
-
- public int compare(Object o1, Object o2) {
-
- int result = 0;
- JavaBeanWrapper w1 = (JavaBeanWrapper) o1;
- JavaBeanWrapper w2 = (JavaBeanWrapper) o2;
-
- for (int i = 0; i < fields.length && result == 0; i++) {
-
- String prop = fields[i].getName();
- Boolean asc = fields[i].getAscending();
-
- Object p1 = w1.getProperty(prop);
- Object p2 = w2.getProperty(prop);
-
- if (p1 instanceof Comparable) {
- result = ((Comparable) p1).compareTo(p2);
- }
-
- if (asc != null && !asc.booleanValue()) {
- result = -result;
- }
-
- }
-
-
- return result;
- }
-}
\ No newline at end of file
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasic.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasic.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasic.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,82 +0,0 @@
-package org.richfaces.renderkit.html.iconimages;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.util.Date;
-
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.resource.GifRenderer;
-import org.ajax4jsf.resource.InternetResourceBuilder;
-import org.ajax4jsf.resource.Java2Dresource;
-import org.ajax4jsf.resource.ResourceContext;
-import org.ajax4jsf.util.HtmlColor;
-import org.ajax4jsf.util.Zipper;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-
-public abstract class ScrollableDataTableIconBasic extends Java2Dresource {
-
- public ScrollableDataTableIconBasic() {
- setRenderer(new GifRenderer());
- setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
- }
-
- public Dimension getDimensions(FacesContext facesContext, Object data) {
- return calculateDimensions();
- }
- protected Dimension getDimensions(ResourceContext resourceContext) {
- return calculateDimensions();
- }
-
- protected Object deserializeData(byte[] objectArray) {
- if (objectArray == null) {
- return null;
- }
-
- Object [] stored = new Object[2];
- stored[0] = new Color(Zipper.unzip(objectArray, 0));
- stored[1] = new Color(Zipper.unzip(objectArray, 3));
-
- return stored;
- }
-
- public abstract Dimension calculateDimensions();
-
-
- protected Object getDataToStore(FacesContext context, Object data) {
- Skin skin = SkinFactory.getInstance().getSkin(context);
- Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(context);
-
- Color col = null;
-
- String skinParameter = "headerTextColor";
- String headerTextColor = (String) skin.getParameter(context, skinParameter);
- if (null == headerTextColor || "".equals(headerTextColor))
- headerTextColor = (String) defaultSkin.getParameter(context, skinParameter);
-
- if (headerTextColor == null) {
- return null;
- }
-
- col = HtmlColor.decode(headerTextColor);
-
- byte[] ret = new byte[6];
- Zipper.zip(ret, col.getRGB(), 0);
-
- skinParameter = "headerBackgroundColor";
- String headerBackgroundColor = (String) skin.getParameter(context, skinParameter);
- if (null == headerBackgroundColor || "".equals(headerBackgroundColor))
- headerBackgroundColor = (String) defaultSkin.getParameter(context, skinParameter);
-
- if (headerBackgroundColor == null) {
- return null;
- }
-
- col = HtmlColor.decode(headerBackgroundColor);
-
- Zipper.zip(ret, col.getRGB(), 3);
-
- return ret;
- }
-}
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortAsc.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortAsc.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortAsc.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,33 +0,0 @@
-package org.richfaces.renderkit.html.iconimages;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.GeneralPath;
-
-import org.ajax4jsf.resource.ResourceContext;
-
-public class ScrollableDataTableIconSortAsc extends ScrollableDataTableIconBasic {
-
- public Dimension calculateDimensions() {
- return new Dimension(13, 4);
- }
-
- protected void paint(ResourceContext context, Graphics2D g2d) {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
- GeneralPath path = new GeneralPath();
-
- path.moveTo(1,4);
- path.lineTo(4,0);
- path.lineTo(8,4);
- path.closePath();
- Object [] data = (Object[]) restoreData(context);
- Color col = (Color)data[0];
-
- g2d.setColor(col);
- g2d.fill(path);
- }
-}
Deleted:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortDesc.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortDesc.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSortDesc.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,33 +0,0 @@
-package org.richfaces.renderkit.html.iconimages;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.GeneralPath;
-
-import org.ajax4jsf.resource.ResourceContext;
-
-public class ScrollableDataTableIconSortDesc extends ScrollableDataTableIconBasic {
-
- public Dimension calculateDimensions() {
- return new Dimension(13, 4);
- }
-
- protected void paint(ResourceContext context, Graphics2D g2d) {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
- GeneralPath path = new GeneralPath();
-
- path.moveTo(1,0);
- path.lineTo(4,4);
- path.lineTo(8,0);
- path.closePath();
- Object [] data = (Object[]) restoreData(context);
- Color col = (Color)data[0];
-
- g2d.setColor(col);
- g2d.fill(path);
- }
-}
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSplit.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSplit.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconSplit.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -7,7 +7,7 @@
import org.ajax4jsf.resource.ResourceContext;
-public class ScrollableDataTableIconSplit extends ScrollableDataTableIconBasic {
+public class ScrollableDataTableIconSplit extends DataTableIconBasic {
public Dimension calculateDimensions() {
return new Dimension(2, 13);
Modified:
trunk/ui/scrollableDataTable/src/main/resources/org/richfaces/renderkit/html/css/scrollable-data-table.xcss
===================================================================
---
trunk/ui/scrollableDataTable/src/main/resources/org/richfaces/renderkit/html/css/scrollable-data-table.xcss 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/main/resources/org/richfaces/renderkit/html/css/scrollable-data-table.xcss 2008-01-09
10:34:40 UTC (rev 5210)
@@ -304,12 +304,12 @@
</u:selector>
<u:selector name=".dr-sdt-sort-asc">
<u:style name="background-image">
- <f:resource
f:key="org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSortAsc"/>
+ <f:resource
f:key="org.richfaces.renderkit.html.iconimages.DataTableIconSortAsc"/>
</u:style>
</u:selector>
<u:selector name=".dr-sdt-sort-desc">
<u:style name="background-image">
- <f:resource
f:key="org.richfaces.renderkit.html.iconimages.ScrollableDataTableIconSortDesc"/>
+ <f:resource
f:key="org.richfaces.renderkit.html.iconimages.DataTableIconSortDesc"/>
</u:style>
</u:selector>
<u:selector name=".dr-sdt-hsep">
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -30,6 +30,7 @@
import org.richfaces.model.SortField;
import org.richfaces.model.SortOrder;
+
/**
* @author Maksim Kaszynski
*
Deleted:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/JavaBeanWrapperTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,76 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import java.util.Collections;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class JavaBeanWrapperTest extends TestCase {
-
-
- private JavaBeanWrapper wrapper;
- final Boolean test = Boolean.TRUE;
- final Map props = Collections.singletonMap("true", test);
- /**
- * @param name
- */
- public JavaBeanWrapperTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- wrapper = new JavaBeanWrapper(test, props);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- wrapper = null;
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.JavaBeanWrapper#getProperty(java.lang.String)}.
- */
- public void testGetProperty() {
- assertEquals(test, wrapper.getProperty("true"));
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.JavaBeanWrapper#getWrappedObject()}.
- */
- public void testGetWrappedObject() {
- assertEquals(test, wrapper.getWrappedObject());
- }
-
-}
Deleted:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/NullExpressionTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,63 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import junit.framework.TestCase;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class NullExpressionTest extends TestCase {
-
-
- private Expression expression;
-
- /**
- * @param name
- */
- public NullExpressionTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- expression = new NullExpression("_id2");
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- expression = null;
- }
-
- public void testEvaluate() {
- Object o = new Object();
- assertNull(expression.evaluate(o));
- }
-
-}
Deleted:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ObjectWrapperFactoryTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,198 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Random;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.richfaces.model.SortField;
-import org.richfaces.model.SortOrder;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class ObjectWrapperFactoryTest extends AbstractAjax4JsfTestCase {
-
-
- /**
- *
- */
- SortField [] sortFields;
- SortOrder sortOrder;
- private ObjectWrapperFactory factory;
- private String var = "abc";
-
- public ObjectWrapperFactoryTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
- sortFields = new SortField[3];
- sortFields[0] = new SortField("_id1", 0, Boolean.TRUE);
- sortFields[1] = new SortField("name", 1, Boolean.FALSE);
- sortFields[2] = new SortField("#{" +var + ".name}", 2,
Boolean.TRUE);
- sortOrder = new SortOrder(sortFields);
-
- factory = new ObjectWrapperFactory(facesContext, var, sortOrder);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- public void tearDown() throws Exception {
- super.tearDown();
-
- sortFields = null;
- sortOrder = null;
- factory = null;
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.ObjectWrapperFactory#convertList(java.util.List,
org.richfaces.model.internal.ObjectWrapperFactory.ObjectConvertor)}.
- */
- public final void testConvertList() {
-
-
- List objects = new ArrayList();
- objects.add(Boolean.TRUE);
- int size = objects.size();
- factory.convertList(objects, new ObjectWrapperFactory.ObjectConvertor() {
- public Object convert(Object o ) {
-
- return new Boolean(!((Boolean) o).booleanValue());
- }
- });
-
- assertEquals(size, objects.size());
- assertEquals(Boolean.FALSE, objects.get(0));
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.ObjectWrapperFactory#unwrapList(java.util.List)}.
- */
- public final void testUnwrapList() {
- List objects = new ArrayList(10);
- int [] ints = new int[10];
- Random random = new Random();
- for(int i = 0; i < 10; i++) {
- ints[i] = random.nextInt();
- objects.add(new TestObj(String.valueOf(ints[i])));
- }
-
- List l1 = factory.wrapList(objects);
- List l2 = factory.unwrapList(l1);
-
- assertSame(objects, l1);
- assertSame(objects, l2);
- assertEquals(10, l2.size());
-
- for(int i = 0; i < 10; i++) {
- TestObj t = (TestObj) l2.get(i);
- assertEquals(String.valueOf(ints[i]), t.getName());
- }
-
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.ObjectWrapperFactory#unwrapObject(java.lang.Object)}.
- */
- public final void testUnwrapObject() {
-
- TestObj t = new TestObj("20");
-
- JavaBeanWrapper wrapper = new JavaBeanWrapper(t, new HashMap());
-
- Object wrapped = factory.unwrapObject(wrapper);
-
- assertSame(t, wrapped);
-
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.ObjectWrapperFactory#wrapList(java.util.List)}.
- */
- public final void testWrapList() {
- List objects = new ArrayList(10);
- int [] ints = new int[10];
- Random random = new Random();
- for(int i = 0; i < 10; i++) {
- ints[i] = random.nextInt();
- objects.add(new TestObj(String.valueOf(ints[i])));
- }
-
- List l1 = factory.wrapList(objects);
-
- assertSame(objects, l1);
- assertEquals(10, l1.size());
-
- for(int i = 0; i < 10; i++) {
- JavaBeanWrapper wrapper = (JavaBeanWrapper) l1.get(i);
- TestObj t = (TestObj) wrapper.getWrappedObject();
-
- String string = String.valueOf(ints[i]);
-
- assertEquals(string, t.getName());
-
- Object prop1 = wrapper.getProperty("name");
- Object prop2 = wrapper.getProperty("#{abc.name}");
-
- assertNotNull(prop1);
- assertNotNull(prop2);
- assertEquals(string, prop1);
- assertEquals(string, prop2);
- }
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.ObjectWrapperFactory#wrapObject(java.lang.Object)}.
- */
- public final void testWrapObject() {
- TestObj t = new TestObj("20");
-
-
-
- JavaBeanWrapper wrapper = factory.wrapObject(t);
-
- Object wrapped = wrapper.getWrappedObject();
-
- assertSame(t, wrapped);
-
- Object prop1 = wrapper.getProperty("name");
- Object prop2 = wrapper.getProperty("#{abc.name}");
-
- assertNotNull(prop1);
- assertNotNull(prop2);
- assertEquals("20", prop1);
- assertEquals("20", prop2);
-
-
- }
-
-}
Deleted:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/SimplePropertyExpressionTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,75 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class SimplePropertyExpressionTest extends AbstractAjax4JsfTestCase {
-
- final static String property = "name";
- private SimplePropertyExpression expression;
-
- /**
- * @param name
- */
- public SimplePropertyExpressionTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
- expression = new SimplePropertyExpression("name",
application.getPropertyResolver());
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- public void tearDown() throws Exception {
- super.tearDown();
- expression = null;
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.SimplePropertyExpression#evaluate(java.lang.Object)}.
- */
- public final void testEvaluate() {
- TestObj testObj = new TestObj("aaaa");
- Object prop = expression.evaluate(testObj);
- assertNotNull(prop);
- assertEquals("aaaa", prop);
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.Expression#getExpressionString()}.
- */
- public final void testGetExpressionString() {
- assertEquals(property, expression.getExpressionString());
- }
-
-}
Deleted:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ValueBindingExpressionTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,73 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class ValueBindingExpressionTest extends AbstractAjax4JsfTestCase {
-
- private ValueBindingExpression expression;
- static final String var = "obj";
- static final String el = "#{" + var + ".name}";
-
- public ValueBindingExpressionTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
- expression = new ValueBindingExpression(facesContext, el, var);
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
- */
- public void tearDown() throws Exception {
- super.tearDown();
- expression = null;
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.ValueBindingExpression#evaluate(java.lang.Object)}.
- */
- public final void testEvaluate() {
- TestObj testObj = new TestObj("aaaa");
- Object prop = expression.evaluate(testObj);
- assertNotNull(prop);
- assertEquals("aaaa", prop);
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.Expression#getExpressionString()}.
- */
- public final void testGetExpressionString() {
- assertEquals(el, expression.getExpressionString());
- }
-
-}
Deleted:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/WrappedBeanComparatorTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -1,100 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.model.internal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.richfaces.model.SortField;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class WrappedBeanComparatorTest extends TestCase {
-
- private SortField[] sortFields;
- private WrappedBeanComparator comparator;
-
- private static final int [][] testData = {{0,0}, {0,1}, {1, 0}, {1, 1} };
-
- private JavaBeanWrapper [] testWrapers;
-
- public WrappedBeanComparatorTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- sortFields = new SortField[2];
- sortFields[0] = new SortField("a", 1, Boolean.FALSE);
- sortFields[1] = new SortField("b", 2, Boolean.TRUE);
-
-
- comparator = new WrappedBeanComparator(sortFields);
-
- testWrapers = new JavaBeanWrapper[testData.length];
- for(int i = 0; i < testData.length; i++) {
- testWrapers[i] = w(testData[i]);
- }
-
- }
-
- private JavaBeanWrapper w(int [] ints) {
- Map m = new HashMap();
- m.put("a", new Integer(ints[0]));
- m.put("b", new Integer(ints[1]));
-
- return new JavaBeanWrapper(m, m);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- sortFields = null;
- comparator = null;
- testWrapers = null;
- }
-
- /**
- * Test method for {@link
org.richfaces.model.internal.WrappedBeanComparator#compare(java.lang.Object,
java.lang.Object)}.
- */
- public final void testCompare() {
-
- assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
- assertTrue(comparator.compare(w(new int[] {1, 1}), w(new int [] {0, 0})) < 0);
- assertTrue(comparator.compare(w(new int[] {0, 0}), w(new int [] {0, 1})) < 0);
- assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 0})) == 0);
- //assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
- //assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
-
- }
-
-}
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java 2008-01-09
10:23:38 UTC (rev 5209)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/iconimages/ScrollableDataTableIconBasicTest.java 2008-01-09
10:34:40 UTC (rev 5210)
@@ -23,7 +23,7 @@
public void testSaveResources(){
- ScrollableDataTableIconBasic icon = new ScrollableDataTableIconSortAsc();
+ DataTableIconBasic icon = new DataTableIconSortAsc();
Skin skin = SkinFactory.getInstance().getSkin(facesContext);
Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(facesContext);