Search in sources :

Example 6 with PackageNameReferenceEditorCombo

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();
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 7 with PackageNameReferenceEditorCombo

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);
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(javax.swing.event.DocumentEvent) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo) ActionListener(java.awt.event.ActionListener) DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)

Example 8 with PackageNameReferenceEditorCombo

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());
}
Also used : ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(javax.swing.event.DocumentEvent) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) TreeJavaClassChooserDialog(com.intellij.ide.util.TreeJavaClassChooserDialog) Project(com.intellij.openapi.project.Project) ActionListener(java.awt.event.ActionListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)

Example 9 with PackageNameReferenceEditorCombo

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;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ActionEvent(java.awt.event.ActionEvent) JavaTestFramework(com.intellij.testIntegration.JavaTestFramework) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) DumbService(com.intellij.openapi.project.DumbService) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo) TestFramework(com.intellij.testIntegration.TestFramework) JavaTestFramework(com.intellij.testIntegration.JavaTestFramework) ActionListener(java.awt.event.ActionListener)

Aggregations

PackageNameReferenceEditorCombo (com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)9 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 Document (com.intellij.openapi.editor.Document)3 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)3 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)3 DestinationFolderComboBox (com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)3 DocumentEvent (javax.swing.event.DocumentEvent)3 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2 NameSuggestionsField (com.intellij.refactoring.ui.NameSuggestionsField)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 TreeJavaClassChooserDialog (com.intellij.ide.util.TreeJavaClassChooserDialog)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 DumbService (com.intellij.openapi.project.DumbService)1 Project (com.intellij.openapi.project.Project)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 JavaTestFramework (com.intellij.testIntegration.JavaTestFramework)1