use of com.github.bordertech.wcomponents.AbstractWSingleSelectList in project wcomponents by BorderTech.
the class AbstractCompare method getTriggerValue.
/**
* Get the value for the trigger.
* <p>
* If no request is passed in, the current value of the trigger is used.
* </p>
* <p>
* It will return the same "value" the client would have used in its subordinate logic.
* </p>
* <p>
* The trigger value will either be (i) a date formatted String for WDateFields, (ii) a BigDecimal for WNumberFields
* or (iii) a List of String values for MultiSelect components or (iv) a String value.
* </p>
*
* @param request the request being processed, can be null
* @return the value to be used for the trigger
*/
protected Object getTriggerValue(final Request request) {
// Date Compare (Use Date Formatted String - YYYY-MM-DD)
if (trigger instanceof WDateField) {
final WDateField input = (WDateField) trigger;
Date date;
if (request == null) {
date = input.getValue();
} else {
date = input.getRequestValue(request);
}
return date == null ? null : new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date);
} else if (trigger instanceof WNumberField) {
// Number Compare (Use Number Object)
final WNumberField input = (WNumberField) trigger;
if (request == null) {
return input.getValue();
} else {
return input.getRequestValue(request);
}
} else if (trigger instanceof AbstractWSingleSelectList) {
// String Compare for Single Select Lists (Use the Option's Code)
final AbstractWSingleSelectList list = (AbstractWSingleSelectList) trigger;
final Object selected;
if (request == null) {
selected = list.getValue();
} else {
selected = list.getRequestValue(request);
}
// Convert selected option to its "code" (Should always have a value)
String code = list.optionToCode(selected);
return code;
} else if (trigger instanceof AbstractWMultiSelectList) {
// String Compare for Multi Select Lists (Use the Option's Code)
final AbstractWMultiSelectList list = (AbstractWMultiSelectList) trigger;
final List<?> selected;
if (request == null) {
selected = list.getValue();
} else {
selected = list.getRequestValue(request);
}
// Empty is treated the same as null
if (selected == null || selected.isEmpty()) {
return null;
}
// Convert selected options to their "code" (Should always have a value)
List<String> codes = new ArrayList<>(selected.size());
for (Object select : selected) {
String code = list.optionToCode(select);
codes.add(code);
}
return codes;
} else if (trigger instanceof Input) {
// String Compare - Use the String Value of the Input
final Input input = (Input) trigger;
final Object inputValue;
if (request == null) {
inputValue = input.getValue();
} else {
inputValue = input.getRequestValue(request);
}
// Treat empty the same as null
return (inputValue == null || Util.empty(inputValue.toString())) ? null : inputValue.toString();
} else {
throw new SystemException("Trigger is not a valid type.");
}
}
Aggregations