package com.intellij.execution;

import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.LayeredIcon;

import javax.swing.*;

/**
 * @author spleaner
 */
public class ExecutionUtil {

  private static final Icon INVALID_CONFIGURATION = IconLoader.getIcon("/runConfigurations/invalidConfigurationLayer.png");

  private ExecutionUtil() {
  }

  public static Icon getConfigurationIcon(final Project project, final RunnerAndConfigurationSettings settings, final boolean invalid) {
    final RunManager runManager = RunManager.getInstance(project);
    RunConfiguration configuration = settings.getConfiguration();
    final Icon icon = settings.getFactory().getIcon(configuration);
    final Icon configurationIcon = runManager.isTemporary(configuration) ? IconLoader.getTransparentIcon(icon, 0.3f) : icon;
    if (invalid) {
      return LayeredIcon.create(configurationIcon, INVALID_CONFIGURATION);
    }

    return configurationIcon;
  }

  public static Icon getConfigurationIcon(final Project project, final RunnerAndConfigurationSettings settings) {
    try {
      settings.checkSettings();
      return getConfigurationIcon(project, settings, false);
    }
    catch (RuntimeConfigurationException ex) {
      return getConfigurationIcon(project, settings, true);
    }
  }

  public static String shortenName(final String name, final int toBeAdded) {
    if (name == null) return "";
    final int symbols = Math.max(10, 20 - toBeAdded);
    if (name.length() < symbols) return name;
    else return name.substring(0, symbols) + "...";
  }

}

@@ -74,20 +74,16 @@
 ions.Run
-time
 Configur
@@ -87,25 +87,16 @@
 guration
-Exception
 ;%0Aimport
@@ -129,32 +129,36 @@
 nfigurations.Run
+time
 Configuration;%0Ai
@@ -146,32 +146,41 @@
 imeConfiguration
+Exception
 ;%0Aimport com.int
@@ -278,25 +278,101 @@
 llij.ui.
-LayeredIc
+DeferredIconImpl;%0Aimport com.intellij.ui.LayeredIcon;%0Aimport com.intellij.util.Functi
 on;%0A%0Aimp
@@ -1328,113 +1328,395 @@
     
-try %7B%0A      settings.checkSettings();%0A      return getConfigurationIcon(project, settings, false);%0A
+final Icon baseIcon = getConfigurationIcon(project, settings, false);%0A    return new DeferredIconImpl%3CRunnerAndConfigurationSettings%3E(baseIcon, settings, new Function%3CRunnerAndConfigurationSettings, Icon%3E() %7B%0A      public Icon fun(RunnerAndConfigurationSettings runnerAndConfigurationSettings) %7B%0A        try %7B%0A          settings.checkSettings();%0A          return baseIcon;%0A   
     
+ 
 %7D%0A
+    
     
@@ -1760,24 +1760,28 @@
 ex) %7B%0A      
+  
+  
 return getCo
@@ -1826,17 +1826,37 @@
 e);%0A    
-%7D
+    %7D%0A      %7D%0A    %7D);
 %0A  %7D%0A%0A  

test fix