use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class ResourceBundleEditorRenderer method customize.
private boolean customize(Object value) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (!(userObject instanceof TreeElementWrapper)) {
return false;
}
final TreeElement treeElement = ((TreeElementWrapper) userObject).getValue();
if (treeElement == null) {
return false;
}
final ItemPresentation presentation = treeElement.getPresentation();
if (presentation instanceof TextAttributesPresentation) {
final TextAttributesPresentation textAttributesPresentation = (TextAttributesPresentation) presentation;
final String text = textAttributesPresentation.getPresentableText();
if (text != null) {
final SimpleTextAttributes attr = SimpleTextAttributes.fromTextAttributes(textAttributesPresentation.getTextAttributes(getColorsScheme()));
append(text, new SimpleTextAttributes(attr.getBgColor(), attr.getFgColor(), attr.getWaveColor(), attr.getStyle() | SimpleTextAttributes.STYLE_OPAQUE));
return true;
}
}
return false;
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class PyHierarchyNodeDescriptor method update.
@Override
public boolean update() {
boolean changes = super.update();
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
if (element == null) {
final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
}
return true;
}
final ItemPresentation presentation = element.getPresentation();
if (presentation != null) {
if (element instanceof PyFunction) {
final PyClass cls = ((PyFunction) element).getContainingClass();
if (cls != null) {
myHighlightedText.getEnding().addText(cls.getName() + ".");
}
}
myHighlightedText.getEnding().addText(presentation.getPresentableText());
myHighlightedText.getEnding().addText(" " + presentation.getLocationString(), HierarchyNodeDescriptor.getPackageNameAttributes());
}
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class PyElementNode method updateImpl.
@Override
protected void updateImpl(PresentationData data) {
final PyElement value = getValue();
final String name = value.getName();
final ItemPresentation presentation = value.getPresentation();
String presentableText = name != null ? name : PyNames.UNNAMED_ELEMENT;
Icon presentableIcon = value.getIcon(0);
if (presentation != null) {
final String text = presentation.getPresentableText();
if (text != null) {
presentableText = text;
}
final Icon icon = presentation.getIcon(false);
if (icon != null) {
presentableIcon = icon;
}
}
data.setPresentableText(presentableText);
data.setIcon(presentableIcon);
}
use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.
the class PyFileImpl method getPresentation.
@Override
public ItemPresentation getPresentation() {
return new ItemPresentation() {
@Override
public String getPresentableText() {
return getModuleName(PyFileImpl.this);
}
@Override
public String getLocationString() {
final String name = getLocationName();
return name != null ? "(" + name + ")" : null;
}
@Override
public Icon getIcon(final boolean open) {
if (PyUtil.isPackage(PyFileImpl.this)) {
return AllIcons.Modules.SourceFolder;
}
return PyFileImpl.this.getIcon(0);
}
@NotNull
private String getModuleName(@NotNull PyFile file) {
if (PyUtil.isPackage(file)) {
final PsiDirectory dir = file.getContainingDirectory();
if (dir != null) {
return dir.getName();
}
}
return FileUtil.getNameWithoutExtension(file.getName());
}
@Nullable
private String getLocationName() {
final QualifiedName name = QualifiedNameFinder.findShortestImportableQName(PyFileImpl.this);
if (name != null) {
final QualifiedName prefix = name.removeTail(1);
if (prefix.getComponentCount() > 0) {
return prefix.toString();
}
}
final String relativePath = getRelativeContainerPath();
if (relativePath != null) {
return relativePath;
}
final PsiDirectory psiDirectory = getParent();
if (psiDirectory != null) {
return psiDirectory.getVirtualFile().getPresentableUrl();
}
return null;
}
@Nullable
private String getRelativeContainerPath() {
final PsiDirectory psiDirectory = getParent();
if (psiDirectory != null) {
final VirtualFile virtualFile = getVirtualFile();
if (virtualFile != null) {
final VirtualFile root = ProjectFileIndex.SERVICE.getInstance(getProject()).getContentRootForFile(virtualFile);
if (root != null) {
final VirtualFile parent = virtualFile.getParent();
final VirtualFile rootParent = root.getParent();
if (rootParent != null && parent != null) {
return VfsUtilCore.getRelativePath(parent, rootParent, File.separatorChar);
}
}
}
}
return null;
}
};
}
use of com.intellij.navigation.ItemPresentation in project kotlin by JetBrains.
the class ReferenceUtils method renderAsGotoImplementation.
public static String renderAsGotoImplementation(@NotNull PsiElement element) {
PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) {
//default presenter return null for companion object
KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class);
assert containingClass != null;
return "companion object of " + renderAsGotoImplementation(containingClass);
}
if (navigationElement instanceof KtStringTemplateExpression) {
return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement);
}
Assert.assertTrue(navigationElement instanceof NavigationItem);
ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
if (presentation == null) {
String elementText = element.getText();
return elementText != null ? elementText : navigationElement.getText();
}
String presentableText = presentation.getPresentableText();
String locationString = presentation.getLocationString();
if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
locationString = "<anonymous>";
}
return locationString == null || navigationElement instanceof PsiPackage ? // for PsiPackage, presentableText is FQ name of current package
presentableText : locationString + "." + presentableText;
}
Aggregations