• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {assertDefined} from 'common/assert_utils';
18import {PropertyTreeNode} from 'trace/tree_node/property_tree_node';
19import {DiffNode} from './diff_node';
20import {DiffType} from './diff_type';
21
22export class UiPropertyTreeNode extends PropertyTreeNode implements DiffNode {
23  private diff: DiffType = DiffType.NONE;
24  private displayName: string = this.name;
25  private oldValue = 'null';
26  private propagate = false;
27
28  static from(node: PropertyTreeNode): UiPropertyTreeNode {
29    const displayNode = new UiPropertyTreeNode(
30      node.id,
31      node.name,
32      node.source,
33      (node as UiPropertyTreeNode).value,
34    );
35    if ((node as UiPropertyTreeNode).formatter) {
36      displayNode.setFormatter(
37        assertDefined((node as UiPropertyTreeNode).formatter),
38      );
39    }
40
41    displayNode.setIsRoot(node.isRoot());
42
43    const children = [...node.getAllChildren()].sort((a, b) =>
44      a.name < b.name ? -1 : 1,
45    );
46
47    children.forEach((child) => {
48      displayNode.addOrReplaceChild(UiPropertyTreeNode.from(child));
49    });
50    return displayNode;
51  }
52
53  setDiff(diff: DiffType): void {
54    this.diff = diff;
55  }
56
57  getDiff(): DiffType {
58    return this.diff;
59  }
60
61  setDisplayName(name: string) {
62    this.displayName = name;
63  }
64
65  getDisplayName(): string {
66    return this.displayName;
67  }
68
69  setOldValue(value: string) {
70    this.oldValue = value;
71  }
72
73  getOldValue(): string {
74    return this.oldValue;
75  }
76
77  canPropagate(): boolean {
78    return this.propagate;
79  }
80
81  setCanPropagate(value: boolean) {
82    this.propagate = value;
83  }
84}
85