Search in sources :

Example 6 with PresentationData

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);
    }
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 7 with PresentationData

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;
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData)

Example 8 with PresentationData

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) PsiTestUtil(com.intellij.testFramework.PsiTestUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PresentableNodeDescriptor(com.intellij.ide.util.treeView.PresentableNodeDescriptor) Function(java.util.function.Function) ModuleGroupTestsKt(com.intellij.module.ModuleGroupTestsKt) List(java.util.List) PresentationData(com.intellij.ide.projectView.PresentationData) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Queryable(com.intellij.openapi.ui.Queryable) ModuleManagerImpl(com.intellij.openapi.module.impl.ModuleManagerImpl) Module(com.intellij.openapi.module.Module) PresentableNodeDescriptor(com.intellij.ide.util.treeView.PresentableNodeDescriptor) PresentationData(com.intellij.ide.projectView.PresentationData) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) List(java.util.List) Module(com.intellij.openapi.module.Module)

Example 9 with PresentationData

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PresentationData(com.intellij.ide.projectView.PresentationData) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PresentationData

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;
        }
    };
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) RelativePoint(com.intellij.ui.awt.RelativePoint) ExporterToTextFile(com.intellij.ide.ExporterToTextFile) ChangeListener(javax.swing.event.ChangeListener) TreeUtil(com.intellij.util.ui.tree.TreeUtil)

Aggregations

PresentationData (com.intellij.ide.projectView.PresentationData)14 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)3 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)3 PresentableNodeDescriptor (com.intellij.ide.util.treeView.PresentableNodeDescriptor)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 PsIssue (com.android.tools.idea.gradle.structure.model.PsIssue)1 PsModel (com.android.tools.idea.gradle.structure.model.PsModel)1 ExporterToTextFile (com.intellij.ide.ExporterToTextFile)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1