Search in sources :

Example 16 with TreeClassChooser

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

the class AddFieldBreakpointDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myClassChooser.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        public void textChanged(DocumentEvent event) {
            updateUI();
        }
    });
    myClassChooser.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            PsiClass currentClass = getSelectedClass();
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(DebuggerBundle.message("add.field.breakpoint.dialog.classchooser.title"));
            if (currentClass != null) {
                PsiFile containingFile = currentClass.getContainingFile();
                if (containingFile != null) {
                    PsiDirectory containingDirectory = containingFile.getContainingDirectory();
                    if (containingDirectory != null) {
                        chooser.selectDirectory(containingDirectory);
                    }
                }
            }
            chooser.showDialog();
            PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                myClassChooser.setText(selectedClass.getQualifiedName());
            }
        }
    });
    myFieldChooser.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            PsiClass selectedClass = getSelectedClass();
            if (selectedClass != null) {
                PsiField[] fields = selectedClass.getFields();
                MemberChooser<PsiFieldMember> chooser = new MemberChooser<>(ContainerUtil.map2Array(fields, PsiFieldMember.class, PsiFieldMember::new), false, false, myProject);
                chooser.setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.field.chooser.title", fields.length));
                chooser.setCopyJavadocVisible(false);
                TransactionGuard.getInstance().submitTransactionAndWait(() -> chooser.show());
                List<PsiFieldMember> selectedElements = chooser.getSelectedElements();
                if (selectedElements != null && selectedElements.size() == 1) {
                    PsiField field = selectedElements.get(0).getElement();
                    myFieldChooser.setText(field.getName());
                }
            }
        }
    });
    myFieldChooser.setEnabled(false);
    return myPanel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) PsiFieldMember(com.intellij.codeInsight.generation.PsiFieldMember) DocumentEvent(javax.swing.event.DocumentEvent) MemberChooser(com.intellij.ide.util.MemberChooser) ActionListener(java.awt.event.ActionListener) List(java.util.List)

Example 17 with TreeClassChooser

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

Example 18 with TreeClassChooser

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

Example 19 with TreeClassChooser

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

the class ClassHierarchyScopeDescriptor method getScope.

@Nullable
public SearchScope getScope() {
    if (myCachedScope == null) {
        TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(IdeBundle.message("prompt.choose.base.class.of.the.hierarchy"));
        if (myRootClass != null) {
            chooser.select(myRootClass);
        }
        chooser.showDialog();
        PsiClass aClass = chooser.getSelected();
        if (aClass == null) {
            myCachedScope = GlobalSearchScope.EMPTY_SCOPE;
        } else {
            final List<PsiElement> classesToSearch = new LinkedList<>();
            classesToSearch.add(aClass);
            classesToSearch.addAll(ClassInheritorsSearch.search(aClass).findAll());
            FunctionalExpressionSearch.search(aClass).forEach(expression -> {
                classesToSearch.add(expression);
                return true;
            });
            myCachedScope = new LocalSearchScope(PsiUtilCore.toPsiElementArray(classesToSearch), IdeBundle.message("scope.hierarchy", ClassPresentationUtil.getNameForClass(aClass, true)));
        }
    }
    return myCachedScope;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) PsiClass(com.intellij.psi.PsiClass) LinkedList(java.util.LinkedList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with TreeClassChooser

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

the class AddFieldBreakpointDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myClassChooser.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            updateUI();
        }
    });
    myClassChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PsiClass currentClass = getSelectedClass();
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser(DebuggerBundle.message("add.field.breakpoint.dialog.classchooser.title"));
            if (currentClass != null) {
                PsiFile containingFile = currentClass.getContainingFile();
                if (containingFile != null) {
                    PsiDirectory containingDirectory = containingFile.getContainingDirectory();
                    if (containingDirectory != null) {
                        chooser.selectDirectory(containingDirectory);
                    }
                }
            }
            chooser.showDialog();
            PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                myClassChooser.setText(selectedClass.getQualifiedName());
            }
        }
    });
    myFieldChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            PsiClass selectedClass = getSelectedClass();
            DescriptorMemberChooserObject[] properties = FieldBreakpointDialogUtilKt.collectProperties(selectedClass);
            MemberChooser<DescriptorMemberChooserObject> chooser = new MemberChooser<DescriptorMemberChooserObject>(properties, false, false, myProject);
            chooser.setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.field.chooser.title", properties.length));
            chooser.setCopyJavadocVisible(false);
            chooser.show();
            List<DescriptorMemberChooserObject> selectedElements = chooser.getSelectedElements();
            if (selectedElements != null && selectedElements.size() == 1) {
                KtProperty field = (KtProperty) selectedElements.get(0).getElement();
                myFieldChooser.setText(field.getName());
            }
        }
    });
    myFieldChooser.setEnabled(false);
    return myPanel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) MemberChooser(com.intellij.ide.util.MemberChooser) KtProperty(org.jetbrains.kotlin.psi.KtProperty) DescriptorMemberChooserObject(org.jetbrains.kotlin.idea.core.util.DescriptorMemberChooserObject) ActionListener(java.awt.event.ActionListener) List(java.util.List)

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