consulo.ide.IconDescriptorUpdaters Java Examples

The following examples show how to use consulo.ide.IconDescriptorUpdaters. 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: CSharpLookupElementBuilder.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private static <E extends DotNetGenericParameterListOwner & DotNetQualifiedElement> LookupElementBuilder buildTypeLikeElement(@Nonnull E element, @Nonnull DotNetGenericExtractor extractor)
{
	String genericText = CSharpElementPresentationUtil.formatGenericParameters(element, extractor);

	String name = CSharpNamedElement.getEscapedName(element);

	LookupElementBuilder builder = LookupElementBuilder.create(element, name + (extractor == DotNetGenericExtractor.EMPTY ? "" : genericText));

	builder = builder.withPresentableText(name); // always show only name

	builder = builder.withIcon(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY));

	builder = builder.withTypeText(element.getPresentableParentQName());

	builder = builder.withTailText(genericText, true);

	if(extractor == DotNetGenericExtractor.EMPTY)
	{
		builder = withGenericInsertHandler(element, builder);
	}
	return builder;
}
 
Example #2
Source File: CoverageListNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void update(final PresentationData presentation) {
  ApplicationManager.getApplication().runReadAction(new Runnable() {
    public void run() {
      final Object value = getValue();
      if (value instanceof PsiNamedElement) {

        if (value instanceof PsiQualifiedNamedElement &&
            (myStateBean.myFlattenPackages && ((PsiNamedElement)value).getContainingFile() == null ||
             getParent() instanceof CoverageListRootNode)) {
          presentation.setPresentableText(((PsiQualifiedNamedElement)value).getQualifiedName());
        }
        else {
          presentation.setPresentableText(((PsiNamedElement)value).getName());
        }
        presentation.setIcon(IconDescriptorUpdaters.getIcon(((PsiElement)value), 0));
      }
    }
  });
}
 
Example #3
Source File: PsiFileNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example #4
Source File: NavBarPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("MethodMayBeStatic")
@Nullable
public Icon getIcon(final Object object) {
  if (!NavBarModel.isValid(object)) return null;
  if (object instanceof Project) return AllIcons.Nodes.ProjectTab;
  if (object instanceof Module) return AllIcons.Nodes.Module;
  try {
    if (object instanceof PsiElement) {
      Icon icon = TargetAWT.to(AccessRule.read(() -> ((PsiElement)object).isValid() ? IconDescriptorUpdaters.getIcon(((PsiElement)object), 0) : null));

      if (icon != null && (icon.getIconHeight() > JBUI.scale(16) || icon.getIconWidth() > JBUI.scale(16))) {
        icon = IconUtil.cropIcon(icon, JBUI.scale(16), JBUI.scale(16));
      }
      return icon;
    }
  }
  catch (IndexNotReadyException e) {
    return null;
  }
  if (object instanceof ModuleExtensionWithSdkOrderEntry) {
    return TargetAWT.to(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)object).getSdk()));
  }
  if (object instanceof LibraryOrderEntry) return AllIcons.Nodes.PpLibFolder;
  if (object instanceof ModuleOrderEntry) return AllIcons.Nodes.Module;
  return null;
}
 
Example #5
Source File: PsiFileImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation() {
  return new ItemPresentation() {
    @Override
    public String getPresentableText() {
      return getName();
    }

    @Override
    public String getLocationString() {
      final PsiDirectory psiDirectory = getParent();
      if (psiDirectory != null) {
        return psiDirectory.getVirtualFile().getPresentableUrl();
      }
      return null;
    }

    @Override
    public Image getIcon() {
      return IconDescriptorUpdaters.getIcon(PsiFileImpl.this, 0);
    }
  };
}
 
