Search in sources :

Example 11 with NameSuggestionsField

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

the class GrIntroduceConstantDialog method createUIComponents.

private void createUIComponents() {
    myJavaVisibilityPanel = new JavaVisibilityPanel(false, true);
    final GrVariable var = myContext.getVar();
    final GrExpression expression = myContext.getExpression();
    final StringPartInfo stringPart = myContext.getStringPart();
    if (expression != null) {
        myTypeCombo = GrTypeComboBox.createTypeComboBoxFromExpression(expression);
    } else if (stringPart != null) {
        myTypeCombo = GrTypeComboBox.createTypeComboBoxFromExpression(stringPart.getLiteral());
    } else {
        assert var != null;
        myTypeCombo = GrTypeComboBox.createTypeComboBoxWithDefType(var.getDeclaredType(), var);
    }
    List<String> names = new ArrayList<>();
    if (var != null) {
        names.add(var.getName());
    }
    if (expression != null) {
        ContainerUtil.addAll(names, suggestNames());
    }
    myNameField = new NameSuggestionsField(ArrayUtil.toStringArray(names), myContext.getProject(), GroovyFileType.GROOVY_FILE_TYPE);
    GrTypeComboBox.registerUpDownHint(myNameField, myTypeCombo);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) JavaVisibilityPanel(com.intellij.refactoring.ui.JavaVisibilityPanel) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)

Example 12 with NameSuggestionsField

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

the class GrIntroduceFieldDialog method createUIComponents.

private void createUIComponents() {
    final GrExpression expression = myContext.getExpression();
    final GrVariable var = myContext.getVar();
    final StringPartInfo stringPart = myContext.getStringPart();
    List<String> list = new ArrayList<>();
    if (var != null) {
        list.add(var.getName());
    }
    ContainerUtil.addAll(list, suggestNames());
    myNameField = new NameSuggestionsField(ArrayUtil.toStringArray(list), myContext.getProject(), GroovyFileType.GROOVY_FILE_TYPE);
    if (expression != null) {
        myTypeComboBox = GrTypeComboBox.createTypeComboBoxFromExpression(expression);
    } else if (stringPart != null) {
        myTypeComboBox = GrTypeComboBox.createTypeComboBoxFromExpression(stringPart.getLiteral());
    } else {
        myTypeComboBox = GrTypeComboBox.createTypeComboBoxWithDefType(var.getDeclaredType(), var);
    }
    GrTypeComboBox.registerUpDownHint(myNameField, myTypeComboBox);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) ArrayList(java.util.ArrayList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)

Example 13 with NameSuggestionsField

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

the class KotlinExtractFunctionDialog method init.

@Override
protected void init() {
    super.init();
    ExtractableCodeDescriptor extractableCodeDescriptor = originalDescriptor.getDescriptor();
    functionNameField = new NameSuggestionsField(ArrayUtil.toStringArray(extractableCodeDescriptor.getSuggestedNames()), project, KotlinFileType.INSTANCE);
    functionNameField.addDataChangedListener(new NameSuggestionsField.DataChanged() {

        @Override
        public void dataChanged() {
            update();
        }
    });
    functionNamePanel.add(functionNameField, BorderLayout.CENTER);
    functionNameLabel.setLabelFor(functionNameField);
    List<KotlinType> possibleReturnTypes = ExtractableCodeDescriptorKt.getPossibleReturnTypes(extractableCodeDescriptor.getControlFlow());
    if (possibleReturnTypes.size() > 1) {
        DefaultComboBoxModel returnTypeBoxModel = new DefaultComboBoxModel(possibleReturnTypes.toArray());
        returnTypeBox.setModel(returnTypeBoxModel);
        returnTypeBox.setRenderer(new DefaultListCellRenderer() {

            @NotNull
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                setText(IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType((KotlinType) value));
                return this;
            }
        });
        returnTypeBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(@NotNull ItemEvent e) {
                update();
            }
        });
    } else {
        returnTypePanel.getParent().remove(returnTypePanel);
    }
    boolean enableVisibility = isVisibilitySectionAvailable();
    visibilityBox.setEnabled(enableVisibility);
    if (enableVisibility) {
        String defaultVisibility = extractableCodeDescriptor.getVisibility();
        if (defaultVisibility.isEmpty()) {
            defaultVisibility = KtTokens.PUBLIC_KEYWORD.getValue();
        }
        visibilityBox.setSelectedItem(defaultVisibility);
    }
    visibilityBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(@NotNull ItemEvent e) {
            update();
        }
    });
    parameterTablePanel = new ExtractFunctionParameterTablePanel() {

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

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

        @Override
        protected void onCancelAction() {
            doCancelAction();
        }
    };
    parameterTablePanel.init(extractableCodeDescriptor.getReceiverParameter(), extractableCodeDescriptor.getParameters());
    inputParametersPanel.setText("&Parameters");
    inputParametersPanel.setLabelFor(parameterTablePanel.getTable());
    inputParametersPanel.add(parameterTablePanel);
}
Also used : ItemEvent(java.awt.event.ItemEvent) KotlinType(org.jetbrains.kotlin.types.KotlinType) NotNull(org.jetbrains.annotations.NotNull) ItemListener(java.awt.event.ItemListener) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField) KotlinSignatureComponent(org.jetbrains.kotlin.idea.refactoring.introduce.ui.KotlinSignatureComponent)

Example 14 with NameSuggestionsField

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

the class DartRenameDialog method createNewNameComponent.

private void createNewNameComponent() {
    String[] suggestedNames = getSuggestedNames();
    myNameSuggestionsField = new NameSuggestionsField(suggestedNames, myProject, FileTypes.PLAIN_TEXT, myEditor) {

        @Override
        protected boolean shouldSelectAll() {
            return myEditor == null || myEditor.getSettings().isPreselectRename();
        }
    };
    myNameSuggestionsField.addDataChangedListener(this::processNewNameChanged);
}
Also used : 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