/*
 * Copyright 2000-2009 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.
 */

/*
 * User: anna
 * Date: 04-Dec-2008
 */
package com.maddyhome.idea.copyright.ui;

import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.maddyhome.idea.copyright.util.FileTypeUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.util.Arrays;

public class CopyrightFormattingConfigurable extends SearchableConfigurable.Parent.Abstract implements Configurable.NoScroll {
  private final Project myProject;
  private TemplateCommentPanel myPanel;

  CopyrightFormattingConfigurable(Project project) {
    myProject = project;
  }

  @NotNull
  public String getId() {
    return "template.copyright.formatting";
  }

  public Runnable enableSearch(String option) {
    return null;
  }

  @Nls
    public String getDisplayName() {
    return "Formatting";
  }

  public String getHelpTopic() {
    return getId();
  }

  public JComponent createComponent() {
    myPanel = new TemplateCommentPanel(null, null, null, myProject);
    return myPanel.createComponent();
  }

  public boolean isModified() {
    return myPanel.isModified();
  }

  public void apply() throws ConfigurationException {
    myPanel.apply();
  }

  public void reset() {
    myPanel.reset();
  }

  public void disposeUIResources() {
    myPanel.disposeUIResources();
    myPanel = null;
  }

  public boolean hasOwnContent() {
    return true;
  }

  protected Configurable[] buildConfigurables() {
    final FileType[] types = FileTypeUtil.getInstance().getSupportedTypes();
    final Configurable[] children = new Configurable[types.length];
    Arrays.sort(types, new FileTypeUtil.SortByName());
    for (int i = 0; i < types.length; i++) {
      children[i] = FileTypeCopyrightConfigurableFactory.createFileTypeConfigurable(myProject, types[i], myPanel);
    }
    return children;
  }
}

@@ -1736,24 +1736,180 @@
 mponent() %7B%0A
+    getOrCreateMainPanel();%0A    return myPanel.createComponent();%0A  %7D%0A%0A  private TemplateCommentPanel getOrCreateMainPanel() %7B%0A    if (myPanel == null) %7B%0A  
     myPanel 
@@ -1965,16 +1965,22 @@
 oject);%0A
+    %7D%0A
     retu
@@ -1989,34 +1989,16 @@
  myPanel
-.createComponent()
 ;%0A  %7D%0A%0A 
@@ -2749,23 +2749,38 @@
 pes%5Bi%5D, 
-my
+getOrCreateMain
 Panel
+()
 );%0A    %7D

fix initialization order configurables (IDEA-104512)