/*
 * Copyright 2000-2016 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.internal.statistic.ideSettings;

import com.intellij.util.containers.HashSet;

import javax.swing.*;
import java.util.Collections;
import java.util.Set;

public final class IdeInitialConfigButtonUsages {

  public static final Set<String> ALL_PLUGINS_SELECTED = Collections.unmodifiableSet(Collections.emptySet());

  private static volatile ConfigImport ourConfigImport = ConfigImport.NO_INIT;

  private static volatile String ourSkipRemainingPressedScreen = "";

  private static volatile Set<String> ourPredefinedDisabledPlugins = ALL_PLUGINS_SELECTED;

  private static Set<String> ourDownloadedPlugins = Collections.emptySet();

  public static ConfigImport getConfigImport() {
    return ourConfigImport;
  }

  public static void setConfigImport(JRadioButton ...buttons) {
    if (buttons.length < ConfigImport.values().length) {
      for (int i = 0; i < buttons.length; i++) {
        if (buttons[i] != null && buttons[i].isSelected()) {
          ourConfigImport = ConfigImport.values()[i];
        }
      }
    }
  }

  public static String getSkipRemainingPressedScreen() {
    return ourSkipRemainingPressedScreen;
  }

  public static void setSkipRemainingPressedScreen(String skipRemainingPressedScreen) {
    ourSkipRemainingPressedScreen = skipRemainingPressedScreen;
  }

  public static Set<String> getPredefinedDisabledPlugins() {
    return ourPredefinedDisabledPlugins;
  }

  public static void setPredefinedDisabledPlugins(Set<String> predefinedDisabledPlugins) {
    if (predefinedDisabledPlugins.isEmpty()) {
      return;
    }
    ourPredefinedDisabledPlugins = predefinedDisabledPlugins;
  }

  public synchronized static Set<String> getDownloadedPlugins() {
    return ourDownloadedPlugins;
  }

  public synchronized static void addDownloadedPlugin(String pluginId) {
    if (ourDownloadedPlugins.isEmpty()) {
      ourDownloadedPlugins = new HashSet<>();
    }
    ourDownloadedPlugins.add(pluginId);
  }

  public enum ConfigImport {
    DO_NOT_IMPORT,
    IMPORT_PATH,
    IMPORT_AUTO,
    IMPORT_CUSTOM,
    NO_INIT
  }
}

@@ -1386,172 +1386,517 @@
 ton 
-...buttons) %7B%0A    if (buttons.length %3C ConfigImport.values().length) %7B%0A      for (int i = 0; i %3C buttons.length; i++) %7B%0A        if (buttons%5Bi%5D != null && buttons%5Bi%5D
+myRbDoNotImport,%0A                                     JRadioButton myRbImport,%0A                                     JRadioButton myRbImportAuto,%0A                                     JRadioButton myCustomButton) %7B%0A    if (myRbDoNotImport != null && myRbDoNotImport.isSelected()) %7B%0A      ourConfigImport = ConfigImport.DO_NOT_IMPORT;%0A    %7D%0A    else if (myRbImport != null && myRbImport.isSelected()) %7B%0A      ourConfigImport = ConfigImport.IMPORT_PATH;%0A    %7D%0A    else if (myRbImportAuto != null && myRbImportAuto
 .isS
@@ -1908,20 +1908,16 @@
 ed()) %7B%0A
-    
       ou
@@ -1949,38 +1949,148 @@
 ort.
-values()%5Bi%5D
+IMPORT_AUTO
 ;%0A    
+%7D%0A
     
-%7D%0A      %7D
+else if (myCustomButton != null && myCustomButton.isSelected()) %7B%0A      ourConfigImport = ConfigImport.IMPORT_CUSTOM;
 %0A   

use more explicit code to map buttons selection into enum