Author: abelevich
Date: 2007-05-29 06:36:33 -0400 (Tue, 29 May 2007)
New Revision: 922
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java
Removed:
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/ScrollableGridDataModel.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridRange.java
Log:
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java 2007-05-29
10:35:38 UTC (rev 921)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModelFeatures.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -1,7 +1,5 @@
package org.richfaces.model;
-import java.util.Collection;
-
import org.richfaces.model.snapshot.ObjectLocator;
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-29
10:35:38 UTC (rev 921)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridRange.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -23,5 +23,4 @@
public void setSortOrder(SortOrder sortOrder) {
this.sortOrder = sortOrder;
}
-
}
Deleted:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java 2007-05-29
10:35:38 UTC (rev 921)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContext.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -1,54 +0,0 @@
-/*
- * 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);
- }
-
-}
Deleted:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java 2007-05-29
10:35:38 UTC (rev 921)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ModelContextTask.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -1,8 +0,0 @@
-package org.richfaces.model;
-
-import org.ajax4jsf.ajax.repeat.ExtendedDataModel;
-
-public interface ModelContextTask {
-
- public void execute(ExtendedDataModel model);
-}
Deleted:
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-29
10:35:38 UTC (rev 921)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -1,27 +0,0 @@
-package org.richfaces.model;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-import javax.faces.model.DataModel;
-
-import org.ajax4jsf.ajax.repeat.DataVisitor;
-import org.ajax4jsf.ajax.repeat.Range;
-import org.ajax4jsf.ajax.repeat.SequenceDataModel;
-
-public class ScrollableGridDataModel extends SequenceDataModel{
-
- public ScrollableGridDataModel(DataModel model) {
- super(model);
- }
-
-// public void createDataRange(GridVisualModel model){
-//
-// }
-
- public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
- super.walk(context, visitor, range, argument);
- }
-
-
-}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -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 ScrollableGridDataModel extends ExtendedDataModel implements
+ GridDataModelFeatures {
+
+ private static final Log log = LogFactory.getLog(ScrollableGridDataModel.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
Deleted:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java 2007-05-29
10:35:38 UTC (rev 921)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/ScrollableGridDataModel2.java 2007-05-29
10:36:33 UTC (rev 922)
@@ -1,215 +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/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