/*
 * 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.
 */
package com.intellij.execution.configurations;

import com.intellij.execution.BeforeRunTask;
import com.intellij.execution.RunManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.util.IconUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * Factory for run configuration instances.
 *
 * @see com.intellij.execution.configurations.ConfigurationType#getConfigurationFactories()
 * @author dyoma
 */
public abstract class ConfigurationFactory {
  public static final Icon ADD_ICON = IconUtil.getAddIcon();

  private final ConfigurationType myType;

  protected ConfigurationFactory(@NotNull final ConfigurationType type) {
    myType = type;
  }

  /**
   * Creates a new run configuration with the specified name by cloning the specified template.
   *
   * @param name the name for the new run configuration.
   * @param template the template from which the run configuration is copied
   * @return the new run configuration.
   */
  public RunConfiguration createConfiguration(String name, RunConfiguration template) {
    RunConfiguration newConfiguration = template.clone();
    newConfiguration.setName(name);
    return newConfiguration;
  }

  /**
   * Override this method and return {@code false} to hide the configuration from 'New' popup in 'Edit Configurations' dialog
   *
   * @return {@code true} if it makes sense to create configurations of this type in {@code project}
   */
  public boolean isApplicable(@NotNull Project project) {
    return true;
  }

  /**
   * Creates a new template run configuration within the context of the specified project.
   *
   * @param project the project in which the run configuration will be used
   * @return the run configuration instance.
   */
  public abstract RunConfiguration createTemplateConfiguration(Project project);

  public RunConfiguration createTemplateConfiguration(Project project, RunManager runManager) {
    return createTemplateConfiguration(project);
  }

  /**
   * Returns the name of the run configuration variant created by this factory.
   *
   * @return the name of the run configuration variant created by this factory
   */
  public String getName() {
    return myType.getDisplayName();
  }

  public Icon getAddIcon() {
    return ADD_ICON;
  }

  public Icon getIcon(@NotNull final RunConfiguration configuration) {
    return getIcon();
  }

  public Icon getIcon() {
    return myType.getIcon();
  }

  @NotNull
  public ConfigurationType getType() {
    return myType;
  }

  /**
   * In this method you can configure defaults for the task, which are preferable to be used for your particular configuration type
   * @param providerID
   * @param task
   */
  public void configureBeforeRunTaskDefaults(Key<? extends BeforeRunTask> providerID, BeforeRunTask task) {
  }

  public boolean isConfigurationSingletonByDefault() {
    return false;
  }

  public boolean canConfigurationBeSingleton() {
    return true; // Configuration may be marked as singleton by default
  }
}

@@ -816,43 +816,8 @@
 ey;%0A
-import com.intellij.util.IconUtil;%0A
 impo
@@ -929,16 +929,33 @@
 ces.%0A *%0A
+ * @author dyoma%0A
  * @see 
@@ -1038,33 +1038,16 @@
 ories()%0A
- * @author dyoma%0A
  */%0Apubl
@@ -1091,70 +1091,8 @@
 y %7B%0A
-  public static final Icon ADD_ICON = IconUtil.getAddIcon();%0A%0A
   pr
@@ -1352,16 +1352,20 @@
 am name 
+    
 the name
@@ -2769,63 +2769,8 @@
  %7D%0A%0A
-  public Icon getAddIcon() %7B%0A    return ADD_ICON;%0A  %7D%0A%0A
   pu
@@ -3135,16 +3135,21 @@
 on type%0A
+   *%0A
    * @pa

drop useless field