package org.jetbrains.plugins.scala.lang.formatting.settings;

import com.intellij.application.options.codeStyle.CommenterForm;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.ImmutableList;
import com.intellij.util.ui.JBInsets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.scala.ScalaBundle;
import org.jetbrains.plugins.scala.ScalaLanguage;

import javax.swing.*;

public final class CodeGenerationPanel extends ScalaCodeStylePanelBase {

    private final JPanel panel;
    private final CommenterForm myCommenterForm;

    CodeGenerationPanel(@NotNull CodeStyleSettings settings) {
        super(settings, ScalaBundle.message("codegeneration.panel.title"));

        panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setBorder(IdeBorderFactory.createEmptyBorder(new JBInsets(0, 10, 10, 10)));

        myCommenterForm = new CommenterForm(ScalaLanguage.INSTANCE);
        // TODO: show also BLOCK_COMMENT_ADD_SPACE and use it
        myCommenterForm.showStandardOptions(SupportedCommenterStandardOptionNames.toArray(new String[]{}));

        panel.add(myCommenterForm.getCommenterPanel());
    }

    public static ImmutableList<String> SupportedCommenterStandardOptionNames = ContainerUtil.immutableList(
            CodeStyleSettingsCustomizable.CommenterOption.LINE_COMMENT_AT_FIRST_COLUMN.name(),
            CodeStyleSettingsCustomizable.CommenterOption.LINE_COMMENT_ADD_SPACE.name(),
            CodeStyleSettingsCustomizable.CommenterOption.BLOCK_COMMENT_AT_FIRST_COLUMN.name()
    );

    @Override
    public void apply(CodeStyleSettings settings) {
        if (isModified(settings))
            myCommenterForm.apply(settings);
    }

    @Override
    public boolean isModified(CodeStyleSettings settings) {
        return myCommenterForm.isModified(settings);
    }

    @Override
    protected JComponent getPanelInner() {
        return panel;
    }

    @Override
    protected void resetImpl(CodeStyleSettings settings) {
        myCommenterForm.reset(settings);
    }
}

@@ -876,24 +876,202 @@
 .title%22));%0A%0A
+        myCommenterForm = new CommenterForm(ScalaLanguage.INSTANCE);%0A        myCommenterForm.showStandardOptions(SupportedCommenterStandardOptionNames.toArray(new String%5B%5D%7B%7D));%0A%0A
         pane
@@ -1239,33 +1239,32 @@
  10, 10)));%0A
-%0A
         
 myCommenterF
@@ -1243,32 +1243,42 @@
  10)));%0A        
+panel.add(
 myCommenterForm 
@@ -1268,39 +1268,36 @@
 (myCommenterForm
- = new 
+.get
 CommenterForm(Sc
@@ -1293,380 +1293,323 @@
 nter
-Form(ScalaLanguage.INSTANCE
+Panel()
 );%0A    
+%7D%0A%0A
     
-// TODO: show also BLOCK_COMMENT_ADD_SPACE and use it%0A        myCommenterForm.showStandardOptions(SupportedCommenterStandardOptionNames.toArray(new String%5B%5D%7B%7D));%0A%0A        panel.add(myCommenterForm.getCommenterPanel());%0A
+public static ImmutableList%3CString%3E SupportedCommenterStandardOptionNames = ContainerUtil.immutableList(%0A            CodeStyleSettingsCustomizable.CommenterOption.LINE_COMMENT_ADD_SPACE.name(),%0A  
     
-%7D%0A%0A
     
-public static ImmutableList%3CString%3E SupportedCommenterStandardOptionNames = ContainerUtil.immutableList(
+  CodeStyleSettingsCustomizable.CommenterOption.LINE_COMMENT_ADD_SPACE_ON_REFORMAT.name(),
 %0A   
@@ -1750,36 +1750,37 @@
 CommenterOption.
-LINE
+BLOCK
 _COMMENT_ADD_SPA
@@ -1769,32 +1769,38 @@
 CK_COMMENT_A
-DD_SPACE
+T_FIRST_COLUMN
 .name(),%0A   
@@ -1865,38 +1865,32 @@
 CK_COMMENT_A
-T_FIRST_COLUMN
+DD_SPACE
 .name()%0A    
@@ -1992,28 +1992,16 @@
 ttings))
-%0A           
  myComme

Add 'Enforce on reformat' and 'Add spaces around block comments' to comment generation settings