use of com.android.tools.profilers.memory.adapters.FieldObject in project android by JetBrains.
the class MemoryInstanceView method ensureTreeInitialized.
private void ensureTreeInitialized(@NotNull JPanel parentPanel) {
if (myTree != null) {
assert myTreeModel != null && myTreeRoot != null;
return;
}
myTreeRoot = new MemoryObjectTreeNode<>(new InstanceObject() {
@NotNull
@Override
public String getName() {
return "";
}
});
myTreeModel = new DefaultTreeModel(myTreeRoot);
JTree tree = new Tree(myTreeModel);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.addTreeSelectionListener(e -> {
TreePath path = e.getPath();
if (!e.isAddedPath()) {
return;
}
assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode instanceObject = (MemoryObjectTreeNode) path.getLastPathComponent();
assert instanceObject.getAdapter() instanceof InstanceObject;
InstanceObject selectedInstanceObject = (InstanceObject) instanceObject.getAdapter();
myStage.selectInstance(selectedInstanceObject);
});
// Not all nodes have been populated during buildTree. Here we capture the TreeExpansionEvent to check whether any children
// under the expanded node need to be populated.
tree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
TreePath path = event.getPath();
assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode treeNode = (MemoryObjectTreeNode) path.getLastPathComponent();
for (int i = 0; i < treeNode.getChildCount(); i++) {
assert treeNode.getChildAt(i) instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode childNode = (MemoryObjectTreeNode) treeNode.getChildAt(i);
// Anything below the top level should be FieldObjects
assert childNode.getAdapter() instanceof FieldObject;
FieldObject childObject = (FieldObject) childNode.getAdapter();
if (childObject.getValueType() == ValueType.OBJECT && childNode.getChildCount() == 0) {
populateFields(childNode);
myTreeModel.nodeStructureChanged(childNode);
}
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
// No-op. TODO remove unseen children?
}
});
assert myClassObject != null;
List<InstanceAttribute> attributes = myClassObject.getInstanceAttributes();
ColumnTreeBuilder builder = new ColumnTreeBuilder(tree);
for (InstanceAttribute attribute : attributes) {
builder.addColumn(myAttributeColumns.get(attribute).getBuilder());
}
builder.setTreeSorter((Comparator<MemoryObjectTreeNode<InstanceObject>> comparator, SortOrder sortOrder) -> {
myTreeRoot.sort(comparator);
myTreeModel.nodeStructureChanged(myTreeRoot);
});
builder.setBackground(ProfilerColors.MONITOR_BACKGROUND);
myTree = builder.build();
parentPanel.add(myTree, BorderLayout.CENTER);
}
Aggregations