2a4249929538e051e329f907cd68d014fe1ed966
[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.intellij.psi.PsiFile;
11 import com.jetbrains.edu.coursecreator.CCUtils;
12 import com.jetbrains.edu.learning.StudyUtils;
13 import com.jetbrains.edu.learning.projectView.StudyTreeStructureProvider;
14 import org.jetbrains.annotations.NotNull;
15
16 import java.util.Collection;
17
18 public class CCTreeStructureProvider extends StudyTreeStructureProvider {
19   @NotNull
20   @Override
21   public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
22                                              @NotNull Collection<AbstractTreeNode> children,
23                                              ViewSettings settings) {
24     if (!needModify(parent)) {
25       return children;
26     }
27     Collection<AbstractTreeNode> modifiedChildren = super.modify(parent, children, settings);
28
29     for (AbstractTreeNode node : children) {
30       Project project = node.getProject();
31       if (project == null) {
32         continue;
33       }
34       if (node.getValue() instanceof PsiDirectory) {
35         String name = ((PsiDirectory)node.getValue()).getName();
36         if ("zip".equals(FileUtilRt.getExtension(name))) {
37           modifiedChildren.add(node);
38           continue;
39         }
40       }
41       if (node instanceof PsiFileNode) {
42         PsiFileNode fileNode = (PsiFileNode)node;
43         VirtualFile virtualFile = fileNode.getVirtualFile();
44         if (virtualFile == null) {
45           continue;
46         }
47         if (StudyUtils.getTaskFile(project, virtualFile) != null || StudyUtils.isTaskDescriptionFile(virtualFile.getName())) {
48           continue;
49         }
50         PsiFile psiFile = ((PsiFileNode)node).getValue();
51         modifiedChildren.add(new CCStudentInvisibleFileNode(project, psiFile, settings));
52       }
53     }
54     return modifiedChildren;
55   }
56
57   protected boolean needModify(@NotNull final AbstractTreeNode parent) {
58     Project project = parent.getProject();
59     if (project == null) {
60       return false;
61     }
62     return CCUtils.isCourseCreator(project);
63   }
64 }