Search in sources :

Example 96 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class GrIntroduceParameterDialog method init.

@Override
protected void init() {
    super.init();
    JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
    initReplaceFieldsWithGetters(settings);
    myDeclareFinalCheckBox.setSelected(hasFinalModifier());
    myDelegateViaOverloadingMethodCheckBox.setVisible(myInfo.getToSearchFor() != null);
    setTitle(RefactoringBundle.message("introduce.parameter.title"));
    myTable.init(myInfo);
    final GrParameter[] parameters = myInfo.getToReplaceIn().getParameters();
    toRemoveCBs.forEachEntry(new TObjectIntProcedure<JCheckBox>() {

        @Override
        public boolean execute(JCheckBox checkbox, int index) {
            checkbox.setSelected(true);
            final GrParameter param = parameters[index];
            final ParameterInfo pinfo = findParamByOldName(param.getName());
            if (pinfo != null) {
                pinfo.passAsParameter = false;
            }
            return true;
        }
    });
    updateSignature();
    if (myCanIntroduceSimpleParameter) {
        mySignaturePanel.setVisible(false);
        //action to hide signature panel if we have variants to introduce simple parameter
        myTypeComboBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                mySignaturePanel.setVisible(myTypeComboBox.isClosureSelected());
                pack();
            }
        });
    }
    final PsiType closureReturnType = inferClosureReturnType();
    if (PsiType.VOID.equals(closureReturnType)) {
        myForceReturnCheckBox.setEnabled(false);
        myForceReturnCheckBox.setSelected(false);
    } else {
        myForceReturnCheckBox.setSelected(isForceReturn());
    }
    if (myInfo.getToReplaceIn() instanceof GrClosableBlock) {
        myDelegateViaOverloadingMethodCheckBox.setEnabled(false);
        myDelegateViaOverloadingMethodCheckBox.setToolTipText("Delegating is not allowed in closure context");
    }
    pack();
}
Also used : JavaRefactoringSettings(com.intellij.refactoring.JavaRefactoringSettings) ItemEvent(java.awt.event.ItemEvent) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) ItemListener(java.awt.event.ItemListener) ParameterInfo(org.jetbrains.plugins.groovy.refactoring.extract.ParameterInfo) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) PsiType(com.intellij.psi.PsiType)

Example 97 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class ComponentItemDialog method showGroupChooser.

void showGroupChooser(GroupItem defaultGroup) {
    myGroupLabel.setVisible(true);
    myGroupComboBox.setVisible(true);
    List<GroupItem> groups = Palette.getInstance(myProject).getGroups();
    myGroupComboBox.setModel(new DefaultComboBoxModel(groups.toArray()));
    myGroupComboBox.setSelectedItem(defaultGroup);
    myGroupComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            updateOKAction();
        }
    });
    updateOKAction();
}
Also used : ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener)

Example 98 with ItemListener

use of java.awt.event.ItemListener 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 99 with ItemListener

use of java.awt.event.ItemListener in project kotlin by JetBrains.

the class KotlinPullUpDialogBase method initClassCombo.

@SuppressWarnings("unchecked")
@Override
protected void initClassCombo(JComboBox classCombo) {
    classCombo.setRenderer(new KotlinOrJavaClassCellRenderer());
    classCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                if (myMemberSelectionPanel == null)
                    return;
                AbstractMemberSelectionTable<KtNamedDeclaration, KotlinMemberInfo> table = myMemberSelectionPanel.getTable();
                if (table == null)
                    return;
                table.setMemberInfos(myMemberInfos);
                table.fireExternalDataChange();
            }
        }
    });
}
Also used : AbstractMemberSelectionTable(com.intellij.refactoring.ui.AbstractMemberSelectionTable) ItemEvent(java.awt.event.ItemEvent) KotlinOrJavaClassCellRenderer(org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinOrJavaClassCellRenderer) ItemListener(java.awt.event.ItemListener)

Example 100 with ItemListener

use of java.awt.event.ItemListener in project intellij-community by JetBrains.

the class PyChangeSignatureDialog method getTableEditor.