Example #6
Source File: UsageListCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(final JList list,
                                     final Object value,
                                     final int index,
                                     final boolean selected,
                                     final boolean hasFocus) {
  Usage usage = (Usage)value;
  UsagePresentation presentation = usage.getPresentation();
  setIcon(presentation.getIcon());
  VirtualFile virtualFile = getVirtualFile(usage);
  if (virtualFile != null) {
    append(virtualFile.getName() + ": ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
    setIcon(virtualFile.getFileType().getIcon());
    PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
    if (psiFile != null) {
      setIcon(IconDescriptorUpdaters.getIcon(psiFile, 0));
    }
  }

  TextChunk[] text = presentation.getText();
  for (TextChunk textChunk : text) {
    SimpleTextAttributes simples = textChunk.getSimpleAttributesIgnoreBackground();
    append(textChunk.getText(), simples);
  }
}
 
Example #7
Source File: PomTargetPsiElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Image getIcon() {
  Image icon = TypePresentationService.getInstance().getIcon(myTarget);
  if (icon != null) return icon;

  if (myTarget instanceof PsiTarget) {
    return IconDescriptorUpdaters.getIcon(((PsiTarget)myTarget).getNavigationElement(), 0);
  }
  return null;
}
 
Example #8
Source File: MethodNodeBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void customizeRenderer(ColoredTreeCellRenderer renderer) {
  if (myMethod == null) return;
  int flags = Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS;
  renderer.setIcon(IconDescriptorUpdaters.getIcon(myMethod, flags));

  customizeRendererText(renderer);
}
 
Example #9
Source File: BasePsiNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon() {
  final PsiElement element = getPsiElement();
  if (myIcon == null) {
    myIcon = element != null && element.isValid() ? TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS)) : null;
  }
  return myIcon;
}
 
Example #10
Source File: IconUtilEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Image getIcon(Object object, @Iconable.IconFlags int flags, Project project) {
  if (object instanceof PsiElement) {
    return IconDescriptorUpdaters.getIcon(((PsiElement)object), flags);
  }
  if (object instanceof Module) {
    return AllIcons.Nodes.Module;
  }
  if (object instanceof VirtualFile) {
    VirtualFile file = (VirtualFile)object;
    return VfsIconUtil.getIcon(file, flags, project);
  }
  return null;
}
 
Example #11
Source File: SmartElementDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public boolean update() {
  PsiElement element = mySmartPointer.getElement();
  if (element == null) return true;
  int flags = Iconable.ICON_FLAG_VISIBILITY;
  if (isMarkReadOnly()){
    flags |= Iconable.ICON_FLAG_READ_STATUS;
  }
  consulo.ui.image.Image icon = null;
  try {
    icon = IconDescriptorUpdaters.getIcon(element, flags);
  }
  catch (IndexNotReadyException ignored) {
  }
  Color color = null;

  if (isMarkModified() ){
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
    if (virtualFile != null) {
      color = FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor();
    }
  }
  if (CopyPasteManager.getInstance().isCutElement(element)) {
    color = CopyPasteManager.CUT_COLOR;
  }

  boolean changes = !Comparing.equal(icon, getIcon()) || !Comparing.equal(color, myColor);
  setIcon(icon);
  myColor = color;
  return changes;
}
 
Example #12
Source File: TodoDirNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void setupIcon(PresentationData data, PsiDirectory psiDirectory) {
  final VirtualFile virtualFile = psiDirectory.getVirtualFile();
  if (ProjectRootsUtil.isModuleContentRoot(virtualFile, psiDirectory.getProject())) {
    data.setIcon(IconDescriptorUpdaters.getIcon(psiDirectory, 0));
  }
  else {
    super.setupIcon(data, psiDirectory);
  }
}
 
