Search in sources :

Example 1 with TreeClassChooserFactory

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

Example 2 with TreeClassChooserFactory

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

the class UiUtils method createAddRemoveTreeClassChooserPanel.

public static JPanel createAddRemoveTreeClassChooserPanel(final ListTable table, final String chooserTitle, @NonNls String... ancestorClasses) {
    final ClassFilter filter;
    if (ancestorClasses.length == 0) {
        filter = ClassFilter.ALL;
    } else {
        filter = new SubclassFilter(ancestorClasses);
    }
    final JPanel panel = ToolbarDecorator.createDecorator(table).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final DataContext dataContext = DataManager.getInstance().getDataContext(table);
            final Project project = CommonDataKeys.PROJECT.getData(dataContext);
            final int rowIndex;
            final ListWrappingTableModel tableModel = table.getModel();
            if (project == null) {
                tableModel.addRow();
                rowIndex = tableModel.getRowCount() - 1;
            } else {
                final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project);
                final TreeClassChooser classChooser = chooserFactory.createWithInnerClassesScopeChooser(chooserTitle, GlobalSearchScope.allScope(project), filter, null);
                classChooser.showDialog();
                final PsiClass selectedClass = classChooser.getSelected();
                if (selectedClass == null) {
                    return;
                }
                final String qualifiedName = selectedClass.getQualifiedName();
                final int index = tableModel.indexOf(qualifiedName, 0);
                if (index < 0) {
                    tableModel.addRow(qualifiedName);
                    rowIndex = tableModel.getRowCount() - 1;
                } else {
                    rowIndex = index;
                }
            }
            editTableCell(table, rowIndex, table.getColumnCount() > 1 && project != null ? 1 : 0);
        }
    }).setRemoveAction(button -> TableUtil.removeSelectedItems(table)).disableUpDownActions().createPanel();
    panel.setPreferredSize(JBUI.size(150, 100));
    return panel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) PsiClass(com.intellij.psi.PsiClass) ListWrappingTableModel(com.intellij.codeInspection.ui.ListWrappingTableModel) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) TreeClassChooserFactory(com.intellij.ide.util.TreeClassChooserFactory) ClassFilter(com.intellij.ide.util.ClassFilter)

Aggregations

TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2 TreeClassChooserFactory (com.intellij.ide.util.TreeClassChooserFactory)2 PsiClass (com.intellij.psi.PsiClass)2 ListWrappingTableModel (com.intellij.codeInspection.ui.ListWrappingTableModel)1 ClassFilter (com.intellij.ide.util.ClassFilter)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Project (com.intellij.openapi.project.Project)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 Nullable (org.jetbrains.annotations.Nullable)1