SelectionAPI¶
Interface SelectionAPI
addToSelection(
nodeID: number | number[],
silent?: boolean,
): Promise<ChangeSelectionResult>;
clearSelection(silent?: boolean): Promise<ChangeSelectionResult>;
getSelectedLeafNodes(): number[];
getSelectedNodes(): number[];
getSelection(): Promise<number[]>;
invertSelection(silent?: boolean): Promise<ChangeSelectionResult>;
isSelected(nodeID: number): Promise<boolean>;
removeFromSelection(
nodeID: number | number[],
silent?: boolean,
): Promise<ChangeSelectionResult>;
selectCollection(
collectionID: number,
silent?: boolean,
): Promise<ChangeSelectionResult>;
setSelection(
nodeID: number | number[],
silent?: boolean,
): Promise<ChangeSelectionResult>;
}
Hierarchy (View Summary)
- SelectionAPI
Methods
add To Selection
Adds the specified nodes to the current selection.
Triggers a SelectionChangedEvent if silent is set to false.
Parameters
- nodeID: number | number[]
The ID or array of IDs of the nodes to add to the selection.
Optionalsilent: booleanIf set to true, no event will be emitted. Default: false
Returns Promise<ChangeSelectionResult>
The result of the selection change.
- nodeID: number | number[]
clear Selection
Clears the current selection.
Triggers a SelectionChangedEvent if silent is set to false.
Parameters
Optionalsilent: booleanIf set to true, no event will be emitted. Default: false
Returns Promise<ChangeSelectionResult>
The result of the selection change.
get Selected Leaf Nodes
Returns a list of all selected leaf nodes.
Returns number[]
An array which contains the IDs of all leaf nodes in the current selection.
get Selected Nodes
Returns a list of all selected nodes. When a whole subtree is selected, only the parent node will be included in the returned array. To get the selected leaf nodes of the subtree, use getSelectedLeafNodes instead.
Returns number[]
An array which contains the IDs of all nodes in the current selection.
get Selection
Returns a list of all selected nodes.
Returns Promise<number[]>
An array which contains the IDs of all nodes in the current selection.
Deprecated
getSelection is deprecated, please use getSelectedNodes instead.
invert Selection
Inverts the current selection.
Selected nodes will be unselected, and then all previously unselected leaf nodes will be selected. When all child nodes of a parent are selected, the selection moves up the hierarchy as usual.
For example, consider the following hierarchy:
Node 0 |- Node 1 |- Node 1.1 |- Node 1.2 |- Node 2 |- Node 2.1 |- Node 2.2If the initial selection is only
Node 2.1, callinginvertSelectionwill result in the selection includingNode 2.2,Node 1.1,Node 1.2, and therefore alsoNode 1.Node 0andNode 2will not become selected, even though they were not selected initially. If getSelectedNodes is called at this point, it will return[Node 1, Node 2.2].Triggers a SelectionChangedEvent if silent is set to false.
Parameters
Optionalsilent: booleanIf set to true, no event will be emitted. Default: false
Returns Promise<ChangeSelectionResult>
The result of the selection change.
is Selected
Checks if the specified node is part of the selection.
Parameters
- nodeID: number
The ID of the node to check for selection status.
Returns Promise<boolean>
True if the given node is selected, otherwise false.
- nodeID: number
remove From Selection
Removes the specified nodes from the current selection.
Triggers a SelectionChangedEvent if silent is set to false.
Parameters
- nodeID: number | number[]
The ID or array of IDs of the nodes to remove from the selection.
Optionalsilent: booleanIf set to true, no event will be emitted. Default: false
Returns Promise<ChangeSelectionResult>
The result of the selection change.
- nodeID: number | number[]
select Collection
Parameters
- collectionID: number
The ID of the collection.
Optionalsilent: booleanIf set to true, no event will be emitted. Default: false
Returns Promise<ChangeSelectionResult>
Deprecated
selectCollection is deprecated, please use setSelection instead.
Replaces the current selection with the nodes from the given collection.
Triggers a SelectionChangedEvent if silent is set to false.
- collectionID: number
set Selection
Replaces the current selection with the specified nodes.
Triggers a SelectionChangedEvent if silent is set to false.
Parameters
- nodeID: number | number[]
The ID or array of IDs of the nodes to select.
Optionalsilent: booleanIf set to true, no event will be emitted. Default: false
Returns Promise<ChangeSelectionResult>
The result of the selection change.
- nodeID: number | number[]
SelectionAPI
Overview
The SelectionAPI provides basic functionalities to manipulate the current selection of nodes. It allows adding, removing, and checking the selection status of nodes, as well as replacing the current selection.
Quick Start
Example: add a node to the selection, query the selection, and clear the selection in the end.
Reading the selection state of a node
Instead of using the isSelected method, you can also check whether a node is selected by using the getProperty method. The property Property.SELECTED can be used to check the selection state of a node.
The selection state is recursive, meaning:
The getSelectedNodes method returns the list of selected nodes. If a parent node is selected, it will return the parent node, but not its children.
To get a list of all selected leaf nodes (nodes without children), you can use the getSelectedLeafNodes method.
Events
The following event is associated with the SelectionAPI: