use of mage.client.dialog.PickCheckBoxDialog in project mage by magefree.
the class FastSearchUtil method showFastSearchForStringComboBox.
/**
* Show fast choice modal dialog with incremental searching for any string CheckBoxList components
*
* @param combo CheckBoxList control with default data model
* @param chooseMessage caption message for dialog
*/
public static void showFastSearchForStringComboBox(CheckBoxList combo, String chooseMessage) {
// fast search/choice dialog for string combobox
mage.choices.Choice choice = new ChoiceImpl(false);
// collect data from expansion combobox (String)
DefaultListModel comboModel = (DefaultListModel) combo.getModel();
Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
String item;
for (int i = 0; i < comboModel.size(); i++) {
item = comboModel.getElementAt(i).toString();
choiceItems.put(item, item);
// need so sorting
choiceSorting.put(item, i);
}
choice.setKeyChoices(choiceItems);
choice.setSortData(choiceSorting);
choice.setMessage(chooseMessage);
// current selection value restore
String needSelectValue = null;
if (comboModel.size() > 0) {
needSelectValue = comboModel.firstElement().toString();
}
// ask for new value
PickCheckBoxDialog dlg = new PickCheckBoxDialog(combo);
dlg.setWindowSize(300, 500);
dlg.showDialog(choice, needSelectValue);
if (choice.isChosen()) {
item = choice.getChoiceKey();
// compatible select for object's models (use setSelectedIndex instead setSelectedObject)
for (int i = 0; i < comboModel.getSize(); i++) {
if (comboModel.getElementAt(i).toString().equals(item)) {
combo.setSelectedIndex(i);
}
}
}
}
Aggregations