Search in sources :

Example 26 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class GotoImplementationHandler method getChooserTitle.

@Override
@NotNull
protected String getChooserTitle(@NotNull PsiElement sourceElement, String name, int length, boolean finished) {
    ItemPresentation presentation = ((NavigationItem) sourceElement).getPresentation();
    String fullName;
    if (presentation == null) {
        fullName = name;
    } else {
        PsiElement container = getContainer(sourceElement);
        ItemPresentation containerPresentation = container == null || container instanceof PsiFile ? null : ((NavigationItem) container).getPresentation();
        String containerText = containerPresentation == null ? null : containerPresentation.getPresentableText();
        fullName = (containerText == null ? "" : containerText + ".") + presentation.getPresentableText();
    }
    return CodeInsightBundle.message("goto.implementation.chooserTitle", fullName, length, finished ? "" : " so far");
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class JavaModulePresentationProvider method getPresentation.

@Override
public ItemPresentation getPresentation(@NotNull final PsiJavaModule item) {
    return new ItemPresentation() {

        @Override
        public String getPresentableText() {
            return item.getName();
        }

        @Nullable
        @Override
        public String getLocationString() {
            VirtualFile file = PsiImplUtil.getModuleVirtualFile(item);
            FileIndexFacade index = FileIndexFacade.getInstance(item.getProject());
            if (index.isInLibraryClasses(file)) {
                Matcher matcher = JAR_NAME.matcher(file.getPath());
                if (matcher.find()) {
                    return matcher.group(1);
                }
            } else if (index.isInSource(file)) {
                Module module = index.getModuleForFile(file);
                if (module != null) {
                    return '[' + module.getName() + ']';
                }
            }
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return AllIcons.Nodes.JavaModule;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Matcher(java.util.regex.Matcher) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiJavaModule(com.intellij.psi.PsiJavaModule) Module(com.intellij.openapi.module.Module) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 28 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class AbstractMvcPsiNodeDescriptor method updateImpl.

@Override
protected void updateImpl(final PresentationData data) {
    final PsiElement psiElement = extractPsiFromValue();
    if (psiElement instanceof NavigationItem) {
        final ItemPresentation presentation = ((NavigationItem) psiElement).getPresentation();
        assert presentation != null;
        data.setPresentableText(presentation.getPresentableText());
    }
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiElement(com.intellij.psi.PsiElement)

Example 29 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class XPathEvalAction method showUsageView.

public static void showUsageView(@NotNull final Project project, MyUsageTarget usageTarget, Factory<UsageSearcher> searcherFactory, final EditExpressionAction editAction) {
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setTargetsNodeText("XPath Expression");
    presentation.setCodeUsages(false);
    presentation.setCodeUsagesString("Found Matches");
    presentation.setNonCodeUsagesString("Result");
    presentation.setUsagesString("XPath Result");
    presentation.setUsagesWord("match");
    final ItemPresentation targetPresentation = usageTarget.getPresentation();
    if (targetPresentation != null) {
        presentation.setTabText(StringUtil.shortenTextWithEllipsis("XPath '" + targetPresentation.getPresentableText() + '\'', 60, 0, true));
    } else {
        presentation.setTabText("XPath");
    }
    presentation.setScopeText("XML Files");
    presentation.setOpenInNewTab(FindSettings.getInstance().isShowResultsInSeparateView());
    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
    processPresentation.setProgressIndicatorFactory(() -> new FindProgressIndicator(project, "XML Document(s)"));
    processPresentation.setShowPanelIfOnlyOneUsage(true);
    processPresentation.setShowNotFoundMessage(true);
    final UsageTarget[] usageTargets = { usageTarget };
    UsageViewManager.getInstance(project).searchAndShowUsages(usageTargets, searcherFactory, processPresentation, presentation, new UsageViewManager.UsageViewStateListener() {

        @Override
        public void usageViewCreated(@NotNull UsageView usageView) {
            usageView.addButtonToLowerPane(editAction, "&Edit Expression");
        }

        @Override
        public void findingUsagesFinished(UsageView usageView) {
        }
    });
}
Also used : FindProgressIndicator(com.intellij.find.FindProgressIndicator) ItemPresentation(com.intellij.navigation.ItemPresentation)

Example 30 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class UsageViewTreeCellRenderer method getPlainTextForNode.

// computes the node text regardless of the node visibility
@NotNull
String getPlainTextForNode(Object value) {
    boolean showAsReadOnly = false;
    StringBuilder result = new StringBuilder();
    if (value instanceof Node) {
        Node node = (Node) value;
        if (!node.isValid()) {
            result.append(UsageViewBundle.message("node.invalid")).append(" ");
        }
        if (myPresentation.isShowReadOnlyStatusAsRed() && node.isReadOnly()) {
            showAsReadOnly = true;
        }
    }
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
        Object userObject = treeNode.getUserObject();
        if (userObject instanceof UsageTarget) {
            UsageTarget usageTarget = (UsageTarget) userObject;
            if (usageTarget.isValid()) {
                final ItemPresentation presentation = usageTarget.getPresentation();
                LOG.assertTrue(presentation != null);
                if (showAsReadOnly) {
                    result.append(UsageViewBundle.message("node.readonly")).append(" ");
                }
                final String text = presentation.getPresentableText();
                result.append(text == null ? "" : text);
            } else {
                result.append(UsageViewBundle.message("node.invalid"));
            }
        } else if (treeNode instanceof GroupNode) {
            GroupNode node = (GroupNode) treeNode;
            if (node.isRoot()) {
                result.append(StringUtil.capitalize(myPresentation.getUsagesWord()));
            } else {
                result.append(node.getGroup().getText(myView));
            }
            int count = node.getRecursiveUsageCount();
            result.append(" (").append(StringUtil.pluralize(count + " " + myPresentation.getUsagesWord(), count)).append(")");
        } else if (treeNode instanceof UsageNode) {
            UsageNode node = (UsageNode) treeNode;
            if (showAsReadOnly) {
                result.append(UsageViewBundle.message("node.readonly")).append(" ");
            }
            if (node.isValid()) {
                TextChunk[] text = node.getUsage().getPresentation().getText();
                for (TextChunk textChunk : text) {
                    result.append(textChunk.getText());
                }
            }
        } else if (userObject instanceof String) {
            result.append((String) userObject);
        } else {
            result.append(userObject == null ? "" : userObject.toString());
        }
    } else {
        result.append(value);
    }
    return result.toString();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ItemPresentation(com.intellij.navigation.ItemPresentation) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ItemPresentation (com.intellij.navigation.ItemPresentation)40 NotNull (org.jetbrains.annotations.NotNull)10 NavigationItem (com.intellij.navigation.NavigationItem)8 Nullable (org.jetbrains.annotations.Nullable)8 PsiFile (com.intellij.psi.PsiFile)6 Parent (org.elixir_lang.navigation.item_presentation.Parent)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 PsiElement (com.intellij.psi.PsiElement)5 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)3 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)3 LayeredIcon (com.intellij.ui.LayeredIcon)3 DartClass (com.jetbrains.lang.dart.psi.DartClass)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 ColoredItemPresentation (com.intellij.navigation.ColoredItemPresentation)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 JBColor (com.intellij.ui.JBColor)2 RowIcon (com.intellij.ui.RowIcon)2