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
.extractSuperclass
;
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.psi
.PsiClass
;
20 import com
.intellij
.psi
.PsiMember
;
21 import com
.intellij
.psi
.PsiMethod
;
22 import com
.intellij
.refactoring
.HelpID
;
23 import com
.intellij
.refactoring
.JavaRefactoringSettings
;
24 import com
.intellij
.refactoring
.RefactoringBundle
;
25 import com
.intellij
.refactoring
.classMembers
.MemberInfoChange
;
26 import com
.intellij
.refactoring
.classMembers
.MemberInfoModel
;
27 import com
.intellij
.refactoring
.memberPullUp
.PullUpHelper
;
28 import com
.intellij
.refactoring
.ui
.MemberSelectionPanel
;
29 import com
.intellij
.refactoring
.util
.DocCommentPolicy
;
30 import com
.intellij
.refactoring
.util
.classMembers
.InterfaceContainmentVerifier
;
31 import com
.intellij
.refactoring
.util
.classMembers
.MemberInfo
;
32 import com
.intellij
.refactoring
.util
.classMembers
.UsesAndInterfacesDependencyMemberInfoModel
;
36 import java
.util
.ArrayList
;
37 import java
.util
.List
;
39 class ExtractSuperclassDialog
extends ExtractSuperBaseDialog
{
40 private final InterfaceContainmentVerifier myContainmentVerifier
= new InterfaceContainmentVerifier() {
41 public boolean checkedInterfacesContain(PsiMethod psiMethod
) {
42 return PullUpHelper
.checkedInterfacesContain(myMemberInfos
, psiMethod
);
46 public static interface Callback
{
47 boolean checkConflicts(ExtractSuperclassDialog dialog
);
50 private JLabel myClassNameLabel
;
51 private JLabel myPackageLabel
;
52 private final Callback myCallback
;
54 public ExtractSuperclassDialog(Project project
, PsiClass sourceClass
, List
<MemberInfo
> selectedMembers
, Callback callback
) {
55 super(project
, sourceClass
, selectedMembers
, ExtractSuperclassHandler
.REFACTORING_NAME
);
56 myCallback
= callback
;
60 public MemberInfo
[] getSelectedMemberInfos() {
61 ArrayList
<MemberInfo
> list
= new ArrayList
<MemberInfo
>(myMemberInfos
.size());
62 for (MemberInfo info
: myMemberInfos
) {
63 if (info
.isChecked()) {
67 return list
.toArray(new MemberInfo
[list
.size()]);
70 InterfaceContainmentVerifier
getContainmentVerifier() {
71 return myContainmentVerifier
;
74 protected JComponent
createNorthPanel() {
75 Box box
= Box
.createVerticalBox();
77 JPanel _panel
= new JPanel(new BorderLayout());
78 _panel
.add(new JLabel(RefactoringBundle
.message("extract.superclass.from")), BorderLayout
.NORTH
);
79 _panel
.add(mySourceClassField
, BorderLayout
.CENTER
);
82 box
.add(Box
.createVerticalStrut(10));
84 box
.add(createActionComponent());
86 box
.add(Box
.createVerticalStrut(10));
88 myClassNameLabel
= new JLabel();
89 myClassNameLabel
.setLabelFor(myExtractedSuperNameField
);
90 _panel
= new JPanel(new BorderLayout());
91 _panel
.add(myClassNameLabel
, BorderLayout
.NORTH
);
92 _panel
.add(myExtractedSuperNameField
, BorderLayout
.CENTER
);
94 box
.add(Box
.createVerticalStrut(5));
97 _panel
= new JPanel(new BorderLayout());
98 myPackageLabel
= new JLabel();
99 myPackageLabel
.setText(RefactoringBundle
.message("package.for.new.superclass"));
100 _panel
.add(myPackageLabel
, BorderLayout
.NORTH
);
101 _panel
.add(myPackageNameField
, BorderLayout
.CENTER
);
102 //_panel.add(myBtnPackageChooser, BorderLayout.EAST);
104 box
.add(Box
.createVerticalStrut(10));
106 JPanel panel
= new JPanel(new BorderLayout());
107 panel
.add(box
, BorderLayout
.CENTER
);
111 protected String
getClassNameLabelText() {
112 return RefactoringBundle
.message("superclass.name");
115 protected JLabel
getClassNameLabel() {
116 return myClassNameLabel
;
119 protected JLabel
getPackageNameLabel() {
120 return myPackageLabel
;
123 protected String
getEntityName() {
124 return RefactoringBundle
.message("ExtractSuperClass.superclass");
127 protected JComponent
createCenterPanel() {
128 JPanel panel
= new JPanel(new BorderLayout());
129 final MemberSelectionPanel memberSelectionPanel
= new MemberSelectionPanel(RefactoringBundle
.message("members.to.form.superclass"),
130 myMemberInfos
, RefactoringBundle
.message("make.abstract"));
131 panel
.add(memberSelectionPanel
, BorderLayout
.CENTER
);
132 final MemberInfoModel
<PsiMember
, MemberInfo
> memberInfoModel
=
133 new UsesAndInterfacesDependencyMemberInfoModel(mySourceClass
, null, false, myContainmentVerifier
) {
134 public Boolean
isFixedAbstract(MemberInfo member
) {
138 memberInfoModel
.memberInfoChanged(new MemberInfoChange
<PsiMember
, MemberInfo
>(myMemberInfos
));
139 memberSelectionPanel
.getTable().setMemberInfoModel(memberInfoModel
);
140 memberSelectionPanel
.getTable().addMemberInfoChangeListener(memberInfoModel
);
142 panel
.add(myJavaDocPanel
, BorderLayout
.EAST
);
148 protected String
getJavaDocPanelName() {
149 return RefactoringBundle
.message("javadoc.for.abstracts");
153 protected String
getExtractedSuperNameNotSpecifiedKey() {
154 return RefactoringBundle
.message("no.superclass.name.specified");
158 protected boolean checkConflicts() {
159 return myCallback
.checkConflicts(this);
163 protected int getJavaDocPolicySetting() {
164 return JavaRefactoringSettings
.getInstance().EXTRACT_SUPERCLASS_JAVADOC
;
168 protected void setJavaDocPolicySetting(int policy
) {
169 JavaRefactoringSettings
.getInstance().EXTRACT_SUPERCLASS_JAVADOC
= policy
;
174 protected ExtractSuperBaseProcessor
createProcessor() {
175 return new ExtractSuperClassProcessor(myProject
, getTargetDirectory(), getExtractedSuperName(),
176 mySourceClass
, getSelectedMemberInfos(), false,
177 new DocCommentPolicy(getJavaDocPolicy()));
181 protected String
getHelpId() {
182 return HelpID
.EXTRACT_SUPERCLASS
;