Search in sources :

Example 11 with ItemPresentation

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

the class PsiElement2UsageTargetAdapter method update.

private void update(PsiElement element) {
    if (element != null && element.isValid()) {
        final ItemPresentation presentation = ((NavigationItem) element).getPresentation();
        myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
        myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
        myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
        if (myIconOpen == null || myIconClosed == null) {
            if (element instanceof PsiMetaOwner) {
                final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) element;
                final PsiMetaData metaData = psiMetaOwner.getMetaData();
                if (metaData instanceof PsiPresentableMetaData) {
                    final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData) metaData;
                    if (myIconOpen == null)
                        myIconOpen = ComputableIcon.create(psiPresentableMetaData);
                    if (myIconClosed == null)
                        myIconClosed = ComputableIcon.create(psiPresentableMetaData);
                }
            } else if (element instanceof PsiFile) {
                final PsiFile psiFile = (PsiFile) element;
                final VirtualFile virtualFile = psiFile.getVirtualFile();
                if (virtualFile != null) {
                    myIconOpen = ComputableIcon.create(virtualFile);
                    myIconClosed = ComputableIcon.create(virtualFile);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) PsiMetaData(com.intellij.psi.meta.PsiMetaData) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Example 12 with ItemPresentation

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

the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.

@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
    if (!(value instanceof NavigationItem))
        return false;
    NavigationItem item = (NavigationItem) value;
    TextAttributes attributes = getNavigationItemAttributes(item);
    SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
    Color color = list.getForeground();
    if (nameAttributes == null)
        nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
    renderer.append(item + " ", nameAttributes);
    ItemPresentation itemPresentation = item.getPresentation();
    assert itemPresentation != null;
    renderer.setIcon(itemPresentation.getIcon(true));
    String locationString = itemPresentation.getLocationString();
    if (!StringUtil.isEmpty(locationString)) {
        renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
    }
    return true;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 13 with ItemPresentation

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

the class ExternalLibrariesNode method getChildren.

@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    Project project = Objects.requireNonNull(getProject());
    List<AbstractTreeNode> children = new ArrayList<>();
    ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
    Module[] modules = ModuleManager.getInstance(project).getModules();
    Set<Library> processedLibraries = new THashSet<>();
    Set<Sdk> processedSdk = new THashSet<>();
    for (Module module : modules) {
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
        for (final OrderEntry orderEntry : orderEntries) {
            if (orderEntry instanceof LibraryOrderEntry) {
                final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
                final Library library = libraryOrderEntry.getLibrary();
                if (library == null)
                    continue;
                if (processedLibraries.contains(library))
                    continue;
                processedLibraries.add(library);
                if (!hasExternalEntries(fileIndex, libraryOrderEntry))
                    continue;
                final String libraryName = library.getName();
                if (libraryName == null || libraryName.length() == 0) {
                    addLibraryChildren(libraryOrderEntry, children, project, this);
                } else {
                    children.add(new NamedLibraryElementNode(project, new NamedLibraryElement(null, libraryOrderEntry), getSettings()));
                }
            } else if (orderEntry instanceof JdkOrderEntry) {
                final JdkOrderEntry jdkOrderEntry = (JdkOrderEntry) orderEntry;
                final Sdk jdk = jdkOrderEntry.getJdk();
                if (jdk != null) {
                    if (processedSdk.contains(jdk))
                        continue;
                    processedSdk.add(jdk);
                    children.add(new NamedLibraryElementNode(project, new NamedLibraryElement(null, jdkOrderEntry), getSettings()));
                }
            }
        }
    }
    for (AdditionalLibraryRootsProvider provider : AdditionalLibraryRootsProvider.EP_NAME.getExtensions()) {
        Collection<SyntheticLibrary> libraries = provider.getAdditionalProjectLibraries(project);
        for (SyntheticLibrary library : libraries) {
            //noinspection InstanceofIncompatibleInterface
            if (library instanceof ItemPresentation) {
                children.add(new SyntheticLibraryElementNode(project, library, getSettings()));
            }
        }
    }
    return children;
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Sdk(com.intellij.openapi.projectRoots.Sdk) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ItemPresentation

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

the class ElementBase method getElementIcon.

@Nullable
protected Icon getElementIcon(@Iconable.IconFlags int flags) {
    final PsiElement element = (PsiElement) this;
    if (!element.isValid())
        return null;
    RowIcon baseIcon;
    final boolean isLocked = BitUtil.isSet(flags, ICON_FLAG_READ_STATUS) && !element.isWritable();
    int elementFlags = isLocked ? FLAGS_LOCKED : 0;
    if (element instanceof ItemPresentation && ((ItemPresentation) element).getIcon(false) != null) {
        baseIcon = createLayeredIcon(this, ((ItemPresentation) element).getIcon(false), elementFlags);
    } else if (element instanceof PsiFile) {
        PsiFile file = (PsiFile) element;
        VirtualFile virtualFile = file.getVirtualFile();
        final Icon fileTypeIcon;
        if (virtualFile == null) {
            fileTypeIcon = file.getFileType().getIcon();
        } else {
            fileTypeIcon = IconUtil.getIcon(virtualFile, flags & ~ICON_FLAG_READ_STATUS, file.getProject());
        }
        return createLayeredIcon(this, fileTypeIcon, elementFlags);
    } else {
        return null;
    }
    return baseIcon;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiFile(com.intellij.psi.PsiFile) RowIcon(com.intellij.ui.RowIcon) RowIcon(com.intellij.ui.RowIcon) EmptyIcon(com.intellij.util.ui.EmptyIcon) LayeredIcon(com.intellij.ui.LayeredIcon) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with ItemPresentation

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

the class UsageViewTreeCellRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    boolean showAsReadOnly = false;
    if (value instanceof Node && value != tree.getModel().getRoot()) {
        Node node = (Node) value;
        if (!node.isValid()) {
            append(UsageViewBundle.message("node.invalid") + " ", UIUtil.isUnderDarcula() ? ourInvalidAttributesDarcula : ourInvalidAttributes);
        }
        if (myPresentation.isShowReadOnlyStatusAsRed() && node.isReadOnly()) {
            showAsReadOnly = true;
        }
    }
    myCalculated = false;
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
        Object userObject = treeNode.getUserObject();
        Rectangle visibleRect = ((JViewport) tree.getParent()).getViewRect();
        if (!visibleRect.isEmpty()) {
            //Protection against SOE on some OSes and JDKs IDEA-120631
            RowLocation visible = myRowBoundsCalled ? RowLocation.INSIDE_VISIBLE_RECT : isRowVisible(row, visibleRect);
            myRowBoundsCalled = false;
            if (visible != RowLocation.INSIDE_VISIBLE_RECT) {
                // for the node outside visible rect do not compute (expensive) presentation
                return;
            }
            if (!getIpad().equals(STANDARD_IPAD_NOWIFI)) {
                // for the visible node, return its ipad to the standard value
                setIpad(STANDARD_IPAD_NOWIFI);
            }
        }
        // we can be called recursively via isRowVisible()
        if (myCalculated)
            return;
        myCalculated = true;
        if (userObject instanceof UsageTarget) {
            UsageTarget usageTarget = (UsageTarget) userObject;
            if (!usageTarget.isValid()) {
                if (!getCharSequence(false).toString().contains(UsageViewBundle.message("node.invalid"))) {
                    append(UsageViewBundle.message("node.invalid"), ourInvalidAttributes);
                }
                return;
            }
            final ItemPresentation presentation = usageTarget.getPresentation();
            LOG.assertTrue(presentation != null);
            if (showAsReadOnly) {
                append(UsageViewBundle.message("node.readonly") + " ", ourReadOnlyAttributes);
            }
            final String text = presentation.getPresentableText();
            append(text == null ? "" : text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
            setIcon(presentation.getIcon(expanded));
        } else if (treeNode instanceof GroupNode) {
            GroupNode node = (GroupNode) treeNode;
            if (node.isRoot()) {
                append(StringUtil.capitalize(myPresentation.getUsagesWord()), patchAttrs(node, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES));
            } else {
                append(node.getGroup().getText(myView), patchAttrs(node, showAsReadOnly ? ourReadOnlyAttributes : SimpleTextAttributes.REGULAR_ATTRIBUTES));
                setIcon(node.getGroup().getIcon(expanded));
            }
            int count = node.getRecursiveUsageCount();
            SimpleTextAttributes attributes = patchAttrs(node, ourNumberOfUsagesAttribute);
            append(FontUtil.spaceAndThinSpace() + StringUtil.pluralize(count + " " + myPresentation.getUsagesWord(), count), SimpleTextAttributes.GRAYED_ATTRIBUTES.derive(attributes.getStyle(), null, null, null));
        } else if (treeNode instanceof UsageNode) {
            UsageNode node = (UsageNode) treeNode;
            setIcon(node.getUsage().getPresentation().getIcon());
            if (showAsReadOnly) {
                append(UsageViewBundle.message("node.readonly") + " ", patchAttrs(node, ourReadOnlyAttributes));
            }
            if (node.isValid()) {
                TextChunk[] text = node.getUsage().getPresentation().getText();
                for (int i = 0; i < text.length; i++) {
                    TextChunk textChunk = text[i];
                    SimpleTextAttributes simples = textChunk.getSimpleAttributesIgnoreBackground();
                    append(textChunk.getText() + (i == 0 ? " " : ""), patchAttrs(node, simples), true);
                }
            }
        } else if (userObject instanceof String) {
            append((String) userObject, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        } else {
            append(userObject == null ? "" : userObject.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
        }
    } else {
        append(value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
    SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, mySelected);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ItemPresentation(com.intellij.navigation.ItemPresentation) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

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