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);
}
}
}
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations