Search in sources :

Example 6 with ReferenceEditorComboWithBrowseButton

use of com.intellij.ui.ReferenceEditorComboWithBrowseButton in project intellij-community by JetBrains.

the class IntroduceParameterObjectDialog method createUIComponents.

private void createUIComponents() {
    final PsiFile file = mySourceMethod.getContainingFile();
    packageTextField = new PackageNameReferenceEditorCombo(file instanceof PsiJavaFile ? ((PsiJavaFile) file).getPackageName() : "", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
    final Document document = packageTextField.getChildComponent().getDocument();
    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();
        }
    };
    document.addDocumentListener(adapter);
    existingClassField = new ReferenceEditorComboWithBrowseButton(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final Project project = mySourceMethod.getProject();
            final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
            final TreeJavaClassChooserDialog chooser = new TreeJavaClassChooserDialog(RefactorJBundle.message("select.wrapper.class"), project, scope, null, null);
            final String classText = existingClassField.getText();
            final PsiClass currentClass = JavaPsiFacade.getInstance(project).findClass(classText, GlobalSearchScope.allScope(project));
            if (currentClass != null) {
                chooser.select(currentClass);
            }
            chooser.show();
            final PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                final String className = selectedClass.getQualifiedName();
                existingClassField.setText(className);
                RecentsManager.getInstance(myProject).registerRecentEntry(EXISTING_KEY, className);
            }
        }
    }, "", myProject, true, EXISTING_KEY);
    existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
            validateButtons();
            enableGenerateAccessors();
        }
    });
    myDestinationCb = new DestinationFolderComboBox() {

        @Override
        public String getTargetPackage() {
            return getPackageName();
        }
    };
    ((DestinationFolderComboBox) myDestinationCb).setData(myProject, mySourceMethod.getContainingFile().getContainingDirectory(), packageTextField.getChildComponent());
}
Also used : ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(javax.swing.event.DocumentEvent) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) TreeJavaClassChooserDialog(com.intellij.ide.util.TreeJavaClassChooserDialog) Project(com.intellij.openapi.project.Project) ActionListener(java.awt.event.ActionListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)

Example 7 with ReferenceEditorComboWithBrowseButton

use of com.intellij.ui.ReferenceEditorComboWithBrowseButton in project kotlin by JetBrains.

the class MoveKotlinNestedClassesDialog method initClassChooser.

private void initClassChooser(@NotNull KtClassOrObject initialTargetClass) {
    //noinspection ConstantConditions
    originalClassField.setText(originalClass.getFqName().asString());
    //noinspection ConstantConditions
    targetClassChooser = new ReferenceEditorComboWithBrowseButton(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreeClassChooser chooser = new TreeJavaClassChooserDialog(RefactoringBundle.message("choose.destination.class"), myProject, GlobalSearchScope.projectScope(myProject), new ClassFilter() {

                @Override
                public boolean isAccepted(PsiClass aClass) {
                    if (!(aClass instanceof KtLightClassForSourceDeclaration))
                        return false;
                    KtClassOrObject classOrObject = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
                    if (classOrObject instanceof KtObjectDeclaration) {
                        return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
                    }
                    if (classOrObject instanceof KtClass) {
                        KtClass ktClass = (KtClass) classOrObject;
                        return !(ktClass.isInner() || ktClass.isAnnotation());
                    }
                    return false;
                }
            }, null, null, true) {

                @Nullable
                @Override
                protected PsiClass getSelectedFromTreeUserObject(DefaultMutableTreeNode node) {
                    PsiClass psiClass = super.getSelectedFromTreeUserObject(node);
                    if (psiClass != null)
                        return psiClass;
                    Object userObject = node.getUserObject();
                    if (!(userObject instanceof KtClassOrObjectTreeNode))
                        return null;
                    return LightClassUtilsKt.toLightClass(((KtClassOrObjectTreeNode) userObject).getValue());
                }
            };
            chooser.selectDirectory((targetClass != null ? targetClass : originalClass).getContainingFile().getContainingDirectory());
            chooser.showDialog();
            PsiClass aClass = chooser.getSelected();
            if (aClass instanceof KtLightClassForSourceDeclaration) {
                targetClass = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
                targetClassChooser.setText(aClass.getQualifiedName());
            }
        }
    }, initialTargetClass.getFqName().asString(), myProject, true, JavaCodeFragment.VisibilityChecker.PROJECT_SCOPE_VISIBLE, RECENTS_KEY);
    targetClassChooser.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
            targetClass = aClass instanceof KtLightClassForSourceDeclaration ? ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin() : null;
            validateButtons();
        }
    });
    targetClassChooserPanel.add(targetClassChooser);
}
Also used : KtClassOrObjectTreeNode(org.jetbrains.kotlin.idea.projectView.KtClassOrObjectTreeNode) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) KtLightClassForSourceDeclaration(org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) PsiClass(com.intellij.psi.PsiClass) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) TreeJavaClassChooserDialog(com.intellij.ide.util.TreeJavaClassChooserDialog) ActionListener(java.awt.event.ActionListener) ClassFilter(com.intellij.ide.util.ClassFilter)

Example 8 with ReferenceEditorComboWithBrowseButton

use of com.intellij.ui.ReferenceEditorComboWithBrowseButton in project android by JetBrains.

the class ActivityComboProvider method createComponent.

@NotNull
@Override
protected ReferenceEditorComboWithBrowseButton createComponent(@NotNull Parameter parameter) {
    ChooseClassActionListener browseAction = new ChooseClassActionListener(myModule);
    RecentsManager recentsManager = RecentsManager.getInstance(myModule.getProject());
    // Always have a blank entry and make sure it shows up first - because by default, most users
    // won't want to add any parent.
    recentsManager.registerRecentEntry(myRecentsKey, "");
    ReferenceEditorComboWithBrowseButton control = new ReferenceEditorComboWithBrowseButton(browseAction, "", myModule.getProject(), true, new OnlyShowActivities(myModule), myRecentsKey);
    // Need to tell our browse action which component to modify when user hits OK. Ideally we'd
    // pass this into browseAction's constructor but the control isn't created until after.
    browseAction.setOwner(control);
    return control;
}
Also used : RecentsManager(com.intellij.ui.RecentsManager) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)8 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)5 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)5 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 PackageNameReferenceEditorCombo (com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)4 Document (com.intellij.openapi.editor.Document)3 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2 TreeJavaClassChooserDialog (com.intellij.ide.util.TreeJavaClassChooserDialog)2 DestinationFolderComboBox (com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 DocumentEvent (javax.swing.event.DocumentEvent)2 ClassFilter (com.intellij.ide.util.ClassFilter)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 Project (com.intellij.openapi.project.Project)1 PsiClass (com.intellij.psi.PsiClass)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 RecentsManager (com.intellij.ui.RecentsManager)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1