package com.jetbrains.edu.kotlin;

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.*;
import com.jetbrains.edu.learning.ui.StudyToolWindow;
import com.jetbrains.edu.utils.EduIntellijUtils;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class KotlinStudyToolWindowConfigurator implements StudyToolWindowConfigurator {
    @NotNull
    @Override
    public DefaultActionGroup getActionGroup(Project project) {
        final DefaultActionGroup group = new DefaultActionGroup();
        group.add(new KotlinStudyCheckAction());
        group.add(new StudyPreviousStudyTaskAction());
        group.add(new StudyNextStudyTaskAction());
        group.add(new StudyRefreshTaskFileAction());
        group.add(new StudyShowHintAction());
        group.add(new StudyRunAction());
        group.add(new StudyEditInputAction());
        
        return group;
    }

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

    @NotNull
    @Override
    public FileEditorManagerListener getFileEditorManagerListener(@NotNull final Project project, 
                                                                  @NotNull final 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()) && "kotlin".equals(course.getLanguage());
    }
}

@@ -121,134 +121,23 @@
 api.
-fileEditor.FileEditorManagerListener;%0Aimport com.intellij.openapi.project.Project;%0Aimport com.intellij.util.containers.HashMap
+project.Project
 ;%0Aim
@@ -223,60 +223,12 @@
 tudy
-TaskManager;%0Aimport com.jetbrains.edu.learning.Study
+Base
 Tool
@@ -285,120 +285,24 @@
 ing.
-actions.*;%0Aimport com.jetbrains.edu.learning.ui.StudyToolWindow;%0Aimport com.jetbrains.edu.utils.EduIntellijUtils
+StudyTaskManager
 ;%0Aim
@@ -346,31 +346,8 @@
 l;%0A%0A
-import javax.swing.*;%0A%0A
 publ
@@ -393,24 +393,25 @@
 tor 
-implement
+extend
 s Study
+Base
 Tool
@@ -514,32 +514,102 @@
 ject project) %7B%0A
+        DefaultActionGroup baseGroup = super.getActionGroup(project);%0A
         final De
@@ -729,805 +729,53 @@
 .add
-(new StudyPreviousStudyTaskAction());%0A        group.add(new StudyNextStudyTaskAction());%0A        group.add(new StudyRefreshTaskFileAction());%0A        group.add(new StudyShowHintAction());%0A        group.add(new StudyRunAction());%0A        group.add(new StudyEditInputAction());%0A        %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(
+All(baseGroup
 );%0A    
-%7D%0A%0A
     
-@NotNull%0A    @Override%0A    public FileEditorManagerListener getFileEditorManagerListener(@NotNull final Project project, %0A                                                                  @NotNull final StudyToolWindow studyToolWindow) %7B%0A%0A        return EduIntellijUtils.getFileEditorManagerListener(studyToolWindow, project)
+%0A        return group
 ;%0A  

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