@Override
protected JBTableRowEditor getTableEditor(final JTable t, final ParameterTableModelItemBase<PyParameterInfo> item) {
    return new JBTableRowEditor() {

        private EditorTextField myNameEditor;

        private EditorTextField myDefaultValueEditor;

        private JCheckBox myDefaultInSignature;

        @Override
        public void prepareEditor(JTable table, int row) {
            setLayout(new GridLayout(1, 3));
            final JPanel parameterPanel = createParameterPanel();
            add(parameterPanel);
            final JPanel defaultValuePanel = createDefaultValuePanel();
            add(defaultValuePanel);
            final JPanel defaultValueCheckBox = createDefaultValueCheckBox();
            add(defaultValueCheckBox);
            final String nameText = myNameEditor.getText();
            myDefaultValueEditor.setEnabled(!nameText.startsWith("*") && !PyNames.CANONICAL_SELF.equals(nameText));
            myDefaultInSignature.setEnabled(!nameText.startsWith("*") && !PyNames.CANONICAL_SELF.equals(nameText));
        }

        private JPanel createDefaultValueCheckBox() {
            final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
            final JBLabel inSignatureLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.default.value.checkbox"), UIUtil.ComponentStyle.SMALL);
            IJSwingUtilities.adjustComponentsOnMac(inSignatureLabel, myDefaultInSignature);
            defaultValuePanel.add(inSignatureLabel, BorderLayout.WEST);
            myDefaultInSignature = new JCheckBox();
            myDefaultInSignature.setSelected(((PyParameterTableModelItem) item).isDefaultInSignature());
            myDefaultInSignature.addItemListener(new ItemListener() {

                @Override
                public void itemStateChanged(ItemEvent event) {
                    ((PyParameterTableModelItem) item).setDefaultInSignature(myDefaultInSignature.isSelected());
                }
            });
            myDefaultInSignature.addChangeListener(mySignatureUpdater);
            myDefaultInSignature.setEnabled(item.parameter.getOldIndex() == -1);
            defaultValuePanel.add(myDefaultInSignature, BorderLayout.EAST);
            return defaultValuePanel;
        }

        private JPanel createDefaultValuePanel() {
            final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
            final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(item.defaultValueCodeFragment);
            myDefaultValueEditor = new EditorTextField(doc, getProject(), getFileType());
            final JBLabel defaultValueLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.default.value.label"), UIUtil.ComponentStyle.SMALL);
            IJSwingUtilities.adjustComponentsOnMac(defaultValueLabel, myDefaultValueEditor);
            defaultValuePanel.add(defaultValueLabel);
            defaultValuePanel.add(myDefaultValueEditor);
            myDefaultValueEditor.setPreferredWidth(t.getWidth() / 2);
            myDefaultValueEditor.addDocumentListener(mySignatureUpdater);
            return defaultValuePanel;
        }

        private JPanel createParameterPanel() {
            final JPanel namePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
            myNameEditor = new EditorTextField(item.parameter.getName(), getProject(), getFileType());
            final JBLabel nameLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.name.label"), UIUtil.ComponentStyle.SMALL);
            IJSwingUtilities.adjustComponentsOnMac(nameLabel, myNameEditor);
            namePanel.add(nameLabel);
            namePanel.add(myNameEditor);
            myNameEditor.setPreferredWidth(t.getWidth() / 2);
            myNameEditor.addDocumentListener(new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent event) {
                    fireDocumentChanged(event, 0);
                    myDefaultValueEditor.setEnabled(!myNameEditor.getText().startsWith("*"));
                    myDefaultInSignature.setEnabled(!myNameEditor.getText().startsWith("*"));
                }
            });
            myNameEditor.addDocumentListener(mySignatureUpdater);
            return namePanel;
        }

        @Override
        public JBTableRow getValue() {
            return new JBTableRow() {

                @Override
                public Object getValueAt(int column) {
                    switch(column) {
                        case 0:
                            return myNameEditor.getText().trim();
                        case 1:
                            return new Pair<>(item.defaultValueCodeFragment, ((PyParameterTableModelItem) item).isDefaultInSignature());
                    }
                    return null;
                }
            };
        }

        @Override
        public JComponent getPreferredFocusedComponent() {
            return myNameEditor.getFocusTarget();
        }

        @Override
        public JComponent[] getFocusableComponents() {
            final List<JComponent> focusable = new ArrayList<>();
            focusable.add(myNameEditor.getFocusTarget());
            if (myDefaultValueEditor != null) {
                focusable.add(myDefaultValueEditor.getFocusTarget());
            }
            return focusable.toArray(new JComponent[focusable.size()]);
        }
    };
}
Also used : ItemEvent(java.awt.event.ItemEvent) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) JBTableRowEditor(com.intellij.util.ui.table.JBTableRowEditor) EditorTextField(com.intellij.ui.EditorTextField) JBLabel(com.intellij.ui.components.JBLabel) ItemListener(java.awt.event.ItemListener) JBTableRow(com.intellij.util.ui.table.JBTableRow) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) Pair(com.intellij.openapi.util.Pair)

Aggregations

ItemListener (java.awt.event.ItemListener)120 ItemEvent (java.awt.event.ItemEvent)119 ActionEvent (java.awt.event.ActionEvent)34 ActionListener (java.awt.event.ActionListener)31 JCheckBox (javax.swing.JCheckBox)21 JPanel (javax.swing.JPanel)14 JComboBox (javax.swing.JComboBox)10 JLabel (javax.swing.JLabel)10 DocumentEvent (javax.swing.event.DocumentEvent)10 JButton (javax.swing.JButton)9 ArrayList (java.util.ArrayList)8 ChangeEvent (javax.swing.event.ChangeEvent)8 ChangeListener (javax.swing.event.ChangeListener)8 DocumentAdapter (com.intellij.ui.DocumentAdapter)7 GridBagConstraints (java.awt.GridBagConstraints)7 BorderLayout (java.awt.BorderLayout)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)5 List (java.util.List)5 BoxLayout (javax.swing.BoxLayout)5