use of com.intellij.ui.CollectionComboBoxModel in project android by JetBrains.
the class ServicePanelBuilder method addComboBox.
public JComboBox addComboBox(@NotNull final ObservableList<String> backingList) {
final CollectionComboBoxModel<String> model = new CollectionComboBoxModel<String>(backingList) {
@NotNull
@Override
public List<String> getItems() {
return backingList;
}
};
final ComboBox comboBox = new ComboBox(model);
InvalidationListener onListModified = new InvalidationListener() {
@Override
public void onInvalidated(@NotNull ObservableValue<?> sender) {
model.update();
if (backingList.size() > 0 && comboBox.getSelectedIndex() < 0) {
comboBox.setSelectedIndex(0);
}
}
};
addComponent(comboBox);
backingList.addWeakListener(onListModified);
// Keep weak listener alive as long as the combobox is alive
comboBox.putClientProperty("onListModified", onListModified);
return comboBox;
}
use of com.intellij.ui.CollectionComboBoxModel in project intellij-community by JetBrains.
the class ExternalToolsCheckinHandlerFactory method createHandler.
@NotNull
@Override
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
final ToolsProjectConfig config = ToolsProjectConfig.getInstance(panel.getProject());
return new CheckinHandler() {
@Override
public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
final JLabel label = new JLabel(ToolsBundle.message("tools.after.commit.description"));
ComboboxWithBrowseButton listComponent = new ComboboxWithBrowseButton();
final JComboBox comboBox = listComponent.getComboBox();
comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), null));
comboBox.setRenderer(new ListCellRendererWrapper<Object>() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof ToolsGroup) {
setText(StringUtil.notNullize(((ToolsGroup) value).getName(), ToolsBundle.message("tools.unnamed.group")));
} else if (value instanceof Tool) {
setText(" " + StringUtil.notNullize(((Tool) value).getName()));
} else {
setText(ToolsBundle.message("tools.list.item.none"));
}
}
});
listComponent.getButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Object item = comboBox.getSelectedItem();
String id = null;
if (item instanceof Tool) {
id = ((Tool) item).getActionId();
}
final ToolSelectDialog dialog = new ToolSelectDialog(panel.getProject(), id, new ToolsPanel());
if (!dialog.showAndGet()) {
return;
}
comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), dialog.getSelectedTool()));
}
});
BorderLayout layout = new BorderLayout();
layout.setVgap(3);
final JPanel panel = new JPanel(layout);
panel.add(label, BorderLayout.NORTH);
panel.add(listComponent, BorderLayout.CENTER);
listComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 0));
if (comboBox.getItemCount() == 0 || (comboBox.getItemCount() == 1 && comboBox.getItemAt(0) == NONE_TOOL)) {
return null;
}
return new RefreshableOnComponent() {
@Override
public JComponent getComponent() {
return panel;
}
@Override
public void refresh() {
String id = config.getAfterCommitToolsId();
if (id == null) {
comboBox.setSelectedIndex(-1);
} else {
for (int i = 0; i < comboBox.getItemCount(); i++) {
final Object itemAt = comboBox.getItemAt(i);
if (itemAt instanceof Tool && id.equals(((Tool) itemAt).getActionId())) {
comboBox.setSelectedIndex(i);
return;
}
}
}
}
@Override
public void saveState() {
Object item = comboBox.getSelectedItem();
config.setAfterCommitToolId(item instanceof Tool ? ((Tool) item).getActionId() : null);
}
@Override
public void restoreState() {
refresh();
}
};
}
@Override
public void checkinSuccessful() {
final String id = config.getAfterCommitToolsId();
if (id == null) {
return;
}
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(final DataContext context) {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
ToolAction.runTool(id, context);
}
});
}
});
}
};
}
use of com.intellij.ui.CollectionComboBoxModel in project intellij-community by JetBrains.
the class ReadOnlyStatusDialog method initFileList.
private void initFileList() {
//noinspection unchecked
myFileList.setModel(new AbstractListModel() {
public int getSize() {
return myFiles.length;
}
public Object getElementAt(final int index) {
return myFiles[index].getFile();
}
});
boolean hasVcs = false;
for (FileInfo info : myFiles) {
if (info.hasVersionControl()) {
hasVcs = true;
HandleType handleType = info.getSelectedHandleType();
List<String> changelists = handleType.getChangelists();
final String defaultChangelist = handleType.getDefaultChangelist();
//noinspection unchecked
myChangelist.setModel(new CollectionComboBoxModel(changelists, defaultChangelist));
//noinspection unchecked
myChangelist.setRenderer(new ColoredListCellRendererWrapper<String>() {
@Override
protected void doCustomize(JList list, String value, int index, boolean selected, boolean hasFocus) {
if (value == null)
return;
String trimmed = StringUtil.first(value, 50, true);
if (value.equals(defaultChangelist)) {
append(trimmed, selected ? SELECTED_BOLD_ATTRIBUTES : BOLD_ATTRIBUTES);
} else {
append(trimmed, selected ? SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES : SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES);
}
}
});
break;
}
}
myUsingVcsRadioButton.setEnabled(hasVcs);
}
use of com.intellij.ui.CollectionComboBoxModel in project intellij-community by JetBrains.
the class RepositoryLibraryPropertiesEditor method initVersionKindSelector.
private void initVersionKindSelector() {
List<String> versionKinds = Arrays.asList(ProjectBundle.message("maven.version.kind.selector.release"), ProjectBundle.message("maven.version.kind.selector.latest"), ProjectBundle.message("maven.version.kind.selector.select"));
CollectionComboBoxModel<String> versionKindSelectorModel = new CollectionComboBoxModel<>(versionKinds);
//noinspection unchecked
versionKindSelector.setModel(versionKindSelectorModel);
versionKindSelector.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
VersionKind newVersionKind = getSelectedVersionKind();
if (newVersionKind != versionKind) {
versionKind = newVersionKind;
versionKindChanged();
}
}
});
setSelectedVersionKind(getVersionKind(model.getVersion()));
}
use of com.intellij.ui.CollectionComboBoxModel in project intellij-community by JetBrains.
the class RepositoryAttachDialog method updateComboboxSelection.
private void updateComboboxSelection(boolean force) {
final String prevFilter = myFilterString;
final JTextComponent field = (JTextComponent) myCombobox.getEditor().getEditorComponent();
final int caret = field.getCaretPosition();
myFilterString = field.getText();
if (!force && Comparing.equal(myFilterString, prevFilter))
return;
int prevSize = myShownItems.size();
myShownItems.clear();
myInUpdate = true;
final boolean itemSelected = myCoordinates.containsKey(myFilterString) && Comparing.strEqual((String) myCombobox.getSelectedItem(), myFilterString, false);
final boolean filtered;
if (itemSelected) {
myShownItems.addAll(myCoordinates.keySet());
filtered = false;
} else {
final String[] parts = myFilterString.split(" ");
main: for (String coordinate : myCoordinates.keySet()) {
for (String part : parts) {
if (!StringUtil.containsIgnoreCase(coordinate, part))
continue main;
}
myShownItems.add(coordinate);
}
filtered = !myShownItems.isEmpty();
if (!filtered) {
myShownItems.addAll(myCoordinates.keySet());
}
myCombobox.setSelectedItem(null);
}
// use maven version sorter
ArrayList<Comparable> comparables = new ArrayList<>(myShownItems.size());
for (String item : myShownItems) {
comparables.add(new MavenVersionComparable(item));
}
Collections.sort(comparables);
myShownItems.clear();
for (Comparable comparable : comparables) {
myShownItems.add(comparable.toString());
}
((CollectionComboBoxModel) myCombobox.getModel()).update();
myInUpdate = false;
field.setText(myFilterString);
field.setCaretPosition(caret);
updateInfoLabel();
if (filtered) {
if (prevSize < 10 && myShownItems.size() > prevSize && myCombobox.isPopupVisible()) {
myCombobox.setPopupVisible(false);
}
if (!myCombobox.isPopupVisible()) {
myCombobox.setPopupVisible(true);
}
}
}
Aggregations