Permalink
Browse files

Non-blocking update for the table.

  • Loading branch information...
1 parent bdbb10e commit a977b99c276ca4156ab0bd5627e13d8514511e09 @arcusfelis committed Mar 21, 2013
Showing with 51 additions and 33 deletions.
  1. +50 −31 q_src/class/cascadae/BasicTable.js
  2. +1 −2 q_src/class/cascadae/Socket.js
View
81 q_src/class/cascadae/BasicTable.js
@@ -71,6 +71,7 @@ qx.Class.define("cascadae.BasicTable",
{
this.addListener(eventName, eventHandlers[eventName], this);
}
+ this.setAlwaysUpdateCells(false);
},
members :
@@ -151,63 +152,81 @@ qx.Class.define("cascadae.BasicTable",
},
+ __rowQueue : undefined,
+
/**
* DATA MANAGEMENT
*
* @param Rows {var} TODOC
*/
particallyUpdateRows : function(Rows)
{
+ if (!this.__rowQueue)
+ {
+ this.__rowQueue = Rows;
+ qx.event.Timer.once(this.__nonBlockingUpdate, this, 1);
+ } else {
+ var idx = {};
+ for (var i = 0, l = this.__rowQueue.length; i < l; i++)
+ {
+ var row = this.__rowQueue[i];
+ idx[row.id] = i;
+ }
+
+ for (var i = 0, l = Rows.length; i < l; i++)
+ {
+ var row = Rows[i];
+ var oldRowPos = idx[row.id];
+ if (oldRowPos !== undefined)
+ {
+ // previous update is still in queue
+ var oldRow = this.__rowQueue[oldRowPos];
+ qx.lang.Object.mergeWith(oldRow, row);
+ } else {
+ this.__rowQueue.push(Rows[i]);
+ }
+ }
+ }
+ },
+
+ __nonBlockingUpdate : function()
+ {
var tm = this.__tableModel,
- n2p = this.getColumnNameToPositionIndex(),
- sorting_col = tm.getSortColumnIndex(),
- is_sorting_asc = tm.isSortAscending(),
- update_sorting = false;
+ n2p = this.getColumnNameToPositionIndex();
- for (var i=0, count=Rows.length; i<count; i++)
- {
- var row = Rows[i];
- if (typeof (row.id) == 'undefined')
- this.error("Cannot get Rows[i].id");
+ for (var i = 0, l = Math.min(10, this.__rowQueue.length); i < l; i++)
+ {
+ var row = this.__rowQueue.shift();
var pos = tm.locate(n2p.id, row.id);
-
if (isNaN(pos))
{
this.error("Cannot locate row.");
continue;
}
-
+ // Update whole row.
var oldValues = tm.getRowData(pos,
- /* view */ undefined, /* copy */ false);
-
+ /* view */ undefined,
+ /* copy */ false);
if (typeof (oldValues) != "object")
{
this.error("Cannot retrieve old values.");
continue;
}
-
var newValues = qx.lang.Array.clone(oldValues);
newValues = this.fillFields(row, newValues, false);
-
- // Check, if data in the sorted column was changed.
- if (!update_sorting && oldValues[sorting_col] != newValues[sorting_col])
- {
- update_sorting = true;
- }
-
- /* There is moment, when pos can be changed as result of sorting.
- Good practice is to add a mutex, but we just decrease the time
- when it can be recalculated.
- */
-
- var pos = tm.locate(n2p.id, row.id);
+
tm.setRow(pos, newValues);
}
- if (update_sorting)
- //this.updateContent();
- tm.sortByColumn(sorting_col, is_sorting_asc);
- this.fireEvent("tableRefreshed");
+
+ if (this.__rowQueue.length)
+ {
+ qx.event.Timer.once(this.__nonBlockingUpdate, this, 4);
+ console.log("Len " + this.__rowQueue.length);
+ } else {
+ this.__rowQueue = undefined;
+ this.fireEvent("tableRefreshed");
+ }
},
/* The event is from the user. */
View
3 q_src/class/cascadae/Socket.js
@@ -182,8 +182,7 @@ qx.Class.define("cascadae.Socket", {
__fireDataEventFromErlang: function(eventName, objHash, eventData)
{
- this.info("fireDataEvent ", eventName);
- console.dir(eventData);
+// this.info("fireDataEvent ", eventName);
var item = qx.core.ObjectRegistry.fromHashCode(objHash);
item.fireDataEvent(eventName, eventData);
},

0 comments on commit a977b99

Please sign in to comment.