3 * Copyright 2000-2009 JetBrains s.r.o.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package com
.intellij
.refactoring
.migration
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.openapi
.ui
.DialogWrapper
;
21 import com
.intellij
.psi
.JavaPsiFacade
;
22 import com
.intellij
.psi
.PsiManager
;
23 import com
.intellij
.refactoring
.RefactoringBundle
;
24 import com
.intellij
.ui
.DocumentAdapter
;
25 import com
.intellij
.ui
.IdeBorderFactory
;
28 import javax
.swing
.event
.DocumentEvent
;
29 import javax
.swing
.event
.DocumentListener
;
32 public class EditMigrationEntryDialog
extends DialogWrapper
{
33 private JRadioButton myRbPackage
;
34 private JRadioButton myRbClass
;
35 private JTextField myOldNameField
;
36 private JTextField myNewNameField
;
37 private final Project myProject
;
39 public EditMigrationEntryDialog(Project project
) {
42 setTitle(RefactoringBundle
.message("edit.migration.entry.title"));
43 setHorizontalStretch(1.2f
);
47 public JComponent
getPreferredFocusedComponent() {
48 return myOldNameField
;
51 protected JComponent
createCenterPanel() {
55 protected JComponent
createNorthPanel() {
56 JPanel panel
= new JPanel(new GridBagLayout());
57 GridBagConstraints gbConstraints
= new GridBagConstraints();
58 panel
.setBorder(IdeBorderFactory
.createBorder());
59 gbConstraints
.insets
= new Insets(4, 4, 4, 4);
60 gbConstraints
.weighty
= 1;
62 gbConstraints
.gridwidth
= GridBagConstraints
.RELATIVE
;
63 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
64 gbConstraints
.weightx
= 0;
65 myRbPackage
= new JRadioButton(RefactoringBundle
.message("migration.entry.package"));
66 panel
.add(myRbPackage
, gbConstraints
);
68 gbConstraints
.gridwidth
= GridBagConstraints
.RELATIVE
;
69 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
70 gbConstraints
.weightx
= 0;
71 myRbClass
= new JRadioButton(RefactoringBundle
.message("migration.entry.class"));
72 panel
.add(myRbClass
, gbConstraints
);
74 gbConstraints
.gridwidth
= GridBagConstraints
.REMAINDER
;
75 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
76 gbConstraints
.weightx
= 1;
77 panel
.add(new JPanel(), gbConstraints
);
79 ButtonGroup buttonGroup
= new ButtonGroup();
80 buttonGroup
.add(myRbPackage
);
81 buttonGroup
.add(myRbClass
);
83 gbConstraints
.weightx
= 0;
84 gbConstraints
.gridwidth
= GridBagConstraints
.RELATIVE
;
85 gbConstraints
.fill
= GridBagConstraints
.VERTICAL
;
86 JLabel oldNamePrompt
= new JLabel(RefactoringBundle
.message("migration.entry.old.name"));
87 panel
.add(oldNamePrompt
, gbConstraints
);
89 gbConstraints
.gridwidth
= GridBagConstraints
.REMAINDER
;
90 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
91 gbConstraints
.weightx
= 1;
92 myOldNameField
= new JTextField();
93 panel
.add(myOldNameField
, gbConstraints
);
95 gbConstraints
.weightx
= 0;
96 gbConstraints
.gridwidth
= GridBagConstraints
.RELATIVE
;
97 gbConstraints
.fill
= GridBagConstraints
.VERTICAL
;
98 JLabel newNamePrompt
= new JLabel(RefactoringBundle
.message("migration.entry.new.name"));
99 panel
.add(newNamePrompt
, gbConstraints
);
101 gbConstraints
.gridwidth
= GridBagConstraints
.REMAINDER
;
102 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
103 gbConstraints
.weightx
= 1;
104 myNewNameField
= new JTextField();
105 panel
.setPreferredSize(new Dimension(300, panel
.getPreferredSize().height
));
106 panel
.add(myNewNameField
, gbConstraints
);
108 DocumentListener documentListener
= new DocumentAdapter() {
109 public void textChanged(DocumentEvent event
) {
113 myOldNameField
.getDocument().addDocumentListener(documentListener
);
114 myNewNameField
.getDocument().addDocumentListener(documentListener
);
118 private void validateOKButton() {
119 boolean isEnabled
= true;
120 String text
= myOldNameField
.getText();
122 PsiManager manager
= PsiManager
.getInstance(myProject
);
123 if (!JavaPsiFacade
.getInstance(manager
.getProject()).getNameHelper().isQualifiedName(text
)){
126 text
= myNewNameField
.getText();
128 if (!JavaPsiFacade
.getInstance(manager
.getProject()).getNameHelper().isQualifiedName(text
)){
131 setOKActionEnabled(isEnabled
);
134 public void setEntry(MigrationMapEntry entry
) {
135 myOldNameField
.setText(entry
.getOldName());
136 myNewNameField
.setText(entry
.getNewName());
137 myRbPackage
.setSelected(entry
.getType() == MigrationMapEntry
.PACKAGE
);
138 myRbClass
.setSelected(entry
.getType() == MigrationMapEntry
.CLASS
);
142 public void updateEntry(MigrationMapEntry entry
) {
143 entry
.setOldName(myOldNameField
.getText().trim());
144 entry
.setNewName(myNewNameField
.getText().trim());
145 if (myRbPackage
.isSelected()){
146 entry
.setType(MigrationMapEntry
.PACKAGE
);
147 entry
.setRecursive(true);
150 entry
.setType(MigrationMapEntry
.CLASS
);