示例#1
0
 public TableItem(String url) {
   myUrl = url;
   final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
   if (file != null) {
     myCellAppearance = CellAppearanceUtils.forVirtualFile(file);
   } else {
     myCellAppearance = SimpleTextCellAppearance.invalid(url, CellAppearanceUtils.INVALID_ICON);
   }
 }
  @NotNull
  @Override
  public CellAppearanceEx forVirtualFile(@NotNull final VirtualFile file) {
    if (!file.isValid()) {
      return forInvalidUrl(file.getPresentableUrl());
    }

    final VirtualFileSystem fileSystem = file.getFileSystem();
    if (fileSystem.getProtocol().equals(JarFileSystem.PROTOCOL)) {
      return new JarSubfileCellAppearance(file);
    }
    if (fileSystem instanceof HttpFileSystem) {
      return new HttpUrlCellAppearance(file);
    }
    if (file.isDirectory()) {
      return SimpleTextCellAppearance.regular(file.getPresentableUrl(), PlatformIcons.FOLDER_ICON);
    }
    return new ValidFileCellAppearance(file);
  }
  @NotNull
  @Override
  public CellAppearanceEx forIoFile(@NotNull final File file) {
    final String absolutePath = file.getAbsolutePath();
    if (!file.exists()) {
      return forInvalidUrl(absolutePath);
    }

    if (file.isDirectory()) {
      return SimpleTextCellAppearance.regular(absolutePath, PlatformIcons.FOLDER_ICON);
    }

    final String name = file.getName();
    final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(name);
    final File parent = file.getParentFile();
    final CompositeAppearance appearance =
        CompositeAppearance.textComment(name, parent.getAbsolutePath());
    appearance.setIcon(fileType.getIcon());
    return appearance;
  }
 @NotNull
 public CellAppearanceEx forInvalidUrl(@NotNull final String text) {
   return SimpleTextCellAppearance.invalid(text, PlatformIcons.INVALID_ENTRY_ICON);
 }