/*
 * 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.refactoring.inline;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.RefactoringBundle;

import javax.swing.*;
import java.awt.*;

public abstract class InlineOptionsWithSearchSettingsDialog extends InlineOptionsDialog {
  protected JCheckBox myCbSearchInComments;
  protected JCheckBox myCbSearchTextOccurences;

  protected InlineOptionsWithSearchSettingsDialog(Project project, boolean canBeParent, PsiElement element) {
    super(project, canBeParent, element);
  }

  protected abstract boolean isSearchInCommentsAndStrings();
  protected abstract void saveSearchInCommentsAndStrings(boolean searchInComments);
  
  protected abstract boolean isSearchForTextOccurrences();
  protected abstract void saveSearchInTextOccurrences(boolean searchInTextOccurrences);

  @Override
  protected void doAction() {
    final boolean searchInNonJava = myCbSearchTextOccurences.isSelected();
    final boolean searchInComments = myCbSearchInComments.isSelected();
    saveSearchInCommentsAndStrings(searchInComments);
    saveSearchInTextOccurrences(searchInNonJava);
  }

  @Override
  protected JComponent createCenterPanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.gridwidth = 2;
    panel.add(super.createCenterPanel(), gbc);


    myCbSearchInComments = new JCheckBox(RefactoringBundle.message("search.in.comments.and.strings"), isSearchInCommentsAndStrings());
    myCbSearchTextOccurences = new JCheckBox(RefactoringBundle.message("search.for.text.occurrences"), isSearchForTextOccurrences());
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.gridy = 1;
    gbc.gridx = 0;
    panel.add(myCbSearchInComments, gbc);
    gbc.gridx = 1;
    panel.add(myCbSearchTextOccurences, gbc);
    return panel;
  }
}

@@ -810,16 +810,89 @@
 a.awt.*;
+%0Aimport java.awt.event.ActionEvent;%0Aimport java.awt.event.ActionListener;
 %0A%0Apublic
@@ -1706,24 +1706,71 @@
 Selected();%0A
+    if (myCbSearchInComments.isEnabled() ) %7B%0A  
     saveSear
@@ -1819,53 +1819,555 @@
     
-saveSearchInTextOccurrences(searchInNonJava);
+%7D%0A    if (myCbSearchTextOccurences.isEnabled()) %7B%0A      saveSearchInTextOccurrences(searchInNonJava);%0A    %7D%0A  %7D%0A%0A  public void setEnabledSearchSettngs(boolean enabled) %7B%0A    myCbSearchInComments.setEnabled(enabled);%0A    myCbSearchTextOccurences.setEnabled(enabled);%0A    if (enabled) %7B%0A      myCbSearchInComments.setSelected(isSearchInCommentsAndStrings());%0A      myCbSearchTextOccurences.setSelected(isSearchForTextOccurrences());%0A    %7D else %7B%0A      myCbSearchInComments.setSelected(false);%0A      myCbSearchTextOccurences.setSelected(false);%0A    %7D
 %0A  %7D
@@ -3087,24 +3087,24 @@
 .gridx = 1;%0A
-
     panel.ad
@@ -3133,24 +3133,400 @@
 nces, gbc);%0A
+    final ActionListener actionListener = new ActionListener() %7B%0A      @Override%0A      public void actionPerformed(ActionEvent e) %7B%0A        setEnabledSearchSettngs(myRbInlineAll.isSelected());%0A      %7D%0A    %7D;%0A    myRbInlineThisOnly.addActionListener(actionListener);%0A    myRbInlineAll.addActionListener(actionListener);%0A    setEnabledSearchSettngs(myRbInlineAll.isSelected());%0A
     return p

disable search for text occurrences/in comments when inline this is selected (IDEA-89669)