export class TreeNode {
+ // Unique identifier
id: any;
+
+ // Display label
label: string;
+
+ // True if child nodes should be visible
expanded: boolean;
+
children: TreeNode[];
+
+ // Set by the tree.
depth: number;
- active: boolean;
+
+ // Set by the tree.
+ selected: boolean;
+
+ // Optional link to user-provided stuff.
+ // This field is ignored by the tree.
+ callerData: any;
constructor(values: {[key: string]: any}) {
this.children = [];
this.expanded = false;
this.depth = 0;
- this.active = false;
- if (values) {
- if ('id' in values) { this.id = values.id; }
- if ('label' in values) { this.label = values.label; }
- if ('children' in values) { this.children = values.children; }
- if ('expanded' in values) { this.expanded = values.expanded; }
- }
+ this.selected = false;
+
+ if (!values) { return; }
+
+ if ('id' in values) { this.id = values.id; }
+ if ('label' in values) { this.label = values.label; }
+ if ('children' in values) { this.children = values.children; }
+ if ('expanded' in values) { this.expanded = values.expanded; }
+ if ('callerData' in values) { this.callerData = values.callerData; }
}
toggleExpand() {
this.idMap[node.id + ''] = node;
if (hidden) {
- // it could be confusing for a hidden node to be active.
- node.active = false;
+ // it could be confusing for a hidden node to be selected.
+ node.selected = false;
}
if (hidden && filterHidden) {
this.nodeList().forEach(node => node.expanded = false);
}
- activeNode(): TreeNode {
- return this.nodeList().filter(node => node.active)[0];
+ selectedNode(): TreeNode {
+ return this.nodeList().filter(node => node.selected)[0];
}
- activateNode(node: TreeNode) {
- this.nodeList().forEach(n => n.active = false);
- node.active = true;
+ selectNode(node: TreeNode) {
+ this.nodeList().forEach(n => n.selected = false);
+ node.selected = true;
}
}