Search in sources :

Example 6 with DestinationFolderComboBox

use of com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox in project intellij-community by JetBrains.

the class ReplaceConstructorWithBuilderDialog method doAction.

protected void doAction() {
    TableUtil.stopEditing(myTable);
    final String className;
    final String packageName;
    if (myCreateBuilderClassRadioButton.isSelected()) {
        className = myNewClassName.getText().trim();
        packageName = myPackageTextField.getText().trim();
    } else {
        final String fqName = myExistentClassTF.getText().trim();
        className = StringUtil.getShortName(fqName);
        packageName = StringUtil.getPackageName(fqName);
        final PsiClass builderClass = JavaPsiFacade.getInstance(myProject).findClass(StringUtil.getQualifiedName(packageName, className), GlobalSearchScope.projectScope(myProject));
        if (builderClass != null && !CommonRefactoringUtil.checkReadOnlyStatus(myProject, builderClass))
            return;
    }
    invokeRefactoring(new ReplaceConstructorWithBuilderProcessor(getProject(), myConstructors, myParametersMap, className, packageName, ((DestinationFolderComboBox) myDestinationCb).selectDirectory(new PackageWrapper(myConstructors[0].getManager(), packageName), false), myCreateBuilderClassRadioButton.isSelected()));
}
Also used : DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox) PackageWrapper(com.intellij.refactoring.PackageWrapper)

Example 7 with DestinationFolderComboBox

use of com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox 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 8 with DestinationFolderComboBox

use of com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method initPackageChooser.

private void initPackageChooser(String targetPackageName, PsiDirectory targetDirectory, List<KtFile> sourceFiles) {
    if (targetPackageName != null) {
        classPackageChooser.prependItem(targetPackageName);
    }
    ((DestinationFolderComboBox) destinationFolderCB).setData(myProject, targetDirectory, new Pass<String>() {

        @Override
        public void pass(String s) {
            setErrorText(s);
        }
    }, classPackageChooser.getChildComponent());
    cbSpecifyFileNameInPackage.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            updateFileNameInPackageField();
        }
    });
    cbUpdatePackageDirective.setSelected(arePackagesAndDirectoryMatched(sourceFiles));
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)

Aggregations

DestinationFolderComboBox (com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox)8 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 PackageNameReferenceEditorCombo (com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)3 DocumentEvent (javax.swing.event.DocumentEvent)3 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2 PackageWrapper (com.intellij.refactoring.PackageWrapper)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)2 TreeJavaClassChooserDialog (com.intellij.ide.util.TreeJavaClassChooserDialog)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 ParameterInfoImpl (com.intellij.refactoring.changeSignature.ParameterInfoImpl)1 VariableData (com.intellij.refactoring.util.VariableData)1 ArrayList (java.util.ArrayList)1