Search in sources :

Example 6 with ColumnTreeBuilder

use of com.android.tools.adtui.common.ColumnTreeBuilder in project android by JetBrains.

the class AppTrace method generateTopdownTree.

// Convert a HNode tree into an AppStat tree (better suited for rendition in a ColumnTree).
private JComponent generateTopdownTree(HNode<MethodUsage> graph) {
    AppStatTreeNode top = new AppStatTreeNode();
    // Intentionally discard first child
    graph = graph.getFirstChild();
    convertGraphToTree(graph, top);
    JTree tree = new JTree(top);
    JComponent topdownColumnTree = new ColumnTreeBuilder(tree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Method").setRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            AppStatTreeNode node = (AppStatTreeNode) value;
            append(generateNameForColumn(node.getMethodNamespace(), node.getMethodName(), getSeparator()));
        }
    })).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Inclusive stats").setRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            AppStatTreeNode node = (AppStatTreeNode) value;
            append(String.format("%2.1f%%", node.getPercentageInclusive() * 100));
        }
    })).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Exclusive stats").setRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            AppStatTreeNode node = (AppStatTreeNode) value;
            append(String.format("%2.1f%%", node.getPercentageExclusive() * 100));
        }
    })).build();
    return topdownColumnTree;
}
Also used : AppStatTreeNode(com.android.tools.idea.monitor.ui.cpu.view.AppStatTreeNode) ColoredTreeCellRenderer(com.intellij.ui.ColoredTreeCellRenderer) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ColumnTreeBuilder

use of com.android.tools.adtui.common.ColumnTreeBuilder 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)

Example 8 with ColumnTreeBuilder

use of com.android.tools.adtui.common.ColumnTreeBuilder 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);
}
Also used : TreeExpansionListener(javax.swing.event.TreeExpansionListener) FieldObject(com.android.tools.profilers.memory.adapters.FieldObject) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) InstanceAttribute(com.android.tools.profilers.memory.adapters.ClassObject.InstanceAttribute) Comparator(java.util.Comparator) InstanceObject(com.android.tools.profilers.memory.adapters.InstanceObject) TreePath(javax.swing.tree.TreePath) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Aggregations

ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)8 Tree (com.intellij.ui.treeStructure.Tree)6 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)6 Comparator (java.util.Comparator)3 TreePath (javax.swing.tree.TreePath)3 NotNull (org.jetbrains.annotations.NotNull)3 AppStatTreeNode (com.android.tools.idea.monitor.ui.cpu.view.AppStatTreeNode)2 MemoryInfoTreeNode (com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode)2 ColoredTreeCellRenderer (com.intellij.ui.ColoredTreeCellRenderer)2 SdkConstants (com.android.SdkConstants)1 ApkEntry (com.android.tools.idea.apk.viewer.ApkEntry)1 NameRenderer (com.android.tools.idea.apk.viewer.ApkViewPanel.NameRenderer)1 SizeRenderer (com.android.tools.idea.apk.viewer.ApkViewPanel.SizeRenderer)1 EdtExecutor (com.android.tools.idea.ddms.EdtExecutor)1 ClassObject (com.android.tools.profilers.memory.adapters.ClassObject)1 InstanceAttribute (com.android.tools.profilers.memory.adapters.ClassObject.InstanceAttribute)1 FieldObject (com.android.tools.profilers.memory.adapters.FieldObject)1 ClassAttribute (com.android.tools.profilers.memory.adapters.HeapObject.ClassAttribute)1 InstanceObject (com.android.tools.profilers.memory.adapters.InstanceObject)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1