Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspackman committed May 23, 2024
1 parent 8d7393b commit 70e0968
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
7 changes: 7 additions & 0 deletions source/class/qxl/datagrid/source/ArrayDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ qx.Class.define("qxl.datagrid.source.ArrayDataSource", {
return pos;
},

/**
* @Override
*/
isModelValid(value) {
return this.getModel().indexOf(value) >= 0;
},

/**
* @Override
*/
Expand Down
8 changes: 8 additions & 0 deletions source/class/qxl/datagrid/source/IDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ qx.Interface.define("qxl.datagrid.source.IDataSource", {
*/
getPositionOfModel(value) {},

/**
* Called to find out if the model is valid within this data source
*
* @param {*} value
* @return {Boolean}
*/
isModelValid(value) {},

/**
* Returns the size of the datasource
*
Expand Down
7 changes: 7 additions & 0 deletions source/class/qxl/datagrid/source/tree/TreeDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
return null;
},

/**
* @Override
*/
isModelValid(value) {
return !!this.getPositionOfModel(value);
},

/**
* @override
*/
Expand Down
33 changes: 32 additions & 1 deletion source/class/qxl/datagrid/ui/SelectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ qx.Class.define("qxl.datagrid.ui.SelectionManager", {
dataSource: {
init: null,
check: "qxl.datagrid.source.IDataSource",
event: "changeDataSource"
event: "changeDataSource",
apply: "_applyDataSource"
},

/** Whether the user has to select entire rows, or just individual cells */
Expand Down Expand Up @@ -85,6 +86,36 @@ qx.Class.define("qxl.datagrid.ui.SelectionManager", {
/** @type{Array} the oldData for batched notification of selection change */
__selectionChangeOldData: null,

/**
* Apply for `dataSource` property
*/
_applyDataSource(value, oldValue) {
if (oldValue) {
oldValue.removeListener("changeSize", this.__onDataSourceChange, this);
}
if (value) {
value.addListener("changeSize", this.__onDataSourceChange, this);
}
},

/**
* Event handler for changes to the data source's model
*
* @param {qx.event.type.Data} evt
*/
__onDataSourceChange(evt) {
let newSelection = [];
let dataSource = this.getDataSource();
if (dataSource) {
this.__selection.forEach(model => {
if (dataSource.isModelValid(model)) {
newSelection.push(model);
}
});
}
this.__selection.replace(newSelection);
},

/**
* Apply for `selectionStyle`
*/
Expand Down

0 comments on commit 70e0968

Please sign in to comment.