package com.jetbrains.edu.java;

import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.HashMap;
import com.jetbrains.edu.courseFormat.Course;
import com.jetbrains.edu.learning.StudyTaskManager;
import com.jetbrains.edu.learning.StudyToolWindowConfigurator;
import com.jetbrains.edu.learning.actions.StudyNextStudyTaskAction;
import com.jetbrains.edu.learning.actions.StudyPreviousStudyTaskAction;
import com.jetbrains.edu.learning.actions.StudyRefreshTaskFileAction;
import com.jetbrains.edu.learning.actions.StudyShowHintAction;
import com.jetbrains.edu.learning.ui.StudyToolWindow;
import com.jetbrains.edu.utils.EduIntellijUtils;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class EduJavaStudyToolWindowConfigurator implements StudyToolWindowConfigurator {
    @NotNull
    @Override
    public DefaultActionGroup getActionGroup(Project project) {
        DefaultActionGroup group = new DefaultActionGroup();
        group.add(new EduJavaCheckAction());
        group.add(new StudyPreviousStudyTaskAction());
        group.add(new StudyNextStudyTaskAction());
        group.add(new StudyRefreshTaskFileAction());
        group.add(new StudyShowHintAction());
        return group;
    }

    @NotNull
    @Override
    public HashMap<String, JPanel> getAdditionalPanels(Project project) {
        return new HashMap<String, JPanel>();
    }

    @NotNull
    @Override
    public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow studyToolWindow) {
        return EduIntellijUtils.getFileEditorManagerListener(studyToolWindow, project);
    }

    @NotNull
    @Override
    public String getDefaultHighlightingMode() {
        return "text/x-java";
    }

    @Override
    public boolean accept(@NotNull Project project) {
        StudyTaskManager instance = StudyTaskManager.getInstance(project);
        if (instance == null) return false;
        Course course = instance.getCourse();
        return course != null && "PyCharm".equals(course.getCourseType()) && "JAVA".equals(course.getLanguage());
    }
}

@@ -119,134 +119,23 @@
 api.
-fileEditor.FileEditorManagerListener;%0Aimport com.intellij.openapi.project.Project;%0Aimport com.intellij.util.containers.HashMap
+project.Project
 ;%0Aim
@@ -221,60 +221,12 @@
 tudy
-TaskManager;%0Aimport com.jetbrains.edu.learning.Study
+Base
 Tool
@@ -283,348 +283,24 @@
 ing.
-actions.StudyNextStudyTaskAction;%0Aimport com.jetbrains.edu.learning.actions.StudyPreviousStudyTaskAction;%0Aimport com.jetbrains.edu.learning.actions.StudyRefreshTaskFileAction;%0Aimport com.jetbrains.edu.learning.actions.StudyShowHintAction;%0Aimport com.jetbrains.edu.learning.ui.StudyToolWindow;%0Aimport com.jetbrains.edu.utils.EduIntellijUtils
+StudyTaskManager
 ;%0Aim
@@ -344,31 +344,8 @@
 l;%0A%0A
-import javax.swing.*;%0A%0A
 publ
@@ -392,24 +392,25 @@
 tor 
-implement
+extend
 s Study
+Base
 Tool
@@ -513,32 +513,102 @@
 ject project) %7B%0A
+        DefaultActionGroup baseGroup = super.getActionGroup(project);%0A
         DefaultA
@@ -718,628 +718,44 @@
 .add
-(new StudyPreviousStudyTaskAction());%0A        group.add(new StudyNextStudyTaskAction());%0A        group.add(new StudyRefreshTaskFileAction());%0A        group.add(new StudyShowHintAction());%0A        return group;%0A    %7D%0A%0A    @NotNull%0A    @Override%0A    public HashMap%3CString, JPanel%3E getAdditionalPanels(Project project) %7B%0A        return new HashMap%3CString, JPanel%3E();%0A    %7D%0A%0A    @NotNull%0A    @Override%0A    public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow studyToolWindow) %7B%0A        return EduIntellijUtils.getFileEditorManagerListener(studyToolWindow, project)
+All(baseGroup);%0A        return group
 ;%0A  

Use StudyBaseToolWindowConfigurator as the base class for Kotlin and Java tool window configurators