// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.structuralsearch.plugin.ui;

import com.intellij.icons.AllIcons;
import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
import com.intellij.ui.SimpleListCellRenderer;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

import static com.intellij.openapi.util.text.StringUtil.collapseWhiteSpace;
import static com.intellij.openapi.util.text.StringUtil.shortenTextWithEllipsis;

/**
 * @author Bas Leijdekkers
 */
public class ConfigurationCellRenderer extends SimpleListCellRenderer<Configuration> {

  @Override
  public void customize(@NotNull JList<? extends Configuration> list,
                        Configuration value,
                        int index,
                        boolean selected,
                        boolean hasFocus) {
    if (value instanceof ReplaceConfiguration) {
      setIcon(AllIcons.Actions.Replace);
      setText(shortenTextWithEllipsis(collapseWhiteSpace(value.getMatchOptions().getSearchPattern()), 49, 0, true)
              + " ⇒ "
              + shortenTextWithEllipsis(collapseWhiteSpace(value.getReplaceOptions().getReplacement()), 49, 0, true));
    }
    else {
      setIcon(AllIcons.Actions.Find);
      setText(shortenTextWithEllipsis(collapseWhiteSpace(value.getMatchOptions().getSearchPattern()), 100, 0, true));
    }
    setEnabled(list.isEnabled());
  }
}

@@ -208,19 +208,34 @@
 lij.
-icons.AllIc
+structuralsearch.MatchOpti
 ons;
@@ -958,16 +958,130 @@
 ) %7B%0A    
+final MatchOptions matchOptions = value.getMatchOptions();%0A    setIcon(matchOptions.getFileType().getIcon());%0A    
 if (valu
@@ -1120,49 +1120,8 @@
 n) %7B
-%0A      setIcon(AllIcons.Actions.Replace);
 %0A   
@@ -1170,34 +1170,25 @@
 eWhiteSpace(
-value.getM
+m
 atchOptions(
@@ -1178,34 +1178,32 @@
 ace(matchOptions
-()
 .getSearchPatter
@@ -1383,46 +1383,8 @@
 e %7B%0A
-      setIcon(AllIcons.Actions.Find);%0A
     
@@ -1436,26 +1436,17 @@
 teSpace(
-value.getM
+m
 atchOpti
@@ -1444,26 +1444,24 @@
 matchOptions
-()
 .getSearchPa

use file type icons for inspection templates (IDEA-244596)