Search in sources :

Example 11 with TreeClassChooser

use of com.intellij.ide.util.TreeClassChooser in project android by JetBrains.

the class AndroidClassBrowserBase method showDialog.

@Override
protected String showDialog() {
    Project project = getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    Module module = myModuleSelector.getModule();
    if (module == null) {
        Messages.showErrorDialog(project, ExecutionBundle.message("module.not.specified.error.text"), CommonBundle.getErrorTitle());
        return null;
    }
    GlobalSearchScope scope = myIncludeLibraryClasses ? module.getModuleWithDependenciesAndLibrariesScope(true) : module.getModuleWithDependenciesScope();
    PsiClass initialSelection = facade.findClass(getText(), scope);
    TreeClassChooser chooser = createTreeClassChooser(project, scope, initialSelection, new ClassFilter() {

        @Override
        public boolean isAccepted(PsiClass aClass) {
            if (aClass.isInterface())
                return false;
            final PsiModifierList modifierList = aClass.getModifierList();
            return modifierList == null || !modifierList.hasModifierProperty(PsiModifier.ABSTRACT);
        }
    });
    if (chooser == null)
        return null;
    chooser.showDialog();
    PsiClass selClass = chooser.getSelected();
    return selClass != null ? selClass.getQualifiedName() : null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Project(com.intellij.openapi.project.Project) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassFilter(com.intellij.ide.util.ClassFilter) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 12 with TreeClassChooser

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

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

the class PsiClassControl method initReferenceEditorWithBrowseButton.

protected static <T extends JPanel> T initReferenceEditorWithBrowseButton(final T boundedComponent, final ReferenceEditorWithBrowseButton editor, final EditorTextFieldControl control) {
    boundedComponent.removeAll();
    boundedComponent.add(editor);
    final GlobalSearchScope resolveScope = control.getDomWrapper().getResolveScope();
    editor.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final DomElement domElement = control.getDomElement();
            ExtendClass extend = domElement.getAnnotation(ExtendClass.class);
            PsiClass baseClass = null;
            ClassFilter filter = null;
            if (extend != null) {
                baseClass = JavaPsiFacade.getInstance(control.getProject()).findClass(extend.value(), resolveScope);
                if (extend.instantiatable()) {
                    filter = ClassFilter.INSTANTIABLE;
                }
            }
            PsiClass initialClass = null;
            if (domElement instanceof GenericDomValue) {
                final Object value = ((GenericDomValue) domElement).getValue();
                if (value instanceof PsiClass)
                    initialClass = (PsiClass) value;
            }
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(control.getProject()).createInheritanceClassChooser(UIBundle.message("choose.class"), resolveScope, baseClass, initialClass, filter);
            chooser.showDialog();
            final PsiClass psiClass = chooser.getSelected();
            if (psiClass != null) {
                control.setValue(psiClass.getQualifiedName());
            }
        }
    });
    return boundedComponent;
}
Also used : ExtendClass(com.intellij.util.xml.ExtendClass) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) DomElement(com.intellij.util.xml.DomElement) ActionListener(java.awt.event.ActionListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ActionEvent(java.awt.event.ActionEvent) ClassFilter(com.intellij.ide.util.ClassFilter) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 14 with TreeClassChooser

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

the class CreateClassMappingAction method createElement.

@Override
protected DomElement createElement(final T context, final Editor editor, PsiFile file, final Project project) {
    PsiClass selectedClass;
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        PsiClass baseClass = getBaseClass(context, project, myBaseClass);
        TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser(getChooserTitle(), GlobalSearchScope.allScope(project), baseClass, null, new ClassFilter() {

            @Override
            public boolean isAccepted(PsiClass aClass) {
                return !aClass.isInterface() && !aClass.hasModifierProperty(PsiModifier.ABSTRACT);
            }
        });
        chooser.showDialog();
        selectedClass = chooser.getSelected();
    } else {
        selectedClass = getBaseClass(context, project, myBaseClass == null ? CommonClassNames.JAVA_LANG_OBJECT : myBaseClass);
    }
    if (selectedClass == null)
        return null;
    return createElement(context, editor, file, project, selectedClass);
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ClassFilter(com.intellij.ide.util.ClassFilter)

Example 15 with TreeClassChooser

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

the class ManifestFileUtil method selectMainClass.

@Nullable
public static PsiClass selectMainClass(Project project, @Nullable final String initialClassName) {
    final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project);
    final GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
    final PsiClass aClass = initialClassName != null ? JavaPsiFacade.getInstance(project).findClass(initialClassName, searchScope) : null;
    final TreeClassChooser chooser = chooserFactory.createWithInnerClassesScopeChooser("Select Main Class", searchScope, new MainClassFilter(), aClass);
    chooser.showDialog();
    return chooser.getSelected();
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) TreeClassChooserFactory(com.intellij.ide.util.TreeClassChooserFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TreeClassChooser (com.intellij.ide.util.TreeClassChooser)22 PsiClass (com.intellij.psi.PsiClass)12 ClassFilter (com.intellij.ide.util.ClassFilter)10 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 Project (com.intellij.openapi.project.Project)4 DocumentEvent (javax.swing.event.DocumentEvent)4 Nullable (org.jetbrains.annotations.Nullable)4 TreeClassChooserFactory (com.intellij.ide.util.TreeClassChooserFactory)3 DocumentAdapter (com.intellij.ui.DocumentAdapter)3 List (java.util.List)3 MemberChooser (com.intellij.ide.util.MemberChooser)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Module (com.intellij.openapi.module.Module)2 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)2 PsiModifierList (com.intellij.psi.PsiModifierList)2 DestinationFolderComboBox (com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)2 PackageNameReferenceEditorCombo (com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)2 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)2