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.
18 * Created by IntelliJ IDEA.
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com
.intellij
.refactoring
.introduceParameter
;
27 import com
.intellij
.openapi
.project
.Project
;
28 import com
.intellij
.openapi
.ui
.DialogWrapper
;
29 import com
.intellij
.psi
.PsiMethod
;
30 import com
.intellij
.refactoring
.RefactoringBundle
;
31 import com
.intellij
.refactoring
.ui
.MethodCellRenderer
;
32 import com
.intellij
.ui
.IdeBorderFactory
;
36 import java
.util
.List
;
38 public class EnclosingMethodSelectionDialog
extends DialogWrapper
{
39 private final List
<PsiMethod
> myEnclosingMethods
;
41 private JList myEnclosingMethodsList
= null;
42 private final JCheckBox myCbReplaceInstanceOf
= new JCheckBox(RefactoringBundle
.message("use.interface.superclass.in.instanceof"));
43 private static final String REFACTORING_NAME
= RefactoringBundle
.message("introduce.parameter.title");
45 EnclosingMethodSelectionDialog(Project project
, List
<PsiMethod
> enclosingMethods
) {
48 myEnclosingMethods
= enclosingMethods
;
50 setTitle(REFACTORING_NAME
);
54 public PsiMethod
getSelectedMethod() {
55 if(myEnclosingMethodsList
!= null) {
56 return (PsiMethod
) myEnclosingMethodsList
.getSelectedValue();
63 protected Action
[] createActions() {
64 return new Action
[]{getOKAction(), getCancelAction()/*, getHelpAction()*/};
67 public JComponent
getPreferredFocusedComponent() {
68 return myEnclosingMethodsList
;
71 protected JComponent
createNorthPanel() {
72 JPanel panel
= new JPanel();
73 panel
.setBorder(IdeBorderFactory
.createBorder());
75 panel
.setLayout(new GridBagLayout());
76 GridBagConstraints gbConstraints
= new GridBagConstraints();
78 gbConstraints
.insets
= new Insets(4, 8, 4, 8);
79 gbConstraints
.weighty
= 0;
80 gbConstraints
.weightx
= 1;
81 gbConstraints
.gridy
= 0;
82 gbConstraints
.gridwidth
= GridBagConstraints
.REMAINDER
;
83 gbConstraints
.gridheight
= 1;
84 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
85 gbConstraints
.anchor
= GridBagConstraints
.WEST
;
86 panel
.add(new JLabel(RefactoringBundle
.message("introduce.parameter.to.method")), gbConstraints
);
88 gbConstraints
.weighty
= 1;
89 myEnclosingMethodsList
= new JList(myEnclosingMethods
.toArray());
90 myEnclosingMethodsList
.setCellRenderer(new MethodCellRenderer());
91 myEnclosingMethodsList
.getSelectionModel().setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
93 int indexToSelect
= 0;
94 myEnclosingMethodsList
.setSelectedIndex(indexToSelect
);
95 gbConstraints
.gridy
++;
96 panel
.add(new JScrollPane(myEnclosingMethodsList
), gbConstraints
);
101 protected String
getDimensionServiceKey() {
102 return "#com.intellij.refactoring.introduceParameter.EnclosingMethodSelectonDialog";
105 protected void doOKAction() {
106 if (!isOKActionEnabled())
112 protected JComponent
createCenterPanel() {