com.intellij.ide.projectView.ProjectViewNode Java Examples

The following examples show how to use com.intellij.ide.projectView.ProjectViewNode. 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: TreeFileChooserDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private PsiFile calcSelectedClass() {
  if (myTabbedPane.getSelectedIndex() == 1) {
    return (PsiFile)myGotoByNamePanel.getChosenElement();
  }
  else {
    final TreePath path = myTree.getSelectionPath();
    if (path == null) return null;
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
    final Object userObject = node.getUserObject();
    if (!(userObject instanceof ProjectViewNode)) return null;
    ProjectViewNode pvNode = (ProjectViewNode) userObject;
    VirtualFile vFile = pvNode.getVirtualFile();
    if (vFile != null && !vFile.isDirectory()) {
      return PsiManager.getInstance(myProject).findFile(vFile);
    }

    return null;
  }
}
 
Example #2
Source File: ProjectViewTestUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void checkContainsMethod(final Object rootElement,
                                       final AbstractTreeStructure structure,
                                       Function<AbstractTreeNode, VirtualFile[]> converterFunction) {
  MultiValuesMap<VirtualFile, AbstractTreeNode> map = new MultiValuesMap<VirtualFile, AbstractTreeNode>();
  collect((AbstractTreeNode)rootElement, map, structure, converterFunction);

  for (VirtualFile eachFile : map.keySet()) {
    Collection<AbstractTreeNode> nodes = map.values();
    for (final AbstractTreeNode node : nodes) {
      ProjectViewNode eachNode = (ProjectViewNode)node;
      boolean actual = eachNode.contains(eachFile);
      boolean expected = map.get(eachFile).contains(eachNode);
      if (actual != expected) {
        boolean actual1 = eachNode.contains(eachFile);
        boolean expected1 = map.get(eachFile).contains(eachNode);

        Assert.assertTrue("file=" + eachFile + " node=" + eachNode.getTestPresentation() + " expected:" + expected, false);
      }
    }
  }
}
 
Example #3
Source File: AddToFavoritesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addPsiElementNode(PsiElement psiElement,
                                      final Project project,
                                      final ArrayList<AbstractTreeNode> result,
                                      final ViewSettings favoritesConfig) {

  Class<? extends AbstractTreeNode> klass = getPsiElementNodeClass(psiElement);
  if (klass == null) {
    psiElement = PsiTreeUtil.getParentOfType(psiElement, PsiFile.class);
    if (psiElement != null) {
      klass = PsiFileNode.class;
    }
  }

  final Object value = psiElement;
  try {
    if (klass != null && value != null) {
      result.add(ProjectViewNode.createTreeNode(klass, project, value, favoritesConfig));
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
}
 
Example #4
Source File: TodoFileDirAndModuleComparator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(NodeDescriptor obj1, NodeDescriptor obj2){
  final int weight1 = obj1.getWeight();
  final int weight2 = obj2.getWeight();
  if (weight1 != weight2) return weight1 - weight2;
  if (obj1 instanceof ProjectViewNode && obj2 instanceof ProjectViewNode) {
    return ((ProjectViewNode)obj1).getTitle().compareToIgnoreCase(((ProjectViewNode)obj2).getTitle());
  }
  if (obj1 instanceof ModuleToDoNode && obj2 instanceof ModuleToDoNode){
    return ((ModuleToDoNode)obj1).getValue().getName().compareToIgnoreCase(((ModuleToDoNode)obj2).getValue().getName());
  } else if(obj1 instanceof ModuleToDoNode) {
    return -1;
  } else if(obj2 instanceof ModuleToDoNode) {
    return 1;
  } else{
    throw new IllegalArgumentException(obj1.getClass().getName()+","+obj2.getClass().getName());
  }
}
 
Example #5
Source File: ProjectTreeBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateNodesContaining(@Nonnull Collection<VirtualFile> filesToRefresh, @Nonnull DefaultMutableTreeNode rootNode) {
  if (!(rootNode.getUserObject() instanceof ProjectViewNode)) return;
  ProjectViewNode node = (ProjectViewNode)rootNode.getUserObject();
  Collection<VirtualFile> containingFiles = null;
  for (VirtualFile virtualFile : filesToRefresh) {
    if (!virtualFile.isValid()) {
      addSubtreeToUpdate(rootNode); // file must be deleted
      return;
    }
    if (node.contains(virtualFile)) {
      if (containingFiles == null) containingFiles = new SmartList<>();
      containingFiles.add(virtualFile);
    }
  }
  if (containingFiles != null) {
    updateNode(rootNode);
    Enumeration children = rootNode.children();
    while (children.hasMoreElements()) {
      DefaultMutableTreeNode child = (DefaultMutableTreeNode)children.nextElement();
      updateNodesContaining(containingFiles, child);
    }
  }
}
 
Example #6
Source File: KotlinSyncStatusContributor.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) {
  if (!projectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.KOTLIN)) {
    return null;
  }
  if (node instanceof KtFileTreeNode) {
    KtFile file = ((KtFileTreeNode) node).getKtFile();
    return new PsiFileAndName(file, file.getName());
  }
  if (node instanceof KtClassOrObjectTreeNode) {
    KtClassOrObject kt = ((KtClassOrObjectTreeNode) node).getValue();
    return kt != null ? new PsiFileAndName(kt.getContainingKtFile(), kt.getName()) : null;
  }
  return null;
}
 
