1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {PropertyFormatter} from './formatters'; 18import {TreeNode} from './tree_node'; 19 20export class PropertyTreeNode extends TreeNode { 21 protected formatter: PropertyFormatter | undefined = undefined; 22 protected internalIsRoot = false; 23 24 constructor( 25 id: string, 26 name: string, 27 readonly source: PropertySource, 28 protected readonly value: any, 29 ) { 30 super(id, name); 31 } 32 33 getValue(): any { 34 return this.value; 35 } 36 37 setFormatter(formatter: PropertyFormatter): this { 38 this.formatter = formatter; 39 return this; 40 } 41 42 setIsRoot(value: boolean) { 43 this.internalIsRoot = value; 44 } 45 46 override isRoot(): boolean { 47 return this.internalIsRoot; 48 } 49 50 formattedValue(): string { 51 if (this.formatter) { 52 return this.formatter.format(this); 53 } 54 55 return ''; 56 } 57} 58 59export enum PropertySource { 60 PROTO, 61 DEFAULT, 62 CALCULATED, 63} 64