Search in sources :

Example 1 with TreeStructureProvider

use of com.intellij.ide.projectView.TreeStructureProvider in project intellij-community by JetBrains.

the class AbstractTreeStructureBase method getChildElements.

@Override
public Object[] getChildElements(Object element) {
    LOG.assertTrue(element instanceof AbstractTreeNode, element != null ? element.getClass().getName() : null);
    AbstractTreeNode<?> treeNode = (AbstractTreeNode) element;
    Collection<? extends AbstractTreeNode> elements = treeNode.getChildren();
    List<TreeStructureProvider> providers = getProvidersDumbAware();
    if (!providers.isEmpty()) {
        ViewSettings settings = treeNode instanceof SettingsProvider ? ((SettingsProvider) treeNode).getSettings() : ViewSettings.DEFAULT;
        for (TreeStructureProvider provider : providers) {
            try {
                elements = provider.modify(treeNode, (Collection<AbstractTreeNode>) elements, settings);
            } catch (ProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    for (AbstractTreeNode node : elements) {
        node.setParent(treeNode);
    }
    return ArrayUtil.toObjectArray(elements);
}
Also used : SettingsProvider(com.intellij.ide.projectView.SettingsProvider) ViewSettings(com.intellij.ide.projectView.ViewSettings) Collection(java.util.Collection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with TreeStructureProvider

use of com.intellij.ide.projectView.TreeStructureProvider in project android by JetBrains.

the class GradleSyncTest method jdkNodeModificationInProjectView.

@Test
public void jdkNodeModificationInProjectView() throws IOException {
    guiTest.importSimpleApplication();
    Project project = guiTest.ideFrame().getProject();
    AndroidTreeStructureProvider treeStructureProvider = null;
    TreeStructureProvider[] treeStructureProviders = Extensions.getExtensions(TreeStructureProvider.EP_NAME, project);
    for (TreeStructureProvider current : treeStructureProviders) {
        if (current instanceof AndroidTreeStructureProvider) {
            treeStructureProvider = (AndroidTreeStructureProvider) current;
        }
    }
    List<AbstractTreeNode> changedNodes = Lists.newArrayList();
    treeStructureProvider.addChangeListener((parent, newChildren) -> changedNodes.add(parent));
    ProjectViewFixture projectView = guiTest.ideFrame().getProjectView();
    ProjectViewFixture.PaneFixture projectPane = projectView.selectProjectPane();
    ProjectViewFixture.NodeFixture externalLibrariesNode = projectPane.findExternalLibrariesNode();
    projectPane.expand();
    // 2 nodes should be changed: JDK (remove all children except rt.jar) and rt.jar (remove all children except packages 'java' and
    // 'javax'.
    Wait.seconds(1).expecting("'Project View' to be customized").until(() -> changedNodes.size() == 2);
    List<ProjectViewFixture.NodeFixture> libraryNodes = externalLibrariesNode.getChildren();
    ProjectViewFixture.NodeFixture jdkNode = null;
    // Find JDK node.
    for (ProjectViewFixture.NodeFixture node : libraryNodes) {
        if (node.isJdk()) {
            jdkNode = node;
            break;
        }
    }
    ProjectViewFixture.NodeFixture finalJdkNode = jdkNode;
    Wait.seconds(1).expecting("JDK node to be customized").until(() -> finalJdkNode.getChildren().size() == 1);
    // Now we verify that the JDK node has only these children:
    // - jdk
    //   - rt.jar
    //     - java
    //     - javax
    List<ProjectViewFixture.NodeFixture> jdkChildren = jdkNode.getChildren();
    assertThat(jdkChildren).hasSize(1);
    ProjectViewFixture.NodeFixture rtJarNode = jdkChildren.get(0);
    rtJarNode.requireDirectory("rt.jar");
    List<ProjectViewFixture.NodeFixture> rtJarChildren = rtJarNode.getChildren();
    assertThat(rtJarChildren).hasSize(2);
    rtJarChildren.get(0).requireDirectory("java");
    rtJarChildren.get(1).requireDirectory("javax");
}
Also used : Project(com.intellij.openapi.project.Project) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) AndroidTreeStructureProvider(com.android.tools.idea.gradle.projectView.AndroidTreeStructureProvider) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) AndroidTreeStructureProvider(com.android.tools.idea.gradle.projectView.AndroidTreeStructureProvider) Test(org.junit.Test)

Example 3 with TreeStructureProvider

use of com.intellij.ide.projectView.TreeStructureProvider in project intellij-community by JetBrains.

the class ProjectViewSelectInTarget method select.

@Override
public void select(PsiElement element, final boolean requestFocus) {
    PsiElement toSelect = null;
    for (TreeStructureProvider provider : getProvidersDumbAware()) {
        if (provider instanceof SelectableTreeStructureProvider) {
            toSelect = ((SelectableTreeStructureProvider) provider).getTopLevelElement(element);
        }
        if (toSelect != null)
            break;
    }
    toSelect = findElementToSelect(element, toSelect);
    if (toSelect != null) {
        VirtualFile virtualFile = PsiUtilCore.getVirtualFile(toSelect);
        select(toSelect, virtualFile, requestFocus);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SelectableTreeStructureProvider(com.intellij.ide.projectView.SelectableTreeStructureProvider) PsiElement(com.intellij.psi.PsiElement) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) SelectableTreeStructureProvider(com.intellij.ide.projectView.SelectableTreeStructureProvider)

Example 4 with TreeStructureProvider

use of com.intellij.ide.projectView.TreeStructureProvider in project intellij-community by JetBrains.

the class TreeFileChooserDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
    myTree = new Tree(model);
    final ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {

        @Override
        public boolean isFlattenPackages() {
            return false;
        }

        @Override
        public boolean isShowMembers() {
            return false;
        }

        @Override
        public boolean isHideEmptyMiddlePackages() {
            return true;
        }

        @Override
        public Object[] getChildElements(final Object element) {
            return filterFiles(super.getChildElements(element));
        }

        @Override
        public boolean isAbbreviatePackageNames() {
            return false;
        }

        @Override
        public boolean isShowLibraryContents() {
            return myShowLibraryContents;
        }

        @Override
        public boolean isShowModules() {
            return false;
        }

        @Override
        public List<TreeStructureProvider> getProviders() {
            return myDisableStructureProviders ? null : super.getProviders();
        }
    };
    myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
    myTree.setRootVisible(false);
    myTree.expandRow(0);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setCellRenderer(new NodeRenderer());
    UIUtil.setLineStyleAngled(myTree);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                doOKAction();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            final TreePath path = myTree.getPathForLocation(e.getX(), e.getY());
            if (path != null && myTree.isPathSelected(path)) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            handleSelectionChanged();
        }
    });
    new TreeSpeedSearch(myTree);
    myTabbedPane = new TabbedPaneWrapper(getDisposable());
    final JPanel dummyPanel = new JPanel(new BorderLayout());
    String name = null;
    if (myInitialFile != null) {
        name = myInitialFile.getName();
    }
    PsiElement context = myInitialFile == null ? null : myInitialFile;
    myGotoByNamePanel = new ChooseByNamePanel(myProject, new MyGotoFileModel(), name, true, context) {

        @Override
        protected void close(final boolean isOk) {
            super.close(isOk);
            if (isOk) {
                doOKAction();
            } else {
                doCancelAction();
            }
        }

        @Override
        protected void initUI(final ChooseByNamePopupComponent.Callback callback, final ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
            //IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()).requestFocus();
            if (mySelectSearchByNameTab) {
                myTabbedPane.setSelectedIndex(1);
            }
        }

        @Override
        protected void showTextFieldPanel() {
        }

        @Override
        protected void chosenElementMightChange() {
            handleSelectionChanged();
        }
    };
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
    SwingUtilities.invokeLater(() -> myGotoByNamePanel.invoke(new MyCallback(), ModalityState.stateForComponent(getRootPane()), false));
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            handleSelectionChanged();
        }
    });
    return myTabbedPane.getComponent();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) KeyEvent(java.awt.event.KeyEvent) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) Tree(com.intellij.ui.treeStructure.Tree) ChangeListener(javax.swing.event.ChangeListener) PsiElement(com.intellij.psi.PsiElement) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChooseByNamePanel(com.intellij.ide.util.gotoByName.ChooseByNamePanel) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) ModalityState(com.intellij.openapi.application.ModalityState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ChooseByNamePopupComponent(com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent)

Aggregations

TreeStructureProvider (com.intellij.ide.projectView.TreeStructureProvider)4 PsiElement (com.intellij.psi.PsiElement)2 AndroidTreeStructureProvider (com.android.tools.idea.gradle.projectView.AndroidTreeStructureProvider)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 SelectableTreeStructureProvider (com.intellij.ide.projectView.SelectableTreeStructureProvider)1 SettingsProvider (com.intellij.ide.projectView.SettingsProvider)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)1 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)1 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)1 ChooseByNamePanel (com.intellij.ide.util.gotoByName.ChooseByNamePanel)1 ChooseByNamePopupComponent (com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DoubleClickListener (com.intellij.ui.DoubleClickListener)1 TabbedPaneWrapper (com.intellij.ui.TabbedPaneWrapper)1