Author: maksimkaszynski
Date: 2007-07-23 14:51:52 -0400 (Mon, 23 Jul 2007)
New Revision: 1806
Added:
trunk/framework/impl-parent/
trunk/framework/impl-parent/pom.xml
trunk/sandbox/impl/
trunk/sandbox/impl/pom.xml
trunk/sandbox/impl/src/
trunk/sandbox/impl/src/main/
trunk/sandbox/impl/src/main/java/
trunk/sandbox/impl/src/main/java/org/
trunk/sandbox/impl/src/main/java/org/richfaces/
trunk/sandbox/impl/src/main/java/org/richfaces/model/
trunk/sandbox/impl/src/main/java/org/richfaces/model/DataModelCache.java
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ArrayDataModel.java
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ListDataModel.java
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/SimpleGridDataModel.java
trunk/sandbox/impl/src/main/java/org/richfaces/model/selection/
trunk/sandbox/impl/src/main/java/org/richfaces/model/selection/ClientSelection.java
trunk/sandbox/impl/src/test/
trunk/sandbox/impl/src/test/java/
trunk/sandbox/impl/src/test/java/org/
trunk/sandbox/impl/src/test/java/org/richfaces/
trunk/sandbox/impl/src/test/java/org/richfaces/model/
trunk/sandbox/impl/src/test/java/org/richfaces/model/selection/
trunk/sandbox/impl/src/test/java/org/richfaces/model/selection/ClientSelectionTest.java
Modified:
trunk/framework/impl/pom.xml
trunk/framework/pom.xml
trunk/framework/test/pom.xml
trunk/pom.xml
trunk/sandbox/api/pom.xml
trunk/sandbox/pom.xml
Log:
introduced framework/impl-parent and sandbox/impl modules
Modified: trunk/framework/impl/pom.xml
===================================================================
--- trunk/framework/impl/pom.xml 2007-07-23 18:00:49 UTC (rev 1805)
+++ trunk/framework/impl/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -3,9 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <artifactId>framework</artifactId>
- <groupId>org.richfaces</groupId>
+ <artifactId>impl-parent</artifactId>
+ <groupId>org.richfaces.framework</groupId>
<version>3.1.0-SNAPSHOT</version>
+ <relativePath>../impl-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.richfaces.framework</groupId>
@@ -94,209 +95,6 @@
</plugins>
</build>
</profile>
- <profile>
- <id>jsf1_1</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- <property>
- <name>jsfVersion</name>
- <value>1.1</value>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.4</source>
- <target>1.4</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jsp-api</artifactId>
- <version>2.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-api</artifactId>
- <version>1.1_02</version>
- <exclusions>
- <exclusion>
- <artifactId>jsp-api</artifactId>
- <groupId>javax.servlet.jsp</groupId>
- </exclusion>
- <exclusion>
- <artifactId>jstl</artifactId>
- <groupId>javax.servlet.jsp.jstl</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-impl</artifactId>
- <version>1.1_02</version>
- <scope>runtime</scope>
- <exclusions>
- <exclusion>
- <artifactId>jsp-api</artifactId>
- <groupId>javax.servlet.jsp</groupId>
- </exclusion>
- <exclusion>
- <artifactId>jstl</artifactId>
- <groupId>javax.servlet.jsp.jstl</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- <version>1.0</version>
- </dependency>
- </dependencies>
- </profile>
- <profile>
- <id>jsf1_2</id>
- <activation>
- <property>
- <name>jsfVersion</name>
- <value>1.2</value>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0</version>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>
- build-helper-maven-plugin
- </artifactId>
- <executions>
- <execution>
- <id>add-source</id>
- <phase>process-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/main/jsf12</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet.jsp</groupId>
- <artifactId>jsp-api</artifactId>
- <version>2.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-api</artifactId>
- <version>1.2_03</version>
- </dependency>
- <dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-impl</artifactId>
- <version>1.2_03</version>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
- </profile>
</profiles>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>opensymphony</groupId>
- <artifactId>oscache</artifactId>
- <version>2.3</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>com.sun.facelets</groupId>
- <artifactId>jsf-facelets</artifactId>
- <version>1.1.11</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>javax.el</groupId>
- <artifactId>el-api</artifactId>
- <version>1.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>nekohtml</groupId>
- <artifactId>nekohtml</artifactId>
- <version>0.9.5</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.14</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.7.0</version>
- </dependency>
- <dependency>
- <groupId>commons-digester</groupId>
- <artifactId>commons-digester</artifactId>
- <version>1.8</version>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2</version>
- </dependency>
- <dependency>
- <groupId>org.richfaces.framework</groupId>
- <artifactId>richfaces-api</artifactId>
- <version>3.1.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <properties>
- <jsfVersion>1.1</jsfVersion>
- </properties>
</project>
Added: trunk/framework/impl-parent/pom.xml
===================================================================
--- trunk/framework/impl-parent/pom.xml (rev 0)
+++ trunk/framework/impl-parent/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>framework</artifactId>
+ <groupId>org.richfaces</groupId>
+ <version>3.1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>impl-parent</artifactId>
+ <packaging>pom</packaging>
+ <name>Java Server Faces AJAX framework implementation parent file</name>
+ <profiles>
+ <profile>
+ <id>jsf1_1</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ <property>
+ <name>jsfVersion</name>
+ <value>1.1</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>1.1_02</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>jsp-api</artifactId>
+ <groupId>javax.servlet.jsp</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jstl</artifactId>
+ <groupId>javax.servlet.jsp.jstl</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <version>1.1_02</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>jsp-api</artifactId>
+ <groupId>javax.servlet.jsp</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jstl</artifactId>
+ <groupId>javax.servlet.jsp.jstl</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>jsf1_2</id>
+ <activation>
+ <property>
+ <name>jsfVersion</name>
+ <value>1.2</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>
+ build-helper-maven-plugin
+ </artifactId>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/main/jsf12</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>1.2_03</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <version>1.2_03</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>opensymphony</groupId>
+ <artifactId>oscache</artifactId>
+ <version>2.3</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.facelets</groupId>
+ <artifactId>jsf-facelets</artifactId>
+ <version>1.1.11</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>0.9.5</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ <version>1.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-api</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <jsfVersion>1.1</jsfVersion>
+ </properties>
+</project>
+
Modified: trunk/framework/pom.xml
===================================================================
--- trunk/framework/pom.xml 2007-07-23 18:00:49 UTC (rev 1805)
+++ trunk/framework/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -16,6 +16,7 @@
<modules>
<module>api-parent</module>
<module>api</module>
+ <module>impl-parent</module>
<module>impl</module>
<module>test</module>
</modules>
Modified: trunk/framework/test/pom.xml
===================================================================
--- trunk/framework/test/pom.xml 2007-07-23 18:00:49 UTC (rev 1805)
+++ trunk/framework/test/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -7,6 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-test</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
<name>Ajax4Jsf test framework</name>
<url>https://ajax4jsf.dev.java.net</url>
<dependencies>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2007-07-23 18:00:49 UTC (rev 1805)
+++ trunk/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -13,7 +13,7 @@
<module>ui</module>
<module>ui/assembly</module>
<module>extensions</module>
- <module>docs</module>
+ <!--module>docs</module-->
<module>samples</module>
<!--
<module>sandbox</module>
Modified: trunk/sandbox/api/pom.xml
===================================================================
--- trunk/sandbox/api/pom.xml 2007-07-23 18:00:49 UTC (rev 1805)
+++ trunk/sandbox/api/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -11,6 +11,7 @@
<groupId>org.richfaces.sandbox</groupId>
<artifactId>richfaces-sandbox-api</artifactId>
<name>Richfaces Sandbox API</name>
+ <version>3.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.richfaces.framework</groupId>
Property changes on: trunk/sandbox/impl
___________________________________________________________________
Name: svn:ignore
+ .classpath
.project
.settings
target
Added: trunk/sandbox/impl/pom.xml
===================================================================
--- trunk/sandbox/impl/pom.xml (rev 0)
+++ trunk/sandbox/impl/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -0,0 +1,34 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>impl-parent</artifactId>
+ <groupId>org.richfaces.framework</groupId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../../framework/impl-parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.sandbox</groupId>
+ <artifactId>richfaces-sandbox-impl</artifactId>
+ <name>Richfaces Sandbox Implementation</name>
+ <version>3.1.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.richfaces.sandbox</groupId>
+ <artifactId>richfaces-sandbox-api</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-impl</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-test</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
\ No newline at end of file
Added: trunk/sandbox/impl/src/main/java/org/richfaces/model/DataModelCache.java
===================================================================
--- trunk/sandbox/impl/src/main/java/org/richfaces/model/DataModelCache.java
(rev 0)
+++ trunk/sandbox/impl/src/main/java/org/richfaces/model/DataModelCache.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,186 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SerializableDataModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Implementation stores last loaded data, so no additional requests to db will be
performed
+ * Acts as a proxy between the component and original data model
+ * @author Maksim Kaszynski
+ *
+ */
+public class DataModelCache extends GridDataModel {
+
+ private static Log log = LogFactory.getLog(DataModelCache.class);
+
+ private static class DataRange {
+ private int startRow;
+ private int endRow;
+ private SortOrder sortOrder;
+ private List loadedData;
+
+ public DataRange(int startRow, int endRow, SortOrder sortOrder,
+ List loadedData) {
+ super();
+ this.startRow = startRow;
+ this.endRow = endRow;
+ this.sortOrder = sortOrder;
+ this.loadedData = loadedData;
+ }
+
+ public boolean match(int s, int e, SortOrder sortOrder) {
+ return s == startRow
+ && e == endRow
+ && sortOrdersMatch(sortOrder, this.sortOrder);
+ }
+
+ private boolean sortOrdersMatch(SortOrder sortOrder1, SortOrder sortOrder2) {
+ boolean result = sortOrder1 == sortOrder2;
+
+ if (sortOrder1 != null && sortOrder2 != null) {
+ result = sortOrder1.equals(sortOrder2);
+ }
+
+ return result;
+ }
+
+ }
+
+ private Map secondaryMapping = new HashMap();
+
+ private DataRange dataRange;
+
+ private GridDataModel gridDataModel;
+
+ private int rowCount = Integer.MIN_VALUE;
+
+ public DataModelCache(GridDataModel gridDataModel) {
+ super();
+ this.gridDataModel = gridDataModel;
+
+ if (log.isTraceEnabled()) {
+ log.trace("initializing with " + gridDataModel);
+ }
+ }
+
+ public void addDataModelListener(DataModelListener listener) {
+ gridDataModel.addDataModelListener(listener);
+ }
+
+ public DataModelListener[] getDataModelListeners() {
+ return gridDataModel.getDataModelListeners();
+ }
+
+ public Object getObjectById(Object id) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Trying to get object by id" + id);
+ }
+ //First try to find data in inner cache
+ //If not found - get it from original model
+ Object cached = secondaryMapping.get(id);
+
+ if (cached == null) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Cache miss " + id + " falling back to original
model");
+ }
+
+ cached = gridDataModel.getObjectById(id);
+ secondaryMapping.put(id, cached);
+
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("At last found element " + cached);
+ }
+
+ return cached;
+ }
+
+ public int getRowCount() {
+ if (rowCount == Integer.MIN_VALUE) {
+ rowCount = gridDataModel.getRowCount();
+ }
+ return rowCount;
+ }
+
+ public Object getRowData() {
+ Object secondaryMapped = secondaryMapping.get(getRowKey());
+
+ if (secondaryMapped == null) {
+ secondaryMapped = super.getRowData();
+ }
+ return secondaryMapped;
+ }
+
+ public int getRowIndex() {
+ return gridDataModel.getRowIndex();
+ }
+
+ public Object getRowKey() {
+ return gridDataModel.getRowKey();
+ }
+
+ public SerializableDataModel getSerializableModel(Range range) {
+ return gridDataModel.getSerializableModel(range);
+ }
+
+ public Object getWrappedData() {
+ return gridDataModel.getWrappedData();
+ }
+
+ public boolean isRowAvailable() {
+ return secondaryMapping.containsKey(getRowKey()) || super.isRowAvailable();
+ }
+
+ public List loadData(int startRow, int endRow, SortOrder sortOrder) {
+ if (dataRange == null || !dataRange.match(startRow, endRow, sortOrder)) {
+ List data = gridDataModel.loadData(startRow, endRow, sortOrder);
+ dataRange = new DataRange(startRow, endRow, sortOrder, data);
+ }
+ return dataRange.loadedData;
+ }
+
+ public void removeDataModelListener(DataModelListener listener) {
+ gridDataModel.removeDataModelListener(listener);
+ }
+
+ public void setRowIndex(int arg0) {
+ gridDataModel.setRowIndex(arg0);
+ }
+
+ public void setRowKey(Object key) {
+ gridDataModel.setRowKey(key);
+ super.setRowKey(key);
+ }
+
+ public void setWrappedData(Object arg0) {
+ gridDataModel.setWrappedData(arg0);
+ }
+
+ public Object getId(Object o) {
+ return gridDataModel.getId(o);
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+ // TODO Auto-generated method stub
+ super.walk(context, visitor, range, argument);
+ }
+
+}
Added: trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ArrayDataModel.java
===================================================================
--- trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ArrayDataModel.java
(rev 0)
+++
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ArrayDataModel.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,90 @@
+/**
+ *
+ */
+package org.richfaces.model.impl;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ArrayDataModel extends SimpleGridDataModel {
+
+ private Object [] data;
+
+ public ArrayDataModel() {
+ this(null);
+ }
+
+ public ArrayDataModel(Object [] data) {
+ super();
+ setWrappedData(data);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.GridDataModel#loadData(int, int,
org.richfaces.model.SortOrder)
+ */
+ public List loadData(int startRow, int endRow, SortOrder sortOrder) {
+
+ if (data != null && getRowCount() > 0) {
+ Object [] sortedList = data;
+
+ if (sortOrder != null) {
+
+ sortedList = new Object[data.length];
+
+ System.arraycopy(data, 0, sortedList, 0, data.length);
+
+ Comparator comparator = createComparator(sortOrder);
+
+ if (comparator == null) {
+
+ Arrays.sort(sortedList);
+
+ } else {
+
+ Arrays.sort(sortedList, comparator);
+
+ }
+
+ }
+
+ Object [] subArray = new Object[endRow - startRow];
+
+ System.arraycopy(sortedList, startRow, subArray, 0, subArray.length);
+
+ return Arrays.asList(subArray);
+ }
+
+ return Collections.EMPTY_LIST;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ return data == null ? 0 : data.length;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ return data;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ this.data = (Object[]) data;
+ }
+}
Added: trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ListDataModel.java
===================================================================
--- trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ListDataModel.java
(rev 0)
+++
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/ListDataModel.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,84 @@
+/**
+ *
+ */
+package org.richfaces.model.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ListDataModel extends SimpleGridDataModel {
+
+ private List data;
+
+ public ListDataModel() {
+ this(null);
+ }
+
+ public ListDataModel(List data) {
+ super();
+ setWrappedData(data);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.GridDataModel#loadData(int, int,
org.richfaces.model.SortOrder)
+ */
+ public List loadData(int startRow, int endRow, SortOrder sortOrder) {
+
+ if (data != null && getRowCount() > 0) {
+ List sortedList = data;
+
+ if (sortOrder != null) {
+ sortedList = new ArrayList(data);
+
+ Comparator comparator = createComparator(sortOrder);
+
+ if (comparator == null) {
+
+ Collections.sort(sortedList);
+
+ } else {
+
+ Collections.sort(sortedList, comparator);
+
+ }
+
+ }
+
+ return sortedList.subList(startRow, endRow);
+ }
+
+ return Collections.EMPTY_LIST;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ return data == null ? 0 : data.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ return data;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ this.data = (List) data;
+ }
+
+}
Added:
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java
===================================================================
---
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java
(rev 0)
+++
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,88 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2006
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/components/data-view-grid/src/component/com/exadel/jsf/model/impl/PropertyResolverComparator.java,v
$
+ * $Revision: 1.2 $
+ */
+
+package org.richfaces.model.impl;
+
+import java.util.Comparator;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyResolver;
+
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class PropertyResolverComparator implements Comparator {
+
+ private PropertyResolver resolver;
+
+ private SortOrder sortOrder;
+
+ public PropertyResolverComparator(SortOrder sortOrder) {
+ ApplicationFactory factory = (ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application application = factory.getApplication();
+ resolver = application.getPropertyResolver();
+ this.sortOrder = sortOrder;
+ }
+
+ public int compare(Object arg0, Object arg1) {
+ int result = 0;
+ /*Object prop1 = null;
+
+ SortField [ sortOrder.getFields();
+ while (result == 0 && )
+
+ try {
+ prop1 = resolver.getValue(arg0, sortOrder.getSortColumn());
+ } catch (EvaluationException e) {
+ //prop1 remains null
+ }
+
+ Object prop2 = null;
+
+ try {
+ prop2 = resolver.getValue(arg1, sortOrder.getSortColumn());
+ } catch (EvaluationException e) {
+ //prop1 remains null
+ }
+
+ if (prop1 == null) {
+ if (prop2 == null) {
+ result = 0;
+ } else {
+ result = -1;
+ }
+ } else {
+ if (prop2 == null) {
+ result = 1;
+ } else {
+ if (prop1 instanceof Comparable && prop2 instanceof Comparable) {
+ result = ((Comparable) prop1).compareTo(prop2);
+ } else {
+ result = prop1.toString().compareTo(prop2.toString());
+ }
+
+ }
+ }
+ if (!sortOrder.isAscending()) {
+ result = -result;
+ }*/
+ return result;
+ }
+
+}
Added: trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/SimpleGridDataModel.java
===================================================================
--- trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/SimpleGridDataModel.java
(rev 0)
+++
trunk/sandbox/impl/src/main/java/org/richfaces/model/impl/SimpleGridDataModel.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,14 @@
+package org.richfaces.model.impl;
+
+import java.util.Comparator;
+
+import org.richfaces.model.GridDataModel;
+import org.richfaces.model.SortOrder;
+
+public abstract class SimpleGridDataModel extends GridDataModel {
+
+ protected Comparator createComparator(SortOrder sortOrder) {
+ return new PropertyResolverComparator(sortOrder);
+ }
+
+}
Added:
trunk/sandbox/impl/src/main/java/org/richfaces/model/selection/ClientSelection.java
===================================================================
--- trunk/sandbox/impl/src/main/java/org/richfaces/model/selection/ClientSelection.java
(rev 0)
+++
trunk/sandbox/impl/src/main/java/org/richfaces/model/selection/ClientSelection.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,129 @@
+/**
+ *
+ */
+package org.richfaces.model.selection;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ClientSelection implements Serializable{
+
+ private static final long serialVersionUID = 5855157282287053681L;
+
+ public static final String FLAG_RESET = "x";
+
+ public static final String FLAG_ALL = "a";
+
+ private String selectionFlag;
+
+ private List ranges = new ArrayList();
+
+ public ClientSelection() {
+ }
+
+
+ public void addRange(SelectionRange range) {
+ ranges.add(range);
+ }
+
+ public boolean isSelected(int i) {
+ boolean result = false;
+ Iterator iterator = ranges.iterator();
+ while (iterator.hasNext() && !result) {
+ result |= ((SelectionRange) iterator.next()).within(i);
+ }
+ return result;
+ }
+
+ public List getRanges() {
+ return ranges;
+ }
+
+ public void addIndex(int j) {
+ if(this.isSelected(j)) return;
+
+
+
+ SelectionRange firstRange = null;
+
+ int s = ranges.size();
+
+ int insertPosition = 0;
+
+ for(int i = 0; i < s && insertPosition >= 0 ; i++) {
+
+ firstRange = (SelectionRange) ranges.get(i);
+
+ if (firstRange.getStartIndex() == j + 1) {
+
+ firstRange.setStartIndex(j);
+ insertPosition = -1;
+
+ } else if (firstRange.getEndIndex() == j - 1) {
+
+ firstRange.setEndIndex(j);
+
+ if (i + 1 < s) {
+ SelectionRange range2 = (SelectionRange) ranges.get(i + 1);
+
+ if (range2.getStartIndex() == j || range2.getStartIndex() == j + 1) {
+
+ ranges.remove(i + 1);
+
+ firstRange.setEndIndex(range2.getEndIndex());
+ }
+ }
+
+ insertPosition = -1;
+
+ } else if (firstRange.getStartIndex() > j) {
+ insertPosition = i;
+ }
+
+ }
+
+ if (insertPosition >= 0) {
+ firstRange = new SelectionRange(j,j);
+ ranges.add(insertPosition, firstRange);
+
+ return;
+ }
+
+
+ }
+
+ private boolean reset = false;
+ public boolean isReset() {
+ return reset;
+ }
+
+ private boolean selectAll = false;
+ public boolean isSelectAll() {
+ return selectAll;
+ }
+
+
+ public String getSelectionFlag() {
+ return selectionFlag;
+ }
+
+
+ public void setSelectionFlag(String selectionFlag) {
+ this.selectionFlag = selectionFlag;
+
+ reset = false;
+ selectAll = false;
+
+ if (FLAG_ALL.equals(selectionFlag)) {
+ selectAll = true;
+ } else if (FLAG_RESET.equals(selectionFlag)) {
+ reset = true;
+ }
+ }
+}
Added:
trunk/sandbox/impl/src/test/java/org/richfaces/model/selection/ClientSelectionTest.java
===================================================================
---
trunk/sandbox/impl/src/test/java/org/richfaces/model/selection/ClientSelectionTest.java
(rev 0)
+++
trunk/sandbox/impl/src/test/java/org/richfaces/model/selection/ClientSelectionTest.java 2007-07-23
18:51:52 UTC (rev 1806)
@@ -0,0 +1,93 @@
+package org.richfaces.model.selection;
+
+import junit.framework.TestCase;
+
+public class ClientSelectionTest extends TestCase {
+
+
+ private ClientSelection clientSelection;
+
+ public ClientSelectionTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ clientSelection = new ClientSelection();
+ }
+
+ protected void tearDown() throws Exception {
+ clientSelection = null;
+ super.tearDown();
+ }
+
+ public void testAddRange() {
+ SelectionRange range = new SelectionRange(10, 20);
+ clientSelection.addRange(range);
+ assertTrue(clientSelection.isSelected(10));
+ assertTrue(clientSelection.isSelected(11));
+ assertTrue(clientSelection.isSelected(15));
+ assertTrue(clientSelection.isSelected(20));
+ assertFalse(clientSelection.isSelected(0));
+ assertFalse(clientSelection.isSelected(30));
+ }
+
+ public void testIsSelected() {
+ SelectionRange range = new SelectionRange(10, 20);
+ clientSelection.addRange(range);
+ assertTrue(clientSelection.isSelected(10));
+ assertTrue(clientSelection.isSelected(11));
+ assertTrue(clientSelection.isSelected(15));
+ assertTrue(clientSelection.isSelected(20));
+ assertFalse(clientSelection.isSelected(0));
+ assertFalse(clientSelection.isSelected(30));
+ }
+
+ public void testGetRanges() {
+ SelectionRange range = new SelectionRange(10, 20);
+ clientSelection.addRange(range);
+ range = new SelectionRange(30, 40);
+ clientSelection.addRange(range);
+
+ assertNotNull(clientSelection.getRanges());
+ assertEquals(2, clientSelection.getRanges().size());
+ }
+
+ public void testAddIndex() {
+ clientSelection.addRange(new SelectionRange(10, 20));
+ clientSelection.addIndex(21);
+ assertEquals(1, clientSelection.getRanges().size());
+ assertTrue(clientSelection.isSelected(21));
+ clientSelection.addRange(new SelectionRange(23, 30));
+ assertEquals(2, clientSelection.getRanges().size());
+ assertFalse(clientSelection.isSelected(22));
+ assertTrue(clientSelection.isSelected(23));
+
+ clientSelection.addIndex(22);
+ assertTrue(clientSelection.isSelected(22));
+ assertEquals(1, clientSelection.getRanges().size());
+
+
+ }
+
+ public void testSetSelectionFlag() {
+ clientSelection.setSelectionFlag(null);
+ assertFalse(clientSelection.isReset());
+ assertFalse(clientSelection.isSelectAll());
+
+ clientSelection.setSelectionFlag(ClientSelection.FLAG_ALL);
+ assertFalse(clientSelection.isReset());
+ assertTrue(clientSelection.isSelectAll());
+
+ clientSelection.setSelectionFlag(ClientSelection.FLAG_RESET);
+ assertTrue(clientSelection.isReset());
+ assertFalse(clientSelection.isSelectAll());
+
+ clientSelection.setSelectionFlag("zzzzzz");
+ assertFalse(clientSelection.isReset());
+ assertFalse(clientSelection.isSelectAll());
+
+ }
+
+
+}
Modified: trunk/sandbox/pom.xml
===================================================================
--- trunk/sandbox/pom.xml 2007-07-23 18:00:49 UTC (rev 1805)
+++ trunk/sandbox/pom.xml 2007-07-23 18:51:52 UTC (rev 1806)
@@ -19,6 +19,7 @@
-->
<modules>
<module>api</module>
+ <module>impl</module>
<module>ui</module>
<module>samples</module>
</modules>