add colored speed search for AbstractFileTreeTable

This commit is contained in:
Sergey Ignatov
2016-01-27 23:06:42 +03:00
parent ba75fc2c4d
commit 6ce5184d93
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,10 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.TableUtil;
import com.intellij.ui.TreeTableSpeedSearch;
import com.intellij.ui.speedSearch.SpeedSearchUtil;
import com.intellij.ui.treeStructure.treetable.TreeTable;
import com.intellij.ui.treeStructure.treetable.TreeTableCellRenderer;
import com.intellij.ui.treeStructure.treetable.TreeTableModel;
@@ -101,24 +103,29 @@ public class AbstractFileTreeTable<T> extends TreeTable {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
getTree().setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded,
final boolean leaf, final int row, final boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
SimpleColoredComponent c = new SimpleColoredComponent();
if (value instanceof ProjectRootNode) {
setText(getProjectNodeText());
setIcon(AllIcons.Nodes.Project);
return this;
}
FileNode fileNode = (FileNode)value;
VirtualFile file = fileNode.getObject();
setText(fileNode.getParent() instanceof FileNode ? file.getName() : file.getPresentableUrl());
if (file.isDirectory()) {
setIcon(fileIndex.isExcluded(file) ? AllIcons.Modules.ExcludeRoot : PlatformIcons.DIRECTORY_CLOSED_ICON);
c.append(getProjectNodeText());
c.setIcon(AllIcons.Nodes.Project);
}
else {
setIcon(IconUtil.getIcon(file, 0, null));
FileNode fileNode = (FileNode)value;
VirtualFile file = fileNode.getObject();
c.append(fileNode.getParent() instanceof FileNode ? file.getName() : file.getPresentableUrl());
Icon icon = file.isDirectory()
? fileIndex.isExcluded(file) ? AllIcons.Modules.ExcludeRoot
: PlatformIcons.DIRECTORY_CLOSED_ICON : IconUtil.getIcon(file, 0, null);
c.setIcon(icon);
}
return this;
SpeedSearchUtil.applySpeedSearchHighlighting(AbstractFileTreeTable.this, c, false, selected);
return c;
}
});
getTableHeader().setReorderingAllowed(false);