Author: abelevich
Date: 2007-05-28 14:11:36 -0400 (Mon, 28 May 2007)
New Revision: 900
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataModelExt.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataRange.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataModelExt.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataRange.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/SequenceDataModelExt.java
Log:
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataModelExt.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataModelExt.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataModelExt.java 2007-05-28
18:11:36 UTC (rev 900)
@@ -0,0 +1,82 @@
+/*
+ * 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/ArrayDataModelExt.java,v
$
+ * $Revision: 1.2 $
+ */
+
+package org.richfaces.model.impl;
+
+import java.util.Arrays;
+
+import org.richfaces.model.DataRange;
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ArrayDataModelExt extends SequenceDataModelExt {
+
+ private Object [] wrappedData;
+ private int rowIndex;
+ public ArrayDataModelExt(Object [] array) {
+ wrappedData = array;
+ }
+
+ protected DataRange createDataRange(int startRow, int endRow,
+ SortOrder sortOrder) {
+
+ if (sortOrder != null && sortOrder.getSortColumn() != -1) {
+ Arrays.sort(wrappedData, getComparator(sortOrder)) ;
+ }
+
+ return new ArrayDataRange(0, getRowCount(), sortOrder, wrappedData);
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ return wrappedData.length;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ public int getRowIndex() {
+ return rowIndex;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ return wrappedData;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return rowIndex < wrappedData.length;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ wrappedData = (Object[]) data;
+ }
+
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataRange.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataRange.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ArrayDataRange.java 2007-05-28
18:11:36 UTC (rev 900)
@@ -0,0 +1,45 @@
+/*
+ * 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/ArrayDataRange.java,v
$
+ * $Revision: 1.2 $
+ */
+
+package org.richfaces.model.impl;
+
+import org.richfaces.model.DataRange;
+import org.richfaces.model.SortOrder;
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ArrayDataRange extends DataRange {
+
+ private Object [] wrapped;
+
+ /**
+ * @param startRow
+ * @param endRow
+ * @param sortOrder
+ * @param wrappedData
+ */
+ public ArrayDataRange(int startRow, int endRow, SortOrder sortOrder,
+ Object [] wrappedData) {
+ super(startRow, endRow, sortOrder);
+ wrapped = wrappedData;
+ }
+
+ /**
+ * @see com.exadel.jsf.model.DataRange#getRowData(int)
+ */
+ public Object getRowData(int index) {
+ // TODO Auto-generated method stub
+ return ((Object[]) wrapped)[index];
+ }
+
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataModelExt.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataModelExt.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataModelExt.java 2007-05-28
18:11:36 UTC (rev 900)
@@ -0,0 +1,69 @@
+/*
+ * 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/ListDataModelExt.java,v
$
+ * $Revision: 1.5 $
+ */
+
+package org.richfaces.model.impl;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.richfaces.model.DataRange;
+import org.richfaces.model.SortOrder;
+
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ListDataModelExt extends SequenceDataModelExt {
+ private List wrappedData;
+ private int rowIndex;
+
+ public ListDataModelExt(List wrappedData) {
+ this.wrappedData = wrappedData;
+ }
+
+ protected DataRange createDataRange(int startRow, int endRow, SortOrder sortOrder) {
+ List wrapped = (List) getWrappedData();
+ boolean shouldSort = sortOrder != null && sortOrder.getSortColumn() != -1;
+ if (shouldSort) {
+ Comparator comparator = getComparator(sortOrder);
+ if (comparator != null) {
+ Collections.sort(wrapped, comparator);
+ }
+ }
+ return new ListDataRange(0, getRowCount(), sortOrder, wrapped);
+ }
+
+ public int getRowCount() {
+ return wrappedData.size();
+ }
+
+ public int getRowIndex() {
+ return rowIndex;
+ }
+
+ public Object getWrappedData() {
+ return wrappedData;
+ }
+
+ public boolean isRowAvailable() {
+ return rowIndex < wrappedData.size();
+ }
+
+ public void setRowIndex(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ public void setWrappedData(Object data) {
+ wrappedData = (List) data;
+ }
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataRange.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataRange.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/ListDataRange.java 2007-05-28
18:11:36 UTC (rev 900)
@@ -0,0 +1,56 @@
+/*
+ * 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/ListDataRange.java,v
$
+ * $Revision: 1.2 $
+ */
+
+package org.richfaces.model.impl;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.richfaces.model.DataRange;
+import org.richfaces.model.SortOrder;
+
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ListDataRange extends DataRange {
+
+ private int lastIndex = -1;;
+ private transient Iterator wrappedIterator;
+ private List list;
+ /**
+ * @param startRow
+ * @param endRow
+ * @param sortOrder
+ * @param wrappedData
+ */
+ public ListDataRange(int startRow, int endRow, SortOrder sortOrder, List wrappedData) {
+ super(startRow, endRow, sortOrder);
+ list = wrappedData;
+ }
+
+ /**
+ * @see com.exadel.jsf.model.DataRange#getRowData(int)
+ */
+ public Object getRowData(int index) {
+
+ if (index >= 0 && index - lastIndex == 1 && wrappedIterator != null)
{
+
+ } else {
+ wrappedIterator = list.listIterator(index);
+ }
+
+ lastIndex = index;
+ return wrappedIterator.next();
+ }
+
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/PropertyResolverComparator.java 2007-05-28
18:11:36 UTC (rev 900)
@@ -0,0 +1,84 @@
+/*
+ * 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.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;
+
+ 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/scrollable-grid/src/main/java/org/richfaces/model/impl/SequenceDataModelExt.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/SequenceDataModelExt.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/impl/SequenceDataModelExt.java 2007-05-28
18:11:36 UTC (rev 900)
@@ -0,0 +1,64 @@
+/*
+ * 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/SequenceDataModelExt.java,v
$
+ * $Revision: 1.4 $
+ */
+
+package org.richfaces.model.impl;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.richfaces.model.ScrollableGridDataModel2;
+import org.richfaces.model.SortOrder;
+
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class SequenceDataModelExt extends ScrollableGridDataModel2 {
+
+ private transient Map comparators;
+
+
+ /**
+ *
+ */
+ public SequenceDataModelExt() {
+ super();
+ }
+
+ protected Comparator getComparator(SortOrder sortOrder) {
+ Comparator comp = (Comparator) getComparators().get(sortOrder);
+ if (comp == null) {
+ comp = createComparator(sortOrder);
+ }
+
+ if (comp != null) {
+ getComparators().put(sortOrder, comp);
+ }
+
+ return comp;
+ }
+
+ protected Comparator createComparator(SortOrder sortOrder) {
+ return new PropertyResolverComparator(sortOrder);
+ }
+
+ protected Map getComparators() {
+ if (comparators == null) {
+ comparators = new HashMap();
+
+ }
+ return comparators;
+ }
+
+
+}
\ No newline at end of file