Search in sources :

Example 1 with ClassAttribute

use of com.android.tools.profilers.memory.adapters.HeapObject.ClassAttribute in project android by JetBrains.

the class MemoryClassView method ensureTreeInitialized.

private void ensureTreeInitialized(@NotNull JPanel parentPanel, @NotNull HeapObject heapObject) {
    if (myClassesTree != null) {
        assert myClassesTreeModel != null && myClassesTreeRoot != null;
        return;
    }
    myClassesTreeRoot = new MemoryObjectTreeNode<>(new ClassObject() {

        @NotNull
        @Override
        public List<InstanceAttribute> getInstanceAttributes() {
            return Collections.emptyList();
        }
    });
    myClassesTreeModel = new DefaultTreeModel(myClassesTreeRoot);
    JTree tree = new Tree(myClassesTreeModel);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.addTreeSelectionListener(e -> {
        TreePath path = e.getPath();
        if (!e.isAddedPath()) {
            return;
        }
        assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
        MemoryObjectTreeNode classObject = (MemoryObjectTreeNode) path.getLastPathComponent();
        assert classObject.getAdapter() instanceof ClassObject;
        myStage.selectClass((ClassObject) classObject.getAdapter());
    });
    List<HeapObject.ClassAttribute> attributes = heapObject.getClassAttributes();
    ColumnTreeBuilder builder = new ColumnTreeBuilder(tree);
    for (ClassAttribute attribute : attributes) {
        builder.addColumn(myAttributeColumns.get(attribute).getBuilder());
    }
    builder.setTreeSorter((Comparator<MemoryObjectTreeNode<ClassObject>> comparator, SortOrder sortOrder) -> {
        myClassesTreeRoot.sort(comparator);
        myClassesTreeModel.nodeStructureChanged(myClassesTreeRoot);
    });
    builder.setBackground(ProfilerColors.MONITOR_BACKGROUND);
    myClassesTree = builder.build();
    parentPanel.add(myClassesTree, BorderLayout.CENTER);
}
Also used : ClassObject(com.android.tools.profilers.memory.adapters.ClassObject) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Comparator(java.util.Comparator) ClassAttribute(com.android.tools.profilers.memory.adapters.HeapObject.ClassAttribute) TreePath(javax.swing.tree.TreePath) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree)

Aggregations

ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)1 ClassObject (com.android.tools.profilers.memory.adapters.ClassObject)1 ClassAttribute (com.android.tools.profilers.memory.adapters.HeapObject.ClassAttribute)1 Tree (com.intellij.ui.treeStructure.Tree)1 Comparator (java.util.Comparator)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 TreePath (javax.swing.tree.TreePath)1