Search in sources :

Example 6 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class PsiMethodTreeElement method getChildrenBase.

@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    final List<StructureViewTreeElement> emptyResult = Collections.emptyList();
    final PsiMethod element = getElement();
    if (element == null || element instanceof SyntheticElement)
        return emptyResult;
    final PsiFile psiFile = element.getContainingFile();
    if (psiFile == null || psiFile instanceof PsiCompiledElement)
        return emptyResult;
    final TextRange range = element.getTextRange();
    if (range == null)
        return emptyResult;
    final String fileText = psiFile.getText();
    if (fileText == null)
        return emptyResult;
    if (!range.substring(fileText).contains(PsiKeyword.CLASS))
        return emptyResult;
    final ArrayList<StructureViewTreeElement> result = new ArrayList<>();
    element.accept(new JavaRecursiveElementWalkingVisitor() {

        @Override
        public void visitClass(PsiClass aClass) {
            if (!(aClass instanceof PsiAnonymousClass) && !(aClass instanceof PsiTypeParameter)) {
                result.add(new JavaClassTreeElement(aClass, isInherited(), new HashSet<>(Arrays.asList(aClass.getSupers()))));
            }
        }
    });
    return result;
}
Also used : MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) TextRange(com.intellij.openapi.util.TextRange) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-plugins by JetBrains.

the class CfmlStructureViewElement method getChildrenBase.

@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    PsiElement element = getElement();
    Collection<StructureViewTreeElement> result = new LinkedList<>();
    if (element != null && (element instanceof CfmlFile || !(element instanceof CfmlFunction))) {
        collectResultsFromChildren(result, element);
    }
    return result;
}
Also used : CfmlFunction(com.intellij.coldFusion.model.psi.CfmlFunction) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElement(com.intellij.psi.PsiElement) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class FileStructureDialog method addCheckbox.

private void addCheckbox(final JPanel panel, final TreeAction action) {
    String text = action instanceof FileStructureFilter ? ((FileStructureFilter) action).getCheckBoxText() : action instanceof FileStructureNodeProvider ? ((FileStructureNodeProvider) action).getCheckBoxText() : null;
    if (text == null)
        return;
    Shortcut[] shortcuts = FileStructurePopup.extractShortcutFor(action);
    final JCheckBox chkFilter = new JCheckBox();
    chkFilter.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            ProjectListBuilder builder = (ProjectListBuilder) myCommanderPanel.getBuilder();
            PsiElement currentParent = null;
            if (builder != null) {
                final AbstractTreeNode parentNode = builder.getParentNode();
                final Object value = parentNode.getValue();
                if (value instanceof StructureViewTreeElement) {
                    final Object elementValue = ((StructureViewTreeElement) value).getValue();
                    if (elementValue instanceof PsiElement) {
                        currentParent = (PsiElement) elementValue;
                    }
                }
            }
            final boolean state = chkFilter.isSelected();
            myTreeActionsOwner.setActionIncluded(action, action instanceof FileStructureFilter ? !state : state);
            myTreeStructure.rebuildTree();
            if (builder != null) {
                if (currentParent != null) {
                    boolean oldNarrowDown = myShouldNarrowDown;
                    myShouldNarrowDown = false;
                    try {
                        builder.enterElement(currentParent, PsiUtilCore.getVirtualFile(currentParent));
                    } finally {
                        myShouldNarrowDown = oldNarrowDown;
                    }
                }
                builder.updateList(true);
            }
            if (SpeedSearchBase.hasActiveSpeedSearch(myCommanderPanel.getList())) {
                final SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myCommanderPanel.getList());
                if (supply != null && supply.isPopupActive())
                    supply.refreshSelection();
            }
        }
    });
    chkFilter.setFocusable(false);
    if (shortcuts.length > 0) {
        text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
        new AnAction() {

            @Override
            public void actionPerformed(final AnActionEvent e) {
                chkFilter.doClick();
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myCommanderPanel);
    }
    chkFilter.setText(text);
    panel.add(chkFilter);
//,new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
}
Also used : ProjectListBuilder(com.intellij.ide.commander.ProjectListBuilder) ActionEvent(java.awt.event.ActionEvent) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ActionListener(java.awt.event.ActionListener) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElement(com.intellij.psi.PsiElement)

