Search in sources :

Example 1 with SimpleTextCellAppearance

use of com.intellij.openapi.roots.ui.util.SimpleTextCellAppearance in project intellij-community by JetBrains.

the class OrderEntryAppearanceServiceImpl method forOrderEntry.

@NotNull
@Override
public CellAppearanceEx forOrderEntry(Project project, @NotNull final OrderEntry orderEntry, final boolean selected) {
    if (orderEntry instanceof JdkOrderEntry) {
        JdkOrderEntry jdkLibraryEntry = (JdkOrderEntry) orderEntry;
        Sdk jdk = jdkLibraryEntry.getJdk();
        if (!orderEntry.isValid()) {
            final String oldJdkName = jdkLibraryEntry.getJdkName();
            return FileAppearanceService.getInstance().forInvalidUrl(oldJdkName != null ? oldJdkName : NO_JDK);
        }
        return forJdk(jdk, false, selected, true);
    } else if (!orderEntry.isValid()) {
        return FileAppearanceService.getInstance().forInvalidUrl(orderEntry.getPresentableName());
    } else if (orderEntry instanceof LibraryOrderEntry) {
        LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
        if (!libraryOrderEntry.isValid()) {
            //library can be removed
            return FileAppearanceService.getInstance().forInvalidUrl(orderEntry.getPresentableName());
        }
        Library library = libraryOrderEntry.getLibrary();
        assert library != null : libraryOrderEntry;
        return forLibrary(project, library, !((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES).isEmpty());
    } else if (orderEntry.isSynthetic()) {
        String presentableName = orderEntry.getPresentableName();
        Icon icon = orderEntry instanceof ModuleSourceOrderEntry ? sourceFolderIcon(false) : null;
        return new SimpleTextCellAppearance(presentableName, icon, SimpleTextAttributes.SYNTHETIC_ATTRIBUTES);
    } else if (orderEntry instanceof ModuleOrderEntry) {
        final Icon icon = ModuleType.get(((ModuleOrderEntry) orderEntry).getModule()).getIcon();
        return SimpleTextCellAppearance.regular(orderEntry.getPresentableName(), icon);
    } else {
        return CompositeAppearance.single(orderEntry.getPresentableName());
    }
}
Also used : SimpleTextCellAppearance(com.intellij.openapi.roots.ui.util.SimpleTextCellAppearance) Sdk(com.intellij.openapi.projectRoots.Sdk) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SimpleTextCellAppearance

use of com.intellij.openapi.roots.ui.util.SimpleTextCellAppearance in project intellij-community by JetBrains.

the class OrderEntryAppearanceServiceImpl method formatRelativePath.

@NotNull
private static CellAppearanceEx formatRelativePath(@NotNull final ContentFolder folder, @NotNull final Icon icon) {
    LightFilePointer folderFile = new LightFilePointer(folder.getUrl());
    VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(folder.getContentEntry().getUrl());
    if (file == null)
        return FileAppearanceService.getInstance().forInvalidUrl(folderFile.getPresentableUrl());
    String contentPath = file.getPath();
    String relativePath;
    SimpleTextAttributes textAttributes;
    VirtualFile folderFileFile = folderFile.getFile();
    if (folderFileFile == null) {
        String absolutePath = folderFile.getPresentableUrl();
        relativePath = absolutePath.startsWith(contentPath) ? absolutePath.substring(contentPath.length()) : absolutePath;
        textAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
    } else {
        relativePath = VfsUtilCore.getRelativePath(folderFileFile, file, File.separatorChar);
        textAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    }
    relativePath = StringUtil.isEmpty(relativePath) ? "." + File.separatorChar : relativePath;
    return new SimpleTextCellAppearance(relativePath, icon, textAttributes);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SimpleTextCellAppearance(com.intellij.openapi.roots.ui.util.SimpleTextCellAppearance) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) LightFilePointer(com.intellij.openapi.vfs.impl.LightFilePointer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SimpleTextCellAppearance (com.intellij.openapi.roots.ui.util.SimpleTextCellAppearance)2 NotNull (org.jetbrains.annotations.NotNull)2 Sdk (com.intellij.openapi.projectRoots.Sdk)1 Library (com.intellij.openapi.roots.libraries.Library)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LightFilePointer (com.intellij.openapi.vfs.impl.LightFilePointer)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1