Java Code Examples for com.intellij.ide.projectView.PresentationData#setIcon()

The following examples show how to use com.intellij.ide.projectView.PresentationData#setIcon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualFileTreeNode.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected void update(@NotNull PresentationData presentation) {
  final PsiManager psiManager = PsiManager.getInstance(myProject);
  final VirtualFile virtualFile = getValue();
  final PsiFile psiElement = virtualFile.isValid() ? psiManager.findFile(virtualFile) : null;
  if (psiElement instanceof PsiDirectory) {
    new PsiDirectoryNode(myProject, (PsiDirectory)psiElement, getSettings()).update(presentation);
  }
  else if (psiElement != null) {
    new PsiFileNode(myProject, psiElement, getSettings()).update(presentation);
  }
  else {
    presentation.setPresentableText(virtualFile.getName());
    presentation.setIcon(virtualFile.isDirectory() ? AllIcons.Nodes.Folder : virtualFile.getFileType().getIcon());
  }
}
 
Example 2
Source File: LibrarySourceItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes,
                   SimpleTextAttributes commentAttributes) {
  final String name = myLibrary.getName();
  if (name != null) {
    presentationData.setIcon(AllIcons.Nodes.PpLib);
    presentationData.addText(name, mainAttributes);
    presentationData.addText(LibraryElementPresentation.getLibraryTableComment(myLibrary), commentAttributes);
  }
  else {
    if (((LibraryEx)myLibrary).isDisposed()) {
      //todo[nik] disposed library should not be shown in the tree
      presentationData.addText("Invalid Library", SimpleTextAttributes.ERROR_ATTRIBUTES);
      return;
    }
    final VirtualFile[] files = myLibrary.getFiles(BinariesOrderRootType.getInstance());
    if (files.length > 0) {
      final VirtualFile file = files[0];
      presentationData.setIcon(VirtualFilePresentation.getIcon(file));
      presentationData.addText(file.getName(), mainAttributes);
    }
    else {
      presentationData.addText("Empty Library", SimpleTextAttributes.ERROR_ATTRIBUTES);
    }
  }
}
 
Example 3
Source File: FileCopyPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
  if (myFile != null && !myFile.isDirectory()) {
    presentationData.setIcon(VirtualFilePresentation.getIcon(myFile));
    presentationData.addText(myOutputFileName, mainAttributes);
    presentationData.addText(" (" + mySourcePath + ")", commentAttributes);
  }
  else {
    presentationData.setIcon(AllIcons.FileTypes.Text);
    presentationData.addText(myOutputFileName, SimpleTextAttributes.ERROR_ATTRIBUTES);
    final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath));
    presentationData.addText("(" + mySourcePath + ")",
                    parentFile != null ? commentAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES);
  }
}
 
Example 4
Source File: BookmarksFavoriteListProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateChildren() {
  if (myProject.isDisposed()) return;
  myChildren.clear();
  List<Bookmark> bookmarks = myBookmarkManager.getValidBookmarks();
  for (final Bookmark bookmark : bookmarks) {
    AbstractTreeNode<Bookmark> child = new AbstractTreeNode<Bookmark>(myProject, bookmark) {
      @Nonnull
      @Override
      public Collection<? extends AbstractTreeNode> getChildren() {
        return Collections.emptyList();
      }

      @Override
      public boolean canNavigate() {
        return bookmark.canNavigate();
      }

      @Override
      public boolean canNavigateToSource() {
        return bookmark.canNavigateToSource();
      }

      @Override
      public void navigate(boolean requestFocus) {
        bookmark.navigate(requestFocus);
      }

      @Override
      protected void update(PresentationData presentation) {
        presentation.setPresentableText(bookmark.toString());
        presentation.setIcon(bookmark.getIcon());
      }
    };
    child.setParent(myNode);
    myChildren.add(child);
  }
  myFavoritesManager.fireListeners(getListName(myProject));
}
 
Example 5
Source File: DirectoryCopyPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
  presentationData.setIcon(AllIcons.Nodes.CopyOfFolder);
  if (myFile == null || !myFile.isDirectory()) {
    mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
    final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath));
    if (parentFile == null) {
      commentAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
    }
  }
  presentationData.addText(CompilerBundle.message("node.text.0.directory.content", mySourceFileName), mainAttributes);
  presentationData.addText(" (" + mySourcePath + ")", commentAttributes);
}
 