Example #7
Source File: AbstractNodeDecoration.java    From SVNToolBox with Apache License 2.0 6 votes vote down vote up
@Nullable
protected ProjectViewStatus getBranchStatusAndCache(ProjectViewNode node) {
    ProjectViewStatusCache cache = ProjectViewManager.getInstance(node.getProject()).getStatusCache();
    VirtualFile vFile = getVirtualFile(node);
    ProjectViewStatus cached = cache.get(vFile);
    if (cached != null) {
        if (!cached.isEmpty()) {
            return cached;
        }
        return null;
    } else {
        PutResult result = cache.add(vFile, ProjectViewStatus.PENDING);                        
        AsyncFileStatusCalculator.getInstance(node.getProject()).scheduleStatusFor(node.getProject(), vFile);
        if (result != null) {
            return result.getFinalStatus();        
        }
        return null;
    }        
}
 
Example #8
Source File: LibraryGroupNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void addLibraryChildren(final OrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  VirtualFile[] files =
    entry instanceof LibraryOrderEntry ? getLibraryRoots((LibraryOrderEntry)entry) : entry.getFiles(BinariesOrderRootType.getInstance());
  for (final VirtualFile file : files) {
    if (!file.isValid()) continue;
    if (file.isDirectory()) {
      final PsiDirectory psiDir = psiManager.findDirectory(file);
      if (psiDir == null) {
        continue;
      }
      children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
    }
    else {
      final PsiFile psiFile = psiManager.findFile(file);
      if (psiFile == null) continue;
      children.add(new PsiFileNode(project, psiFile, node.getSettings()));
    }
  }
}
 
Example #9
Source File: BlazeCoverageProjectViewClassDecorator.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void decorate(@SuppressWarnings("rawtypes") ProjectViewNode node, PresentationData data) {
  CoverageDataManager manager = getCoverageDataManager();
  CoverageSuitesBundle currentSuite = manager.getCurrentSuitesBundle();

  Project project = node.getProject();
  BlazeCoverageAnnotator annotator = getAnnotator(project, currentSuite);
  if (annotator == null) {
    return;
  }
  PsiFile file = getPsiFileForJavaClass(getPsiElement(node));
  if (file == null) {
    return;
  }
  String string = annotator.getFileCoverageInformationString(file, currentSuite, manager);
  if (string != null) {
    data.setLocationString(string);
  }
}
 
Example #10
Source File: AbstractNodeDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
protected boolean isUnderSvn(ProjectViewNode node, Supplier<Integer> PV_SEQ) {
    LogStopwatch watch = LogStopwatch.debugStopwatch(PV_SEQ, () -> "Under SVN").start();
    VirtualFile vFile = getVirtualFile(node);
    watch.tick("Get VFile");
    boolean result = false;
    if (vFile != null) {
        boolean underControl = myStatusCalc.fastAllFilesUnderSvn(node.getProject(), vFile);
        watch.tick("Under control={0}", underControl);
        result = underControl;
    }
    watch.stop();
    return result;
}
 
Example #11
Source File: ModuleDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void applyDecorationUnderSvn(ProjectViewNode node, PresentationData data) {
    ProjectViewStatus status = getBranchStatusAndCache(node);
    if (shouldApplyDecoration(status)) {
        data.addText(formatBranchName(status));
    }
}
 
Example #12
Source File: ModuleDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isForMe(ProjectViewNode node) {
    if (node instanceof PsiDirectoryNode) {
        PsiDirectoryNode dirNode = (PsiDirectoryNode) node;
        final Object parentValue = dirNode.getParent().getValue();
        return parentValue instanceof Project || parentValue instanceof ModuleGroup;
    }
    return false;
}
 
