Search in sources :

Example 1 with NameSuggestionsField

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

the class IntroducePropertyDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myFieldNamePanel.setLayout(new BorderLayout());
    myNameField = new NameSuggestionsField(myProject);
    myNameChangedListener = new NameSuggestionsField.DataChanged() {

        public void dataChanged() {
            updateOkStatus();
        }
    };
    myNameField.addDataChangedListener(myNameChangedListener);
    myNameField.setSuggestions(getSuggestions());
    myFieldNamePanel.add(myNameField, BorderLayout.CENTER);
    List<MavenDomProjectModel> projects = getProjects();
    ComboBoxUtil.setModel(myMavenProjectsComboBox, new DefaultComboBoxModel(), projects, model -> {
        String projectName = model.getName().getStringValue();
        MavenProject mavenProject = MavenDomUtil.findProject(model);
        if (mavenProject != null) {
            projectName = mavenProject.getDisplayName();
        }
        if (StringUtil.isEmptyOrSpaces(projectName)) {
            projectName = "pom.xml";
        }
        return Pair.create(projectName, model);
    });
    myMavenProjectsComboBox.setSelectedItem(myMavenDomProjectModel);
    return myMainPanel;
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenProject(org.jetbrains.idea.maven.project.MavenProject) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField)

Example 2 with NameSuggestionsField

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

the class XmlTagRenameDialog method createNewNameComponent.

private void createNewNameComponent() {
    myNameSuggestionsField = new NameSuggestionsField(new String[] { myTag.getName() }, myProject, FileTypes.PLAIN_TEXT, myEditor);
    myNameChangedListener = new NameSuggestionsField.DataChanged() {

        @Override
        public void dataChanged() {
            validateButtons();
        }
    };
    myNameSuggestionsField.addDataChangedListener(myNameChangedListener);
    myNameSuggestionsField.getComponent().registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            completeVariable(myNameSuggestionsField.getEditor());
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField)

Example 3 with NameSuggestionsField

use of com.intellij.refactoring.ui.NameSuggestionsField in project kotlin by JetBrains.

the class KotlinIntroduceTypeAliasDialog method init.

@Override
protected void init() {
    super.init();
    //noinspection unchecked
    visibilityBox.setModel(new DefaultComboBoxModel(getApplicableVisibilities().toArray()));
    //noinspection unchecked
    visibilityBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            String tokenValue = value != null ? ((KtModifierKeywordToken) value).getValue() : null;
            return super.getListCellRendererComponent(list, tokenValue, index, isSelected, cellHasFocus);
        }
    });
    aliasNameField = new NameSuggestionsField(new String[] { originalDescriptor.getName() }, project, KotlinFileType.INSTANCE);
    aliasNameField.addDataChangedListener(new NameSuggestionsField.DataChanged() {

        @Override
        public void dataChanged() {
            update();
        }
    });
    aliasNamePanel.add(aliasNameField, BorderLayout.CENTER);
    aliasNameLabel.setLabelFor(aliasNameField);
    boolean enableVisibility = isVisibilitySectionAvailable();
    visibilityBox.setEnabled(enableVisibility);
    if (enableVisibility) {
        KtModifierKeywordToken defaultVisibility = originalDescriptor.getVisibility();
        if (defaultVisibility == null) {
            defaultVisibility = KtTokens.PUBLIC_KEYWORD;
        }
        visibilityBox.setSelectedItem(defaultVisibility);
    }
    visibilityBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(@NotNull ItemEvent e) {
            update();
        }
    });
    if (!originalDescriptor.getTypeParameters().isEmpty()) {
        parameterTablePanel = new IntroduceTypeAliasParameterTablePanel() {

            @Override
            protected void updateSignature() {
                KotlinIntroduceTypeAliasDialog.this.update();
            }

            @Override
            protected void onEnterAction() {
                doOKAction();
            }

            @Override
            protected void onCancelAction() {
                doCancelAction();
            }
        };
        parameterTablePanel.init(originalDescriptor.getTypeParameters());
        inputParametersPanel.setText("Type &Parameters");
        inputParametersPanel.setLabelFor(parameterTablePanel.getTable());
        inputParametersPanel.add(parameterTablePanel);
    } else {
        inputParametersPanel.setVisible(false);
    }
}
Also used : ItemEvent(java.awt.event.ItemEvent) KtModifierKeywordToken(org.jetbrains.kotlin.lexer.KtModifierKeywordToken) ItemListener(java.awt.event.ItemListener) KotlinSignatureComponent(org.jetbrains.kotlin.idea.refactoring.introduce.ui.KotlinSignatureComponent) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField)

Example 4 with NameSuggestionsField

use of com.intellij.refactoring.ui.NameSuggestionsField in project kotlin by JetBrains.

the class MoveKotlinNestedClassesToUpperLevelDialog method createUIComponents.

private void createUIComponents() {
    parameterField = new NameSuggestionsField(project);
    packageNameField = new PackageNameReferenceEditorCombo("", project, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
}
Also used : NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 5 with NameSuggestionsField

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

the class RenameDialog method createNewNameComponent.

protected void createNewNameComponent() {
    String[] suggestedNames = getSuggestedNames();
    myOldName = UsageViewUtil.getShortName(myPsiElement);
    myNameSuggestionsField = new NameSuggestionsField(suggestedNames, myProject, FileTypes.PLAIN_TEXT, myEditor) {

        @Override
        protected boolean shouldSelectAll() {
            return myEditor == null || myEditor.getSettings().isPreselectRename();
        }
    };
    if (myPsiElement instanceof PsiFile && myEditor == null) {
        myNameSuggestionsField.selectNameWithoutExtension();
    }
    myNameChangedListener = () -> processNewNameChanged();
    myNameSuggestionsField.addDataChangedListener(myNameChangedListener);
}
Also used : PsiFile(com.intellij.psi.PsiFile) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField)

Aggregations

NameSuggestionsField (com.intellij.refactoring.ui.NameSuggestionsField)14 PackageNameReferenceEditorCombo (com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 KotlinSignatureComponent (org.jetbrains.kotlin.idea.refactoring.introduce.ui.KotlinSignatureComponent)2 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 StringPartInfo (org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)2 PsiFile (com.intellij.psi.PsiFile)1 ClassCellRenderer (com.intellij.refactoring.ui.ClassCellRenderer)1 JavaVisibilityPanel (com.intellij.refactoring.ui.JavaVisibilityPanel)1 NonFocusableCheckBox (com.intellij.ui.NonFocusableCheckBox)1 FormBuilder (com.intellij.util.ui.FormBuilder)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)1 MavenProject (org.jetbrains.idea.maven.project.MavenProject)1