Example 6
Source File: ExtractedDirectoryPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
  presentationData.setIcon(AllIcons.Nodes.ExtractedFolder);
  final String parentPath = PathUtil.getParentPath(myJarPath);
  if (myFile == null || !myFile.isDirectory()) {
    mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
    final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(parentPath);
    if (parentFile == null) {
      commentAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
    }
  }
  presentationData.addText("Extracted '" + PathUtil.getFileName(myJarPath) + myPathInJar + "'", mainAttributes);
  presentationData.addText(" (" + parentPath + ")", commentAttributes);
}
 
Example 7
Source File: ModuleElementPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData,
                   SimpleTextAttributes mainAttributes,
                   SimpleTextAttributes commentAttributes) {
  final Module module = findModule();
  presentationData.setIcon(myContentFolderType.getIcon());

  String moduleName;
  if (module != null) {
    moduleName = module.getName();
    final ModifiableModuleModel moduleModel = myContext.getModifiableModuleModel();
    if (moduleModel != null) {
      final String newName = moduleModel.getNewName(module);
      if (newName != null) {
        moduleName = newName;
      }
    }
  }
  else if (myModulePointer != null) {
    moduleName = myModulePointer.getName();
  }
  else {
    moduleName = "<unknown>";
  }

  presentationData
    .addText(CompilerBundle.message("node.text.0.1.compile.output", moduleName, StringUtil.toLowerCase(myContentFolderType.getName())),
             module != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES);
}
 
Example 8
Source File: LibraryElementPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
  if (myLibrary != null) {
    presentationData.setIcon(AllIcons.Nodes.PpLib);
    presentationData.addText(myLibraryName, mainAttributes);
    presentationData.addText(getLibraryTableComment(myLibrary), commentAttributes);
  }
  else {
    presentationData.addText(myLibraryName + " (" + (myModuleName != null ? "module '" + myModuleName + "'" : myLevel) + ")", 
                             SimpleTextAttributes.ERROR_ATTRIBUTES);
  }
}
 
Example 9
Source File: AbstractModuleNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(PresentationData presentation) {
  if (getValue().isDisposed()) {
    setValue(null);
    return;
  }
  presentation.setPresentableText(getValue().getName());
  if (showModuleNameInBold()) {
    presentation.addText(getValue().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
  }

  presentation.setIcon(AllIcons.Nodes.Module);
}
 
Example 10
Source File: SimpleNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  Object newElement = updateElement();
  if (getElement() != newElement) {
    presentation.setChanged(true);
  }
  if (newElement == null) return;

  Color oldColor = myColor;
  String oldName = myName;
  Image oldIcon = getIcon();
  List<ColoredFragment> oldFragments = new ArrayList<ColoredFragment>(presentation.getColoredText());

  myColor = UIUtil.getTreeTextForeground();
  updateFileStatus();

  doUpdate();

  myName = getName();
  presentation.setPresentableText(myName);

  presentation.setChanged(!Comparing.equal(new Object[]{getIcon(), myName, oldFragments, myColor},
                                           new Object[]{oldIcon, oldName, oldFragments, oldColor}));

  presentation.setForcedTextForeground(myColor);
  presentation.setIcon(getIcon());
}
 
Example 11
Source File: ServersTreeStructure.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  Deployment deployment = getValue();
  presentation.setIcon(getStatusIcon(deployment.getStatus()));
  presentation.setPresentableText(deployment.getName());
  presentation.setTooltip(deployment.getStatusText());
}
 
