Search in sources :

Example 1 with ClassFilter

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

the class ClassBrowser method showDialog.

@Nullable
protected String showDialog() {
    final ClassFilter.ClassFilterWithScope classFilter;
    try {
        classFilter = getFilter();
    } catch (NoFilterException e) {
        final MessagesEx.MessageInfo info = e.getMessageInfo();
        info.showNow();
        return null;
    }
    final TreeClassChooser dialog = createClassChooser(classFilter);
    configureDialog(dialog);
    dialog.showDialog();
    final PsiClass psiClass = dialog.getSelected();
    if (psiClass == null)
        return null;
    onClassChoosen(psiClass);
    return psiClass.getQualifiedName();
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ClassFilter(com.intellij.ide.util.ClassFilter) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ClassFilter

use of com.intellij.ide.util.ClassFilter 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 ClassFilter

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

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

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

the class UiUtils method createTreeClassChooserList.

public static JPanel createTreeClassChooserList(final Collection<String> collection, String borderTitle, final String chooserTitle, String... ancestorClasses) {
    final ClassFilter filter;
    if (ancestorClasses.length == 0) {
        filter = ClassFilter.ALL;
    } else {
        filter = new SubclassFilter(ancestorClasses);
    }
    final JPanel optionsPanel = new JPanel(new BorderLayout());
    final JBList list = new JBList(collection);
    final JPanel panel = ToolbarDecorator.createDecorator(list).disableUpDownActions().setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton anActionButton) {
            final DataContext dataContext = DataManager.getInstance().getDataContext(list);
            final Project project = CommonDataKeys.PROJECT.getData(dataContext);
            if (project == null) {
                return;
            }
            final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createNoInnerClassesScopeChooser(chooserTitle, GlobalSearchScope.allScope(project), filter, null);
            chooser.showDialog();
            final PsiClass selected = chooser.getSelected();
            if (selected == null) {
                return;
            }
            final String qualifiedName = selected.getQualifiedName();
            final DefaultListModel model = (DefaultListModel) list.getModel();
            final int index = model.indexOf(qualifiedName);
            if (index < 0) {
                model.addElement(qualifiedName);
                collection.add(qualifiedName);
            } else {
                list.setSelectedIndex(index);
            }
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton anActionButton) {
            collection.remove(list.getSelectedValue());
            ListUtil.removeSelectedItems(list);
        }
    }).createPanel();
    panel.setPreferredSize(JBUI.size(150, 100));
    optionsPanel.setBorder(IdeBorderFactory.createTitledBorder(borderTitle, false, JBUI.insetsTop(10)));
    optionsPanel.add(panel);
    return optionsPanel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) PsiClass(com.intellij.psi.PsiClass) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ClassFilter(com.intellij.ide.util.ClassFilter) JBList(com.intellij.ui.components.JBList)

Aggregations

ClassFilter (com.intellij.ide.util.ClassFilter)9 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)8 PsiClass (com.intellij.psi.PsiClass)6 Project (com.intellij.openapi.project.Project)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 TreeJavaClassChooserDialog (com.intellij.ide.util.TreeJavaClassChooserDialog)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ListWrappingTableModel (com.intellij.codeInspection.ui.ListWrappingTableModel)1 TreeClassChooserFactory (com.intellij.ide.util.TreeClassChooserFactory)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 Module (com.intellij.openapi.module.Module)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1 PsiModifierList (com.intellij.psi.PsiModifierList)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)1 JBList (com.intellij.ui.components.JBList)1 DomElement (com.intellij.util.xml.DomElement)1