Example 9 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class FileStructureDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myCommanderPanel = new MyCommanderPanel(myProject);
    myTreeStructure = new MyStructureTreeStructure();
    List<FileStructureFilter> fileStructureFilters = new ArrayList<>();
    List<FileStructureNodeProvider> fileStructureNodeProviders = new ArrayList<>();
    if (myTreeActionsOwner != null) {
        for (Filter filter : myBaseTreeModel.getFilters()) {
            if (filter instanceof FileStructureFilter) {
                final FileStructureFilter fsFilter = (FileStructureFilter) filter;
                myTreeActionsOwner.setActionIncluded(fsFilter, true);
                fileStructureFilters.add(fsFilter);
            }
        }
        if (myBaseTreeModel instanceof ProvidingTreeModel) {
            for (NodeProvider provider : ((ProvidingTreeModel) myBaseTreeModel).getNodeProviders()) {
                if (provider instanceof FileStructureNodeProvider) {
                    fileStructureNodeProviders.add((FileStructureNodeProvider) provider);
                }
            }
        }
    }
    PsiFile psiFile = getPsiFile(myProject);
    boolean showRoot = isShowRoot(psiFile);
    ProjectListBuilder projectListBuilder = new ProjectListBuilder(myProject, myCommanderPanel, myTreeStructure, null, showRoot) {

        @Override
        protected boolean shouldEnterSingleTopLevelElement(Object rootChild) {
            Object element = ((StructureViewTreeElement) ((AbstractTreeNode) rootChild).getValue()).getValue();
            return myBaseTreeModel.shouldEnterElement(element);
        }

        @Override
        protected boolean nodeIsAcceptableForElement(AbstractTreeNode node, Object element) {
            return Comparing.equal(((StructureViewTreeElement) node.getValue()).getValue(), element);
        }

        @Override
        protected void refreshSelection() {
            myCommanderPanel.scrollSelectionInView();
            if (myShouldNarrowDown) {
                myCommanderPanel.updateSpeedSearch();
            }
        }

        @Override
        protected List<AbstractTreeNode> getAllAcceptableNodes(final Object[] childElements, VirtualFile file) {
            ArrayList<AbstractTreeNode> result = new ArrayList<>();
            for (Object childElement : childElements) {
                result.add((AbstractTreeNode) childElement);
            }
            return result;
        }
    };
    myCommanderPanel.setBuilder(projectListBuilder);
    myCommanderPanel.setTitlePanelVisible(false);
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final boolean succeeded = myCommanderPanel.navigateSelectedElement();
            if (succeeded) {
                unregisterCustomShortcutSet(myCommanderPanel);
            }
        }
    }.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(), myCommanderPanel);
    myCommanderPanel.setPreferredSize(JBUI.size(400, 500));
    JPanel panel = new JPanel(new BorderLayout());
    JPanel comboPanel = new JPanel(new GridLayout(0, 2, 0, 0));
    addNarrowDownCheckbox(comboPanel);
    for (FileStructureFilter filter : fileStructureFilters) {
        addCheckbox(comboPanel, filter);
    }
    for (FileStructureNodeProvider provider : fileStructureNodeProviders) {
        addCheckbox(comboPanel, provider);
    }
    myCommanderPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    panel.add(comboPanel, BorderLayout.NORTH);
    panel.add(myCommanderPanel, BorderLayout.CENTER);
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectListBuilder(com.intellij.ide.commander.ProjectListBuilder) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement)

Example 10 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class MethodUpDownUtil method addStructureViewElements.

private static void addStructureViewElements(final TreeElement parent, final Collection<PsiElement> array, @NotNull PsiFile file) {
    for (TreeElement treeElement : parent.getChildren()) {
        Object value = ((StructureViewTreeElement) treeElement).getValue();
        if (value instanceof PsiElement) {
            PsiElement element = (PsiElement) value;
            if (array.contains(element) || !file.equals(element.getContainingFile()))
                continue;
            array.add(element);
        }
        addStructureViewElements(treeElement, array, file);
    }
}
Also used : StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElement(com.intellij.psi.PsiElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement)

Aggregations

StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)25 NotNull (org.jetbrains.annotations.NotNull)16 PsiElement (com.intellij.psi.PsiElement)9 ArrayList (java.util.ArrayList)8 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 IProperty (com.intellij.lang.properties.IProperty)3 PsiFile (com.intellij.psi.PsiFile)3 XmlFile (com.intellij.psi.xml.XmlFile)3 ProjectListBuilder (com.intellij.ide.commander.ProjectListBuilder)2 TextRange (com.intellij.openapi.util.TextRange)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)2 CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)1 CfmlFunction (com.intellij.coldFusion.model.psi.CfmlFunction)1 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 StructureView (com.intellij.ide.structureView.StructureView)1 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)1 StructureViewExtension (com.intellij.ide.structureView.StructureViewExtension)1 StructureViewFactoryEx (com.intellij.ide.structureView.StructureViewFactoryEx)1