use of com.servoy.j2db.util.model.ComboModelListModelWrapper in project servoy-client by Servoy.
the class DataComboBox method setSelectedItem.
@Override
public void setSelectedItem(Object anObject) {
Object oldSelection = selectedItemReminder;
if (oldSelection == null || !oldSelection.equals(anObject)) {
if (IValueList.SEPARATOR.equals(anObject)) {
// here we can't know the actual index to choose a nearby item, maybe there are multiple separators, so just ignore it (it's probably nicer anyway);
// reset the editor's value, cause it might have been set as well by an Enter key press
getEditor().setItem(oldSelection);
return;
}
if (anObject != null && !isEditable()) {
// For non editable combo boxes, an invalid selection
// will be rejected.
boolean found = false;
// as the equals value and not the complete date, that can have seperate input fields.
if (anObject instanceof Date && format instanceof StateFullSimpleDateFormat) {
StateFullSimpleDateFormat sfsd = (StateFullSimpleDateFormat) format;
String selectedFormat = sfsd.format(anObject);
for (int i = 0; i < dataModel.getSize(); i++) {
try {
Object element = dataModel.getElementAt(i);
if (!(element instanceof Date))
continue;
String elementFormat = sfsd.format(element);
if (selectedFormat.equals(elementFormat)) {
found = true;
break;
}
} catch (RuntimeException e) {
Debug.error(e);
}
}
} else {
if (dataModel instanceof ComboModelListModelWrapper) {
found = ((ComboModelListModelWrapper) dataModel).indexOf(anObject) != -1;
} else
for (int i = 0; i < dataModel.getSize(); i++) {
if (anObject.equals(dataModel.getElementAt(i))) {
found = true;
break;
}
}
}
if (!found) {
return;
}
}
// Must toggle the state of this flag since this method
// call may result in ListDataEvents being fired.
selectingItem = true;
dataModel.setSelectedItem(anObject);
selectingItem = false;
if (selectedItemReminder != dataModel.getSelectedItem()) {
// in case a users implementation of ComboBoxModel
// doesn't fire a ListDataEvent when the selection
// changes.
selectedItemChanged();
}
}
fireActionEvent();
}
Aggregations