All files / views/trees/definition-tree/nodes/collections collection-class-node.ts

100% Statements 16/16
100% Branches 4/4
100% Functions 6/6
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                    2x   2x       3x       2x   2x 1x     1x       3x 3x   3x 4x     3x   1x   2x         1x       1x    
import * as vscode from "vscode";
import { TreeNode, sortByLabel } from "@src/views/trees/tree-node";
import { ConceptClassNode } from "../concepts/concept-class-node";
import { ClassNodeBase } from "../classes/class-node-base";
 
/**
 * Node of a SKOS collection in the definition tree.
 */
export class CollectionClassNode extends ClassNodeBase {
	override getIcon(): vscode.ThemeIcon | undefined {
		const isOrdered = this.vocabulary.isOrderedCollection(this.getDocumentGraphs(), this.uri);
 
		return new vscode.ThemeIcon(isOrdered ? 'rdf-collection-ordered' : 'rdf-collection', this.getIconColor());
	}
 
	override getIconColor() {
		return new vscode.ThemeColor("mentor.color.concept");
	}
 
	override hasChildren(): boolean {
		const graphs = this.getDocumentGraphs();
 
		for (const _ of this.vocabulary.getCollectionMembers(graphs, this.uri)) {
			return true;
		}
 
		return false;
	}
 
	override getChildren(): TreeNode[] {
		const result = [];
		const graphs = this.getDocumentGraphs();
 
		for (const m of this.vocabulary.getCollectionMembers(graphs, this.uri)) {
			result.push(this.createChildNode(ConceptClassNode, m));
		}
 
		if (this.vocabulary.isOrderedCollection(graphs, this.uri)) {
			// Preserve order for ordered collections.
			return result;
		} else {
			return sortByLabel(result);
		}
	}
 
	override getClassNode(iri: string) {
		return this.createChildNode(ConceptClassNode, iri);
	}
 
	override getIndividualNode(iri: string) {
		return this.createChildNode(ConceptClassNode, iri);
	}
}