Search in sources :

Example 1 with TreeJavaClassChooserDialog

use of com.intellij.ide.util.TreeJavaClassChooserDialog in project intellij-community by JetBrains.

the class ClassChooserTest method testSubclassModel.

public void testSubclassModel() throws Exception {
    myFixture.addClass("class Foo extends Exception {}");
    myFixture.addClass("class Bar {}");
    PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass(CommonClassNames.JAVA_LANG_EXCEPTION, GlobalSearchScope.allScope(getProject()));
    final Ref<ChooseByNameModel> ref = new Ref<>();
    TreeJavaClassChooserDialog dialog = new TreeJavaClassChooserDialog("hey", getProject(), GlobalSearchScope.projectScope(getProject()), null, aClass, null, false) {

        @Override
        protected ChooseByNameModel createChooseByNameModel() {
            ChooseByNameModel model = super.createChooseByNameModel();
            ref.set(model);
            return model;
        }

        @Override
        public JRootPane getRootPane() {
            return new JRootPane();
        }
    };
    Disposer.register(myFixture.getTestRootDisposable(), dialog.getDisposable());
    ChooseByNameModelEx model = (ChooseByNameModelEx) ref.get();
    CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
    model.processNames(processor, false);
    List<String> results = (List<String>) processor.getResults();
    assertEquals(1, results.size());
}
Also used : PsiClass(com.intellij.psi.PsiClass) ChooseByNameModelEx(com.intellij.ide.util.gotoByName.ChooseByNameModelEx) TreeJavaClassChooserDialog(com.intellij.ide.util.TreeJavaClassChooserDialog) ChooseByNameModel(com.intellij.ide.util.gotoByName.ChooseByNameModel) Ref(com.intellij.openapi.util.Ref) List(java.util.List) CommonProcessors(com.intellij.util.CommonProcessors)

Example 2 with TreeJavaClassChooserDialog

use of com.intellij.ide.util.TreeJavaClassChooserDialog in project intellij-plugins by JetBrains.

the class OsmorcFacetManifestGenerationEditorTab method onBundleActivatorSelect.

private void onBundleActivatorSelect() {
    Project project = myEditorContext.getProject();
    PsiClass activatorClass = OsgiPsiUtil.getActivatorClass(project);
    ClassFilter filter = new TreeJavaClassChooserDialog.InheritanceJavaClassFilterImpl(activatorClass, false, true, null);
    GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesScope(myEditorContext.getModule());
    TreeJavaClassChooserDialog dialog = new TreeJavaClassChooserDialog(OsmorcBundle.message("facet.editor.select.bundle.activator"), project, scope, filter, null);
    dialog.showDialog();
    PsiClass psiClass = dialog.getSelected();
    if (psiClass != null) {
        myBundleActivator.setText(psiClass.getQualifiedName());
    }
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassFilter(com.intellij.ide.util.ClassFilter) PsiClass(com.intellij.psi.PsiClass) TreeJavaClassChooserDialog(com.intellij.ide.util.TreeJavaClassChooserDialog)

Example 3 with TreeJavaClassChooserDialog

use of com.intellij.ide.util.TreeJavaClassChooserDialog 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 4 with TreeJavaClassChooserDialog

use of com.intellij.ide.util.TreeJavaClassChooserDialog in project kotlin by JetBrains.

the class MoveKotlinNestedClassesDialog method initClassChooser.

private void initClassChooser(@NotNull KtClassOrObject initialTargetClass) {
    //noinspection ConstantConditions
    originalClassField.setText(originalClass.getFqName().asString());
    //noinspection ConstantConditions
    targetClassChooser = new ReferenceEditorComboWithBrowseButton(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreeClassChooser chooser = new TreeJavaClassChooserDialog(RefactoringBundle.message("choose.destination.class"), myProject, GlobalSearchScope.projectScope(myProject), new ClassFilter() {

                @Override
                public boolean isAccepted(PsiClass aClass) {
                    if (!(aClass instanceof KtLightClassForSourceDeclaration))
                        return false;
                    KtClassOrObject classOrObject = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
                    if (classOrObject instanceof KtObjectDeclaration) {
                        return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
                    }
                    if (classOrObject instanceof KtClass) {
                        KtClass ktClass = (KtClass) classOrObject;
                        return !(ktClass.isInner() || ktClass.isAnnotation());
                    }
                    return false;
                }
            }, null, null, true) {

                @Nullable
                @Override
                protected PsiClass getSelectedFromTreeUserObject(DefaultMutableTreeNode node) {
                    PsiClass psiClass = super.getSelectedFromTreeUserObject(node);
                    if (psiClass != null)
                        return psiClass;
                    Object userObject = node.getUserObject();
                    if (!(userObject instanceof KtClassOrObjectTreeNode))
                        return null;
                    return LightClassUtilsKt.toLightClass(((KtClassOrObjectTreeNode) userObject).getValue());
                }
            };
            chooser.selectDirectory((targetClass != null ? targetClass : originalClass).getContainingFile().getContainingDirectory());
            chooser.showDialog();
            PsiClass aClass = chooser.getSelected();
            if (aClass instanceof KtLightClassForSourceDeclaration) {
                targetClass = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
                targetClassChooser.setText(aClass.getQualifiedName());
            }
        }
    }, initialTargetClass.getFqName().asString(), myProject, true, JavaCodeFragment.VisibilityChecker.PROJECT_SCOPE_VISIBLE, RECENTS_KEY);
    targetClassChooser.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
            targetClass = aClass instanceof KtLightClassForSourceDeclaration ? ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin() : null;
            validateButtons();
        }
    });
    targetClassChooserPanel.add(targetClassChooser);
}
Also used : KtClassOrObjectTreeNode(org.jetbrains.kotlin.idea.projectView.KtClassOrObjectTreeNode) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) KtLightClassForSourceDeclaration(org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) PsiClass(com.intellij.psi.PsiClass) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) TreeJavaClassChooserDialog(com.intellij.ide.util.TreeJavaClassChooserDialog) ActionListener(java.awt.event.ActionListener) ClassFilter(com.intellij.ide.util.ClassFilter)

Aggregations

TreeJavaClassChooserDialog (com.intellij.ide.util.TreeJavaClassChooserDialog)4 PsiClass (com.intellij.psi.PsiClass)3 ClassFilter (com.intellij.ide.util.ClassFilter)2 Project (com.intellij.openapi.project.Project)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)1 ChooseByNameModel (com.intellij.ide.util.gotoByName.ChooseByNameModel)1 ChooseByNameModelEx (com.intellij.ide.util.gotoByName.ChooseByNameModelEx)1 Document (com.intellij.openapi.editor.Document)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 Ref (com.intellij.openapi.util.Ref)1 DestinationFolderComboBox (com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)1 PackageNameReferenceEditorCombo (com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 CommonProcessors (com.intellij.util.CommonProcessors)1 List (java.util.List)1