Author: maksimkaszynski
Date: 2007-06-13 13:18:10 -0400 (Wed, 13 Jun 2007)
New Revision: 1170
Added:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/benchmark/
Modified:
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/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/WEB-INF/web.xml
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/pages/scrollable-grid.xhtml
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataModelCache.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js
Log:
fixed some bugs with data model
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataModelCache.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataModelCache.java 2007-06-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/DataModelCache.java 2007-06-13
17:18:10 UTC (rev 1170)
@@ -113,7 +113,12 @@
}
public Object getRowData() {
- return gridDataModel.getRowData();
+ Object secondaryMapped = secondaryMapping.get(getRowKey());
+
+ if (secondaryMapped == null) {
+ secondaryMapped = super.getRowData();
+ }
+ return secondaryMapped;
}
public int getRowIndex() {
@@ -133,7 +138,7 @@
}
public boolean isRowAvailable() {
- return secondaryMapping.containsKey(getRowKey()) || gridDataModel.isRowAvailable();
+ return secondaryMapping.containsKey(getRowKey()) || super.isRowAvailable();
}
public List loadData(int startRow, int endRow, SortOrder sortOrder) {
@@ -154,6 +159,7 @@
public void setRowKey(Object key) {
gridDataModel.setRowKey(key);
+ super.setRowKey(key);
}
public void setWrappedData(Object arg0) {
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java 2007-06-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/GridDataModel.java 2007-06-13
17:18:10 UTC (rev 1170)
@@ -4,6 +4,7 @@
package org.richfaces.model;
import java.io.IOException;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -22,12 +23,34 @@
*/
public abstract class GridDataModel extends ExtendedDataModel {
+ private static class SimpleRowKey implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+ private int i;
+
+ public SimpleRowKey(int i) {
+ super();
+ this.i = i;
+ }
+
+ public int intValue() {
+ return i;
+ }
+
+ public String toString() {
+ return String.valueOf(i);
+ }
+ }
+
+
private static final Log log = LogFactory.getLog(GridDataModel.class);
private Object rowKey;
private Map mapping;
+ private SortOrder lastSortOrder;
+
public Object getRowKey() {
return rowKey;
}
@@ -47,20 +70,21 @@
int startIndex = sequenceRange.getFirst();
int last = sequenceRange.getLast();
-
- List objects = loadData(startIndex, last, sequenceRange.getSortOrder());
+ lastSortOrder = sequenceRange.getSortOrder();
+
+ List objects = loadData(startIndex, last, lastSortOrder);
+
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);
+ Object key = getId(data);
+
+ if (key == null) {
+ key = new SimpleRowKey(startIndex);
}
+
mapping.put(key, data);
visitor.process(context, key, argument);
@@ -72,11 +96,48 @@
}
}
-
+
+ /**
+ * Load range of data items from the source
+ * @param startRow
+ * @param endRow
+ * @param sortOrder
+ * @return
+ */
public abstract List loadData(int startRow, int endRow, SortOrder sortOrder);
- public abstract Object getObjectById(Object id);
+ /**
+ * This method is the reverse of getObjectId
+ * Default implementation returns null anyway
+ * @param id
+ * @return
+ */
+ public Object getObjectById(Object id) {
+
+ if (id instanceof SimpleRowKey) {
+ int i = ((SimpleRowKey) id).intValue();
+
+ List l = loadData(i, i + 1, lastSortOrder);
+
+ return l.get(0);
+
+ }
+
+ return null;
+ }
+ /**
+ * To get rid of Entity interface, method is introduced
+ * Implementations may override it to provide domain-specific searches
+ * Id should be serializable
+ * @param o
+ * @return
+ */
+ public Object getId(Object o) {
+ return null;
+ }
+
+
private Object loadAndMap(Object id) {
if (log.isTraceEnabled()) {
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js 2007-06-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js 2007-06-13
17:18:10 UTC (rev 1170)
@@ -2,6 +2,7 @@
DOM: {
copyAttributes : function(target, source, opts) {
+
//LOG.debug("copyAttributes");
var attrs = source.attributes;
@@ -80,6 +81,7 @@
},
_clearAttributes : function(node) {
+
var attrs = node.attributes;
if (node.clearAttributes) {
node.clearAttributes();
@@ -190,13 +192,6 @@
if(rowindex >= rowCount){
rowindex -= rowCount;
}
- //var id = baseid + ":f:" + rowindex;
- //var row = Utils.DOM.replaceNode(id, request);
- //id = baseid + ":n:" + rowindex;
- //row = Utils.DOM.replaceNode(id, request);
-
- //var suffixes =
-
[":f:", ":n:"].unbreakableEach(
function(suffix) {
var id = baseid + suffix + rowindex;
@@ -210,6 +205,7 @@
);
}
+
}
);
@@ -219,10 +215,25 @@
dataModel.eventDataReady.fire(localOptions);
}
}
-
-
};
-
+/*
+var _cAtt = Utils.DOM._clearAttributes;
+Utils.DOM._clearAttributes = function() {
+ return;
+ var d1 = new Date().getTime();
+ _cAtt.apply(Utils.DOM, arguments);
+ var d2 = new Date().getTime();
+ ClientUILib.log(ClientUILogger.INFO, "Utils.DOM._clearAttributes " + (d2 - d1)
+ "ms");
+};
+var cAtt = Utils.DOM._clearAttributes;
+Utils.DOM.copyAttributes = function() {
+ return;
+ var d1 = new Date().getTime();
+ cAtt.apply(Utils.DOM, arguments);
+ var d2 = new Date().getTime();
+ ClientUILib.log(ClientUILogger.INFO, "Utils.DOM.copyAttributes " + (d2 - d1) +
"ms");
+};
+*/
Array.prototype.unbreakableEach = function(f) {
for (var i = 0; i < this.length; i++) {
f(this[i], i);
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js 2007-06-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js 2007-06-13
17:18:10 UTC (rev 1170)
@@ -25,6 +25,7 @@
];
this.init2 = this.init.bindAsEventListener(this);
+ this.startUpTime = new Date().getTime();
this.rowCallbacks = [];
@@ -38,19 +39,29 @@
var progress = new ClientUI.common.box.SplashBox(this.splash_id, null, 300, true);
this.setProgressCtrl(progress);
Event.observe(this.eventOnSort, "on sort",
this.onSorted.bindAsEventListener(this));
- this.selectionManager = new ClientUI.controls.grid.SelectionManager(this);
+ if (this.options.selectionInput) {
+ this.selectionManager = new ClientUI.controls.grid.SelectionManager(this);
+ }
+
+ if (this.startUpTime) {
+ ClientUILib.log(ClientUILogger.ERROR, "Load Time'" + (new
Date().getTime() - this.startUpTime) + "' ms");
+ }
},
onSortComplete : function(request, event, data){
var options = request.getJSON("options");
Utils.AJAX.updateRows(options,request,this,this.client_id,
[this.updateSelectionCallBack]);
- this.selectionManager.restoreState();
+ if (this.selectionManager) {
+ this.selectionManager.restoreState();
+ }
},
onScrollComplete : function(request, event, data){
var options = this.dataModel.getCurrentOptions();
Utils.AJAX.updateRows(options,request,this,this.client_id,
[this.updateSelectionCallBack]);
- this.selectionManager.restoreState();
+ if (this.selectionManager) {
+ this.selectionManager.restoreState();
+ }
},
onSorted: function(sortEvent) {
@@ -58,7 +69,9 @@
},
updateSelectionCallBack: function(argMap) {
- this.selectionManager.addListener(argMap.row, argMap.index);
+ if (this.selectionManager) {
+ this.selectionManager.addListener(argMap.row, argMap.index);
+ }
}
});
Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js 2007-06-13 17:11:30
UTC (rev 1169)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js 2007-06-13 17:18:10
UTC (rev 1170)
@@ -203,7 +203,7 @@
}
};
-ClientUILib.load();
+ClientUILib.load(true);
// declare predefined packages
var ClientUI = {
Modified:
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 2007-06-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel2.java 2007-06-13
17:18:10 UTC (rev 1170)
@@ -5,6 +5,8 @@
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.richfaces.demo.datagrid.model.Channel;
import org.richfaces.demo.datagrid.model.Issue;
import org.richfaces.demo.datagrid.model.Key;
@@ -17,6 +19,12 @@
*/
public class ChannelDataModel2 extends GridDataModel {
+ private final Log log = LogFactory.getLog(ChannelDataModel2.class);
+
+ public static final int BIG_QUERY_DELAY = 1000;
+
+ public static final int SMALL_QUERY_DELAY = 500;
+
private Channel channel;
/* (non-Javadoc)
@@ -24,6 +32,22 @@
*/
@Override
public Object getObjectById(Object id) {
+
+ if (log.isTraceEnabled()) {
+ log.trace(id);
+ }
+
+ log.info("sleeping " + SMALL_QUERY_DELAY + "ms");
+
+ try {
+ Thread.sleep(SMALL_QUERY_DELAY);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ log.info("Awoke from slumber");
+
return channel.findIssueByKey((Key) id);
}
@@ -32,6 +56,21 @@
*/
@Override
public List <Issue> loadData(int startRow, int endRow, SortOrder sortOrder) {
+
+ if (log.isTraceEnabled()){
+ log.trace("startRow=" + startRow + ", endRow=" + endRow +
",sortOrder=" + sortOrder);
+ }
+
+ log.info("sleeping " + BIG_QUERY_DELAY);
+
+ try {
+ Thread.sleep(BIG_QUERY_DELAY);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ log.info("Awoke from slumber");
+
return channel.executeQuery(startRow, endRow, 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-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/model/Issue.java 2007-06-13
17:18:10 UTC (rev 1170)
@@ -18,7 +18,7 @@
* @author Maksim Kaszynski
*
*/
-public class Issue implements Entity{
+public class Issue implements Serializable{
private static int issueIndex = 0;
private int index = ++issueIndex;
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-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/faces-config.xml 2007-06-13
17:18:10 UTC (rev 1170)
@@ -263,38 +263,7 @@
</list-entries>
</managed-property>
</managed-bean>
-
- <managed-bean>
- <managed-bean-name>PriorityConverter</managed-bean-name>
-
<managed-bean-class>org.richfaces.demo.converters.PriorityConverter</managed-bean-class>
- <managed-bean-scope>session</managed-bean-scope>
- <managed-property>
- <property-name>prioritiesList</property-name>
- <list-entries>
- <value>#{priority_blocker}</value>
- <value>#{priority_critical}</value>
- <value>#{priority_major}</value>
- <value>#{priority_minor}</value>
- <value>#{priority_cosmetic}</value>
- </list-entries>
- </managed-property>
- </managed-bean>
-
- <!--
-
- <converter>
- <description>converter for issues status</description>
- <converter-id>status_converter</converter-id>
-
<converter-class>org.richfaces.demo.converters.StatusConverter</converter-class>
- </converter>
-<lifecycle>
+ <lifecycle>
<phase-listener>org.richfaces.demo.benchmark.PhaseDemarcationNotifier</phase-listener>
- </lifecycle>
- <converter>
- <description>converter for issues priority</description>
- <converter-id>priority_converter</converter-id>
-
<converter-class>org.richfaces.demo.converters.PriorityConverter</converter-class>
- </converter>
- -->
-
+ </lifecycle>
</faces-config>
Modified: trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/web.xml 2007-06-13
17:11:30 UTC (rev 1169)
+++ trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/WEB-INF/web.xml 2007-06-13
17:18:10 UTC (rev 1170)
@@ -21,11 +21,23 @@
<param-value>.xhtml</param-value>
</context-param>
<filter>
+ <display-name>Request Metrics</display-name>
+ <filter-name>metrics</filter-name>
+
<filter-class>org.richfaces.demo.benchmark.RequestBenchMarkFilter</filter-class>
+ </filter>
+ <filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
+ <filter-name>metrics</filter-name>
+ <servlet-name>Faces Servlet</servlet-name>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ </filter-mapping>
+ <filter-mapping>
<filter-name>ajax4jsf</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
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-13
17:11:30 UTC (rev 1169)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/webapp/pages/scrollable-grid.xhtml 2007-06-13
17:18:10 UTC (rev 1170)
@@ -30,7 +30,8 @@
<sg:scrollable-grid value="#{dataModel2}"
var="issues"
frozenColCount="3"
- first="0"
+ first="0"
+ rows="40"
defaultRows="40"
width="800px"
height="500px">