1 package com.jetbrains.edu.coursecreator.ui;
3 import com.intellij.openapi.project.Project;
4 import com.intellij.openapi.ui.DialogWrapper;
5 import com.intellij.openapi.ui.ValidationInfo;
6 import com.intellij.openapi.util.text.StringUtil;
7 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
8 import org.jetbrains.annotations.NotNull;
9 import org.jetbrains.annotations.Nullable;
13 public class CCCreateAnswerPlaceholderDialog extends DialogWrapper {
15 private static final String ourTitle = "Add Answer Placeholder";
16 private final AnswerPlaceholder myAnswerPlaceholder;
17 private final CCCreateAnswerPlaceholderPanel myPanel;
18 private final Project myProject;
20 public Project getProject() {
24 public CCCreateAnswerPlaceholderDialog(@NotNull final Project project,
25 @NotNull final AnswerPlaceholder answerPlaceholder) {
28 myAnswerPlaceholder = answerPlaceholder;
29 myPanel = new CCCreateAnswerPlaceholderPanel();
30 if (answerPlaceholder.getHint() != null) {
31 setHintText(answerPlaceholder);
34 String answerPlaceholderTaskText = answerPlaceholder.getTaskText();
35 myPanel.setAnswerPlaceholderText(answerPlaceholderTaskText != null ? answerPlaceholderTaskText : "");
36 String hintName = answerPlaceholder.getHint();
37 myPanel.setHintText(hintName != null ? hintName : "");
42 @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
43 private void setHintText(AnswerPlaceholder answerPlaceholder) {
44 String hintText = answerPlaceholder.getHint();
47 myPanel.setHintText(hintText);
51 protected void doOKAction() {
52 String answerPlaceholderText = myPanel.getAnswerPlaceholderText();
53 myAnswerPlaceholder.setTaskText(StringUtil.notNullize(answerPlaceholderText));
54 myAnswerPlaceholder.setLength(StringUtil.notNullize(answerPlaceholderText).length());
55 myAnswerPlaceholder.setHint(myPanel.getHintText());
61 protected JComponent createCenterPanel() {
67 public ValidationInfo doValidate() {
68 return myAnswerPlaceholder.getHint() != null ? null : new ValidationInfo("Type hint");
73 public JComponent getPreferredFocusedComponent() {
74 return myPanel.getPreferredFocusedComponent();