@Override public void listBoxValueChanged(String newValue) { if (customPrompt.equals(newValue)) { // "Custom..." selected, show textBox with empty value setListBoxValue(""); setTextBoxValue(""); view.setListBoxVisible(false); view.setTextBoxVisible(true); view.setTextBoxFocus(true); } else if (newValue.startsWith("*")) { // Not a valid value setListBoxValue(""); setTextBoxValue(""); } else if (newValue.startsWith(listBoxValues.getEditPrefix())) { // "Edit <value> ..." selected, show textBox with appropriate value String value = view.getModelValue(); setTextBoxValue(value); view.setListBoxVisible(false); view.setTextBoxVisible(true); view.setTextBoxFocus(true); } else if (listBoxValues.isCustomValue(newValue)) { // A Custom value has been selected String textValue = listBoxValues.getValueForDisplayValue(newValue); if (quoteStringValues) { textValue = StringUtils.createUnquotedConstant(textValue); } setListBoxValue(newValue); setTextBoxValue(textValue); } else if (newValue != null) { // A non-custom value has been selected setListBoxValue(newValue); setTextBoxValue(""); } updateListBoxValues(view.getListBoxValue()); }
@Override public void updateListBoxValues(String listBoxValue) { if (showCustomValues) { List<String> updatedValues = listBoxValues.update(listBoxValue); view.setAcceptableValues(updatedValues); } else { List<String> values = listBoxValues.getAcceptableValuesWithoutCustomValues(); view.setAcceptableValues(values); } }
@Override public void textBoxValueChanged(String newValue) { if (newValue != null) { if (!quoteStringValues) { newValue = newValue.trim(); } if (!newValue.isEmpty()) { String nonCustomValue = listBoxValues.getNonCustomValueForUserString(newValue); if (nonCustomValue != null) { setListBoxValue(nonCustomValue); setTextBoxValue(""); currentTextValue = ""; } else { String oldValue = currentTextValue; String displayValue = addCustomValueToListBoxValues(newValue, oldValue); setTextBoxValue(newValue); currentTextValue = newValue; setListBoxValue(displayValue); } } else { // Set the value even if it's "" setTextBoxValue(newValue); setListBoxValue(newValue); currentTextValue = newValue; } } view.setTextBoxVisible(false); view.setListBoxVisible(true); }
@Override public String addCustomValueToListBoxValues(String newValue, String oldValue) { if (quoteStringValues) { newValue = StringUtils.createQuotedConstant(newValue); oldValue = StringUtils.createQuotedConstant(oldValue); } return listBoxValues.addCustomValue(newValue, oldValue); }
private void initComboBoxTest( boolean quoteStringValues, String customPrompt, String placeholder, String editPrefix, String editSuffix, List<String> listBoxStartValues) { initPresenter(); initListBox(); initTextBox(); ListBoxValues listBoxValues = new ListBoxValues(customPrompt, editPrefix, null); listBoxValues.addValues(listBoxStartValues); comboBox.view = view; comboBox.init(modelPresenter, listBox, textBox, quoteStringValues, customPrompt, placeholder); comboBox.setListBoxValues(listBoxValues); comboBox.setShowCustomValues(true); this.quoteStringValues = quoteStringValues; this.editPrefix = editPrefix; this.editSuffix = editSuffix; this.customPrompt = customPrompt; }