Example #13
Source File: RTMergerTreeStructureProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
private static Map<String, ProjectViewNode> map(ProjectViewNode[] copy) {
    Map<String, ProjectViewNode> rtJsFiles = new HashMap<String, ProjectViewNode>();
    for (ProjectViewNode element : copy) {
        if (RTFileUtil.isRTJSFile(element.getVirtualFile()) || hasJsExt(element.getVirtualFile()) || hasTsExt(element.getVirtualFile())) {
            rtJsFiles.put(element.getVirtualFile().getName(), element);
        }
    }
    return rtJsFiles;
}
 
Example #14
Source File: FileDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void applyDecorationUnderSvn(ProjectViewNode node, PresentationData data) {
    ProjectViewStatus status = getBranchStatusAndCache(node);
    if (shouldApplyDecoration(status)) {
        data.addText(getName(node), SimpleTextAttributes.REGULAR_ATTRIBUTES);
        data.addText(formatBranchName(status));
    }
}
 
Example #15
Source File: AbstractNodeDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public final void decorate(ProjectViewNode node, PresentationData data) {
    Supplier<Integer> PV_SEQ = SvnToolBoxProject.getInstance(node.getProject()).sequence();
    if (isUnderSvn(node, PV_SEQ)) {
        LogStopwatch watch = LogStopwatch.debugStopwatch(PV_SEQ, () -> "Decorate").start();
        applyDecorationUnderSvn(node, data);
        watch.stop();
    }
}
 
Example #16
Source File: ContentRootDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void applyDecorationUnderSvn(ProjectViewNode node, PresentationData data) {
    ProjectViewStatus status = getBranchStatusAndCache(node);
    if (shouldApplyDecoration(status)) {
        data.addText(formatBranchName(status));
    }
}
 
Example #17
Source File: ContentRootDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isForMe(ProjectViewNode node) {
    if (node instanceof PsiDirectoryNode) {
        PsiDirectoryNode dirNode = (PsiDirectoryNode) node;            
        final PsiDirectory psiDirectory = dirNode.getValue();
        if (psiDirectory != null) {
            final Project project = dirNode.getProject();
            final VirtualFile directoryFile = psiDirectory.getVirtualFile();
            return ProjectRootsUtil.isModuleContentRoot(directoryFile, project)
                    || ProjectRootsUtil.isInSource(directoryFile, project);
        }
    }
    return false;
}
 
