Permalink
Browse files

Completed optimizing table panes.

  • Loading branch information...
1 parent a2bcd5c commit 16fcbd7231d3e8dbd3ed8cb69466e0d1c49a7174 @arcusfelis committed Mar 23, 2013
@@ -47,6 +47,10 @@ qx.Class.define("cascadae.BasicTable",
return new cascadae.Pane(obj);
}
});
+ this.set({
+ alwaysUpdateCells: false,
+ showCellFocusIndicator: false
+ });
// INIT SELECTION MODEL
var sm = this.__selectionModel = this.getSelectionModel();
@@ -74,7 +78,6 @@ qx.Class.define("cascadae.BasicTable",
{
this.addListener(eventName, eventHandlers[eventName], this);
}
- this.setAlwaysUpdateCells(false);
},
members :
@@ -197,15 +200,15 @@ qx.Class.define("cascadae.BasicTable",
var tm = this.__tableModel,
n2p = this.getColumnNameToPositionIndex();
- tm.saveSelection();
- console.log("non blocking update start");
+ var selected = tm.getSelection();
+// console.log("non blocking update start");
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.");
+ this.error("Cannot locate row " + row.id);
continue;
}
// Update whole row.
@@ -226,15 +229,18 @@ qx.Class.define("cascadae.BasicTable",
/* fireEvent */ false,
/* preserveSelection */ false);
}
- console.log("non blocking update stop");
- tm.restoreSelection();
+// console.log("non blocking update stop");
+ if (!qx.lang.Array.equals(selected, tm.getSelection()))
+ {
+ tm.restoreSelection();
+ }
tm.forceRedraw();
- console.log("non blocking update end");
+// console.log("non blocking update end");
if (this.__rowQueue.length)
{
qx.event.Timer.once(this.__nonBlockingUpdate, this, 4);
- console.log("Len " + this.__rowQueue.length);
+// console.log("Len " + this.__rowQueue.length);
} else {
this.__rowQueue = undefined;
this.fireEvent("tableRefreshed");
@@ -94,7 +94,6 @@ qx.Class.define("cascadae.Pane",
apply : "_applyFirstVisibleRow"
},
-
/** The number of rows to show. */
visibleRowCount :
{
@@ -120,6 +119,12 @@ qx.Class.define("cascadae.Pane",
{
refine : true,
init : false
+ },
+
+ forceSyncUpdate :
+ {
+ check : "Boolean",
+ init : false
}
},
@@ -312,7 +317,7 @@ qx.Class.define("cascadae.Pane",
*/
__rowCacheClear : function()
{
- this.info("Clear cache");
+// this.info("Clear cache");
this.__rowCache = [];
this.__rowCacheCount = 0;
},
@@ -381,34 +386,35 @@ qx.Class.define("cascadae.Pane",
*/
updateContent : function(completeUpdate, scrollOffset, onlyRow, onlySelectionOrFocusChanged)
{
- var updateNow = completeUpdate || onlyRow || onlySelectionOrFocusChanged;
- // If there is an old timer and we will update the timer or redraw whole
- // table, then delete the old timer.
- if (this.__updateTRef && (!updateNow || completeUpdate)) {
- clearTimeout(this.__updateTRef);
- this.info("Cancel TO.");
+ if (!this.getTable().isVisible())
+ {
+// this.info("Invisible");
+ return;
}
+ if (completeUpdate)
+ {
+ this.__rowCacheClear();
+ }
+ var updateNow = this.getForceSyncUpdate() || onlyRow || onlySelectionOrFocusChanged;
if (updateNow)
- {
- this.doUpdateContent(completeUpdate, scrollOffset, onlyRow,
- onlySelectionOrFocusChanged);
+ {
+ this.doUpdateContent(scrollOffset, onlyRow, onlySelectionOrFocusChanged);
} else {
+ if (this.__updateTRef) {
+ clearTimeout(this.__updateTRef);
+// this.info("Cancel TO.");
+ }
var pane = this;
var cb = function() {
- pane.doUpdateContent(completeUpdate, scrollOffset, onlyRow,
- onlySelectionOrFocusChanged);
+ pane.doUpdateContent(scrollOffset, onlyRow, onlySelectionOrFocusChanged);
};
- this.__updateTRef = setTimeout(cb, 1);
+ this.__updateTRef = setTimeout(cb, 100);
}
},
- doUpdateContent : function(completeUpdate, scrollOffset, onlyRow, onlySelectionOrFocusChanged)
+ doUpdateContent : function(scrollOffset, onlyRow, onlySelectionOrFocusChanged)
{
- if (completeUpdate) {
- this.__rowCacheClear();
- }
-
- var start = new Date();
+// var start = new Date();
if (scrollOffset && Math.abs(scrollOffset) <= Math.min(10, this.getVisibleRowCount()))
{
@@ -422,11 +428,11 @@ qx.Class.define("cascadae.Pane",
}
else
{
- this.debug("full update");
+// this.debug("full update");
this._updateAllRows();
}
- this.debug("render time: " + (new Date() - start) + "ms");
+// this.debug("render time: " + (new Date() - start) + "ms");
},
@@ -544,7 +550,7 @@ qx.Class.define("cascadae.Pane",
var focusedRow = (this.__focusedRow == row);
var rowData = tableModel.getRowData(row, undefined, false); // readonly
var rowId = tableModel.getRowId(rowData);
- var rowVersion = tableModel.getRowVersion(rowData);
+ var rowVersion = tableModel.getRowVersion(rowData, firstRow, rowCount);
var cachedRow = this.__rowCacheGet(rowId, rowVersion, selected, focusedRow);
if (cachedRow) {
@@ -709,6 +715,7 @@ qx.Class.define("cascadae.Pane",
__hasAppearListener : false,
+ __lastModelRowCount : 0,
/**
* Updates the content of the pane (implemented using array joins).
@@ -723,20 +730,29 @@ qx.Class.define("cascadae.Pane",
this.addListenerOnce("appear", arguments.callee, this);
this.__hasAppearListener = true;
}
+// this.debug("skip invisible");
return;
}
var table = this.getTable();
var tableModel = table.getTableModel();
+
+ var modelRowCount = tableModel.getRowCount();
+ if (modelRowCount === 0 && this.__lastModelRowCount === 0)
+ {
+// this.debug("skip empty");
+ return;
+ }
+
+ this.__lastModelRowCount = modelRowCount;
var paneModel = this.getPaneScroller().getTablePaneModel();
var colCount = paneModel.getColumnCount();
var rowHeight = table.getRowHeight();
var firstRow = this.getFirstVisibleRow();
var rowCount = this.getVisibleRowCount();
- var modelRowCount = tableModel.getRowCount();
if (firstRow + rowCount > modelRowCount) {
rowCount = Math.max(0, modelRowCount - firstRow);
@@ -17,6 +17,8 @@ qx.Class.define("cascadae.files.Model",
},
sortByColumn : function(columnIndex, ascending) {
+// console.dir(this._rowArr);
+// console.dir(this._nodeArr);
this.__columnIndex = columnIndex;
this.__asc = ascending;
@@ -35,8 +37,27 @@ qx.Class.define("cascadae.files.Model",
rows[sid].push(row);
}
tree.setRowsBulk(rows);
+ this.fireEvent("metaDataChanged");
+// this.forceRedraw();
+ },
+
+ forceRedraw : function()
+ {
+ if (this.hasListener("dataChanged"))
+ {
+ var data =
+ {
+ firstRow : 0,
+ lastRow : this._rowArr.length - 1,
+ firstColumn : 0,
+ lastColumn : this.getColumnCount() - 1
+ };
+
+ this.fireDataEvent("dataChanged", data);
+ }
},
+
getSortColumnIndex : function() {
return this.__columnIndex;
},
@@ -52,15 +73,21 @@ qx.Class.define("cascadae.files.Model",
ascending : this.__asc
};
this.fireDataEvent("sorted", data);
- this.fireEvent("metaDataChanged");
},
getRowId : function(row) {
return row[this.__keyColumn];
},
- getRowVersion : function(row) {
- return row[4] + row[5]; // progress + mode
+ getRowVersion : function(row, firstRow, rowCount) {
+ if (firstRow)
+ {
+ // Called from the metadata pane
+ return "" + row[4] + row[5]; // progress + mode
+ } else {
+ // Called from the tree pane
+ return "" + row[0].bOpened + row[0].icon;
+ }
},
sortRows : function(rows) {
@@ -74,6 +101,103 @@ qx.Class.define("cascadae.files.Model",
comparator.columnIndex = this.__columnIndex;
rows.sort(comparator);
+ },
+
+ __selectionIndex : undefined,
+ __selectionModel : undefined,
+ __selectedRows : undefined,
+
+ indexedSelection: function(columnIndex, selectionModel)
+ {
+ this.__selectionIndex = columnIndex;
+ this.__selectionModel = selectionModel;
+ this.__selectedRows = [];
+ },
+
+ // Save the list of indices corresponding to the set of selected rows
+ // (push).
+ getSelection: function()
+ {
+ if (!this.__selectionModel ||
+ this.__selectionIndex < 0 ||
+ this.__selectionIndex >= this.getColumnCount())
+ {
+ return;
+ }
+
+ // Initialize the array containing the selected rows.
+ var selected = [];
+
+ // Iterate through the selected rows. For each selected row...
+ this.__selectionModel.iterateSelection(
+ function(row)
+ {
+ // Get the value from the indexed column, and push it to the
+ // selected rows array.
+ selected.push(this.getValue(this.__selectionIndex, row));
+ },
+ this);
+ return selected;
+ },
+
+
+ setSelection: function(selected)
+ {
+ // If there's no indexed selection, there's nothing to restore.
+ if (! this.__selectionModel ||
+ this.__selectionIndex < 0 ||
+ this.__selectionIndex >= this.getColumnCount())
+ {
+ return;
+ }
+
+ // Get a local reference ot the selection model
+ var sm = this.__selectionModel;
+
+ // Queue events for selection changes
+ sm.setBatchMode(true);
+
+ // ... then clear the current selection
+ this.__clearSelection();
+
+ // For each selected row...
+ for (var i = 0; i < selected.length; i++)
+ {
+ // Find that row
+ var row = this.find(this.__selectionIndex, selected[i]);
+
+ // If it was found...
+ if (row !== undefined)
+ {
+ // ... then add it to the selection in the selection model
+// console.log("Add selection interval " +row);
+ sm.addSelectionInterval(row, row);
+ }
+ }
+
+ // Send selection events now.
+ sm.setBatchMode(false);
+ },
+
+ find: function(columnIndex, value)
+ {
+ var rows = this._rowArr;
+ for (var i = 0, l = rows.length; i < l; i++)
+ if (rows[i][columnIndex] === value)
+ return i;
+ return undefined;
+ },
+
+ //
+ // Clear the selection.
+ //
+ __clearSelection: function()
+ {
+ var sm = this.__selectionModel;
+ if (sm)
+ {
+ sm.resetSelection();
+ }
}
}
});
Oops, something went wrong.

0 comments on commit 16fcbd7

Please sign in to comment.