Search in sources :

Example 6 with TreeClassChooser

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

the class PsiClassTableCellEditor method getTableCellEditorComponent.

public final Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    final Document document = JavaReferenceEditorUtil.createDocument(value == null ? "" : (String) value, myProject, true);
    myEditor = new EditorTextField(document, myProject, StdFileTypes.JAVA) {

        protected boolean shouldHaveBorder() {
            return false;
        }

        public void addNotify() {
            super.addNotify();
            final JComponent editorComponent = getEditor().getContentComponent();
            editorComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
            editorComponent.getActionMap().put("ENTER", new AbstractAction() {

                public void actionPerformed(ActionEvent e) {
                    stopCellEditing();
                }
            });
        }
    };
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(myEditor);
    final FixedSizeButton button = new FixedSizeButton(myEditor);
    panel.add(button, BorderLayout.EAST);
    button.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createInheritanceClassChooser(UIBundle.message("choose.class"), mySearchScope, null, true, true, Conditions.alwaysTrue());
            chooser.showDialog();
            final PsiClass psiClass = chooser.getSelected();
            if (psiClass != null) {
                myEditor.setText(psiClass.getQualifiedName());
            }
        }
    });
    panel.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            if (!e.isTemporary() && myEditor != null) {
                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                    IdeFocusManager.getGlobalInstance().requestFocus(myEditor, true);
                });
            }
        }

        public void focusLost(FocusEvent e) {
        }
    });
    myEditor.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                stopCellEditing();
            }
        }
    });
    return panel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) PsiClass(com.intellij.psi.PsiClass) Document(com.intellij.openapi.editor.Document) EditorTextField(com.intellij.ui.EditorTextField) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton)

Example 7 with TreeClassChooser

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

the class ClassFilterEditor method addClassFilter.

protected void addClassFilter() {
    TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createNoInnerClassesScopeChooser(UIBundle.message("class.filter.editor.choose.class.title"), GlobalSearchScope.allScope(myProject), myChooserFilter, null);
    chooser.showDialog();
    PsiClass selectedClass = chooser.getSelected();
    if (selectedClass != null) {
        com.intellij.ui.classFilter.ClassFilter filter = createFilter(getJvmClassName(selectedClass));
        myTableModel.addRow(filter);
        int row = myTableModel.getRowCount() - 1;
        myTable.getSelectionModel().setSelectionInterval(row, row);
        myTable.scrollRectToVisible(myTable.getCellRect(row, 0, true));
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
            IdeFocusManager.getGlobalInstance().requestFocus(myTable, true);
        });
    }
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) PsiClass(com.intellij.psi.PsiClass)

Example 8 with TreeClassChooser

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

the class ClassFilterEditorAddDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    final JLabel header = new JLabel(UIBundle.message("label.class.filter.editor.add.dialog.filter.pattern"));
    myClassName = new TextFieldWithBrowseButton(new JTextField(35));
    final JLabel iconLabel = new JLabel(Messages.getQuestionIcon());
    panel.add(header, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0));
    panel.add(myClassName, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0));
    panel.add(iconLabel, new GridBagConstraints(0, 0, 1, 2, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 0), 0, 0));
    myClassName.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            PsiClass currentClass = getSelectedClass();
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createNoInnerClassesScopeChooser(UIBundle.message("class.filter.editor.choose.class.title"), GlobalSearchScope.allScope(myProject), null, null);
            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) {
                myClassName.setText(selectedClass.getQualifiedName());
            }
        }
    });
    myClassName.setEnabled(myProject != null);
    return panel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener)

Example 9 with TreeClassChooser

use of com.intellij.ide.util.TreeClassChooser in project moe-ide-integration by multi-os-engine.

the class MOETestClassBrowser method showDialog.

@Override
protected String showDialog() {
    Project project = getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    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) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 10 with TreeClassChooser

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

the class AndroidCreateOnClickHandlerAction method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final AndroidFacet facet = AndroidFacet.getInstance(file);
    assert facet != null;
    final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);
    assert attrValue != null;
    final String methodName = attrValue.getValue();
    assert methodName != null;
    final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) attrValue.getParent());
    assert domValue != null;
    final OnClickConverter converter = (OnClickConverter) domValue.getConverter();
    final PsiClass activityBaseClass = JavaPsiFacade.getInstance(project).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, facet.getModule().getModuleWithDependenciesAndLibrariesScope(false));
    if (activityBaseClass == null) {
        return;
    }
    final GlobalSearchScope scope = facet.getModule().getModuleScope(false);
    final PsiClass selectedClass;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        final Ref<PsiClass> selClassRef = Ref.create();
        ClassInheritorsSearch.search(activityBaseClass, scope, true, true, false).forEach(new Processor<PsiClass>() {

            @Override
            public boolean process(PsiClass psiClass) {
                if (!psiClass.isInterface() && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
                    selClassRef.set(psiClass);
                    return false;
                }
                return true;
            }
        });
        selectedClass = selClassRef.get();
    } else {
        final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser("Choose Activity to Create the Method", scope, activityBaseClass, null, new ClassFilter() {

            @Override
            public boolean isAccepted(PsiClass aClass) {
                return !converter.findHandlerMethod(aClass, methodName);
            }
        });
        chooser.showDialog();
        selectedClass = chooser.getSelected();
    }
    if (selectedClass != null) {
        addHandlerMethodAndNavigate(project, selectedClass, methodName, converter.getDefaultMethodParameterType(selectedClass));
    }
}
Also used : OnClickConverter(org.jetbrains.android.dom.converters.OnClickConverter) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassFilter(com.intellij.ide.util.ClassFilter) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

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