Author: maksimkaszynski
Date: 2008-01-12 08:01:03 -0500 (Sat, 12 Jan 2008)
New Revision: 5325
Added:
trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java
trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent2.java
trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener2.java
trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java
trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java
trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java
trunk/framework/api/src/main/java/org/richfaces/model/filter/
trunk/framework/api/src/main/java/org/richfaces/model/filter/Filter.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
trunk/sandbox/ui/sortableHeader/src/main/config/
trunk/sandbox/ui/sortableHeader/src/main/config/component/
trunk/sandbox/ui/sortableHeader/src/main/config/component/sortControl.xml
trunk/sandbox/ui/sortableHeader/src/main/java/org/
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/Mode.java
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/UISortableControl.java
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/event/
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/renderkit/
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/renderkit/html/
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/renderkit/html/SortControlRenderer.java
Modified:
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/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/ValueBindingExpression.java
trunk/sandbox/api/pom.xml
trunk/sandbox/ui/sortableHeader/pom.xml
trunk/ui/dataTable/
trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumn.java
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/scripts/data-table.js
Log:
initial placement of sortControl. Introduction of Sortable2
Added: trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/component/Sortable2.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import org.richfaces.model.SortOrder2;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface Sortable2 {
+
+ public SortOrder2 getSortOrder();
+
+ public void setSortOrder(SortOrder2 sortOrder);
+
+}
Added: trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent2.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent2.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,52 @@
+/**
+ *
+ */
+package org.richfaces.event.sort;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortEvent2 extends FacesEvent{
+
+ private static final long serialVersionUID = -3141067055845421505L;
+
+ //TODO: making ValueExpression here - should redesign SortOrder/SortField?
+ private ValueExpression sortExpression;
+
+ private boolean force;
+
+ public SortEvent2(UIComponent component, ValueExpression sortExpression,
+ boolean force) {
+ super(component);
+ this.sortExpression = sortExpression;
+ this.force = force;
+ }
+
+ public SortEvent2(UIComponent component, ValueExpression sortExpression) {
+ this(component, sortExpression, false);
+ }
+
+ @Override
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof SortListener2;
+ }
+
+ @Override
+ public void processListener(FacesListener listener) {
+ ((SortListener2) listener).processSorting(this);
+ }
+
+ public boolean isForce() {
+ return force;
+ }
+
+ public ValueExpression getSortExpression() {
+ return sortExpression;
+ }
+}
Added: trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener2.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/event/sort/SortListener2.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,7 @@
+package org.richfaces.event.sort;
+
+import javax.faces.event.FacesListener;
+
+public interface SortListener2 extends FacesListener{
+ public void processSorting(SortEvent2 event);
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/Ordering.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,10 @@
+package org.richfaces.model;
+/**
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public enum Ordering {
+ ASCENDING {},
+ DESCENDING {}
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/SortField2.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,80 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.Serializable;
+
+import javax.el.ValueExpression;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortField2 implements Serializable{
+
+ private static final long serialVersionUID = 2122437301428777493L;
+
+ private Ordering ordering;
+
+ private ValueExpression expression;
+
+ public SortField2(ValueExpression expression) {
+ super();
+ this.expression = expression;
+ }
+
+ public SortField2(ValueExpression expression, Ordering ordering) {
+ super();
+ this.expression = expression;
+ this.ordering = ordering;
+ }
+
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SortField2 other = (SortField2) obj;
+ if (expression == null) {
+ if (other.expression != null)
+ return false;
+ } else if
(!expression.getExpressionString().equals(other.expression.getExpressionString()))
+ return false;
+ if (ordering == null) {
+ if (other.ordering != null)
+ return false;
+ } else if (!ordering.equals(other.ordering))
+ return false;
+ return true;
+ }
+ public ValueExpression getExpression() {
+ return expression;
+ }
+ public Ordering getOrdering() {
+ return ordering;
+ }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((expression == null) ? 0 : expression.hashCode());
+ result = prime * result
+ + ((ordering == null) ? 0 : ordering.hashCode());
+ return result;
+ }
+
+ public void setExpression(ValueExpression expression) {
+ this.expression = expression;
+ }
+
+ public void setOrdering(Ordering ordering) {
+ this.ordering = ordering;
+ }
+
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/SortOrder2.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,62 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortOrder2 implements Serializable{
+
+ private static final long serialVersionUID = -8464361988367479001L;
+
+ private List<SortField2> fields = new LinkedList<SortField2>();
+
+ public List<SortField2> getFields() {
+ return fields;
+ }
+
+ public void setFields(List<SortField2> fields) {
+ this.fields = fields;
+ }
+
+ public void addField(SortField2 field2) {
+ fields.add(field2);
+ }
+
+ public boolean isEmpty() {
+ return fields == null || fields.isEmpty();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((fields == null) ? 0 : fields.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SortOrder2 other = (SortOrder2) obj;
+ if (fields == null) {
+ if (other.fields != null)
+ return false;
+ } else if (!fields.equals(other.fields))
+ return false;
+ return true;
+ }
+
+
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/filter/Filter.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/filter/Filter.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/filter/Filter.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package org.richfaces.model.filter;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface Filter<T> {
+ public boolean accept(T t);
+}
Modified: trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java 2008-01-12
12:04:13 UTC (rev 5324)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortableModel.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -101,10 +101,9 @@
boolean result = false;
if (range instanceof SortableRange) {
SortableRange sortableRange = (SortableRange) range;
- SortOrder sortOrder = sortableRange.getSortOrder();
+ SortOrder2 sortOrder = sortableRange.getSortOrder();
if (sortOrder != null) {
- SortField[] fields = sortOrder.getFields();
- result = fields != null && fields.length > 0;
+ result = !sortOrder.isEmpty();
}
}
return result;
Modified: trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java 2008-01-12
12:04:13 UTC (rev 5324)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortableRange.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -11,16 +11,16 @@
*/
public class SortableRange extends SequenceRange {
- private SortOrder sortOrder;
+ private SortOrder2 sortOrder;
private String var;
- public SortableRange(int firstRow, int rows, String var, SortOrder sortOrder) {
+ public SortableRange(int firstRow, int rows, String var, SortOrder2 sortOrder) {
super(firstRow, rows);
this.sortOrder = sortOrder;
this.var = var;
}
- public SortOrder getSortOrder() {
+ public SortOrder2 getSortOrder() {
return sortOrder;
}
Modified: trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java 2008-01-12
12:04:13 UTC (rev 5324)
+++ trunk/framework/impl/src/main/java/org/richfaces/model/SortedModel.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -16,7 +16,7 @@
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;
+import org.richfaces.model.impl.expressive.WrappedBeanComparator2;
@@ -59,9 +59,9 @@
log.error(e.getMessage(), e);
}
- SortOrder sortOrder = range.getSortOrder();
+ SortOrder2 sortOrder = range.getSortOrder();
ObjectWrapperFactory wrapperFactory = new ObjectWrapperFactory(context, range.getVar(),
sortOrder);
- WrappedBeanComparator wrappedBeanComparator = new
WrappedBeanComparator(sortOrder.getFields());
+ WrappedBeanComparator2 wrappedBeanComparator = new WrappedBeanComparator2(sortOrder);
wrapperFactory.wrapList(collection);
Collections.sort(collection, wrappedBeanComparator);
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/NullExpression.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/NullExpression.java 2008-01-12
12:04:13 UTC (rev 5324)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/NullExpression.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -8,8 +8,8 @@
/**
* @param n
*/
- NullExpression(String n) {
- super(n);
+ NullExpression(String name) {
+ super(name);
}
public Object evaluate(Object base) {
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2008-01-12
12:04:13 UTC (rev 5324)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -35,7 +35,9 @@
import org.ajax4jsf.util.ELUtils;
import org.richfaces.model.SortField;
+import org.richfaces.model.SortField2;
import org.richfaces.model.SortOrder;
+import org.richfaces.model.SortOrder2;
/**
*
* class responsible for packaging objects with their properties evaluated using EL.
@@ -88,6 +90,40 @@
}
+ public ObjectWrapperFactory(FacesContext context, final String var, SortOrder2
sortOrder) {
+
+ this.context = context;
+
+ Application application = context.getApplication();
+ ELResolver resolver = application.getELResolver();
+ ELContext elContext = context.getELContext();
+ this.var = var;
+
+ List<SortField2> fields = sortOrder.getFields();
+
+ expressions = new Expression[fields.size()];
+
+ int i = 0;
+ for (SortField2 field : fields) {
+ ValueExpression valueExpression = field.getExpression();
+ Expression expression;
+
+ if (valueExpression.isLiteralText()) {
+ String expressionString = valueExpression.getExpressionString();
+
+ if (expressionString.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
+ expression = new NullExpression(expressionString);
+ } else {
+ expression = new SimplePropertyExpression(expressionString, elContext, resolver);
+ }
+ } else {
+ expression = new ValueBindingExpression(context, valueExpression, var);
+ }
+
+ expressions[i++] = expression;
+ }
+
+ }
void convertList (List<? super Object> list, ObjectConvertor c) {
int l = list.size();
Modified:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java 2008-01-12
12:04:13 UTC (rev 5324)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ValueBindingExpression.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -37,6 +37,16 @@
mapper = context.getVariableMapper();
factory = expressionFactory;
}
+
+ ValueBindingExpression(FacesContext faces, ValueExpression valueExpression, String var)
{
+ super(valueExpression.getExpressionString());
+ this.context = faces.getELContext();
+ this.var = var;
+ ExpressionFactory expressionFactory = faces.getApplication().getExpressionFactory();
+ this.valueExpression = valueExpression;
+ mapper = context.getVariableMapper();
+ factory = expressionFactory;
+ }
public Object evaluate(Object base) {
mapper.setVariable(var, factory.createValueExpression(base, Object.class));
Added:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,67 @@
+package org.richfaces.model.impl.expressive;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.el.ValueExpression;
+
+import org.richfaces.model.Ordering;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortField2;
+import org.richfaces.model.SortOrder2;
+
+/**
+ * Comparator for {@link JavaBeanWrapper} objects.
+ * Compares them using {@link SortField} sequence.
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public final class WrappedBeanComparator2 implements Comparator<Object> {
+
+ private final SortOrder2 sortOrder;
+
+ public WrappedBeanComparator2(SortOrder2 sortOrder) {
+ super();
+ this.sortOrder = sortOrder;
+ }
+
+ 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;
+
+ List<SortField2> fields = sortOrder.getFields();
+
+ for (Iterator<SortField2> iterator = fields.iterator(); iterator.hasNext()
&& result == 0;) {
+ SortField2 sortField2 = iterator.next();
+ ValueExpression expression = sortField2.getExpression();
+ String prop = expression.getExpressionString();
+ Ordering ordering = sortField2.getOrdering();
+ if (ordering != null) {
+ Object p1 = w1.getProperty(prop);
+ Object p2 = w2.getProperty(prop);
+
+ if (p1 instanceof Comparable && p2 instanceof Comparable) {
+ result = ((Comparable<Object>) p1).compareTo(p2);
+ } else if (p1 == null && p2 != null) {
+ result = 1;
+ } else if (p2 == null && p1 != null) {
+ result = -1;
+ }
+
+ if (ordering.equals(Ordering.DESCENDING)) {
+ result = -result;
+ }
+ }
+
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
Added:
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package org.richfaces.model.impl.expressive;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class WrappedBeanFilter implements
org.richfaces.model.filter.Filter<JavaBeanWrapper>{
+
+ public boolean accept(JavaBeanWrapper t) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}
Modified: trunk/sandbox/api/pom.xml
===================================================================
--- trunk/sandbox/api/pom.xml 2008-01-12 12:04:13 UTC (rev 5324)
+++ trunk/sandbox/api/pom.xml 2008-01-12 13:01:03 UTC (rev 5325)
@@ -9,12 +9,29 @@
<artifactId>richfaces-sandbox-api</artifactId>
<name>Richfaces Sandbox API</name>
<version>3.2.0-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-api</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-impl</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
Modified: trunk/sandbox/ui/sortableHeader/pom.xml
===================================================================
--- trunk/sandbox/ui/sortableHeader/pom.xml 2008-01-12 12:04:13 UTC (rev 5324)
+++ trunk/sandbox/ui/sortableHeader/pom.xml 2008-01-12 13:01:03 UTC (rev 5325)
@@ -9,6 +9,38 @@
<artifactId>sortableHeader</artifactId>
<name>sortableHeader</name>
<version>3.2.0-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ <!--execution>
+ <id>generate-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>generate-tests</goal>
+ </goals>
+ </execution-->
+ </executions>
+ <configuration>
+ <library>
+ <prefix>org.richfaces.sandbox</prefix>
+ <taglib>
+ <shortName>sortable</shortName>
+ </taglib>
+ </library>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
@@ -22,16 +54,6 @@
<artifactId>richfaces-impl</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.richfaces.sandbox</groupId>
- <artifactId>richfaces-sandbox-api</artifactId>
- <version>3.2.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.richfaces.sandbox</groupId>
- <artifactId>richfaces-sandbox-impl</artifactId>
- <version>3.2.0-SNAPSHOT</version>
- </dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>core</artifactId>
Added: trunk/sandbox/ui/sortableHeader/src/main/config/component/sortControl.xml
===================================================================
--- trunk/sandbox/ui/sortableHeader/src/main/config/component/sortControl.xml
(rev 0)
+++ trunk/sandbox/ui/sortableHeader/src/main/config/component/sortControl.xml 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE components PUBLIC "-//AJAX4JSF//CDK Generator config/EN"
"https://ajax4jsf.dev.java.net/nonav/dtds/component-config.dtd" >
+<components>
+ <component>
+ <name>org.richfaces.SortControl</name>
+ <family>org.richfaces.SortControl</family>
+ <classname>org.richfaces.component.HtmlSortableControl</classname>
+ <superclass>org.richfaces.component.UISortableControl</superclass>
+ <description>
+ <![CDATA[
+ ]]>
+ </description>
+ <renderer generate="false" override="false">
+ <name>org.richfaces.SortControlRenderer</name>
+ <classname>org.richfaces.renderkit.html.SortControlRenderer</classname>
+ </renderer>
+ <tag>
+ <name>sortControl</name>
+ <classname>org.richfaces.taglib.SortControlTag</classname>
+ <superclass>
+ org.ajax4jsf.webapp.taglib.HtmlComponentTagBase
+ </superclass>
+ <test/>
+ </tag>
+ &ui_component_attributes;
+ </component>
+</components>
Added: trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/Mode.java
===================================================================
--- trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/Mode.java
(rev 0)
+++
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/Mode.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,14 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public enum Mode {
+ AJAX,
+ SERVER,
+ CLIENT
+}
Added:
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/UISortableControl.java
===================================================================
---
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/UISortableControl.java
(rev 0)
+++
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/component/UISortableControl.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,71 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class UISortableControl extends UIComponentBase{
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.SortControl";
+
+ public static final String COMPONENT_TYPE = "org.richfaces.SortControl";
+
+ private ValueExpression sortExpression;
+
+ private Mode mode;
+
+ public ValueExpression getSortExpression() {
+ return sortExpression;
+ }
+
+ public void setSortExpression(ValueExpression sortExpression) {
+ this.sortExpression = sortExpression;
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public Mode getMode() {
+ return mode;
+ }
+
+ public UIDataTable getTable() {
+ UIComponent component = getParent();
+ while(component != null && !(component instanceof UIDataTable)) {
+ component = component.getParent();
+ }
+ return (UIDataTable) component;
+ }
+
+ public void setMode(Mode mode) {
+ this.mode = mode;
+ }
+
+ @Override
+ public Object saveState(FacesContext context) {
+ Object [] o = new Object[3];
+ o[0] = super.saveState(context);
+ o[1] = mode;
+ o[2] = saveAttachedState(context, sortExpression);
+ return o;
+ }
+
+ @Override
+ public void restoreState(FacesContext context, Object state) {
+ Object [] o = (Object[]) state;
+ super.restoreState(context, o[0]);
+ mode = (Mode) o[1];
+ sortExpression = (ValueExpression) restoreAttachedState(context, o[2]);
+ }
+
+}
Added:
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/renderkit/html/SortControlRenderer.java
===================================================================
---
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/renderkit/html/SortControlRenderer.java
(rev 0)
+++
trunk/sandbox/ui/sortableHeader/src/main/java/org/richfaces/renderkit/html/SortControlRenderer.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -0,0 +1,168 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import static org.ajax4jsf.renderkit.RendererUtils.HTML.SCRIPT_ELEM;
+import static org.ajax4jsf.renderkit.RendererUtils.HTML.INPUT_ELEM;
+import static org.ajax4jsf.renderkit.RendererUtils.HTML.NAME_ATTRIBUTE;
+import static org.ajax4jsf.renderkit.RendererUtils.HTML.id_ATTRIBUTE;
+import static org.richfaces.component.Mode.AJAX;
+import static org.richfaces.component.Mode.CLIENT;
+import static org.richfaces.component.Mode.SERVER;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.component.UIDataAdaptor;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.AjaxScript;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.PrototypeScript;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.resource.InternetResource;
+import org.richfaces.component.Mode;
+import org.richfaces.component.UIDataTable;
+import org.richfaces.component.UISortableControl;
+import org.richfaces.event.sort.SortEvent2;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortControlRenderer extends HeaderResourcesRendererBase{
+
+ interface RendererCommand {
+ void encodeMarkup(ResponseWriter writer, FacesContext context, UISortableControl
control) throws IOException;
+ }
+
+ private final static InternetResource[] scripts = {
+ new AjaxScript(),
+ new PrototypeScript()
+ };
+
+ private RendererCommand[] commands = new RendererCommand[Mode.values().length];
+
+ public SortControlRenderer() {
+ commands[AJAX.ordinal()] = new RendererCommand() {
+ public void encodeMarkup(ResponseWriter writer, FacesContext context,
+ UISortableControl control) throws IOException {
+
+ JSFunction constructor = new JSFunction("new RichFaces.SortControl.Ajax");
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(control, context);
+
+ constructor.addParameter(control.getClientId(context));
+ constructor.addParameter(ajaxFunction);
+ writeScript(context, control, constructor);
+ }
+ };
+ commands[CLIENT.ordinal()] = new RendererCommand() {
+ public void encodeMarkup(ResponseWriter writer, FacesContext context,
+ UISortableControl control) throws IOException {
+
+ UIDataAdaptor table = control.getTable();
+ String sortBy = null;
+ ValueExpression sortExpression = control.getSortExpression();
+
+ if (sortExpression != null) {
+ sortBy = sortExpression.getExpressionString();
+ }
+
+ JSFunction function = new JSFunction("new RichFaces.SortControl");
+
+ function.addParameter(control.getClientId(context));
+ function.addParameter(table.getClientId(context));
+ function.addParameter(sortBy == null ? JSReference.NULL: new JSReference(sortBy));
+ function.addParameter(control.getParent().getClientId(context));
+ writeScript(context, control, function);
+ }
+ };
+ commands[SERVER.ordinal()] = new RendererCommand() {
+ public void encodeMarkup(ResponseWriter writer, FacesContext context,
+ UISortableControl control) throws IOException {
+
+ JSFunction constructor = new JSFunction("new
RichFaces.SortControl.Server");
+
+ constructor.addParameter(control.getClientId(context));
+ writeScript(context, control, constructor);
+ writer.startElement(INPUT_ELEM, control);
+ writer.writeAttribute(NAME_ATTRIBUTE, control.getClientId(context),
"name");
+ writer.writeAttribute(id_ATTRIBUTE, control.getClientId(context) + "s",
"name");
+ writer.endElement(INPUT_ELEM);
+ }
+ };
+ }
+
+ private void writeScript(FacesContext context, UIComponent component, Object script)
+ throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(SCRIPT_ELEM, component);
+ writer.writeAttribute(id_ATTRIBUTE, component.getClientId(context), "id");
+ writer.writeText(script, null);
+ writer.endElement(SCRIPT_ELEM);
+ }
+
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UISortableControl.class;
+ }
+
+ @Override
+ protected InternetResource[] getScripts() {
+ return scripts;
+ }
+
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
+
+ UISortableControl control = (UISortableControl) component;
+ String clientId = control.getClientId(context);
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, String> parameterMap = externalContext.getRequestParameterMap();
+ String string = parameterMap.get(clientId);
+ if (string != null) {
+ UIDataTable table = control.getTable();
+
+ new SortEvent2(table, control.getSortExpression());
+
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
+
+ //TODO: AjaxEvent?
+ if (ajaxContext.isAjaxRequest()) {
+ ajaxContext.addComponentToAjaxRender(table);
+ }
+ }
+
+
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return false;
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
+ UIComponent component) throws IOException {
+
+ UISortableControl control = (UISortableControl) component;
+ Mode mode = control.getMode();
+ if (mode == null) {
+ mode = SERVER;
+ }
+ RendererCommand rendererCommand = commands[mode.ordinal()];
+ if (rendererCommand != null) {
+ rendererCommand.encodeMarkup(writer, context, control);
+ }
+
+ }
+}
Property changes on: trunk/ui/dataTable
___________________________________________________________________
Name: svn:ignore
- target
.settings
.classpath
.project
+ target
.settings
.classpath
.project
.buildpath
.externalToolBuilders
bin
Modified: trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumn.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumn.java 2008-01-12
12:04:13 UTC (rev 5324)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/component/UIColumn.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -33,4 +33,7 @@
public static final String COMPONENT_FAMILY = "org.richfaces.Column";
+ public abstract String getSortMode();
+
+ public abstract void setSortMode(String mode);
}
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-12
12:04:13 UTC (rev 5324)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataTable.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -42,7 +42,7 @@
* JSF component class
*
*/
-public abstract class UIDataTable extends SequenceDataAdaptor implements Sortable {
+public abstract class UIDataTable extends SequenceDataAdaptor implements Sortable2 {
/**
* @author shura
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-12
12:04:13 UTC (rev 5324)
+++
trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2008-01-12
13:01:03 UTC (rev 5325)
@@ -32,6 +32,7 @@
import org.ajax4jsf.component.UIDataAdaptor;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
@@ -39,8 +40,6 @@
import org.richfaces.component.Row;
import org.richfaces.component.UIDataTable;
-import com.sun.org.apache.xpath.internal.compiler.OpCodes;
-
/**
* @author shura
*
@@ -147,18 +146,35 @@
writer.writeAttribute("scope", "col", null);
getUtils().encodeAttribute(context, column, "colspan");
- if (column instanceof Column) {
- Column col = (Column) column;
- String clientId = column.getClientId(context) + facetName;
+ if (column instanceof org.richfaces.component.UIColumn) {
+ org.richfaces.component.UIColumn col =
+ (org.richfaces.component.UIColumn) column;
+ String clientId = col.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());
+ String sortMode = col.getSortMode();
+ if ("client".equals(sortMode)) {
+ 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());
+ } else if ("ajax".equals(sortMode)) {
+
+ //AjaxRendererUtils.buildOnClick(uiComponent, facesContext)
+
+ JSFunction function = new JSFunction("new RichFaces.SortControl.Ajax");
+ function.addParameter(clientId);
+ getUtils().writeScript(context, column, function.toScript());
+
+ } else {
+ JSFunction function = new JSFunction("new
RichFaces.SortControl.Server");
+ function.addParameter(clientId);
+ getUtils().writeScript(context, column, function.toScript());
+ }
+
}
}
Modified:
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 2008-01-12
12:04:13 UTC (rev 5324)
+++
trunk/ui/dataTable/src/main/resources/org/richfaces/renderkit/html/scripts/data-table.js 2008-01-12
13:01:03 UTC (rev 5325)
@@ -1,6 +1,4 @@
-if (!window.RichFaces) {
- window.RichFaces = {};
-}
+if (!window.RichFaces) var RichFaces = {};
@@ -86,27 +84,34 @@
this.tableId = tableId;
this.columnId = columnId;
this.sortExpression = sortExpression;
- this.onclick = this.invoke.bindAsEventListener(this);
+ this.prepareEvents();
+ //TODO:Set cursor via clazz
+ //element.setStyle({cursor: "pointer"});
- var element = $(this.id);
- element.observe("click", this.onclick);
- element.setStyle({cursor: "pointer"});
-
RichFaces.SortController.registerControl(this);
},
+
+ prepareEvents : function() {
+ this.onclick = this.invoke.bindAsEventListener(this);
+ var element = this.getElement();
+ element.observe("click", this.onclick);
+ },
+ getElement : function () {
+ return $($(this.id).parentNode);
+ },
displaySortedAscending : function() {
- $(this.id)
+ this.getElement()
.removeClassName("rich-sort-desc")
.addClassName("rich-sort-asc");
},
displaySortedDescending : function() {
- $(this.id)
+ this.getElement()
.removeClassName("rich-sort-asc")
.addClassName("rich-sort-desc");
},
displayNotSortedAtAll : function() {
- $(this.id)
+ this.getElement()
.removeClassName("rich-sort-desc")
.removeClassName("rich-sort-asc");
},
@@ -268,4 +273,20 @@
}
-});
\ No newline at end of file
+});
+RichFaces.SortControl.Server = Class.create(RichFaces.SortControl, {
+ invoke : function(event) {
+ $(this.id + 's').click();
+ }
+});
+RichFaces.SortControl.Ajax = Class.create(RichFaces.SortControl, {
+ initialize: function(id, f) {
+ this.id = id;
+ this.f = f;
+ this.prepareEvents();
+ },
+ invoke : function(event) {
+ this.f(event);
+ }
+});
+