Example #13
Source File: BookmarkItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void setupRenderer(SimpleColoredComponent renderer, Project project, Bookmark bookmark, boolean selected) {
  VirtualFile file = bookmark.getFile();
  if (!file.isValid()) {
    return;
  }

  PsiManager psiManager = PsiManager.getInstance(project);

  PsiElement fileOrDir = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);
  if (fileOrDir != null) {
    renderer.setIcon(IconDescriptorUpdaters.getIcon(fileOrDir, 0));
  }

  String description = bookmark.getDescription();
  if (description != null) {
    renderer.append(description + " ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
  }

  FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
  TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
  renderer.append(file.getName(), SimpleTextAttributes.fromTextAttributes(attributes));
  if (bookmark.getLine() >= 0) {
    renderer.append(":", SimpleTextAttributes.GRAYED_ATTRIBUTES);
    renderer.append(String.valueOf(bookmark.getLine() + 1), SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }

  if (!selected) {
    FileColorManager colorManager = FileColorManager.getInstance(project);
    if (fileOrDir instanceof PsiFile) {
      Color color = colorManager.getRendererBackground((PsiFile)fileOrDir);
      if (color != null) {
        renderer.setBackground(color);
      }
    }
  }
}
 
Example #14
Source File: PsiTreeElementBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Image getIcon() {
  final PsiElement element = getElement();
  if (element != null) {
    int flags = Iconable.ICON_FLAG_READ_STATUS;
    if (!(element instanceof PsiFile) || !element.isWritable()) flags |= Iconable.ICON_FLAG_VISIBILITY;
    return IconDescriptorUpdaters.getIcon(element, flags);
  }
  else {
    return null;
  }
}
 
Example #15
Source File: DirectoryNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon() {
  if (myDirectory != null) {
    return TargetAWT.to(IconDescriptorUpdaters.getIcon(myDirectory, 0));
  }
  return AllIcons.Nodes.TreeOpen;
}
 
Example #16
Source File: FileInfoManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Object getFileLookupItem(PsiElement psiElement) {
  if (!(psiElement instanceof PsiFile) || !(psiElement.isPhysical())) {
    return psiElement;
  }

  final PsiFile file = (PsiFile)psiElement;
  return getFileInfoManager()._getLookupItem(file, file.getName(), TargetAWT.to(IconDescriptorUpdaters.getIcon(file, 0)));
}
 
Example #17
Source File: DefaultLookupItemRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Icon _getRawIcon(LookupElement item, boolean real) {
  if (item instanceof LookupItem) {
    Icon icon = (Icon)((LookupItem)item).getAttribute(LookupItem.ICON_ATTR);
    if (icon != null) return icon;
  }

  Object o = item.getObject();

  if (!real) {
    if (item.getObject() instanceof String) {
      return EmptyIcon.ICON_0;
    }

    return new EmptyIcon(IconUtil.getDefaultNodeIconSize() * 2, IconUtil.getDefaultNodeIconSize());
  }

  if (o instanceof Iconable && !(o instanceof PsiElement)) {
    return TargetAWT.to(((Iconable)o).getIcon(Iconable.ICON_FLAG_VISIBILITY));
  }

  final PsiElement element = item.getPsiElement();
  if (element != null && element.isValid()) {
    return TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY));
  }
  return null;
}
 
Example #18
Source File: RefElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Icon getIcon(final boolean expanded) {
  final PsiElement element = getPsiElement();
  if (element != null && element.isValid()) {
    return TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS));
  }
  return null;
}
 
Example #19
Source File: UsageInfo2UsageAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Image getIcon() {
  Image icon = myIcon;
  if (icon == null) {
    PsiElement psiElement = getElement();
    myIcon = icon = psiElement != null && psiElement.isValid() ? IconDescriptorUpdaters.getIcon(psiElement, 0) : null;
  }
  return icon;
}
 
Example #20
Source File: CSharpBaseGroupingRule.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Image getIcon()
{
	T element = myPointer.getElement();
	if(element == null)
	{
		return null;
	}
	return IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
}
 
Example #21
Source File: CSharpMemberChooseObject.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void renderTreeNode(SimpleColoredComponent component, JTree tree)
{
	component.setIcon(IconDescriptorUpdaters.getIcon(myDeclaration, Iconable.ICON_FLAG_VISIBILITY));
	component.append(getPresentationText());
}
 
