Author: maksimkaszynski
Date: 2007-06-05 09:06:12 -0400 (Tue, 05 Jun 2007)
New Revision: 1017
Added:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel2.java
trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/commons-logging.properties
trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/logging.properties
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/Entity.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/Selection.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Channel.java
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Issue.java
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/pages/scrollable-grid.xhtml
trunk/sandbox/scrollable-grid/src/main/config/component/scrollable-grid.xml
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Log:
fixed save state
Modified: trunk/sandbox/scrollable-grid/src/main/config/component/scrollable-grid.xml
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/config/component/scrollable-grid.xml 2007-06-05
12:54:25 UTC (rev 1016)
+++ trunk/sandbox/scrollable-grid/src/main/config/component/scrollable-grid.xml 2007-06-05
13:06:12 UTC (rev 1017)
@@ -43,7 +43,12 @@
<description>grid width</description>
<defaultvalue>"700px"</defaultvalue>
</property>
-
+
+ <property attachedstate="true">
+ <name>sortOrder</name>
+ <classname>org.richfaces.model.SortOrder</classname>
+ </property>
+
&ui_component_attributes;
</component>
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-06-05
12:54:25 UTC (rev 1016)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -27,10 +27,12 @@
import org.apache.commons.collections.iterators.IteratorChain;
import org.richfaces.event.sort.SortEvent;
import org.richfaces.model.BufferedSequenceRange;
+import org.richfaces.model.GridDataModel;
import org.richfaces.model.ScrollableGridDataModel;
import org.richfaces.model.SortOrder;
import org.richfaces.model.impl.ArrayDataModelExt;
import org.richfaces.model.impl.ListDataModelExt;
+import org.richfaces.model.selection.Selection;
@@ -52,19 +54,13 @@
private Collection responseData = new ArrayList();
- private SortOrder sortOrder;
-
public Collection getResponseData() {
return responseData;
}
- public SortOrder getSortOrder() {
- return sortOrder;
- }
+ public abstract SortOrder getSortOrder();
- public void setSortOrder(SortOrder sortOrder) {
- this.sortOrder = sortOrder;
- }
+ public abstract void setSortOrder(SortOrder sortOrder) ;
public void setResponseData(Collection responseData) {
this.responseData = responseData;
@@ -107,6 +103,10 @@
ScrollableGridDataModel model = null;
Object value = getValue();
+ if (value instanceof GridDataModel) {
+ return (GridDataModel) value;
+ }
+
if (value instanceof ScrollableGridDataModel) {
ScrollableGridDataModel dataModel = (ScrollableGridDataModel) value;
model = dataModel;
@@ -152,9 +152,6 @@
values[1] = _requestedRows;
values[2] = _startRow;
values[3] = _dataIndex;
- values[4] = responseData;
- values[5] = saveAttachedState(context, sortOrder);
-
return (Object)values;
}
@@ -166,9 +163,6 @@
_requestedRows = (Integer)values[1];
_startRow = (Integer)values[2];
_dataIndex = (Integer)values[3];
- responseData = (Collection)values[4];
- sortOrder = (SortOrder) restoreAttachedState(context, values[5]);
-
}
protected Iterator dataChildren() {
Added: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/Entity.java
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/Entity.java
(rev 0)
+++ trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/Entity.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,14 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.Serializable;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface Entity {
+ public Serializable getId();
+}
Added: trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,121 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class GridDataModel extends ExtendedDataModel {
+
+ private static final Log log = LogFactory.getLog(GridDataModel.class);
+
+ private Serializable rowKey;
+
+ private Map mapping;
+
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ public void setRowKey(Object key) {
+ rowKey = (Serializable) key;
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+
+ if (log.isTraceEnabled()) {
+ log.trace("Starting walk");
+ }
+
+ BufferedSequenceRange sequenceRange = (BufferedSequenceRange) range;
+
+ int startIndex = sequenceRange.getFirst();
+ int last = sequenceRange.getLast();
+
+ List objects = loadData(startIndex, last, sequenceRange.getSortOrder());
+
+ mapping = new HashMap();
+
+ for (int i = 0; i < objects.size(); i++,startIndex++) {
+ Object data = objects.get(i);
+ Object key = null;
+ if (data instanceof Entity) {
+ Entity entity = (Entity) data;
+ key = entity.getId();
+ } else {
+ key = new Integer(startIndex);
+ }
+ mapping.put(key, data);
+
+ visitor.process(context, key, argument);
+
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("Ending walk");
+ }
+
+ }
+
+ public abstract List loadData(int startRow, int endRow, SortOrder sortOrder);
+
+ public abstract Object getObjectById(Serializable id);
+
+ private Object loadAndMap(Serializable id) {
+
+ if (log.isTraceEnabled()) {
+ log.trace("loadAndMap " + id);
+ }
+
+ Object o = getObjectById(id);
+ if (o != null) {
+ if (mapping == null) {
+ mapping = new HashMap();
+ }
+ mapping.put(id, o);
+ }
+ return o;
+ }
+
+ public Object getRowData() {
+
+ if (mapping != null && mapping.containsKey(rowKey)) {
+ return mapping.get(rowKey);
+ } else {
+ return loadAndMap(rowKey);
+ }
+
+ }
+
+ public int getRowIndex() {
+ throw new UnsupportedOperationException("getRowIndex");
+ }
+
+ public boolean isRowAvailable() {
+ //boolean result
+ return mapping != null && mapping.containsKey(getRowKey());
+ }
+
+ public void setRowIndex(int arg0) {
+ throw new UnsupportedOperationException("setRowIndex");
+ }
+
+
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/Selection.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/Selection.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/Selection.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.richfaces.model.selection;
+
+import java.io.Serializable;
+import java.util.Iterator;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface Selection extends Serializable {
+
+ public Iterator getKeys();
+
+ public int size();
+
+ public boolean isSelected(Serializable rowKey);
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.richfaces.model.selection;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimpleSelection implements Selection {
+
+ private static final long serialVersionUID = 1L;
+
+ private Set keys = new HashSet();
+
+ public boolean addKey(Serializable rowKey) {
+ return keys.add(rowKey);
+ }
+
+ public Iterator getKeys() {
+ return keys.iterator();
+ }
+
+ public int size() {
+ return keys.size();
+ }
+
+ public boolean isSelected(Serializable rowKey) {
+ return keys.contains(rowKey);
+ }
+
+}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-05
12:54:25 UTC (rev 1016)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -223,7 +223,7 @@
boolean normalTRRendered = false;
- System.out.println("row index: " + grid.getRowIndex());
+ //System.out.println("row index: " + grid.getRowIndex());
for (Iterator iter = grid.getChildren().iterator(); iter.hasNext(); ) {
UIComponent kid = (UIComponent) iter.next();
Added:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel2.java
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel2.java
(rev 0)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel2.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package org.richfaces.demo.datagrid.bean;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.richfaces.demo.datagrid.model.Channel;
+import org.richfaces.model.GridDataModel;
+import org.richfaces.model.SortOrder;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ChannelDataModel2 extends GridDataModel {
+
+ private Channel channel;
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.GridDataModel#getObjectById(java.io.Serializable)
+ */
+ @Override
+ public Object getObjectById(Serializable id) {
+ return channel.findById((Integer) id);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.GridDataModel#loadData(int, int,
org.richfaces.model.SortOrder)
+ */
+ @Override
+ public List loadData(int startRow, int endRow, SortOrder sortOrder) {
+ return channel.executeQuery(startRow, endRow, sortOrder);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ @Override
+ public int getRowCount() {
+ return channel.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ @Override
+ public Object getWrappedData() {
+ return channel;
+ }
+
+ @Override
+ public void setWrappedData(Object arg0) {
+ this.channel = (Channel) arg0;
+ }
+
+}
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Channel.java
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Channel.java 2007-06-05
12:54:25 UTC (rev 1016)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Channel.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -17,6 +17,7 @@
import java.util.List;
import java.util.Map;
+import org.richfaces.model.Entity;
import org.richfaces.model.SortOrder;
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Issue.java
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Issue.java 2007-06-05
12:54:25 UTC (rev 1016)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Issue.java 2007-06-05
13:06:12 UTC (rev 1017)
@@ -10,11 +10,15 @@
package org.richfaces.demo.datagrid.model;
+import java.io.Serializable;
+
+import org.richfaces.model.Entity;
+
/**
* @author Maksim Kaszynski
*
*/
-public class Issue {
+public class Issue implements Entity{
private static int issueIndex = 0;
private int index = ++issueIndex;
@@ -373,4 +377,9 @@
return getPriority().getId();
}
+ public Serializable getId() {
+ // TODO Auto-generated method stub
+ return getIndex();
+ }
+
}
Added:
trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/commons-logging.properties
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/commons-logging.properties
(rev 0)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/commons-logging.properties 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,14 @@
+org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
+java.util.logging.config.file=logging.properties
+
+java.util.logging.config.file = logging.properties
+handlers = java.util.logging.ConsoleHandler
+java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
+
+# If you want to provide finer grained logging, restrict the level for the
+# specific package name.
+# For example:
+# org.apache.cactus.server.level = ALL
+# org.apache.commons.httpclient.level = ALL
+# .level = ALL
+.level = ALL
\ No newline at end of file
Added: trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/logging.properties
===================================================================
--- trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/logging.properties
(rev 0)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/resources/logging.properties 2007-06-05
13:06:12 UTC (rev 1017)
@@ -0,0 +1,19 @@
+ # Specify the handlers to create in the root logger
+ # (all loggers are children of the root logger)
+ # The following creates two handlers
+ handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
+
+ # Set the default logging level for the root logger
+ .level = ALL
+
+ # Set the default logging level for new ConsoleHandler instances
+ java.util.logging.ConsoleHandler.level = INFO
+
+ # Set the default logging level for new FileHandler instances
+ java.util.logging.FileHandler.level = ALL
+
+ # Set the default formatter for new ConsoleHandler instances
+ java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+ # Set the default logging level for the logger named com.mycompany
+ com.mycompany.level = ALL
\ No newline at end of file
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/faces-config.xml 2007-06-05
12:54:25 UTC (rev 1016)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/faces-config.xml 2007-06-05
13:06:12 UTC (rev 1017)
@@ -214,6 +214,16 @@
</managed-bean>
<managed-bean>
+ <managed-bean-name>dataModel2</managed-bean-name>
+
<managed-bean-class>org.richfaces.demo.datagrid.bean.ChannelDataModel2</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>wrappedData</property-name>
+ <value>#{jiraService.channel}</value>
+ </managed-property>
+ </managed-bean>
+
+ <managed-bean>
<managed-bean-name>selectionBean</managed-bean-name>
<managed-bean-class>org.richfaces.demo.datagrid.bean.SelectionBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/pages/scrollable-grid.xhtml
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/pages/scrollable-grid.xhtml 2007-06-05
12:54:25 UTC (rev 1016)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/pages/scrollable-grid.xhtml 2007-06-05
13:06:12 UTC (rev 1017)
@@ -37,14 +37,13 @@
<h:form>
<sg:scrollable-grid id="grid"
- value="#{dataModel}"
+ value="#{dataModel2}"
var="issues"
frozenColCount="3"
first="0"
rows="40"
width="800px"
- height="500px"
- visualModel="#{selectionBean.visualModel}">
+ height="500px">
<f:facet name="splash">
<h:panelGroup id="splash">