PsiReferences and Icons

Hi all,
I try to implement fancy navigation inside of XML file.  IN some cases where is ambiguity, I  provide multiple PSI references in an array:
------------------%<-----------------
  public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) {
        DomElement domElement = DomUtil.getDomElement(element);
        Event event = DomUtil.getParentOfType(domElement, Event.class, true);

        // outgoing sequence
        if (null != event.getType() && null != event.getType().getValue()) {
            if (event.getType().getValue().isSource()) {
                return new PsiReference[] { new BoundLinkInReference(element), new OutgoingSequenceReference(element) };
            }    else {
                return new PsiReference[] { new BoundLinkOutReference(element), new IncomingSequenceReference(element) };
            }
        }

        // incoming message
        return  PsiReference.EMPTY_ARRAY;

    }
-----------------------%<---------------------

They are presented as fancy dropdown selection list,  and navigation works as intendent,  but I would like to add icons to them.  I tried to add icon to variant extraction like this:

------------------------%<-------------------------
   @NotNull
    @Override
    public Object[] getVariants() {
        ArrayList<Object> variants = new ArrayListModel<Object>();
        for (ResolveResult resolveResult : getCandidates()) {
            XmlAttributeValue psiElement = (XmlAttributeValue) resolveResult.getElement();
            variants.add(extractVariant(psiElement));
        }
        return variants.toArray();
    }

   protected Object extractVariant(XmlAttributeValue psiElement) {
        return LookupElementBuilder.create(psiElement, psiElement.getValue()).withIcon(ApdlIcons.CallActivity);
    }
-----------------------%<----------------------------

Yet there is no icon displayed.

Classical question is:  what I'm doing wrong

1 comment
Comment actions Permalink

Icon probably comes from com.intellij.navigation.NavigationItem#getPresentation -> com.intellij.navigation.ItemPresentation#getIcon (implemented by target of reference). Most likely You need to decorate your PsiElement and override getPresentation method (or implement NavigationItem or NavigatablePsiElement interface if needed).

0

Please sign in to leave a comment.