Search in sources :

Example 6 with AbstractTreeStructure

use of com.intellij.ide.util.treeView.AbstractTreeStructure in project android by JetBrains.

the class TreeGrid method setModel.

private void setModel(@NotNull AbstractTreeStructure model, boolean showSectionHeaders) {
    // using the AbstractTreeStructure instead of the model as the actual TreeModel when used with IJ components
    // works in a very strange way, each time you expand or contract a node it will add or remove all its children.
    Object root = model.getRootElement();
    Object[] sections = model.getChildElements(root);
    mySectionToComponent.clear();
    myLists.clear();
    myHideables.clear();
    removeAll();
    setAutoscrolls(false);
    ListSelectionListener listSelectionListener = e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        ListSelectionModel sourceSelectionModel = (ListSelectionModel) e.getSource();
        if (!sourceSelectionModel.isSelectionEmpty()) {
            for (JList<T> aList : myLists) {
                if (sourceSelectionModel != aList.getSelectionModel()) {
                    aList.clearSelection();
                }
            }
        }
    };
    for (Object section : sections) {
        String name = section.toString();
        FilteringListModel<T> listModel = new FilteringListModel<>(new AbstractListModel() {

            @Override
            public int getSize() {
                return model.getChildElements(section).length;
            }

            @Override
            public Object getElementAt(int index) {
                return model.getChildElements(section)[index];
            }
        });
        // Needed as otherwise the filtered list does not show any content.
        listModel.refilter();
        // JBList does not work with HORIZONTAL_WRAP
        //noinspection UndesirableClassUsage,unchecked
        JList<T> list = new JList<>(listModel);
        list.setAutoscrolls(false);
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(-1);
        list.getSelectionModel().addListSelectionListener(listSelectionListener);
        // for tests to find the right list
        list.setName(name);
        list.addKeyListener(myKeyListener);
        new ListSpeedSearch(list);
        myLists.add(list);
        if (showSectionHeaders) {
            JPanel panel = new // must be BorderLayout for HideableDecorator to work
            JPanel(// must be BorderLayout for HideableDecorator to work
            new BorderLayout()) {

                @Override
                public Dimension getMaximumSize() {
                    return new Dimension(super.getMaximumSize().width, super.getPreferredSize().height);
                }
            };
            HideableDecorator hidyPanel = new HideableDecorator(panel, name, false);
            myHideables.add(hidyPanel);
            hidyPanel.setContentComponent(list);
            add(panel);
            mySectionToComponent.put(section, panel);
        } else {
            if (getComponentCount() > 0) {
                add(new JSeparator());
            }
            list.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
            add(list);
            mySectionToComponent.put(section, list);
        }
    }
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) KeyListener(java.awt.event.KeyListener) IdentityHashMap(java.util.IdentityHashMap) ModalityState(com.intellij.openapi.application.ModalityState) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) ArrayList(java.util.ArrayList) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Map(java.util.Map) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) ApplicationManager(com.intellij.openapi.application.ApplicationManager) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) MouseListener(java.awt.event.MouseListener) Condition(com.intellij.openapi.util.Condition) HideableDecorator(com.intellij.ui.HideableDecorator) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) javax.swing(javax.swing) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) HideableDecorator(com.intellij.ui.HideableDecorator) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSpeedSearch(com.intellij.ui.ListSpeedSearch)

Example 7 with AbstractTreeStructure

use of com.intellij.ide.util.treeView.AbstractTreeStructure in project android by JetBrains.

the class TargetModulesTreeBuilder method displayTargetModules.

public void displayTargetModules(@NotNull List<AbstractDependencyNode<? extends PsAndroidDependency>> dependencyNodes) {
    AbstractTreeStructure treeStructure = getTreeStructure();
    if (treeStructure instanceof TargetModulesTreeStructure) {
        ((TargetModulesTreeStructure) treeStructure).displayTargetModules(dependencyNodes);
        queueUpdate();
    }
}
Also used : AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 8 with AbstractTreeStructure

use of com.intellij.ide.util.treeView.AbstractTreeStructure in project android by JetBrains.

the class ResolvedDependenciesTreeBuilder method reset.

public void reset() {
    AbstractTreeStructure treeStructure = getTreeStructure();
    if (treeStructure instanceof ResolvedDependenciesTreeStructure) {
        ((ResolvedDependenciesTreeStructure) treeStructure).reset();
        queueUpdateAndRestoreSelection();
    }
}
Also used : AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 9 with AbstractTreeStructure

use of com.intellij.ide.util.treeView.AbstractTreeStructure in project android by JetBrains.

the class TargetArtifactsTreeBuilder method displayTargetArtifacts.

public void displayTargetArtifacts(@Nullable PsAndroidDependency dependency) {
    AbstractTreeStructure treeStructure = getTreeStructure();
    if (treeStructure instanceof TargetArtifactsTreeStructure) {
        ((TargetArtifactsTreeStructure) treeStructure).displayTargetArtifacts(dependency);
        queueUpdate().doWhenDone(this::expandAllNodes);
    }
}
Also used : AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 10 with AbstractTreeStructure

use of com.intellij.ide.util.treeView.AbstractTreeStructure in project android by JetBrains.

the class DependenciesTreeBuilder method reset.

public void reset(@Nullable Runnable onDone) {
    AbstractTreeStructure treeStructure = getTreeStructure();
    if (treeStructure instanceof DependenciesTreeStructure) {
        ((DependenciesTreeStructure) treeStructure).reset();
        ActionCallback callback = queueUpdate();
        if (onDone != null) {
            callback.doWhenDone(onDone);
        }
    }
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Aggregations

AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)14 AllTodosTreeBuilder (com.intellij.ide.todo.AllTodosTreeBuilder)2 SmartTreeStructure (com.intellij.ide.util.treeView.smartTree.SmartTreeStructure)2 Tree (com.intellij.ui.treeStructure.Tree)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 Nullable (org.jetbrains.annotations.Nullable)2 StructureView (com.intellij.ide.structureView.StructureView)1 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)1 CurrentFileTodosTreeBuilder (com.intellij.ide.todo.CurrentFileTodosTreeBuilder)1 TodoTreeStructure (com.intellij.ide.todo.TodoTreeStructure)1 TodoItemNode (com.intellij.ide.todo.nodes.TodoItemNode)1 AbstractTreeBuilder (com.intellij.ide.util.treeView.AbstractTreeBuilder)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 BlockTreeBuilder (com.intellij.internal.psiView.formattingblocks.BlockTreeBuilder)1 BlockTreeNode (com.intellij.internal.psiView.formattingblocks.BlockTreeNode)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1