use of com.intellij.openapi.ui.ComboBox 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.openapi.ui.ComboBox in project intellij-community by JetBrains.
the class ArtifactConfigurable method createTopRightComponent.
@Override
protected JComponent createTopRightComponent() {
final ComboBox artifactTypeBox = new ComboBox();
for (ArtifactType type : ArtifactType.getAllTypes()) {
artifactTypeBox.addItem(type);
}
artifactTypeBox.setRenderer(new ArtifactTypeCellRenderer(artifactTypeBox.getRenderer()));
artifactTypeBox.setSelectedItem(getArtifact().getArtifactType());
artifactTypeBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final ArtifactType selected = (ArtifactType) artifactTypeBox.getSelectedItem();
if (selected != null && !Comparing.equal(selected, getArtifact().getArtifactType())) {
getEditor().setArtifactType(selected);
}
}
});
final JPanel panel = new JPanel(new FlowLayout());
panel.add(new JLabel("Type: "));
panel.add(artifactTypeBox);
return panel;
}
use of com.intellij.openapi.ui.ComboBox in project intellij-community by JetBrains.
the class MakeParameterizedStaticDialog method createComboBoxForName.
private JComboBox createComboBoxForName() {
final ComboBox combobox = new ComboBox(myNameSuggestions);
combobox.setEditable(true);
combobox.setSelectedIndex(0);
combobox.setMaximumRowCount(8);
combobox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updateControls();
}
});
combobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
updateControls();
}
public void keyReleased(KeyEvent e) {
updateControls();
}
public void keyTyped(KeyEvent e) {
updateControls();
}
});
return combobox;
}
use of com.intellij.openapi.ui.ComboBox in project intellij-community by JetBrains.
the class ExternalDependenciesConfigurable method editPluginDependency.
@Nullable
private DependencyOnPlugin editPluginDependency(@NotNull JComponent parent, @NotNull final DependencyOnPlugin original) {
List<String> pluginIds = new ArrayList<>(getPluginNameByIdMap().keySet());
if (!original.getPluginId().isEmpty() && !pluginIds.contains(original.getPluginId())) {
pluginIds.add(original.getPluginId());
}
Collections.sort(pluginIds, (o1, o2) -> getPluginNameById(o1).compareToIgnoreCase(getPluginNameById(o2)));
final ComboBox pluginChooser = new ComboBox(ArrayUtilRt.toStringArray(pluginIds), 250);
pluginChooser.setRenderer(new ListCellRendererWrapper<String>() {
@Override
public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
setText(getPluginNameById(value));
}
});
new ComboboxSpeedSearch(pluginChooser) {
@Override
protected String getElementText(Object element) {
return getPluginNameById((String) element);
}
};
pluginChooser.setSelectedItem(original.getPluginId());
final JBTextField minVersionField = new JBTextField(StringUtil.notNullize(original.getMinVersion()));
final JBTextField maxVersionField = new JBTextField(StringUtil.notNullize(original.getMaxVersion()));
final JBTextField channelField = new JBTextField(StringUtil.notNullize(original.getChannel()));
minVersionField.getEmptyText().setText("<any>");
minVersionField.setColumns(10);
maxVersionField.getEmptyText().setText("<any>");
maxVersionField.setColumns(10);
channelField.setColumns(10);
JPanel panel = FormBuilder.createFormBuilder().addLabeledComponent("Plugin:", pluginChooser).addLabeledComponent("Minimum version:", minVersionField).addLabeledComponent("Maximum version:", maxVersionField).addLabeledComponent("Channel:", channelField).getPanel();
final DialogBuilder dialogBuilder = new DialogBuilder(parent).title("Required Plugin").centerPanel(panel);
dialogBuilder.setPreferredFocusComponent(pluginChooser);
pluginChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialogBuilder.setOkActionEnabled(!StringUtil.isEmpty((String) pluginChooser.getSelectedItem()));
}
});
if (dialogBuilder.show() == DialogWrapper.OK_EXIT_CODE) {
return new DependencyOnPlugin(((String) pluginChooser.getSelectedItem()), StringUtil.nullize(minVersionField.getText().trim()), StringUtil.nullize(maxVersionField.getText().trim()), StringUtil.nullize(channelField.getText().trim()));
}
return null;
}
use of com.intellij.openapi.ui.ComboBox in project intellij-community by JetBrains.
the class ChangeListCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
final PsiFile file = parameters.getOriginalFile();
final Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
if (document == null)
return;
ComboBox comboBox = document.getUserData(COMBO_BOX_KEY);
if (comboBox == null)
return;
final CompletionResultSet resultSet = result.withPrefixMatcher(new PlainPrefixMatcher(document.getText()));
for (int i = 0; i < comboBox.getItemCount(); i++) {
resultSet.addElement(LookupElementBuilder.create(comboBox.getItemAt(i)));
}
}
Aggregations