/**
* Copyright (c) 2014, Oracle and/or its affiliates.
* All rights reserved.
*/
/**
* @export
* A CellSet represents a collection of cells. The CellSet is an object returned by the success callback
* of the fetchCells method on DataGridDataSource. The CollectionCellSet is an oj collection specific
* implementation of methods on CellSet.
* @param {number} startRow the start row index of the cell set
* @param {number} endRow the end row index of the cell set
* @param {number} startColumn the start column index of the cell set
* @param {number} endColumn the end column index of the cell set
* @param {Array|null} columns the set of column keys
* @constructor
*/
oj.CollectionCellSet = function(startRow, endRow, startColumn, endColumn, columns)
{
// assert startRow/startColumn are number
oj.Assert.assertNumber(startRow, null);
oj.Assert.assertNumber(endRow, null);
oj.Assert.assertNumber(startColumn, null);
oj.Assert.assertNumber(endColumn, null);
oj.Assert.assertArrayOrNull(columns);
this.m_startRow = startRow;
this.m_endRow = endRow;
this.m_startColumn = startColumn;
this.m_endColumn = endColumn;
this.m_columns = columns;
};
/**
* Sets the models used in this cell set.
* @param {Array} models an array of oj model for the cell set
* @private
*/
oj.CollectionCellSet.prototype.setModels = function(models)
{
oj.Assert.assertArray(models);
// make sure the array size is valid
if (models != null && models.length === this.getCount("row"))
{
this.m_models = models;
}
};
/**
* Gets the data of the specified index. An error is throw when 1) the range is not yet available
* 2) the index specified is out of bounds.
* @param {Object} indexes the index of each axis in which we want to retrieve the data from.
* @param {number} indexes.row the index of the row axis.
* @param {number} indexes.column the index of the column axis.
* @return {Object} the data object for the specified index.
* @export
*/
oj.CollectionCellSet.prototype.getData = function(indexes)
{
var column, model;
// indexes are validated in _getModel
model = this._getModel(indexes);
if (model == null)
{
return null;
}
// extract column index
column = indexes['column'];
return model.get(this.m_columns[column]);
};
/**
* Gets the metadata of the specified index. An error is throw when 1) the range is not yet available
* 2) the index specified is out of bounds.
* @param {Object} indexes the index of each axis in which we want to retrieve the metadata from.
* @param {number} indexes.row the index of the row axis.
* @param {number} indexes.column the index of the column axis.
* @return the metadata object for the specific index. The metadata that the DataGrid supports are:
* 1) keys - the key (of each axis) of the cell.
* @export
*/
oj.CollectionCellSet.prototype.getMetadata = function(indexes)
{
var column, model, keys;
// indexes are validated in _getModel
model = this._getModel(indexes);
if (model == null)
{
return null;
}
// extract column index
column = indexes['column'];
keys = {"row": oj.CollectionDataGridUtils._getModelKey(model), "column": this.m_columns[column]};
return {"keys": keys};
};
/**
* Gets the Model based on indexes.
* @private
*/
oj.CollectionCellSet.prototype._getModel = function(indexes)
{
var row, column;
// make sure models is populated
if (this.m_models == null)
{
return null;
}
oj.Assert.assertObject(indexes);
// extract row and column index
row = indexes['row'];
column = indexes['column'];
// make sure index are valid
oj.Assert.assert(row >= this.m_startRow && row <= this.m_endRow && column >= this.m_startColumn && column <= this.m_endColumn);
return this.m_models[row - this.m_startRow];
};
/**
* Gets the actual count of the result set for the specified axis. Valid values are "row" and "column".
* @param {string} axis the axis in which to inquire the actual count of the result set.
* @return {number} the actual count of the result set for the specified axis.
* @export
*/
oj.CollectionCellSet.prototype.getCount = function(axis)
{
if (axis === "row")
{
return Math.max(0, this.m_endRow - this.m_startRow);
}
if (axis === "column")
{
return Math.max(0, this.m_endColumn - this.m_startColumn);
}
return 0;
};
/**
* Gets the m_startRow property for testing
* @export
* @ignore
*/
oj.CollectionCellSet.prototype.getStartRow = function()
{
return this.m_startRow;
};
/**
* Gets the m_endRow property for testing
* @export
* @ignore
*/
oj.CollectionCellSet.prototype.getEndRow = function()
{
return this.m_endRow;
};
/**
* Gets the m_startColumn property for testing
* @export
* @ignore
*/
oj.CollectionCellSet.prototype.getStartColumn = function()
{
return this.m_startColumn;
};
/**
* Gets the m_endColumn property for testing
* @export
* @ignore
*/
oj.CollectionCellSet.prototype.getEndColumn = function()
{
return this.m_endColumn;
};
/**
* Gets the m_columns property for testing
* @export
* @ignore
*/
oj.CollectionCellSet.prototype.getColumns = function()
{
return this.m_columns;
};
Source: src/main/javascript/oracle/oj/ojdatagrid-model/CollectionCellSet.js
Oracle® JavaScript Extension Toolkit (JET)
1.1.2
E65298-01