use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.
the class ColoredCommanderRenderer method customizeCellRenderer.
@Override
protected void customizeCellRenderer(@NotNull final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
// Fix GTK background
if (UIUtil.isUnderGTKLookAndFeel()) {
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
UIUtil.changeBackGround(this, background);
}
Color color = UIUtil.getListForeground();
SimpleTextAttributes attributes = null;
String locationString = null;
// for separator, see below
setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
if (value instanceof NodeDescriptor) {
final NodeDescriptor descriptor = (NodeDescriptor) value;
setIcon(descriptor.getIcon());
final Color elementColor = descriptor.getColor();
if (elementColor != null) {
color = elementColor;
}
if (descriptor instanceof AbstractTreeNode) {
final AbstractTreeNode treeNode = (AbstractTreeNode) descriptor;
final TextAttributesKey attributesKey = treeNode.getAttributesKey();
if (attributesKey != null) {
final TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
if (textAttributes != null)
attributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
}
locationString = treeNode.getLocationString();
final PresentationData presentation = treeNode.getPresentation();
if (presentation.hasSeparatorAbove() && !selected) {
setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, GroupedElementsRenderer.POPUP_SEPARATOR_FOREGROUND), BorderFactory.createEmptyBorder(0, 0, 1, 0)));
}
}
}
if (attributes == null)
attributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
final String text = value.toString();
if (myCommanderPanel.isEnableSearchHighlighting()) {
JList list1 = myCommanderPanel.getList();
if (list1 != null) {
SpeedSearchUtil.appendFragmentsForSpeedSearch(list1, text, attributes, selected, this);
}
} else {
append(text != null ? text : "", attributes);
}
if (locationString != null && locationString.length() > 0) {
append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
}
use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.
the class PresentableNodeDescriptor method update.
@Override
public final boolean update() {
if (shouldUpdateData()) {
PresentationData before = getPresentation().clone();
PresentationData updated = getUpdatedPresentation();
return shouldApply() && apply(updated, before);
}
return false;
}
use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.
the class ProjectTreeStructureTest method testQualifiedModuleNames.
public void testQualifiedModuleNames() throws Exception {
VirtualFile testDataRoot = ModuleRootManager.getInstance(myModule).getContentRoots()[0];
Module a = createModule("a");
PsiTestUtil.addContentRoot(a, testDataRoot.findFileByRelativePath("a"));
Module main = createModule("a.main");
PsiTestUtil.addContentRoot(main, testDataRoot.findFileByRelativePath("a/main"));
Module util = createModule("util");
PsiTestUtil.addContentRoot(util, testDataRoot.findFileByRelativePath("a/util"));
Module b = createModule("x.b");
PsiTestUtil.addContentRoot(b, testDataRoot.findFileByRelativePath("a/b"));
myStructure.setShowLibraryContents(false);
//todo[nik] this function is generic enough, it can be moved to testFramework
Function<Object, String> nodePresenter = o -> {
AbstractTreeNode node = (AbstractTreeNode) o;
node.update();
PresentationData presentation = node.getPresentation();
List<PresentableNodeDescriptor.ColoredFragment> fragments = presentation.getColoredText();
if (fragments.isEmpty()) {
return presentation.getPresentableText();
}
return StringUtil.join(fragments, PresentableNodeDescriptor.ColoredFragment::getText, "");
};
String treeStructure = ModuleGroupTestsKt.runWithQualifiedModuleNamesEnabled(() -> PlatformTestUtil.print(myStructure, myStructure.getRootElement(), nodePresenter));
assertEquals("testQualifiedModuleNames\n" + " a.iml\n" + " a.main.iml\n" + " qualifiedModuleNames [testQualifiedModuleNames]\n" + " a\n" + " b [x.b]\n" + " b.txt\n" + " main\n" + " main.txt\n" + " util\n" + " util.txt\n" + " testQualifiedModuleNames.iml\n" + " util.iml\n" + " x.b.iml\n", treeStructure);
}
use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.
the class ClassNameConvertor method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
ArrayList<AbstractTreeNode> result = new ArrayList<>();
for (final AbstractTreeNode aChildren : children) {
ProjectViewNode treeNode = (ProjectViewNode) aChildren;
Object o = treeNode.getValue();
if (o instanceof PsiFile && ((PsiFile) o).getVirtualFile().getExtension().equals("java")) {
final String name = ((PsiFile) o).getName();
ProjectViewNode viewNode = new ProjectViewNode<PsiFile>(myProject, (PsiFile) o, settings) {
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
return Collections.emptyList();
}
@Override
public String toTestString(Queryable.PrintInfo printInfo) {
return super.toTestString(printInfo) + " converted";
}
@Override
public String getTestPresentation() {
return name + " converted";
}
@Override
public boolean contains(@NotNull VirtualFile file) {
return false;
}
@Override
public void update(PresentationData presentation) {
}
};
result.add(viewNode);
} else {
result.add(treeNode);
}
}
return result;
}
use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.
the class FavoritesTreeViewPanel method createTextExporter.
private ExporterToTextFile createTextExporter() {
return new ExporterToTextFile() {
@Override
public JComponent getSettingsEditor() {
return null;
}
@Override
public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException {
}
@Override
public void removeSettingsChangedListener(ChangeListener listener) {
}
@NotNull
@Override
public String getReportText() {
final StringBuilder sb = new StringBuilder();
final Object[] elements = myBuilder.getStructure().getChildElements(myBuilder.getRoot());
final TreeUtil.Traverse traverse = new TreeUtil.Traverse() {
@Override
public boolean accept(Object node) {
if (node instanceof LoadingNode)
return true;
final AbstractTreeNode abstractTreeNode = (AbstractTreeNode) node;
if (sb.length() > 0) {
sb.append('\n');
}
int deepLevel = getDeepLevel((AbstractTreeNode) node);
for (int i = 1; i < deepLevel; i++) {
sb.append('\t');
}
abstractTreeNode.update();
final PresentationData presentation = abstractTreeNode.getPresentation();
sb.append(presentation.getPresentableText());
String locationString = presentation.getLocationString();
if (locationString == null) {
locationString = FavoritesTreeNodeDescriptor.getLocation(abstractTreeNode, myProject);
}
if (locationString != null) {
sb.append(" (").append(locationString).append(")");
}
return true;
}
public int getDeepLevel(AbstractTreeNode node) {
int result = 0;
while (node.getParent() != null) {
result++;
node = node.getParent();
}
return result;
}
};
for (Object element : elements) {
traverseDepth((AbstractTreeNode) element, traverse);
}
return sb.toString();
}
@NotNull
@Override
public String getDefaultFilePath() {
return myProject.getBasePath() + File.separator + "Favorites.txt";
}
@Override
public void exportedTo(String filePath) {
}
@Override
public boolean canExport() {
return true;
}
};
}
Aggregations