Search in sources :

Example 1 with ReferenceEditorComboWithBrowseButton

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

the class GrIntroduceConstantDialog method initializeTargetClassEditor.

private void initializeTargetClassEditor() {
    myTargetClassEditor = new ReferenceEditorComboWithBrowseButton(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myContext.getProject()).createWithInnerClassesScopeChooser(RefactoringBundle.message("choose.destination.class"), GlobalSearchScope.projectScope(myContext.getProject()), new ClassFilter() {

                @Override
                public boolean isAccepted(PsiClass aClass) {
                    return aClass.getParent() instanceof GroovyFile || aClass.hasModifierProperty(PsiModifier.STATIC);
                }
            }, null);
            if (myTargetClass != null) {
                chooser.selectDirectory(myTargetClass.getContainingFile().getContainingDirectory());
            }
            chooser.showDialog();
            PsiClass aClass = chooser.getSelected();
            if (aClass != null) {
                myTargetClassEditor.setText(aClass.getQualifiedName());
            }
        }
    }, "", myContext.getProject(), true, RECENTS_KEY);
    myTargetClassPanel.setLayout(new BorderLayout());
    myTargetClassPanel.add(myTargetClassLabel, BorderLayout.NORTH);
    myTargetClassPanel.add(myTargetClassEditor, BorderLayout.CENTER);
    Set<String> possibleClassNames = new LinkedHashSet<>();
    for (final PsiElement occurrence : myContext.getOccurrences()) {
        final PsiClass parentClass = getParentClass(occurrence);
        if (parentClass != null && parentClass.getQualifiedName() != null) {
            possibleClassNames.add(parentClass.getQualifiedName());
        }
    }
    for (String possibleClassName : possibleClassNames) {
        myTargetClassEditor.prependItem(possibleClassName);
    }
    if (myDefaultTargetClass != null) {
        myTargetClassEditor.prependItem(myDefaultTargetClass.getQualifiedName());
    }
    myTargetClassEditor.getChildComponent().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            targetClassChanged();
            updateOkStatus();
        // enableEnumDependant(introduceEnumConstant());
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) ActionListener(java.awt.event.ActionListener) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 2 with ReferenceEditorComboWithBrowseButton

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

the class MoveKotlinTopLevelDeclarationsDialog method createPackageChooser.

private ReferenceEditorComboWithBrowseButton createPackageChooser() {
    ReferenceEditorComboWithBrowseButton packageChooser = new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
    Document document = packageChooser.getChildComponent().getDocument();
    document.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            validateButtons();
        }
    });
    return packageChooser;
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 3 with ReferenceEditorComboWithBrowseButton

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

the class WrapReturnValueDialog method createUIComponents.

private void createUIComponents() {
    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();
        }
    };
    packageTextField = new PackageNameReferenceEditorCombo("", myProject, RECENT_KEYS, RefactoringBundle.message("choose.destination.package"));
    packageTextField.getChildComponent().getDocument().addDocumentListener(adapter);
    existingClassField = new ReferenceEditorComboWithBrowseButton(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(getProject()).createWithInnerClassesScopeChooser(RefactorJBundle.message("select.wrapper.class"), GlobalSearchScope.allScope(myProject), null, null);
            final String classText = existingClassField.getText();
            final PsiClass currentClass = JavaPsiFacade.getInstance(myProject).findClass(classText, GlobalSearchScope.allScope(myProject));
            if (currentClass != null) {
                chooser.select(currentClass);
            }
            chooser.showDialog();
            final PsiClass selectedClass = chooser.getSelected();
            if (selectedClass != null) {
                existingClassField.setText(selectedClass.getQualifiedName());
            }
        }
    }, "", myProject, true, RECENT_KEYS);
    existingClassField.getChildComponent().getDocument().addDocumentListener(adapter);
    myDestinationCb = new DestinationFolderComboBox() {

        @Override
        public String getTargetPackage() {
            return getPackageName();
        }
    };
    ((DestinationFolderComboBox) myDestinationCb).setData(myProject, sourceMethod.getContainingFile().getContainingDirectory(), packageTextField.getChildComponent());
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) ActionListener(java.awt.event.ActionListener) DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)

Example 4 with ReferenceEditorComboWithBrowseButton

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

the class MoveClassesOrPackagesDialog method createPackageChooser.

