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 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 PyStructureViewElement method getPresentation.
@NotNull
@Override
public ItemPresentation getPresentation() {
final PyElement element = getValue();
final ItemPresentation presentation = element != null ? element.getPresentation() : null;
return new ColoredItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
if (element instanceof PyFile) {
return element.getName();
}
return presentation != null ? presentation.getPresentableText() : PyNames.UNNAMED_ELEMENT;
}
@Nullable
@Override
public TextAttributesKey getTextAttributesKey() {
if (isInherited()) {
return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
}
return null;
}
@Nullable
@Override
public String getLocationString() {
return null;
}
@Nullable
@Override
public Icon getIcon(boolean open) {
if (element == null) {
return null;
}
Icon normal_icon = element.getIcon(0);
// override normal
if (myIcon != null)
normal_icon = myIcon;
if (myVisibility == Visibility.NORMAL) {
return normal_icon;
} else {
LayeredIcon icon = new LayeredIcon(2);
icon.setIcon(normal_icon, 0);
Icon overlay = null;
if (myVisibility == Visibility.PRIVATE || myVisibility == Visibility.PROTECTED) {
overlay = PythonIcons.Python.Nodes.Lock;
} else if (myVisibility == Visibility.PREDEFINED) {
overlay = PythonIcons.Python.Nodes.Cyan_dot;
} else if (myVisibility == Visibility.INVISIBLE) {
overlay = PythonIcons.Python.Nodes.Red_inv_triangle;
}
if (overlay != null) {
icon.setIcon(overlay, 1);
}
return icon;
}
}
};
}
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;
}
Aggregations