Example #22
Source File: CSharpNoVariantsDelegator.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
private static void consumeType(final CompletionParameters completionParameters,
		CSharpReferenceExpression referenceExpression,
		Consumer<LookupElement> consumer,
		boolean insideUsingList,
		DotNetTypeDeclaration someType)
{
	final String parentQName = someType.getPresentableParentQName();
	if(StringUtil.isEmpty(parentQName))
	{
		return;
	}

	String presentationText = MsilHelper.cutGenericMarker(someType.getName());

	int genericCount;
	DotNetGenericParameter[] genericParameters = someType.getGenericParameters();
	if((genericCount = genericParameters.length) > 0)
	{
		presentationText += "<" + StringUtil.join(genericParameters, parameter -> parameter.getName(), ", ");
		presentationText += ">";
	}

	String lookupString = insideUsingList ? someType.getPresentableQName() : someType.getName();
	if(lookupString == null)
	{
		return;
	}
	lookupString = MsilHelper.cutGenericMarker(lookupString);

	DotNetQualifiedElement targetElementForLookup = someType;
	CSharpMethodDeclaration methodDeclaration = someType.getUserData(CSharpResolveUtil.DELEGATE_METHOD_TYPE);
	if(methodDeclaration != null)
	{
		targetElementForLookup = methodDeclaration;
	}
	LookupElementBuilder builder = LookupElementBuilder.create(targetElementForLookup, lookupString);
	builder = builder.withPresentableText(presentationText);
	builder = builder.withIcon(IconDescriptorUpdaters.getIcon(targetElementForLookup, Iconable.ICON_FLAG_VISIBILITY));

	builder = builder.withTypeText(parentQName, true);
	final InsertHandler<LookupElement> ltGtInsertHandler = genericCount == 0 ? null : LtGtInsertHandler.getInstance(genericCount > 0);
	if(insideUsingList)
	{
		builder = builder.withInsertHandler(ltGtInsertHandler);
	}
	else
	{
		builder = builder.withInsertHandler(new InsertHandler<LookupElement>()
		{
			@Override
			@RequiredWriteAction
			public void handleInsert(InsertionContext context, LookupElement item)
			{
				if(ltGtInsertHandler != null)
				{
					ltGtInsertHandler.handleInsert(context, item);
				}

				context.commitDocument();

				new AddUsingAction(completionParameters.getEditor(), context.getFile(), Collections.<NamespaceReference>singleton(new NamespaceReference(parentQName, null))).execute();
			}
		});
	}

	if(DotNetAttributeUtil.hasAttribute(someType, DotNetTypes.System.ObsoleteAttribute))
	{
		builder = builder.withStrikeoutness(true);
	}

	CSharpTypeLikeLookupElement element = CSharpTypeLikeLookupElement.create(builder, DotNetGenericExtractor.EMPTY, referenceExpression);
	element.putUserData(CSharpNoVariantsDelegator.NOT_IMPORTED, Boolean.TRUE);
	consumer.consume(element);
}
 
Example #23
Source File: ImplementationViewComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Icon getIconForFile(PsiFile psiFile) {
  return TargetAWT.to(IconDescriptorUpdaters.getIcon(psiFile.getNavigationElement(), 0));
}
 
Example #24
Source File: PathReference.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Icon fun(final PathReference pathReference) {
  final PsiElement element = pathReference.resolve();
  return element == null ? myDefaultIcon : TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_READ_STATUS));
}
 
Example #25
Source File: LookupElementBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static LookupElementBuilder createWithIcon(@Nonnull PsiNamedElement element) {
  PsiUtilCore.ensureValid(element);
  return create(element).withIcon(IconDescriptorUpdaters.getIcon(element, 0));
}
 
Example #26
Source File: XLineBreakpointType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public Image getIcon() {
  return IconDescriptorUpdaters.getIcon(myElement, 0);
}
 
Example #27
Source File: PsiElementListCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected Image getIcon(PsiElement element) {
  return IconDescriptorUpdaters.getIcon(element, getIconFlags());
}
 
Example #28
Source File: PsiElementUsageGroupBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public PsiElementUsageGroupBase(@Nonnull T element) {
  this(element, IconDescriptorUpdaters.getIcon(element, 0));
}
 
Example #29
Source File: CSharpQualifiedElementPresentationProvider.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Image getIcon()
{
	return IconDescriptorUpdaters.getIcon(myDeclaration, Iconable.ICON_FLAG_VISIBILITY);
}
 
Example #30
Source File: AbstractMemberSelectionTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected Icon getMemberIcon(M memberInfo, @Iconable.IconFlags int flags) {
  return TargetAWT.to(IconDescriptorUpdaters.getIcon(memberInfo.getMember(), flags));
}