Author: abelevich
Date: 2007-05-28 14:12:02 -0400 (Mon, 28 May 2007)
New Revision: 902
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/BufferedSequenceRange.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IOExceptionWrapper.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java
Removed:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataRange.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridRange.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SequenceRange.java
Log:
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/BufferedSequenceRange.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/BufferedSequenceRange.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/BufferedSequenceRange.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,67 @@
+/*
+ * 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/BufferedSequenceRange.java,v
$
+ * $Revision: 1.7 $
+ */
+
+package org.richfaces.model;
+
+
+
+/**
+ * @author Maksim Kaszynski
+ * @modified by Anton Belevich
+ */
+public class BufferedSequenceRange extends GridRange{
+
+ private int first = 0;
+ private int last = 0;
+ private boolean readOnly;
+
+ public IterationBounds getIterationBounds() {
+ return new IterationBounds(this.first, this.last);
+ }
+
+ public boolean isReadOnly() {
+ return readOnly;
+ }
+
+ public void setReadOnly(boolean readOnly) {
+ this.readOnly = readOnly;
+ }
+
+ public BufferedSequenceRange(int first, int last) {
+ super();
+ this.first = first;
+ this.last = last;
+ }
+
+ /**
+ * @return the bufferSize
+ */
+ public int getLast() {
+ return last;
+ }
+ /**
+ * @param bufferSize the bufferSize to set
+ */
+ public void setLast(int lastRow) {
+ this.last = lastRow;
+ }
+ /**
+ * @return the first
+ */
+ public int getFirst() {
+ return first;
+ }
+ /**
+ * @param first the first to set
+ */
+ public void setFirst(int first) {
+ this.first = first;
+ }
+}
Modified: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataRange.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataRange.java 2007-05-28
18:11:47 UTC (rev 901)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataRange.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -18,6 +18,7 @@
*
*
* @author Maksim Kaszynski
+ *
*/
public abstract class DataRange {
private SortOrder sortOrder;
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,19 @@
+package org.richfaces.model;
+
+import java.util.Collection;
+
+import org.richfaces.model.snapshot.ObjectLocator;
+
+
+
+public interface GridDataModelFeatures {
+ public ObjectLocator getObjectLocator();
+ public void setObjectLocator(ObjectLocator locator);
+ public void reset();
+// public Collection getSelectedObjects();
+
+// public void setSelection(Selection selection);
+//
+// public Selection getSelection();
+
+}
Modified: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridRange.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridRange.java 2007-05-28
18:11:47 UTC (rev 901)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridRange.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -7,13 +7,14 @@
/**
* @author maksim
+ * @modidied by Anton Belevich
*
*/
public abstract class GridRange implements Range {
private SortOrder sortOrder;
- public abstract IterationBounds getIterationBounds(int rowCount);
+ public abstract IterationBounds getIterationBounds();
public SortOrder getSortOrder() {
return sortOrder;
@@ -22,7 +23,5 @@
public void setSortOrder(SortOrder sortOrder) {
this.sortOrder = sortOrder;
}
-
-
-
+
}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IOExceptionWrapper.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IOExceptionWrapper.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IOExceptionWrapper.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,28 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2007
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/components/data-view-grid/src/component/com/exadel/jsf/model/IOExceptionWrapper.java,v
$
+ * $Revision: 1.1 $
+ */
+
+package org.richfaces.model;
+
+import java.io.IOException;
+
+public final class IOExceptionWrapper extends RuntimeException {
+ private static final long serialVersionUID = -1173652671552790659L;
+
+ private IOException wrappedException;
+
+ public IOExceptionWrapper(IOException wrapped) {
+ super();
+ this.wrappedException = wrapped;
+ }
+
+ public IOException getWrappedException() {
+ return wrappedException;
+ }
+}
\ No newline at end of file
Deleted:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java 2007-05-28
18:11:47 UTC (rev 901)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -1,63 +0,0 @@
-/*
- * 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/IterationBounds.java,v
$
- * $Revision: 1.3 $
- */
-
-package org.richfaces.model;
-
-import java.io.Serializable;
-
-public class IterationBounds implements Serializable {
-
- public interface RowVisitor {
- public void visit(int rowIndex);
- }
-
- private static final long serialVersionUID = 1L;
-
- private int startRow;
- private int endRow;
-
- public IterationBounds() {
- }
- public IterationBounds(int startRow, int endRow) {
- super();
- this.startRow = startRow;
- this.endRow = endRow;
- }
-
- public boolean within(int i) {
- return i >= startRow && i < endRow;
- }
-
- public void iterate(RowVisitor rowVisitor) {
- for (int i = startRow; i < endRow; i++) {
- rowVisitor.visit(i);
- }
- }
-
- public int size() {
- return endRow - startRow;
- }
-
- public int getEndRow() {
- return endRow;
- }
-
- public int getStartRow() {
- return startRow;
- }
- /**
- * @see java.lang.Object#toString()
- */
-
- public String toString() {
- // TODO Auto-generated method stub
- return "[" + startRow + "," + endRow + "]";
- }
-}
\ No newline at end of file
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/IterationBounds.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,62 @@
+/*
+ * 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/IterationBounds.java,v
$
+ * $Revision: 1.3 $
+ */
+
+package org.richfaces.model;
+
+import java.io.Serializable;
+
+public class IterationBounds implements Serializable {
+
+ public interface RowVisitor {
+ public void visit(int rowIndex);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ private int startRow;
+ private int endRow;
+
+ public IterationBounds() {
+ }
+ public IterationBounds(int startRow, int endRow) {
+ super();
+ this.startRow = startRow;
+ this.endRow = endRow;
+ }
+
+ public boolean within(int i) {
+ return i >= startRow && i < endRow;
+ }
+
+ public void iterate(RowVisitor rowVisitor) {
+ for (int i = startRow; i < endRow; i++) {
+ rowVisitor.visit(i);
+ }
+ }
+
+ public int size() {
+ return endRow - startRow;
+ }
+
+ public int getEndRow() {
+ return endRow;
+ }
+
+ public int getStartRow() {
+ return startRow;
+ }
+ /**
+ * @see java.lang.Object#toString()
+ */
+
+ public String toString() {
+ return "[" + startRow + "," + endRow + "]";
+ }
+}
\ No newline at end of file
Added: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,54 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2007
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/components/data-view-grid/src/component/com/exadel/jsf/model/ModelContext.java,v
$
+ * $Revision: 1.1 $
+ */
+
+package org.richfaces.model;
+
+import org.ajax4jsf.ajax.repeat.ExtendedDataModel;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ModelContext {
+
+ public class ModelState {
+ Object rowKey;
+ }
+
+ private ExtendedDataModel model;
+
+ public ModelContext(ExtendedDataModel model) {
+ this.model = model;
+ }
+
+ public void executeInContext(ModelContextTask task) {
+ ModelState modelState = createState();
+ recordState(modelState, model);
+
+
+ task.execute(model);
+
+ replayState(modelState, model);
+
+ }
+
+ protected ModelState createState() {
+ return new ModelState();
+ }
+
+ protected void recordState(ModelState modelState, ExtendedDataModel model) {
+ modelState.rowKey = model.getRowKey();
+ }
+
+ protected void replayState(ModelState modelState, ExtendedDataModel model) {
+ model.setRowKey(modelState.rowKey);
+ }
+
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,8 @@
+package org.richfaces.model;
+
+import org.ajax4jsf.ajax.repeat.ExtendedDataModel;
+
+public interface ModelContextTask {
+
+ public void execute(ExtendedDataModel model);
+}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java 2007-05-28
18:11:47 UTC (rev 901)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -11,23 +11,17 @@
public class ScrollableGridDataModel extends SequenceDataModel{
- private SortOrder sortOrder;
-
-
public ScrollableGridDataModel(DataModel model) {
super(model);
}
- public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
+// public void createDataRange(GridVisualModel model){
+//
+// }
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
super.walk(context, visitor, range, argument);
}
- public SortOrder getSortOrder(){
- return sortOrder;
- }
- public void setSortOrder(SortOrder sortOrder){
- this.sortOrder = sortOrder;
- }
}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,215 @@
+/*
+ * 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/GridDataModel.java,v
$
+ * $Revision: 1.14 $
+ */
+
+package org.richfaces.model;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.ajax.repeat.DataVisitor;
+import org.ajax4jsf.ajax.repeat.ExtendedDataModel;
+import org.ajax4jsf.ajax.repeat.Range;
+import org.ajax4jsf.ajax.repeat.SerializableDataModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.component.UIDataGrid;
+import org.richfaces.model.snapshot.DataModelSnapshot;
+import org.richfaces.model.snapshot.ObjectLocator;
+
+
+
+/**
+ * To effectively use {@link UIDataGrid} component, a data model is to be
+ * defined.
+ *
+ * Data model to deal with underlying data source. Support for partial load of
+ * data window and sorting. Subclasses must implement
+ * {@link #createDataRange(int, int, SortOrder)} method. This class is mostly
+ * targetted to database fetches, where
+ * {@link #createDataRange(int, int, SortOrder)} method accesses underlying data
+ * source and wraps select result into DataRange object.
+ *
+ * <p>
+ * State saving/restore works as follows:
+ * </p>
+ * <ul>
+ * <li> If {@link #getObjectLocator()} call returns {@link ObjectLocator}
+ * instance, it is used to create a snapshot of model data with object
+ * identifiers instead of full-blown objects. Then the snapshot is saved within
+ * state, and on restore state ObjectLocator is employed to load objects by
+ * their ids. </li>
+ * <li> If there's no {@link ObjectLocator} instance, snapshot is not
+ * serialized. </li>
+ * </ul>
+ *
+ * @author Maksim Kaszynski
+ */
+public abstract class ScrollableGridDataModel2 extends ExtendedDataModel implements
+ GridDataModelFeatures {
+
+ private static final Log log = LogFactory.getLog(ScrollableGridDataModel2.class);
+
+ private final class BearerSettings {
+ SortOrder sortOrder;
+ int startRow = -1;
+ int endRow = -1;
+ public BearerSettings(int startRow, int endRow, SortOrder sortOrder) {
+ super();
+ this.sortOrder = sortOrder;
+ this.startRow = startRow;
+ this.endRow = endRow;
+ }
+
+
+ }
+
+ private ObjectLocator objectLocator;
+
+ private SortOrder sortOrder;
+
+// private Selection selection;
+
+ private DataRange bearer;
+
+ private BearerSettings bearerSettings = null;
+
+ /**
+ * Create new {@link DataRange} - i.e. load a new data window from data
+ * base. Subclasses need to define this method - for example to get
+ * {ResultSet} from database, or ScrollableResult from hibernate.
+ *
+ * @param startRow
+ * @param endRow
+ * @param sortOrder
+ * @return
+ */
+ protected abstract DataRange createDataRange(int startRow, int endRow,
+ SortOrder sortOrder);
+
+ /**
+ * reset data range - we need to load a new one
+ *
+ */
+ public void reset() {
+ bearer = null;
+ sortOrder = null;
+// selection = null;
+ bearerSettings = null;
+ }
+
+ public void setObjectLocator(ObjectLocator objectLocator) {
+ this.objectLocator = objectLocator;
+ }
+
+ public ObjectLocator getObjectLocator() {
+ return objectLocator;
+ }
+
+ public Object getRowData() {
+ int index = getRowIndex();
+ log.debug("GridDataModel.getRowData() " + index );
+ if (index == -1) {
+ return null;
+ }
+
+ if (bearer == null && bearerSettings != null) {
+ bearer = createDataRange(bearerSettings.startRow,
+ bearerSettings.endRow, bearerSettings.sortOrder);
+ bearerSettings = null;
+ }
+
+ if (bearer == null || !bearer.hit(index)) {
+ bearer = createDataRange(index, index + 1, sortOrder);
+ }
+
+ return bearer.getRowData(index);
+ }
+
+ public void walk(final FacesContext context, final DataVisitor visitor,
+ final Range range, final Object argument) throws IOException {
+
+ int rowCount = getRowCount();
+
+ if (rowCount == 0) {
+ return;
+ }
+
+ GridRange sequenceRange = (GridRange) range;
+
+ sortOrder = sequenceRange.getSortOrder();
+
+ IterationBounds bounds = sequenceRange.getIterationBounds();
+
+ bearer = null;
+ bearerSettings = new BearerSettings(bounds.getStartRow(), bounds.getEndRow(),
sortOrder);
+
+ try {
+ bounds.iterate(new IterationBounds.RowVisitor() {
+ public void visit(int rowIndex) {
+ Integer rowKey = new Integer(rowIndex);
+ try {
+ visitor.process(context, rowKey, argument);
+ } catch (IOException e) {
+ throw new IOExceptionWrapper(e);
+ }
+ }
+ });
+
+ } catch (IOExceptionWrapper e) {
+ throw e.getWrappedException();
+ }
+ }
+
+ public Object getRowKey() {
+ int rowIndex = getRowIndex();
+ if (rowIndex == -1) {
+ return null;
+ }
+ return new Integer(rowIndex);
+ }
+
+ public void setRowKey(Object key) {
+ if (key == null) {
+ setRowIndex(-1);
+ } else {
+ setRowIndex(((Integer) key).intValue());
+ }
+ }
+
+// public Collection getSelectedObjects() {
+// return SelectionExtractor.extractSelection(this);
+// }
+//
+// public void setSelection(Selection selection) {
+// this.selection = selection;
+// }
+//
+// public Selection getSelection() {
+// return selection;
+// }
+
+ public SerializableDataModel getSerializableModel(Range range) {
+ BufferedSequenceRange sequenceRange = (BufferedSequenceRange) range;
+ ObjectLocator locator = getObjectLocator();
+ if (locator != null) {
+ return new DataModelSnapshot(this, sequenceRange);
+ }
+ return super.getSerializableModel(range);
+ }
+
+ public SortOrder getSortOrder() {
+ return sortOrder;
+ }
+
+ public void setSortOrder(SortOrder sortOrder) {
+ this.sortOrder = sortOrder;
+ }
+}
\ No newline at end of file
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SequenceRange.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SequenceRange.java 2007-05-28
18:11:47 UTC (rev 901)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SequenceRange.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -37,29 +37,29 @@
/* (non-Javadoc)
* @see com.exadel.jsf.model.GridRange#getIterationBounds(int)
*/
- public IterationBounds getIterationBounds(int rowCount) {
- int a = start, b = end;
-
- if (start > rowCount) {
- a = rowCount;
- }
-
- if (end > rowCount) {
- b = rowCount;
- }
- if (b < 0) {
- b = rowCount;
- }
-
- if (a > b) {
- int c = a;
-
- a = b;
- b = c;
- }
-
-
- return new IterationBounds(a,b);
+ public IterationBounds getIterationBounds() {
+// int a = start, b = end;
+//
+// if (start > rowCount) {
+// a = rowCount;
+// }
+//
+// if (end > rowCount) {
+// b = rowCount;
+// }
+// if (b < 0) {
+// b = rowCount;
+// }
+//
+// if (a > b) {
+// int c = a;
+//
+// a = b;
+// b = c;
+// }
+//
+//
+ return new IterationBounds(0,0);
}
}
Deleted: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java 2007-05-28
18:11:47 UTC (rev 901)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -1,72 +0,0 @@
-package org.richfaces.model;
-
-import java.io.Serializable;
-/**
- *
- * @author Maksim Kaszynski
- *
- */
-public class SortOrder implements Serializable {
-
- private static final long serialVersionUID = 2423450561570551363L;
-
- private String sortField;
-
- private boolean ascending;
-
- public SortOrder(String sortField, boolean _ascending) {
- super();
- this.sortField = sortField;
- this.ascending = _ascending;
- }
-
- public SortOrder() {
- super();
- }
-
- public boolean isAscending() {
- return ascending;
- }
-
- public void setAscending(boolean ascending) {
- this.ascending = ascending;
- }
-
- public String getSortField() {
- return sortField;
- }
-
- public void setSortField(String sortField) {
- this.sortField = sortField;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return "SortOrder: {field:" + sortField + ", ascending: " +
ascending
- + "}";
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
-
- if (obj instanceof SortOrder) {
- SortOrder sortOrder = (SortOrder) obj;
- return sortField.equals(sortOrder.sortField)
- && ascending == sortOrder.ascending;
- }
-
- return super.equals(obj);
- }
-
- public int hashCode() {
- int c = sortField.hashCode();
- if (ascending) {
- c = -c;
- }
- return c;
- }
-}
\ No newline at end of file
Added: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/SortOrder.java 2007-05-28
18:12:02 UTC (rev 902)
@@ -0,0 +1,82 @@
+package org.richfaces.model;
+
+import java.io.Serializable;
+/**
+ *
+ * @author Maksim Kaszynski
+ *
+ *
+ */
+public class SortOrder implements Serializable {
+
+ private static final long serialVersionUID = 2423450561570551363L;
+
+ private boolean ascending;
+
+ private int sortColumn = -1;
+
+ private int startRow = -1;
+
+ private int dataIndex = -1;
+
+
+ public SortOrder( int sortColumn, int startRow, int dataIndex, boolean ascending) {
+ super();
+ this.sortColumn = sortColumn;
+ this.ascending = ascending;
+ this.startRow = startRow;
+ this.dataIndex = dataIndex;
+ }
+
+ public SortOrder() {
+ super();
+ }
+
+ public boolean isAscending() {
+ return ascending;
+ }
+
+ public void setAscending(boolean ascending) {
+ this.ascending = ascending;
+ }
+
+ public int getSortColumn() {
+ return sortColumn;
+ }
+
+ public void setSortColumn(int sortColumn) {
+ this.sortColumn = sortColumn;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return "SortOrder: {field:" + sortColumn + ", ascending: " +
ascending
+ + "}";
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+
+ if (obj instanceof SortOrder) {
+ SortOrder sortOrder = (SortOrder) obj;
+ return sortColumn == sortOrder.sortColumn
+ && startRow == sortOrder.startRow
+ && dataIndex == sortOrder.dataIndex
+ && ascending == sortOrder.ascending;
+
+ }
+ return super.equals(obj);
+ }
+
+ public int hashCode() {
+ int c = (new Integer(sortColumn)).hashCode();
+ if (ascending) {
+ c = -c;
+ }
+ return c;
+ }
+}
\ No newline at end of file