Search in sources :

Example 1 with LookupValueWithUIHint

use of com.intellij.codeInsight.lookup.LookupValueWithUIHint in project intellij-community by JetBrains.

the class CompletionData method objectToLookupItem.

public static LookupElement objectToLookupItem(@NotNull final Object object) {
    if (object instanceof LookupElement)
        return (LookupElement) object;
    String s = null;
    TailType tailType = TailType.NONE;
    if (object instanceof PsiElement) {
        s = PsiUtilCore.getName((PsiElement) object);
    } else if (object instanceof PsiMetaData) {
        s = ((PsiMetaData) object).getName();
    } else if (object instanceof String) {
        s = (String) object;
    } else if (object instanceof Template) {
        s = ((Template) object).getKey();
    } else if (object instanceof PresentableLookupValue) {
        s = ((PresentableLookupValue) object).getPresentation();
    }
    if (s == null) {
        throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
    }
    LookupItem item = new LookupItem(object, s);
    if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
        item.setBold();
    }
    item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
    return item;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) LookupItem(com.intellij.codeInsight.lookup.LookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PresentableLookupValue(com.intellij.codeInsight.lookup.PresentableLookupValue) TailType(com.intellij.codeInsight.TailType) Template(com.intellij.codeInsight.template.Template)

Example 2 with LookupValueWithUIHint

use of com.intellij.codeInsight.lookup.LookupValueWithUIHint in project intellij-community by JetBrains.

the class LookupCellRenderer method setTypeTextLabel.

private int setTypeTextLabel(LookupElement item, final Color background, Color foreground, final LookupElementPresentation presentation, int allowedWidth, boolean selected, boolean nonFocusedSelection, FontMetrics normalMetrics) {
    final String givenText = presentation.getTypeText();
    final String labelText = trimLabelText(StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, normalMetrics);
    int used = RealLookupElementPresentation.getStringWidth(labelText, normalMetrics);
    final Icon icon = presentation.getTypeIcon();
    if (icon != null) {
        myTypeLabel.setIcon(icon);
        used += icon.getIconWidth();
    }
    Color sampleBackground = background;
    Object o = item.isValid() ? item.getObject() : null;
    //noinspection deprecation
    if (o instanceof LookupValueWithUIHint && StringUtil.isEmpty(labelText)) {
        //noinspection deprecation
        Color proposedBackground = ((LookupValueWithUIHint) o).getColorHint();
        if (proposedBackground != null) {
            sampleBackground = proposedBackground;
        }
        myTypeLabel.append("  ");
        used += normalMetrics.stringWidth("WW");
    } else {
        myTypeLabel.append(labelText);
    }
    myTypeLabel.setBackground(sampleBackground);
    myTypeLabel.setForeground(getTypeTextColor(item, foreground, presentation, selected, nonFocusedSelection));
    return used;
}
Also used : LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) EmptyIcon(com.intellij.util.ui.EmptyIcon) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint)

Aggregations

LookupValueWithUIHint (com.intellij.codeInsight.lookup.LookupValueWithUIHint)2 TailType (com.intellij.codeInsight.TailType)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupItem (com.intellij.codeInsight.lookup.LookupItem)1 PresentableLookupValue (com.intellij.codeInsight.lookup.PresentableLookupValue)1 Template (com.intellij.codeInsight.template.Template)1 PsiMetaData (com.intellij.psi.meta.PsiMetaData)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1