Example #18
Source File: Unity3dProjectViewNodeDecorator.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void decorate(ProjectViewNode node, PresentationData data)
{
	Project project = node.getProject();
	if(project == null)
	{
		return;
	}

	VirtualFile virtualFile = node.getVirtualFile();
	if(virtualFile == null || virtualFile.getFileType() != Unity3dMetaFileType.INSTANCE)
	{
		return;
	}

	Unity3dRootModuleExtension rootModuleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(project);
	if(rootModuleExtension == null)
	{
		return;
	}

	if(Unity3dMetaFileProjectViewProvider.haveOwnerFile(virtualFile))
	{
		return;
	}

	data.clearText();
	data.addText(virtualFile.getName(), SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
	String nameWithoutExtension = virtualFile.getNameWithoutExtension();
	data.setTooltip("File(directory) '" + nameWithoutExtension + "' is not exists, meta file can be deleted.");
}
 
Example #19
Source File: ClassFileDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void applyDecorationUnderSvn(ProjectViewNode node, PresentationData data) {
    ProjectViewStatus status = getBranchStatusAndCache(node);
    if (shouldApplyDecoration(status)) {
        data.addText(formatBranchName(status));
    }
}
 
Example #20
Source File: ClassFileDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isForMe(ProjectViewNode node) {
    if (node instanceof ClassTreeNode) {
        ClassTreeNode classNode = (ClassTreeNode) node;
        if (classNode.isTopLevel()) {
            return true;
        }
    }
    return false;
}
 
Example #21
Source File: SvnToolBoxApp.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
public NodeDecoration decorationFor(ProjectViewNode node) {
    for (NodeDecoration candidate : myNodeDecorations) {
        if (candidate.isForMe(node)) {
            return candidate;
        }
    }
    return EmptyDecoration.INSTANCE;
}
 
Example #22
Source File: ProjectListBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateParentTitle() {
  if (myParentTitle == null) return;

  AbstractTreeNode node = getParentNode();
  if (node instanceof ProjectViewNode) {
    myParentTitle.setText(((ProjectViewNode)node).getTitle());
  }
  else {
    myParentTitle.setText(null);
  }
}
 
Example #23
Source File: ProjectListBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AbstractTreeNode> getAllAcceptableNodes(final Object[] childElements, VirtualFile file) {
  ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();

  for (int i = 0; i < childElements.length; i++) {
    ProjectViewNode childElement = (ProjectViewNode)childElements[i];
    if (childElement.contains(file)) result.add(childElement);
  }

  return result;
}
 
Example #24
Source File: FavoritesListNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processUrls(Project project,
                                Collection<TreeItem<Pair<AbstractUrl, String>>> urls,
                                Collection<AbstractTreeNode> result, final AbstractTreeNode me) {
  for (TreeItem<Pair<AbstractUrl, String>> pair : urls) {
    AbstractUrl abstractUrl = pair.getData().getFirst();
    final Object[] path = abstractUrl.createPath(project);
    if (path == null || path.length < 1 || path[0] == null) {
      continue;
    }
    try {
      final String className = pair.getData().getSecond();

      @SuppressWarnings("unchecked")
      final Class<? extends AbstractTreeNode> nodeClass = (Class<? extends AbstractTreeNode>)Class.forName(className);

      final AbstractTreeNode node = ProjectViewNode
        .createTreeNode(nodeClass, project, path[path.length - 1], FavoritesManager.getInstance(project).getViewSettings());
      node.setParent(me);
      node.setIndex(result.size());
      result.add(node);

      if (node instanceof ProjectViewNodeWithChildrenList) {
        final List<TreeItem<Pair<AbstractUrl, String>>> children = pair.getChildren();
        if (children != null && !children.isEmpty()) {
          Collection<AbstractTreeNode> childList = new ArrayList<AbstractTreeNode>();
          processUrls(project, children, childList, node);
          for (AbstractTreeNode treeNode : childList) {
            ((ProjectViewNodeWithChildrenList)node).addChild(treeNode);
          }
        }
      }
    }
    catch (Exception ignored) {
    }
  }
}
 
Example #25
Source File: TodoTreeHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean contains(ProjectViewNode node, Object element) {
  if (element instanceof PackageElement) {
    for (VirtualFile virtualFile : ((PackageElement)element).getRoots()) {
      if (node.contains(virtualFile)) return true;
    }
  }
  return false;
}
 
Example #26
Source File: TodoNodeVisitor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean contains(@Nonnull AbstractTreeNode node, @Nonnull Object element) {
  if (node instanceof SummaryNode || node instanceof ToDoRootNode) return true;
  if (node instanceof ProjectViewNode) {
    if (myFile == null) {
      return TodoTreeHelper.contains((ProjectViewNode)node, element);
    }
  }
  return node instanceof BaseToDoNode && ((BaseToDoNode)node).contains(element) || node instanceof ProjectViewNode && ((ProjectViewNode)node).contains(myFile);
}
 
Example #27
Source File: ProjectViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public PsiElement getParentOfCurrentSelection() {
  final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
  if (viewPane == null) {
    return null;
  }
  TreePath path = viewPane.getSelectedPath();
  if (path == null) {
    return null;
  }
  path = path.getParentPath();
  if (path == null) {
    return null;
  }
  DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
  Object userObject = node.getUserObject();
  if (userObject instanceof ProjectViewNode) {
    ProjectViewNode descriptor = (ProjectViewNode)userObject;
    Object element = descriptor.getValue();
    if (element instanceof PsiElement) {
      PsiElement psiElement = (PsiElement)element;
      if (!psiElement.isValid()) return null;
      return psiElement;
    }
    else {
      return null;
    }
  }
  return null;
}
 
Example #28
Source File: AbstractProjectTreeStructure.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isAlwaysLeaf(Object element) {
  if (element instanceof ProjectViewNode) {
    return ((ProjectViewNode)element).isAlwaysLeaf();
  }
  return super.isAlwaysLeaf(element);
}
 
Example #29
Source File: ExternalLibrariesNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
public static void addLibraryChildren(final LibraryOrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
  final PsiManager psiManager = PsiManager.getInstance(project);
  final VirtualFile[] files = entry.getFiles(BinariesOrderRootType.getInstance());
  for (final VirtualFile file : files) {
    final PsiDirectory psiDir = psiManager.findDirectory(file);
    if (psiDir == null) {
      continue;
    }
    children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
  }
}
 
Example #30
Source File: ModuleGroupNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<VirtualFile> getRoots() {
  Collection<AbstractTreeNode> children = getChildren();
  Set<VirtualFile> result = new HashSet<>();
  for (AbstractTreeNode each : children) {
    if (each instanceof ProjectViewNode) {
      result.addAll(((ProjectViewNode)each).getRoots());
    }
  }

  return result;
}