show invisible nodes in course creator project view
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / projectView / CCTreeStructureProvider.java
1 package com.jetbrains.edu.coursecreator.projectView;
2
3 import com.intellij.ide.projectView.ViewSettings;
4 import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
5 import com.intellij.ide.util.treeView.AbstractTreeNode;
6 import com.intellij.openapi.project.Project;
7 import com.intellij.openapi.util.io.FileUtilRt;
8 import com.intellij.openapi.vfs.VirtualFile;
9 import com.intellij.psi.PsiDirectory;
10 import com.jetbrains.edu.coursecreator.CCUtils;
11 import com.jetbrains.edu.learning.StudyUtils;
12 import com.jetbrains.edu.learning.core.EduNames;
13 import com.jetbrains.edu.learning.projectView.StudyTreeStructureProvider;
14 import org.jetbrains.annotations.NotNull;
15
16 import java.util.ArrayList;
17 import java.util.Collection;
18
19 public class CCTreeStructureProvider extends StudyTreeStructureProvider {
20   @NotNull
21   @Override
22   public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
23                                              @NotNull Collection<AbstractTreeNode> children,
24                                              ViewSettings settings) {
25     if (!needModify(parent)) {
26       return children;
27     }
28     Collection<AbstractTreeNode> modifiedChildren = new ArrayList(super.modify(parent, children, settings));
29
30     for (AbstractTreeNode node : children) {
31       Project project = node.getProject();
32         if (node.getValue() instanceof PsiDirectory) {
33           String name = ((PsiDirectory)node.getValue()).getName();
34           if ("zip".equals(FileUtilRt.getExtension(name))) {
35             modifiedChildren.add(node);
36             continue;
37           }
38         }
39         if (node instanceof PsiFileNode) {
40           PsiFileNode fileNode = (PsiFileNode)node;
41           VirtualFile virtualFile = fileNode.getVirtualFile();
42           if (virtualFile == null) {
43             continue;
44           }
45           if (StudyUtils.getTaskFile(project, virtualFile) == null && !EduNames.TASK_HTML.equals(virtualFile.getName())) {
46             modifiedChildren.add(new CCStudentInvisibleFileNode(project, ((PsiFileNode)node).getValue(), settings));
47           }
48         }
49     }
50     return modifiedChildren;
51   }
52
53   protected boolean needModify(@NotNull final AbstractTreeNode parent) {
54     Project project = parent.getProject();
55     if (project == null) {
56       return false;
57     }
58     return CCUtils.isCourseCreator(project);
59   }
60 }