Skip to content

Commit

Permalink
treedatasource: implement getParentOf
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalinowski-vmn committed Apr 11, 2024
1 parent affc984 commit 0eff6b0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/class/qxl/datagrid/source/tree/TreeDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
let childInspector = this.getNodeInspectorFactory()(node);

childRowMeta.canHaveChildren = childInspector.canHaveChildren(node);
childRowMeta.parentMeta = rowMeta;
this.__rowMetaDatas.push(childRowMeta);
this.__rowMetaDataByNode[node.toHashCode()] = childRowMeta;
rowMeta.childRowMetas.push(childRowMeta);
Expand Down Expand Up @@ -228,6 +229,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
let childRowMeta = this.__createRowMetaData(childNode, rowMetadata.level + 1);
childRowMeta.canHaveChildren = childInspector.canHaveChildren(childNode);
childRowMetas.push(childRowMeta);
childRowMeta.parentMeta = rowMetadata;
this.__rowMetaDataByNode[childNode.toHashCode()] = childRowMeta;
}
let before = this.__rowMetaDatas.slice(0, parentRowIndex + 1);
Expand Down Expand Up @@ -434,6 +436,20 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
return row.node;
},

/**
*
* @param {qx.core.Object} node
* @returns {qx.core.Object}
*/
getParentOf(node) {
let meta = this.__rowMetaDataByNode[node.toHashCode()];
if (!meta) {
throw new Error("Cannot get parent of node. Node is not displayed in tree.");
}

return meta.parentMeta?.node ?? null;
},

/**
* @Override
*/
Expand Down

0 comments on commit 0eff6b0

Please sign in to comment.