private ReferenceEditorComboWithBrowseButton createPackageChooser() {
    final ReferenceEditorComboWithBrowseButton packageChooser = new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
    final Document document = packageChooser.getChildComponent().getDocument();
    document.addDocumentListener(new DocumentAdapter() {

        public void documentChanged(DocumentEvent e) {
            validateButtons();
        }
    });
    return packageChooser;
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 5 with ReferenceEditorComboWithBrowseButton

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

the class IntroduceConstantDialog method createNorthPanel.

protected JComponent createNorthPanel() {
    myTypeSelector = myTypeSelectorManager.getTypeSelector();
    myTypePanel.setLayout(new BorderLayout());
    myTypePanel.add(myTypeSelector.getComponent(), BorderLayout.CENTER);
    if (myTypeSelector.getFocusableComponent() != null) {
        myTypeLabel.setLabelFor(myTypeSelector.getFocusableComponent());
    }
    myNameField = new NameSuggestionsField(myProject);
    myNameSuggestionPanel.setLayout(new BorderLayout());
    myNameField.addDataChangedListener(new NameSuggestionsField.DataChanged() {

        public void dataChanged() {
            updateButtons();
        }
    });
    myNameSuggestionPanel.add(myNameField.getComponent(), BorderLayout.CENTER);
    myNameSuggestionLabel.setLabelFor(myNameField.getFocusableComponent());
    Set<String> possibleClassNames = new LinkedHashSet<>();
    for (final PsiExpression occurrence : myOccurrences) {
        final PsiClass parentClass = new IntroduceConstantHandler().getParentClass(occurrence);
        if (parentClass != null && parentClass.getQualifiedName() != null) {
            possibleClassNames.add(parentClass.getQualifiedName());
        }
    }
    myTfTargetClassName = new ReferenceEditorComboWithBrowseButton(new ChooseClassAction(), "", myProject, true, RECENTS_KEY);
    myTargetClassNamePanel.setLayout(new BorderLayout());
    myTargetClassNamePanel.add(myTfTargetClassName, BorderLayout.CENTER);
    myTargetClassNameLabel.setLabelFor(myTfTargetClassName);
    for (String possibleClassName : possibleClassNames) {
        myTfTargetClassName.prependItem(possibleClassName);
    }
    myTfTargetClassName.getChildComponent().setSelectedItem(myParentClass.getQualifiedName());
    myTfTargetClassName.getChildComponent().addDocumentListener(new DocumentAdapter() {

        public void documentChanged(DocumentEvent e) {
            targetClassChanged();
            enableEnumDependant(introduceEnumConstant());
        }
    });
    myIntroduceEnumConstantCb.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            enableEnumDependant(introduceEnumConstant());
        }
    });
    final JPanel enumPanel = new JPanel(new BorderLayout());
    enumPanel.add(myIntroduceEnumConstantCb, BorderLayout.EAST);
    myTargetClassNamePanel.add(enumPanel, BorderLayout.SOUTH);
    final String propertyName;
    if (myLocalVariable != null) {
        propertyName = myCodeStyleManager.variableNameToPropertyName(myLocalVariable.getName(), VariableKind.LOCAL_VARIABLE);
    } else {
        propertyName = null;
    }
    final NameSuggestionsManager nameSuggestionsManager = new NameSuggestionsManager(myTypeSelector, myNameField, createNameSuggestionGenerator(propertyName, myInitializerExpression, myCodeStyleManager, myEnteredName, myParentClass));
    nameSuggestionsManager.setLabelsFor(myTypeLabel, myNameSuggestionLabel);
    //////////
    if (myOccurrencesCount > 1) {
        myCbReplaceAll.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                updateTypeSelector();
                myNameField.requestFocusInWindow();
            }
        });
        myCbReplaceAll.setText(RefactoringBundle.message("replace.all.occurences", myOccurrencesCount));
    } else {
        myCbReplaceAll.setVisible(false);
    }
    if (myLocalVariable != null) {
        if (myInvokedOnDeclaration) {
            myCbDeleteVariable.setEnabled(false);
            myCbDeleteVariable.setSelected(true);
        } else if (myCbReplaceAll != null) {
            updateCbDeleteVariable();
            myCbReplaceAll.addItemListener(new ItemListener() {

                public void itemStateChanged(ItemEvent e) {
                    updateCbDeleteVariable();
                }
            });
        }
    } else {
        myCbDeleteVariable.setVisible(false);
    }
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    if ((myTypeSelectorManager.isSuggestedType(CommonClassNames.JAVA_LANG_STRING) || (myLocalVariable != null && AnnotationUtil.isAnnotated(myLocalVariable, AnnotationUtil.NON_NLS, false, false))) && LanguageLevelProjectExtension.getInstance(psiManager.getProject()).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5) && JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnnotationUtil.NON_NLS, myParentClass.getResolveScope()) != null) {
        final PropertiesComponent component = PropertiesComponent.getInstance(myProject);
        myCbNonNls.setSelected(component.getBoolean(NONNLS_SELECTED_PROPERTY));
        myCbNonNls.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                component.setValue(NONNLS_SELECTED_PROPERTY, myCbNonNls.isSelected());
            }
        });
    } else {
        myCbNonNls.setVisible(false);
    }
    updateTypeSelector();
    enableEnumDependant(introduceEnumConstant());
    return myPanel;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

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