Example 12
Source File: NamedLibraryElementNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(PresentationData presentation) {
  presentation.setPresentableText(getValue().getName());
  final OrderEntry orderEntry = getValue().getOrderEntry();

  if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry) {
    final ModuleExtensionWithSdkOrderEntry sdkOrderEntry = (ModuleExtensionWithSdkOrderEntry)orderEntry;
    final Sdk sdk = sdkOrderEntry.getSdk();
    presentation.setIcon(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk()));
    if (sdk != null) { //jdk not specified
      final String path = sdk.getHomePath();
      if (path != null) {
        presentation.setLocationString(FileUtil.toSystemDependentName(path));
      }
    }
    presentation.setTooltip(null);
  }
  else if (orderEntry instanceof LibraryOrderEntry) {
    presentation.setIcon(getIconForLibrary(orderEntry));
    presentation.setTooltip(StringUtil.capitalize(IdeBundle.message("node.projectview.library", ((LibraryOrderEntry)orderEntry).getLibraryLevel())));
  }
  else if(orderEntry instanceof OrderEntryWithTracking) {
    Image icon = null;
    CellAppearanceEx cellAppearance = OrderEntryAppearanceService.getInstance().forOrderEntry(orderEntry);
    if(cellAppearance instanceof ModifiableCellAppearanceEx) {
      icon = ((ModifiableCellAppearanceEx)cellAppearance).getIcon();
    }
    presentation.setIcon(icon == null ? AllIcons.Toolbar.Unknown : icon);
  }
}
 
Example 13
Source File: FileGroupingProjectNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  if (myVirtualFile != null && myVirtualFile.isDirectory()) {
    presentation.setIcon(AllIcons.Nodes.TreeClosed);
  }
  else if (myVirtualFile != null) {
    presentation.setIcon(myVirtualFile.getFileType().getIcon());
  }
  else {
    presentation.setIcon(AllIcons.FileTypes.Unknown);
  }
  presentation.setPresentableText(getValue().getName());
}
 
Example 14
Source File: PantsTreeStructureProvider.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private List<PsiFileNode> createNode(ViewSettings settings, Project project, VirtualFile buildFile) {
  final PsiFile buildPsiFile = PsiManager.getInstance(project).findFile(buildFile);
  if(buildPsiFile == null) return Collections.emptyList();

  PsiFileNode node = new PsiFileNode(project, buildPsiFile, settings) {
    @Override
    protected void updateImpl(@NotNull PresentationData data) {
      super.updateImpl(data);
      data.setIcon(PantsIcons.Icon);
    }
  };
  return Collections.singletonList(node);
}
 
Example 15
Source File: PackageElementNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateValidData(final PresentationData presentation) {
  final PackageElement value = getValue();
  final PsiPackage aPackage = value.getPackage();

  if (!getSettings().isFlattenPackages()
      && getSettings().isHideEmptyMiddlePackages()
      && PackageNodeUtil.isPackageEmpty(aPackage, value.getModule(), true, isLibraryElement())) {
    setValue(null);
    return;
  }

  PsiPackage parentPackage;
  Object parentValue = getParentValue();
  if (parentValue instanceof PackageElement) {
    parentPackage = ((PackageElement)parentValue).getPackage();
  }
  else {
    parentPackage = null;
  }
  String qName = aPackage.getQualifiedName();
  String name = TreeViewUtil.getNodeName(getSettings(), aPackage, parentPackage, qName, showFQName(aPackage));
  presentation.setPresentableText(name);

  presentation.setIcon(AllIcons.Nodes.Package);

  for(ProjectViewNodeDecorator decorator: Extensions.getExtensions(ProjectViewNodeDecorator.EP_NAME, myProject)) {
    decorator.decorate(this, presentation);
  }
}
 
Example 16
Source File: ServersTreeStructure.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  presentation.setIcon(AllIcons.Debugger.Console);
  presentation.setPresentableText(getLogName());
}
 
Example 17
Source File: ExternalLibrariesNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  presentation.setPresentableText(IdeBundle.message("node.projectview.external.libraries"));
  presentation.setIcon(AllIcons.Nodes.PpLibFolder);
}
 
Example 18
Source File: FavoritesListNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  presentation.setIcon(AllIcons.Toolwindows.ToolWindowFavorites);
  presentation.setPresentableText(myName);
  presentation.setLocationString(myDescription);
}
 
Example 19
Source File: DirectoryElementPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
  presentationData.setIcon(AllIcons.Nodes.TreeClosed);
  presentationData.addText(myElement.getDirectoryName(), mainAttributes);
}
 
Example 20
Source File: ExternalSystemNodeDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  presentation.setPresentableText(myName);
  presentation.setIcon(getIcon());
  presentation.setTooltip(myDescription);
}