Java Code Examples for com.intellij.codeInsight.lookup.LookupElement#isValid()

The following examples show how to use com.intellij.codeInsight.lookup.LookupElement#isValid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LookupUi.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateHint() {
  myLookup.checkValid();
  if (myHintButton.isVisible()) {
    myHintButton.setVisible(false);
  }

  LookupElement item = myLookup.getCurrentItem();
  if (item != null && item.isValid()) {
    Collection<LookupElementAction> actions = myLookup.getActionsFor(item);
    if (!actions.isEmpty()) {
      myHintAlarm.addRequest(() -> {
        if (ShowHideIntentionIconLookupAction.shouldShowLookupHint() && !((CompletionExtender)myList.getExpandableItemsHandler()).isShowing() && !myProcessIcon.isVisible()) {
          myHintButton.setVisible(true);
        }
      }, 500, myModalityState);
    }
  }
}
 
Example 2
Source File: LookupCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}