コード例 #1
0
 @Override
 public void fileCreated(@NotNull VirtualFileEvent event) {
   final VirtualFile createdFile = event.getFile();
   final VirtualFile taskDir = createdFile.getParent();
   if (taskDir != null && taskDir.getName().contains(Task.TASK_DIR)) {
     int taskIndex = StudyUtils.getIndex(taskDir.getName(), Task.TASK_DIR);
     final VirtualFile lessonDir = taskDir.getParent();
     if (lessonDir != null && lessonDir.getName().contains(StudyNames.LESSON_DIR)) {
       int lessonIndex = StudyUtils.getIndex(lessonDir.getName(), StudyNames.LESSON_DIR);
       if (myCourse != null) {
         List<Lesson> lessons = myCourse.getLessons();
         if (StudyUtils.indexIsValid(lessonIndex, lessons)) {
           final Lesson lesson = lessons.get(lessonIndex);
           final List<Task> tasks = lesson.getTaskList();
           if (StudyUtils.indexIsValid(taskIndex, tasks)) {
             final Task task = tasks.get(taskIndex);
             final TaskFile taskFile = new TaskFile();
             taskFile.init(task, false);
             taskFile.setUserCreated(true);
             task.getTaskFiles().put(createdFile.getName(), taskFile);
           }
         }
       }
     }
   }
 }
コード例 #2
0
 @Nullable
 public TaskFile getTaskFile(@NotNull final VirtualFile file) {
   if (myCourse == null) {
     return null;
   }
   final VirtualFile taskDir = file.getParent();
   if (taskDir == null) {
     return null;
   }
   final String taskDirName = taskDir.getName();
   if (taskDirName.contains(Task.TASK_DIR)) {
     final VirtualFile lessonDir = taskDir.getParent();
     if (lessonDir != null) {
       int lessonIndex = StudyUtils.getIndex(lessonDir.getName(), StudyNames.LESSON_DIR);
       List<Lesson> lessons = myCourse.getLessons();
       if (!StudyUtils.indexIsValid(lessonIndex, lessons)) {
         return null;
       }
       final Lesson lesson = lessons.get(lessonIndex);
       int taskIndex = StudyUtils.getIndex(taskDirName, Task.TASK_DIR);
       final List<Task> tasks = lesson.getTaskList();
       if (!StudyUtils.indexIsValid(taskIndex, tasks)) {
         return null;
       }
       final Task task = tasks.get(taskIndex);
       return task.getFile(file.getName());
     }
   }
   return null;
 }