/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intellij.codeInspection.htmlInspections;

import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.FieldPanel;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author spleaner
 */
public class HtmlUnknownTagInspection extends HtmlUnknownTagInspectionBase {

  public HtmlUnknownTagInspection() {
    super();
  }

  protected HtmlUnknownTagInspection(@NonNls @NotNull final String defaultValues) {
    super(defaultValues);
  }

  @Override
  @Nullable
  public JComponent createOptionsPanel() {
    return createOptionsPanel(this);
  }

  @NotNull
  protected static JComponent createOptionsPanel(@NotNull final HtmlUnknownTagInspectionBase inspection) {
    final JPanel result = new JPanel(new BorderLayout());

    final JPanel internalPanel = new JPanel(new BorderLayout());
    result.add(internalPanel, BorderLayout.NORTH);

    final FieldPanel additionalAttributesPanel = new FieldPanel(null, inspection.getPanelTitle(), null, null);
    additionalAttributesPanel.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        final Document document = e.getDocument();
        try {
          final String text = document.getText(0, document.getLength());
          if (text != null) {
            inspection.myValues = reparseProperties(text.trim());
          }
        }
        catch (BadLocationException e1) {
          inspection.getLogger().error(e1);
        }
      }
    });

    final JCheckBox checkBox = new JCheckBox(inspection.getCheckboxTitle());
    checkBox.setSelected(inspection.myCustomValuesEnabled);
    checkBox.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        final boolean b = checkBox.isSelected();
        if (b != inspection.myCustomValuesEnabled) {
          inspection.myCustomValuesEnabled = b;
          additionalAttributesPanel.setEnabled(inspection.myCustomValuesEnabled);
        }
      }
    });

    internalPanel.add(checkBox, BorderLayout.NORTH);
    internalPanel.add(additionalAttributesPanel, BorderLayout.CENTER);

    additionalAttributesPanel.setPreferredSize(new Dimension(150, additionalAttributesPanel.getPreferredSize().height));
    additionalAttributesPanel.setEnabled(inspection.myCustomValuesEnabled);
    additionalAttributesPanel.setText(inspection.createPropertiesString());

    return result;
  }
}

@@ -673,61 +673,265 @@
 lij.
-ui.DocumentAdapter;%0Aimport com.intellij.ui.FieldPanel
+openapi.ui.Messages;%0Aimport com.intellij.openapi.util.Ref;%0Aimport com.intellij.openapi.util.text.StringUtil;%0Aimport com.intellij.ui.DocumentAdapter;%0Aimport com.intellij.ui.FieldPanel;%0Aimport com.intellij.util.Function;%0Aimport com.intellij.util.PlatformIcons
 ;%0Aim
@@ -1288,16 +1288,39 @@
 istener;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -2007,105 +2007,1066 @@
 nal 
-FieldPanel additionalAttributesPanel = new FieldPanel(null, inspection.getPanelTitle(), null, nul
+Ref%3CFieldPanel%3E panelRef = new Ref%3CFieldPanel%3E();%0A    final FieldPanel additionalAttributesPanel = new FieldPanel(null, null, new ActionListener() %7B%0A      @Override%0A      public void actionPerformed(ActionEvent event) %7B%0A        Messages.showTextAreaDialog(panelRef.get().getTextField(), inspection.getPanelTitle(), %22HtmlUnknownTagInspection%22,%0A                                    new Function%3CString, List%3CString%3E%3E() %7B%0A                                      @Override%0A                                      public List%3CString%3E fun(String s) %7B%0A                                        return reparseProperties(s);%0A                                      %7D%0A                                    %7D, new Function%3CList%3CString%3E, String%3E() %7B%0A            @Override%0A            public String fun(List%3CString%3E strings) %7B%0A              return StringUtil.join(strings, %22,%22);%0A            %7D%0A          %7D%0A        );%0A      %7D%0A    %7D, null);%0A    ((JButton)additionalAttributesPanel.getComponent(1)).setIcon(PlatformIcons.OPEN_EDIT_DIALOG_ICON);%0A    panelRef.set(additionalAttributesPane
 l);%0A

support line-separated editing #WEB-2407 fixed