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()));
}
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;
}
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;
}
});
}
Aggregations