Search in sources :

Example 16 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class Commander method getData.

@Override
public Object getData(final String dataId) {
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return HelpID.COMMANDER;
    } else if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
    } else if (LangDataKeys.TARGET_PSI_ELEMENT.is(dataId)) {
        final AbstractTreeNode parentElement = getInactivePanel().getBuilder().getParentNode();
        if (parentElement == null)
            return null;
        final Object element = parentElement.getValue();
        return element instanceof PsiElement && ((PsiElement) element).isValid() ? element : null;
    } else if (CompareFilesAction.DIFF_REQUEST.is(dataId)) {
        PsiElement primary = getActivePanel().getSelectedElement();
        PsiElement secondary = getInactivePanel().getSelectedElement();
        if (primary != null && secondary != null && primary.isValid() && secondary.isValid() && !PsiTreeUtil.isAncestor(primary, secondary, false) && !PsiTreeUtil.isAncestor(secondary, primary, false)) {
            return PsiDiffContentFactory.comparePsiElements(primary, secondary);
        }
        return null;
    } else {
        return getActivePanel().getDataImpl(dataId);
    }
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 17 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class Commander method writePanel.

private static void writePanel(final CommanderPanel panel, final Element element) {
    /*TODO[anton,vova]: it's a patch!!!*/
    final AbstractListBuilder builder = panel.getBuilder();
    if (builder == null)
        return;
    final AbstractTreeNode parentNode = builder.getParentNode();
    final Object parentElement = parentNode != null ? parentNode.getValue() : null;
    if (parentElement instanceof PsiDirectory) {
        final PsiDirectory directory = (PsiDirectory) parentElement;
        element.setAttribute(ATTRIBUTE_URL, directory.getVirtualFile().getUrl());
    } else if (parentElement instanceof PsiClass) {
        for (PsiElement e = (PsiElement) parentElement; e != null && e.isValid(); e = e.getParent()) {
            if (e instanceof PsiClass) {
                final String qualifiedName = ((PsiClass) e).getQualifiedName();
                if (qualifiedName != null) {
                    element.setAttribute(ATTRIBUTE_CLASS, qualifiedName);
                    break;
                }
            }
        }
    }
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 18 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-plugins by JetBrains.

the class FlexStructureViewTest method testGroupByClass2.

public void testGroupByClass2() throws Exception {
    configureByFile(BASE_PATH + "15.js2");
    final Object[] items = getTopLevelItems();
    assertEquals(3, items.length);
    assertEquals("ZZZ", getText(items[1]));
    assertEquals("ZZZ2", getText(items[2]));
    assertEquals("A15", getText(items[0]));
    List<? extends AbstractTreeNode> treeNodes = getChildren(items[0]);
    assertEquals(7, treeNodes.size());
    final Iterator<? extends AbstractTreeNode> iterator = treeNodes.iterator();
    final AbstractTreeNode node = iterator.next();
    assertEquals("mypackage.ZZZ", getText(node));
    Collection<? extends AbstractTreeNode> treeNodes2 = getChildren(node);
    assertEquals(2, treeNodes2.size());
    final Iterator<? extends AbstractTreeNode> iterator2 = treeNodes2.iterator();
    assertEquals("aaa", getText(iterator2.next()));
    assertEquals("c2", getText(iterator2.next()));
    assertEquals("Object", getText(iterator.next()));
    assertEquals("automation():Object", getText(iterator.next()));
    assertEquals("initialized():Boolean", getText(iterator.next()));
    assertEquals("register(c:Object):void", getText(iterator.next()));
    assertEquals("_automation:Object", getText(iterator.next()));
    assertEquals("delegate:Object", getText(iterator.next()));
    final PsiElement element = checkIfCurrentEditorElementIsValid((AbstractTreeNode) items[1], JSClass.class);
    assertTrue(JSStructureViewModel.shouldEnterElementStatic(element));
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement)

Example 19 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-plugins by JetBrains.

the class FlexStructureViewTest method testBug3.

public void testBug3() throws Exception {
    configureByFiles(null, BASE_PATH + "22.js2", BASE_PATH + "22_2.js2");
    final Object[] items = getTopLevelItems();
    assertEquals(2, items.length);
    assertEquals("XXX", getText(items[0]));
    assertEquals("YYY", getText(items[1]));
    List<? extends AbstractTreeNode> treeNodes = getChildren(items[0]);
    assertEquals(3 + OBJECT_METHODS_COUNT, treeNodes.size());
    assertEquals("constructor():*", getText(treeNodes.get(0)));
    assertEquals("aaa", getText(treeNodes.get(OBJECT_METHODS_COUNT + 1)));
    assertEquals("bbb", getText(treeNodes.get(OBJECT_METHODS_COUNT + 2)));
    AbstractTreeNode node = treeNodes.get(OBJECT_METHODS_COUNT - 5);
    assertEquals("staticFun()", getText(node));
    Icon icon = getIcon(node);
    assertTrue(icon instanceof RowIcon);
    // static mark blended in
    assertTrue(((RowIcon) icon).getIcon(0) instanceof LayeredIcon);
    treeNodes = getChildren(items[1]);
    assertEquals(2 + OBJECT_METHODS_COUNT, treeNodes.size());
    assertEquals("aaa", getText(treeNodes.get(OBJECT_METHODS_COUNT)));
    assertEquals("bbb", getText(treeNodes.get(OBJECT_METHODS_COUNT + 1)));
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) RowIcon(com.intellij.ui.RowIcon) StructureViewTestUtil.getIcon(com.intellij.lang.javascript.StructureViewTestUtil.getIcon) LayeredIcon(com.intellij.ui.LayeredIcon) RowIcon(com.intellij.ui.RowIcon)

Example 20 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode 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)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)154 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)43 Project (com.intellij.openapi.project.Project)36 PsiFile (com.intellij.psi.PsiFile)31 Module (com.intellij.openapi.module.Module)29 PsiDirectory (com.intellij.psi.PsiDirectory)27 PsiElement (com.intellij.psi.PsiElement)17 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 PsiManager (com.intellij.psi.PsiManager)11 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)10 List (java.util.List)10 PresentationData (com.intellij.ide.projectView.PresentationData)6 ViewSettings (com.intellij.ide.projectView.ViewSettings)6 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)6 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)5 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5