@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(Font.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(Font.PLAIN, JBColor.GRAY)); } return true; }
public static boolean openFileWithPsiElement( PsiElement element, boolean searchForOpen, boolean requestFocus) { boolean openAsNative = false; if (element instanceof PsiFile) { VirtualFile virtualFile = ((PsiFile) element).getVirtualFile(); if (virtualFile != null) { openAsNative = ElementBase.isNativeFileType(virtualFile.getFileType()); } } if (searchForOpen) { element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null); } else { element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, true); } if (openAsNative || !activatePsiElementIfOpen(element, searchForOpen, requestFocus)) { final NavigationItem navigationItem = (NavigationItem) element; if (!navigationItem.canNavigate()) return false; navigationItem.navigate(requestFocus); return true; } element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null); return false; }
@NotNull public String getNodeText(@NotNull PsiElement element, boolean useFullName) { if (useFullName) { if (element instanceof NavigationItem) { final NavigationItem navigationItem = ((NavigationItem) element); final ItemPresentation presentation = navigationItem.getPresentation(); if (presentation != null && presentation.getPresentableText() != null) { return presentation.getPresentableText(); } final String name = navigationItem.getName(); if (name != null) { return name; } } } if (element instanceof PsiNamedElement) { final String name = ((PsiNamedElement) element).getName(); if (name != null) return name; } return element.toString(); }