use of com.intellij.refactoring.ui.PackageNameReferenceEditorCombo in project intellij-community by JetBrains.
the class CopyClassDialog method createNorthPanel.
protected JComponent createNorthPanel() {
myNameField = new EditorTextField("");
String qualifiedName = getQualifiedName();
myTfPackage = new PackageNameReferenceEditorCombo(qualifiedName, myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
myTfPackage.setTextFieldPreferredWidth(Math.max(qualifiedName.length() + 5, 40));
myPackageLabel.setText(RefactoringBundle.message("destination.package"));
myPackageLabel.setLabelFor(myTfPackage);
if (myDoClone) {
myTfPackage.setVisible(false);
myPackageLabel.setVisible(false);
}
final JLabel label = new JLabel(RefactoringBundle.message("target.destination.folder"));
final boolean isMultipleSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject).size() > 1;
myDestinationCB.setVisible(!myDoClone && isMultipleSourceRoots);
label.setVisible(!myDoClone && isMultipleSourceRoots);
label.setLabelFor(myDestinationCB);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(myOpenInEditorCb, BorderLayout.EAST);
return FormBuilder.createFormBuilder().addComponent(myInformationLabel).addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNameField, UIUtil.LARGE_VGAP).addLabeledComponent(myPackageLabel, myTfPackage).addLabeledComponent(label, myDestinationCB).addComponent(panel).getPanel();
}
use of com.intellij.refactoring.ui.PackageNameReferenceEditorCombo in project intellij-community by JetBrains.
the class ReplaceConstructorWithBuilderDialog method createUIComponents.
private void createUIComponents() {
final com.intellij.openapi.editor.event.DocumentAdapter adapter = new com.intellij.openapi.editor.event.DocumentAdapter() {
public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
validateButtons();
}
};
myPackageTextField = new PackageNameReferenceEditorCombo(((PsiJavaFile) myConstructors[0].getContainingFile()).getPackageName(), myProject, RECENT_KEYS, RefactoringBundle.message("choose.destination.package"));
myPackageTextField.getChildComponent().getDocument().addDocumentListener(adapter);
myDestinationCb = new DestinationFolderComboBox() {
@Override
public String getTargetPackage() {
return myPackageTextField.getText().trim();
}
};
((DestinationFolderComboBox) myDestinationCb).setData(myProject, myConstructors[0].getContainingFile().getContainingDirectory(), myPackageTextField.getChildComponent());
myExistentClassTF = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(getProject()).createWithInnerClassesScopeChooser("Select Builder Class", GlobalSearchScope.projectScope(myProject), null, null);
final String classText = myExistentClassTF.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(myProject).findClass(classText, GlobalSearchScope.allScope(myProject));
if (currentClass != null) {
chooser.select(currentClass);
}
chooser.showDialog();
final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
myExistentClassTF.setText(selectedClass.getQualifiedName());
}
}
}, "", myProject, true, RECENT_KEYS);
myExistentClassTF.getChildComponent().getDocument().addDocumentListener(adapter);
}
use of com.intellij.refactoring.ui.PackageNameReferenceEditorCombo in project intellij-community by JetBrains.
the class IntroduceParameterObjectDialog method createUIComponents.
private void createUIComponents() {
final PsiFile file = mySourceMethod.getContainingFile();
packageTextField = new PackageNameReferenceEditorCombo(file instanceof PsiJavaFile ? ((PsiJavaFile) file).getPackageName() : "", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
final Document document = packageTextField.getChildComponent().getDocument();
final com.intellij.openapi.editor.event.DocumentAdapter adapter = new com.intellij.openapi.editor.event.DocumentAdapter() {
public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
validateButtons();
}
};
document.addDocumentListener(adapter);
existingClassField = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Project project = mySourceMethod.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final TreeJavaClassChooserDialog chooser = new TreeJavaClassChooserDialog(RefactorJBundle.message("select.wrapper.class"), project, scope, null, null);
final String classText = existingClassField.getText();
final PsiClass currentClass = JavaPsiFacade.getInstance(project).findClass(classText, GlobalSearchScope.allScope(project));
if (currentClass != null) {
chooser.select(currentClass);
}
chooser.show();
final PsiClass selectedClass = chooser.getSelected();
if (selectedClass != null) {
final String className = selectedClass.getQualifiedName();
existingClassField.setText(className);
RecentsManager.getInstance(myProject).registerRecentEntry(EXISTING_KEY, className);
}
}
}, "", myProject, true, EXISTING_KEY);
existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
@Override
public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
validateButtons();
enableGenerateAccessors();
}
});
myDestinationCb = new DestinationFolderComboBox() {
@Override
public String getTargetPackage() {
return getPackageName();
}
};
((DestinationFolderComboBox) myDestinationCb).setData(myProject, mySourceMethod.getContainingFile().getContainingDirectory(), packageTextField.getChildComponent());
}
use of com.intellij.refactoring.ui.PackageNameReferenceEditorCombo in project intellij-community by JetBrains.
the class CreateTestDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints constr = new GridBagConstraints();
constr.fill = GridBagConstraints.HORIZONTAL;
constr.anchor = GridBagConstraints.WEST;
int gridy = 1;
constr.insets = insets(4);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
final JLabel libLabel = new JLabel(CodeInsightBundle.message("intention.create.test.dialog.testing.library"));
libLabel.setLabelFor(myLibrariesCombo);
panel.add(libLabel, constr);
constr.gridx = 1;
constr.weightx = 1;
constr.gridwidth = GridBagConstraints.REMAINDER;
panel.add(myLibrariesCombo, constr);
myFixLibraryPanel = new JPanel(new BorderLayout());
myFixLibraryLabel = new JLabel();
myFixLibraryLabel.setIcon(AllIcons.Actions.IntentionBulb);
myFixLibraryPanel.add(myFixLibraryLabel, BorderLayout.CENTER);
myFixLibraryPanel.add(myFixLibraryButton, BorderLayout.EAST);
constr.insets = insets(1);
constr.gridy = gridy++;
constr.gridx = 0;
panel.add(myFixLibraryPanel, constr);
constr.gridheight = 1;
constr.insets = insets(6);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
constr.gridwidth = 1;
panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.class.name")), constr);
myTargetClassNameField = new EditorTextField(suggestTestClassName(myTargetClass));
myTargetClassNameField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getClassName()));
}
});
constr.gridx = 1;
constr.weightx = 1;
panel.add(myTargetClassNameField, constr);
constr.insets = insets(1);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.super.class")), constr);
mySuperClassField = new ReferenceEditorComboWithBrowseButton(new MyChooseSuperClassAction(), null, myProject, true, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, RECENT_SUPERS_KEY);
mySuperClassField.setMinimumSize(mySuperClassField.getPreferredSize());
constr.gridx = 1;
constr.weightx = 1;
panel.add(mySuperClassField, constr);
constr.insets = insets(1);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
panel.add(new JLabel(CodeInsightBundle.message("dialog.create.class.destination.package.label")), constr);
constr.gridx = 1;
constr.weightx = 1;
String targetPackageName = myTargetPackage != null ? myTargetPackage.getQualifiedName() : "";
myTargetPackageField = new PackageNameReferenceEditorCombo(targetPackageName, myProject, RECENTS_KEY, CodeInsightBundle.message("dialog.create.class.package.chooser.title"));
new AnAction() {
public void actionPerformed(AnActionEvent e) {
myTargetPackageField.getButton().doClick();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myTargetPackageField.getChildComponent());
JPanel targetPackagePanel = new JPanel(new BorderLayout());
targetPackagePanel.add(myTargetPackageField, BorderLayout.CENTER);
panel.add(targetPackagePanel, constr);
constr.insets = insets(6);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.generate")), constr);
constr.gridx = 1;
constr.weightx = 1;
panel.add(myGenerateBeforeBox, constr);
constr.insets = insets(1);
constr.gridy = gridy++;
panel.add(myGenerateAfterBox, constr);
constr.insets = insets(6);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
final JLabel membersLabel = new JLabel(CodeInsightBundle.message("intention.create.test.dialog.select.methods"));
membersLabel.setLabelFor(myMethodsTable);
panel.add(membersLabel, constr);
constr.gridx = 1;
constr.weightx = 1;
panel.add(myShowInheritedMethodsBox, constr);
constr.insets = insets(1, 8);
constr.gridy = gridy++;
constr.gridx = 0;
constr.gridwidth = GridBagConstraints.REMAINDER;
constr.fill = GridBagConstraints.BOTH;
constr.weighty = 1;
panel.add(ScrollPaneFactory.createScrollPane(myMethodsTable), constr);
myLibrariesCombo.setRenderer(new ListCellRendererWrapper<TestFramework>() {
@Override
public void customize(JList list, TestFramework value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.getName());
setIcon(value.getIcon());
}
}
});
final boolean hasTestRoots = !ModuleRootManager.getInstance(myTargetModule).getSourceRoots(JavaModuleSourceRootTypes.TESTS).isEmpty();
final List<TestFramework> attachedLibraries = new ArrayList<>();
final String defaultLibrary = getDefaultLibraryName();
TestFramework defaultDescriptor = null;
final DefaultComboBoxModel model = (DefaultComboBoxModel) myLibrariesCombo.getModel();
final List<TestFramework> descriptors = new ArrayList<>();
descriptors.addAll(Arrays.asList(Extensions.getExtensions(TestFramework.EXTENSION_NAME)));
descriptors.sort((d1, d2) -> Comparing.compare(d1.getName(), d2.getName()));
for (final TestFramework descriptor : descriptors) {
model.addElement(descriptor);
if (hasTestRoots && descriptor.isLibraryAttached(myTargetModule)) {
attachedLibraries.add(descriptor);
if (defaultLibrary == null) {
defaultDescriptor = descriptor;
}
}
if (Comparing.equal(defaultLibrary, descriptor.getName())) {
defaultDescriptor = descriptor;
}
}
myLibrariesCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Object selectedItem = myLibrariesCombo.getSelectedItem();
if (selectedItem != null) {
final DumbService dumbService = DumbService.getInstance(myProject);
dumbService.setAlternativeResolveEnabled(true);
try {
onLibrarySelected((TestFramework) selectedItem);
} finally {
dumbService.setAlternativeResolveEnabled(false);
}
}
}
});
if (defaultDescriptor != null && (attachedLibraries.contains(defaultDescriptor) || attachedLibraries.isEmpty())) {
myLibrariesCombo.setSelectedItem(defaultDescriptor);
} else {
myLibrariesCombo.setSelectedIndex(0);
}
myFixLibraryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mySelectedFramework instanceof JavaTestFramework) {
((JavaTestFramework) mySelectedFramework).setupLibrary(myTargetModule);
} else {
OrderEntryFix.addJarToRoots(mySelectedFramework.getLibraryPath(), myTargetModule, null);
}
myFixLibraryPanel.setVisible(false);
}
});
myShowInheritedMethodsBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateMethodsTable();
}
});
restoreShowInheritedMembersStatus();
updateMethodsTable();
return panel;
}
Aggregations