reorganize answer placeholder actions
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / actions / placeholder / CCDeactivatePlaceholder.java
1 package com.jetbrains.edu.coursecreator.actions.placeholder;
2
3 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
4 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo;
5 import com.jetbrains.edu.learning.courseFormat.TaskFile;
6
7 import java.util.Collections;
8
9 public class CCDeactivatePlaceholder extends CCSubtaskPlaceholderAction {
10
11   public static final String TITLE = "Deactivate";
12
13   protected CCDeactivatePlaceholder() {
14     super(TITLE, TITLE);
15   }
16
17   protected void undoAction(AnswerPlaceholder existingPlaceholder, int subtaskIndex, AnswerPlaceholderSubtaskInfo info) {
18     existingPlaceholder.getSubtaskInfos().put(subtaskIndex, info);
19   }
20
21   @Override
22   protected AnswerPlaceholderSubtaskInfo getInfo(CCState state,
23                                                  int subtaskIndex,
24                                                  AnswerPlaceholder existingPlaceholder) {
25     return existingPlaceholder.getSubtaskInfos().get(subtaskIndex);
26   }
27
28   @Override
29   protected String getTitle() {
30     return TITLE;
31   }
32
33   protected void redoAction(AnswerPlaceholder existingPlaceholder, int subtaskIndex, AnswerPlaceholderSubtaskInfo info) {
34     existingPlaceholder.getSubtaskInfos().remove(subtaskIndex);
35   }
36
37   protected boolean isAvailable(TaskFile taskFile, int offset) {
38     AnswerPlaceholder existingActivePlaceholder = taskFile.getAnswerPlaceholder(offset);
39     if (existingActivePlaceholder == null) {
40       return false;
41     }
42     return Collections.min(existingActivePlaceholder.getSubtaskInfos().keySet()) < taskFile.getTask().getActiveSubtaskIndex();
43   }
44 }