update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / inline / InlineToAnonymousClassDialog.java
blob005cd663ea142c893b2d092a8bdeef180980fe24
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.refactoring.inline;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.help.HelpManager;
20 import com.intellij.psi.PsiCall;
21 import com.intellij.psi.PsiClass;
22 import com.intellij.psi.util.PsiFormatUtil;
23 import com.intellij.refactoring.RefactoringBundle;
24 import com.intellij.refactoring.JavaRefactoringSettings;
25 import com.intellij.refactoring.HelpID;
27 import javax.swing.*;
28 import java.awt.*;
30 /**
31 * @author yole
33 public class InlineToAnonymousClassDialog extends InlineOptionsDialog {
34 private final PsiClass myClass;
35 private final PsiCall myCallToInline;
36 private JCheckBox myCbSearchInComments;
37 private JCheckBox myCbSearchTextOccurences;
39 protected InlineToAnonymousClassDialog(Project project, PsiClass psiClass, final PsiCall callToInline) {
40 super(project, true, psiClass);
41 myClass = psiClass;
42 myCallToInline = callToInline;
43 myInvokedOnReference = (myCallToInline != null);
44 setTitle(RefactoringBundle.message("inline.to.anonymous.refactoring"));
45 init();
48 protected String getNameLabelText() {
49 String className = PsiFormatUtil.formatClass(myClass, PsiFormatUtil.SHOW_NAME);
50 return RefactoringBundle.message("inline.to.anonymous.name.label", className);
53 protected String getBorderTitle() {
54 return RefactoringBundle.message("inline.to.anonymous.border.title");
57 protected String getInlineAllText() {
58 return RefactoringBundle.message("all.references.and.remove.the.class");
61 protected String getInlineThisText() {
62 return RefactoringBundle.message("this.reference.only.and.keep.the.class");
65 protected boolean isInlineThis() {
66 return false;
69 protected JComponent createCenterPanel() {
70 JComponent optionsPanel = super.createCenterPanel();
72 // TODO[yole]: make visible again when "inline this" option is fixed (IDEADEV-17928)
73 myOptionsPanel.setVisible(false);
74 myRbInlineAll.setSelected(true);
76 JPanel panel = new JPanel();
77 panel.setLayout(new GridBagLayout());
78 GridBagConstraints gbc = new GridBagConstraints();
79 gbc.fill = GridBagConstraints.HORIZONTAL;
80 gbc.weightx = 1.0;
81 panel.add(optionsPanel, gbc);
83 JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
84 myCbSearchInComments = new JCheckBox(RefactoringBundle.message("search.in.comments.and.strings"),
85 settings.INLINE_CLASS_SEARCH_IN_COMMENTS);
86 myCbSearchTextOccurences = new JCheckBox(RefactoringBundle.message("search.for.text.occurrences"),
87 settings.INLINE_CLASS_SEARCH_IN_NON_JAVA);
88 gbc.gridy = 1;
89 panel.add(myCbSearchInComments, gbc);
90 gbc.gridy = 2;
91 panel.add(myCbSearchTextOccurences, gbc);
92 return panel;
95 protected void doAction() {
96 final boolean searchInComments = myCbSearchInComments.isSelected();
97 final boolean searchInNonJava = myCbSearchTextOccurences.isSelected();
99 JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
100 settings.INLINE_CLASS_SEARCH_IN_COMMENTS = searchInComments;
101 settings.INLINE_CLASS_SEARCH_IN_NON_JAVA = searchInNonJava;
103 invokeRefactoring(new InlineToAnonymousClassProcessor(getProject(), myClass, myCallToInline, isInlineThisOnly(),
104 searchInComments, searchInNonJava));
107 protected void doHelpAction() {
108 HelpManager.getInstance().invokeHelp(HelpID.INLINE_CLASS);