mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move onTaskFailed logic to StudyChecker (EDU-882)
This commit is contained in:
@@ -205,21 +205,8 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun
|
||||
}
|
||||
|
||||
protected void onTaskFailed(@NotNull String message) {
|
||||
final Course course = StudyTaskManager.getInstance(myProject).getCourse();
|
||||
myTask.setStatus(StudyStatus.Failed);
|
||||
if (course != null) {
|
||||
if (course.isAdaptive()) {
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> {
|
||||
StudyCheckUtils.showTestResultPopUp("Failed", MessageType.ERROR.getPopupBackground(), myProject);
|
||||
StudyCheckUtils.showTestResultsToolWindow(myProject, message, false);
|
||||
});
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication()
|
||||
.invokeLater(() -> StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), myProject));
|
||||
}
|
||||
}
|
||||
myTask.getChecker(myProject).onTaskFailed(message);
|
||||
}
|
||||
|
||||
protected void onTaskSolved(@NotNull String message) {
|
||||
|
||||
+26
-24
@@ -28,8 +28,8 @@ import com.jetbrains.edu.learning.core.EduDocumentListener;
|
||||
import com.jetbrains.edu.learning.core.EduNames;
|
||||
import com.jetbrains.edu.learning.core.EduUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
|
||||
import com.jetbrains.edu.learning.courseFormat.tasks.Task;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.courseFormat.tasks.Task;
|
||||
import com.jetbrains.edu.learning.editor.StudyEditor;
|
||||
import com.jetbrains.edu.learning.navigation.StudyNavigator;
|
||||
import com.jetbrains.edu.learning.ui.StudyTestResultsToolWindowFactory;
|
||||
@@ -202,29 +202,31 @@ public class StudyCheckUtils {
|
||||
}
|
||||
|
||||
public static void showTestResultsToolWindow(@NotNull final Project project, @NotNull final String message, boolean solved) {
|
||||
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
|
||||
ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
|
||||
if (window == null) {
|
||||
toolWindowManager.registerToolWindow(StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM);
|
||||
window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
|
||||
new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window);
|
||||
}
|
||||
|
||||
final Content[] contents = window.getContentManager().getContents();
|
||||
for (Content content : contents) {
|
||||
final JComponent component = content.getComponent();
|
||||
if (component instanceof ConsoleViewImpl) {
|
||||
((ConsoleViewImpl)component).clear();
|
||||
if (!solved) {
|
||||
((ConsoleViewImpl)component).print(message, ConsoleViewContentType.ERROR_OUTPUT);
|
||||
}
|
||||
else {
|
||||
((ConsoleViewImpl)component).print(message, ConsoleViewContentType.NORMAL_OUTPUT);
|
||||
}
|
||||
window.setAvailable(true, () -> {});
|
||||
window.show(() -> {});
|
||||
return;
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
|
||||
ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
|
||||
if (window == null) {
|
||||
toolWindowManager.registerToolWindow(StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM);
|
||||
window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
|
||||
new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window);
|
||||
}
|
||||
}
|
||||
|
||||
final Content[] contents = window.getContentManager().getContents();
|
||||
for (Content content : contents) {
|
||||
final JComponent component = content.getComponent();
|
||||
if (component instanceof ConsoleViewImpl) {
|
||||
((ConsoleViewImpl)component).clear();
|
||||
if (!solved) {
|
||||
((ConsoleViewImpl)component).print(message, ConsoleViewContentType.ERROR_OUTPUT);
|
||||
}
|
||||
else {
|
||||
((ConsoleViewImpl)component).print(message, ConsoleViewContentType.NORMAL_OUTPUT);
|
||||
}
|
||||
window.setAvailable(true, () -> {});
|
||||
window.show(() -> {});
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,9 @@ public class StudyTaskChecker<T extends Task> {
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> StudyCheckUtils.showTestResultPopUp(message, MessageType.INFO.getPopupBackground(), myProject));
|
||||
}
|
||||
|
||||
public void onTaskFailed(@NotNull String message) {
|
||||
ApplicationManager.getApplication()
|
||||
.invokeLater(() -> StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), myProject));
|
||||
}
|
||||
}
|
||||
|
||||
+23
@@ -2,6 +2,11 @@ package com.jetbrains.edu.learning.courseFormat.tasks;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.checker.StudyTaskChecker;
|
||||
import com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel;
|
||||
import com.jetbrains.edu.learning.ui.StudyToolWindow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -48,4 +53,22 @@ public class ChoiceTask extends Task {
|
||||
public String getTaskType() {
|
||||
return "choice";
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudyTaskChecker getChecker(@NotNull Project project) {
|
||||
return new StudyTaskChecker<ChoiceTask>(this, project) {
|
||||
@Override
|
||||
public void onTaskFailed(@NotNull String message) {
|
||||
super.onTaskFailed(message);
|
||||
repaintChoicePanel(project, myTask);
|
||||
}
|
||||
|
||||
private void repaintChoicePanel(@NotNull Project project, @NotNull ChoiceTask task) {
|
||||
final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
|
||||
if (toolWindow != null) {
|
||||
toolWindow.setBottomComponent(new StudyChoiceVariantsPanel(task));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -1,5 +1,8 @@
|
||||
package com.jetbrains.edu.learning.courseFormat.tasks;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.jetbrains.edu.learning.checker.StudyCheckUtils;
|
||||
import com.jetbrains.edu.learning.checker.StudyTaskChecker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CodeTask extends Task {
|
||||
@@ -14,4 +17,15 @@ public class CodeTask extends Task {
|
||||
public String getTaskType() {
|
||||
return "code";
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudyTaskChecker getChecker(@NotNull Project project) {
|
||||
return new StudyTaskChecker<CodeTask>(this, project) {
|
||||
@Override
|
||||
public void onTaskFailed(@NotNull String message) {
|
||||
super.onTaskFailed("Wrong solution");
|
||||
StudyCheckUtils.showTestResultsToolWindow(myProject, message, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+2
-33
@@ -6,7 +6,6 @@ import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.jetbrains.edu.learning.actions.StudyCheckAction;
|
||||
@@ -15,14 +14,10 @@ import com.jetbrains.edu.learning.checker.StudyCheckUtils;
|
||||
import com.jetbrains.edu.learning.checker.StudyTestRunner;
|
||||
import com.jetbrains.edu.learning.core.EduNames;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.StudyStatus;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.courseFormat.tasks.ChoiceTask;
|
||||
import com.jetbrains.edu.learning.courseFormat.tasks.Task;
|
||||
import com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel;
|
||||
import com.jetbrains.edu.learning.editor.StudyEditor;
|
||||
import com.jetbrains.edu.learning.statistics.EduUsagesCollector;
|
||||
import com.jetbrains.edu.learning.ui.StudyToolWindow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -83,9 +78,9 @@ public class PyStudyCheckAction extends StudyCheckAction {
|
||||
return new StudyCheckTask(project, studyState, myCheckInProgress, testProcess, commandLine) {
|
||||
@Override
|
||||
protected void onTaskFailed(@NotNull String message) {
|
||||
super.onTaskFailed(message);
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
if (myTaskDir == null) return;
|
||||
myTask.setStatus(StudyStatus.Failed);
|
||||
for (Map.Entry<String, TaskFile> entry : myTask.getTaskFiles().entrySet()) {
|
||||
final String name = entry.getKey();
|
||||
final TaskFile taskFile = entry.getValue();
|
||||
@@ -99,38 +94,12 @@ public class PyStudyCheckAction extends StudyCheckAction {
|
||||
() -> StudyCheckUtils.runSmartTestProcess(myTaskDir, testRunner, name, taskFile, project)));
|
||||
}
|
||||
}
|
||||
final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
|
||||
if (toolWindow != null) {
|
||||
final Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course != null) {
|
||||
if (course.isAdaptive()) {
|
||||
if (myTask instanceof ChoiceTask) {
|
||||
StudyCheckUtils.showTestResultPopUp("Wrong answer", MessageType.ERROR.getPopupBackground(), project);
|
||||
repaintChoicePanel(project, (ChoiceTask)myTask);
|
||||
}
|
||||
else {
|
||||
StudyCheckUtils.showTestResultPopUp("Wrong answer", MessageType.ERROR.getPopupBackground(), project);
|
||||
StudyCheckUtils.showTestResultsToolWindow(project, message, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), project);
|
||||
}
|
||||
}
|
||||
StudyCheckUtils.navigateToFailedPlaceholder(myStudyState, myTask, myTaskDir, project);
|
||||
}
|
||||
StudyCheckUtils.navigateToFailedPlaceholder(myStudyState, myTask, myTaskDir, project);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void repaintChoicePanel(@NotNull Project project, @NotNull ChoiceTask task) {
|
||||
final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
|
||||
if (toolWindow != null) {
|
||||
toolWindow.setBottomComponent(new StudyChoiceVariantsPanel(task));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static VirtualFile getTaskVirtualFile(@NotNull final StudyState studyState,
|
||||
@NotNull final Task task,
|
||||
|
||||
Reference in New Issue
Block a user