Search in sources :

Example 1 with TypeSelector

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

the class ParameterTablePanel method exchangeRows.

@Override
protected void exchangeRows(int row, int targetRow, VariableData currentItem) {
    super.exchangeRows(row, targetRow, currentItem);
    TypeSelector currentSelector = myParameterTypeSelectors[row];
    myParameterTypeSelectors[row] = myParameterTypeSelectors[targetRow];
    myParameterTypeSelectors[targetRow] = currentSelector;
    myTypeRendererCombo.setModel(new DefaultComboBoxModel<>(getVariableData()));
}
Also used : TypeSelector(com.intellij.refactoring.ui.TypeSelector)

Example 2 with TypeSelector

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

the class CreateFieldFromParameterDialog method createNorthPanel.

@Override
protected JComponent createNorthPanel() {
    if (myNames.length > 1) {
        final ComboBox combobox = new ComboBox(myNames, 200);
        myNameField = combobox;
        combobox.setEditable(true);
        combobox.setSelectedIndex(0);
        combobox.setMaximumRowCount(8);
        combobox.registerKeyboardAction(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (combobox.isPopupVisible()) {
                    combobox.setPopupVisible(false);
                } else {
                    doCancelAction();
                }
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        combobox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                updateOkStatus();
            }
        });
        combobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                updateOkStatus();
            }

            @Override
            public void keyReleased(KeyEvent e) {
                updateOkStatus();
            }

            @Override
            public void keyTyped(KeyEvent e) {
                updateOkStatus();
            }
        });
    } else {
        JTextField field = new JTextField() {

            @Override
            public Dimension getPreferredSize() {
                Dimension size = super.getPreferredSize();
                return new Dimension(200, size.height);
            }
        };
        myNameField = field;
        field.setText(myNames[0]);
        field.getDocument().addDocumentListener(new DocumentAdapter() {

            @Override
            protected void textChanged(DocumentEvent e) {
                updateOkStatus();
            }
        });
    }
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.insets = JBUI.insets(4);
    gbConstraints.anchor = GridBagConstraints.EAST;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 1;
    gbConstraints.weighty = 1;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 0;
    final JLabel typeLabel = new JLabel(CodeInsightBundle.message("dialog.create.field.from.parameter.field.type.label"));
    panel.add(typeLabel, gbConstraints);
    gbConstraints.gridx = 1;
    if (myTypes.length > 1) {
        myTypeSelector = new TypeSelector(myProject);
        myTypeSelector.setTypes(myTypes);
    } else {
        myTypeSelector = new TypeSelector(myTypes[0], myProject);
    }
    panel.add(myTypeSelector.getComponent(), gbConstraints);
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 0;
    gbConstraints.weighty = 1;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 1;
    JLabel namePrompt = new JLabel(CodeInsightBundle.message("dialog.create.field.from.parameter.field.name.label"));
    panel.add(namePrompt, gbConstraints);
    gbConstraints.gridwidth = 1;
    gbConstraints.weightx = 1;
    gbConstraints.gridx = 1;
    gbConstraints.gridy = 1;
    panel.add(myNameField, gbConstraints);
    return panel;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) TypeSelector(com.intellij.refactoring.ui.TypeSelector)

Example 3 with TypeSelector

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

the class ParameterTablePanel method init.

public void init(VariableData[] variableData, Project project, PsiElement... scopeElements) {
    super.init(variableData);
    myParameterTypeSelectors = new TypeSelector[getVariableData().length];
    for (int i = 0; i < myParameterTypeSelectors.length; i++) {
        final VariableData data = variableData[i];
        final TypeSelector selector = createSelector(project, data, scopeElements);
        myParameterTypeSelectors[i] = selector;
        //reverse order
        getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType();
    }
    myTypeRendererCombo = new ComboBox<>(getVariableData());
    myTypeRendererCombo.setOpaque(true);
    myTypeRendererCombo.setBorder(null);
    myTypeRendererCombo.setRenderer(new ListCellRendererWrapper<VariableData>() {

        @Override
        public void customize(JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(value.type.getPresentableText());
            }
        }
    });
    final TableColumn typeColumn = myTable.getColumnModel().getColumn(1);
    typeColumn.setCellEditor(new AbstractTableCellEditor() {

        TypeSelector myCurrentSelector;

        final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent();

        final JLabel myTypeLabel = new JLabel();

        @Nullable
        public Object getCellEditorValue() {
            if (myCurrentSelector.getComponent() instanceof JLabel) {
                return myCurrentSelector.getSelectedType();
            }
            return myEditorComponent.getEditorValue();
        }

        public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
            myCurrentSelector = myParameterTypeSelectors[row];
            if (myParameterTypeSelectors[row].getComponent() instanceof JLabel) {
                PsiType selectedType = myCurrentSelector.getSelectedType();
                if (selectedType != null) {
                    myTypeLabel.setText(selectedType.getPresentableText());
                }
                return myTypeLabel;
            }
            myEditorComponent.setCell(table, row, column);
            myEditorComponent.setOptions(myCurrentSelector.getTypes());
            myEditorComponent.setDefaultValue(getVariableData()[row].type);
            myEditorComponent.setToString(o -> ((PsiType) o).getPresentableText());
            return myEditorComponent;
        }
    });
    myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {

        private final JBComboBoxLabel myLabel = new JBComboBoxLabel();

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (value != null) {
                myLabel.setText(((PsiType) value).getPresentableText());
                myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
                myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
                if (isSelected) {
                    myLabel.setSelectionIcon();
                } else {
                    myLabel.setRegularIcon();
                }
            }
            return myLabel;
        }
    });
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) TableColumn(javax.swing.table.TableColumn) Predicate(java.util.function.Predicate) TypeSelector(com.intellij.refactoring.ui.TypeSelector) ColumnInfo(com.intellij.util.ui.ColumnInfo) TypeSelectorManager(com.intellij.refactoring.ui.TypeSelectorManager) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) LanguageNamesValidation(com.intellij.lang.LanguageNamesValidation) ArrayList(java.util.ArrayList) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) JBComboBoxLabel(com.intellij.ui.components.JBComboBoxLabel) Project(com.intellij.openapi.project.Project) com.intellij.psi(com.intellij.psi) JavaLanguage(com.intellij.lang.java.JavaLanguage) javax.swing(javax.swing) JBComboBoxLabel(com.intellij.ui.components.JBComboBoxLabel) TableColumn(javax.swing.table.TableColumn) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) TypeSelector(com.intellij.refactoring.ui.TypeSelector) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TypeSelector (com.intellij.refactoring.ui.TypeSelector)3 ComboBox (com.intellij.openapi.ui.ComboBox)2 LanguageNamesValidation (com.intellij.lang.LanguageNamesValidation)1 JavaLanguage (com.intellij.lang.java.JavaLanguage)1 Project (com.intellij.openapi.project.Project)1 com.intellij.psi (com.intellij.psi)1 TypeSelectorManager (com.intellij.refactoring.ui.TypeSelectorManager)1 TypeSelectorManagerImpl (com.intellij.refactoring.ui.TypeSelectorManagerImpl)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 ListCellRendererWrapper (com.intellij.ui.ListCellRendererWrapper)1 JBComboBoxLabel (com.intellij.ui.components.JBComboBoxLabel)1 JBComboBoxTableCellEditorComponent (com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent)1 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)1 ColumnInfo (com.intellij.util.ui.ColumnInfo)1 java.awt (java.awt)1 ArrayList (java.util.ArrayList)1 Predicate (java.util.function.Predicate)1 javax.swing (javax.swing)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1