use of org.apache.empire.commons.Options in project empire-db by apache.
the class InputControl method formatValue.
/**
* Returns the value formated as a string
* this is a simple default implementation that does no type-secific formatting
* Derived classes may override formatString an provide further formmatting
* see TextInputControl for details
*
* @param value
* the value to be formatted
* @param vi
* Meta-information about the value
* @return the formatted value
*/
protected String formatValue(Object value, ValueInfo vi) {
// For Enums use toString() to retrieve Value
if ((value instanceof Enum<?>) && !hasFormatOption(vi, "nolookup")) {
// Handle enum
String text = ((Enum<?>) value).toString();
if (text != null)
return vi.getText(text);
// Error
InputControl.log.error("The enum '" + ((Enum<?>) value).name() + "' has no text!");
}
// Lookup and Print value
Options options = vi.getOptions();
if (options != null && !options.isEmpty() && !hasFormatOption(vi, "nolookup")) {
// Check for Options
OptionEntry entry = options.getEntry(value);
if (entry != null)
return vi.getText(entry.getText());
// Error
if (value != null)
InputControl.log.error("The element '" + String.valueOf(value) + "' is not part of the supplied option list.");
}
// value
if (value == null)
value = getFormatOption(vi, InputControl.FORMAT_NULL, InputControl.FORMAT_NULL_ATTRIBUTE);
// Convert to String
String s = StringUtils.toString(value, "");
if (hasFormatOption(vi, "noencode"))
return s;
// Encode Html
return escapeHTML(s);
}
use of org.apache.empire.commons.Options in project empire-db by apache.
the class RadioInputControl method createInputComponents.
@Override
protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList) {
if (!compList.isEmpty())
throw new InvalidArgumentException("compList", compList);
// create
HtmlSelectOneRadio input = InputControlManager.createComponent(context, this.inputComponentClass);
// setValueExpressionFlag
Object value = ii.getValue(false);
input.getAttributes().put(RadioInputControl.VALUE_EXPRESSION_FLAG, (value instanceof ValueExpression));
// copy Attributes
copyAttributes(parent, ii, input);
// disabled
boolean disabled = ii.isDisabled();
input.setDisabled(disabled);
// Options
Options options = ii.getOptions();
boolean addEmpty = getEmptyEntryRequired(ii, disabled) && !options.containsNull();
String nullText = (addEmpty) ? getNullText(ii) : "";
initOptions(input, ii.getTextResolver(), options, addEmpty, nullText);
// add
compList.add(input);
// style
addRemoveDisabledStyle(input, disabled);
addRemoveInvalidStyle(input, ii.hasError());
// Set Value
setInputValue(input, ii);
}
use of org.apache.empire.commons.Options in project empire-db by apache.
the class RadioInputControl method renderValue.
/* Value */
@Override
public void renderValue(ValueInfo vi, ResponseWriter writer) throws IOException {
Object value = vi.getValue(true);
String style = vi.getStyleClass("eCtlRadio") + " eInpDis";
writer.startElement(HTML_TAG_DIV, null);
writer.writeAttribute(HTML_ATTR_CLASS, style, null);
writer.startElement(HTML_TAG_TABLE, null);
writer.writeAttribute(HTML_ATTR_CLASS, style, null);
writer.startElement(HTML_TAG_TR, null);
Options o = vi.getOptions();
for (OptionEntry e : o) {
writer.startElement(HTML_TAG_TD, null);
// input
writer.startElement(HTML_TAG_INPUT, null);
writer.writeAttribute(HTML_ATTR_TYPE, "radio", null);
writer.writeAttribute(HTML_ATTR_DISABLED, "disabled", null);
if (ObjectUtils.compareEqual(e.getValue(), value))
writer.writeAttribute(HTML_ATTR_CHECKED, "checked", null);
writer.endElement(HTML_TAG_INPUT);
// label
writer.startElement(HTML_TAG_LABEL, null);
writer.writeAttribute(HTML_ATTR_CLASS, "eCtlRadio", null);
String text = e.getText();
text = vi.getTextResolver().resolveText(text);
writer.writeText(text, null);
writer.endElement(HTML_TAG_LABEL);
// end
writer.endElement(HTML_TAG_TD);
}
writer.endElement(HTML_TAG_TR);
writer.endElement(HTML_TAG_TABLE);
writer.endElement(HTML_TAG_DIV);
}
use of org.apache.empire.commons.Options in project empire-db by apache.
the class SelectInputControl method syncOptions.
public void syncOptions(UISelectOne input, TextResolver textResolver, InputInfo ii) {
// get the options
Options options = ii.getOptions();
if (options == null) {
// clear or not?
if (ii.getValue(false) != null)
log.warn("No options have been set for column {}", ii.getColumn().getName());
else
input.getChildren().clear();
return;
}
Object currentValue = ii.getValue(true);
boolean hasEmpty = isEmptyEntryRequired(input, options, ii, currentValue);
// boolean isInsideUIData = ii.isInsideUIData();
// Compare child-items with options
Iterator<OptionEntry> ioe = options.iterator();
OptionEntry oe = (ioe.hasNext() ? ioe.next() : null);
List<UIComponent> childList = input.getChildren();
Iterator<UIComponent> ico = childList.iterator();
int lastIndex = 0;
boolean emptyPresent = false;
while (ico.hasNext()) {
lastIndex++;
UIComponent co = ico.next();
if (!(co instanceof UISelectItem))
continue;
UISelectItem si = (UISelectItem) co;
Object ov = si.getItemValue();
if (ObjectUtils.isEmpty(ov) && hasEmpty) {
emptyPresent = true;
continue;
}
// skip inactive
while (oe != null && !oe.isActive()) {
// check for current
if (ObjectUtils.compareEqual(oe.getValue(), currentValue))
break;
// next oe
oe = (ioe.hasNext() ? ioe.next() : null);
}
if (oe == null) {
// remove obsolete items
lastIndex--;
for (int index = childList.size() - 1; index >= lastIndex; index--) childList.remove(index);
// done
return;
}
if (ObjectUtils.compareEqual(ov, oe.getValue())) {
// next
String label = oe.getText();
si.setItemLabel(textResolver.resolveText(label));
oe = (ioe.hasNext() ? ioe.next() : null);
continue;
}
// Not equal - do a full reload
input.getChildren().clear();
if (hasEmpty) {
// add empty entry
addSelectItem(input, textResolver, new OptionEntry("", getNullText(ii)));
}
for (OptionEntry opt : options) {
// Option entries
if (opt.isActive() || ObjectUtils.compareEqual(opt.getValue(), currentValue)) {
// add active or current item
addSelectItem(input, textResolver, opt);
}
}
// done
return;
}
// check empty entry
if (hasEmpty && !emptyPresent) {
// add missing empty entry
addSelectItem(input, textResolver, new OptionEntry("", getNullText(ii)), 0);
}
// Are there any items left?
while (oe != null) {
// add missing item
if (oe.isActive() || ObjectUtils.compareEqual(oe.getValue(), currentValue)) {
// add item
addSelectItem(input, textResolver, oe);
}
oe = (ioe.hasNext() ? ioe.next() : null);
}
}
use of org.apache.empire.commons.Options in project empire-db by apache.
the class SelectInputControl method initOptions.
public void initOptions(UISelectOne input, TextResolver textResolver, InputInfo ii) {
// get the options
Options options = ii.getOptions();
if (options == null) {
// invalid options
if (ii.getColumn() != null)
log.warn("No options given for column {}", ii.getColumn().getName());
else
log.warn("No options given for select tag {}", input.getClientId());
options = new Options();
}
// current
Object currentValue = ii.getValue(true);
if (isEmptyEntryRequired(input, options, ii, currentValue)) {
// Empty entry
addSelectItem(input, textResolver, new OptionEntry(null, getNullText(ii)));
}
if (options != null && options.size() > 0) {
// Add options
for (OptionEntry oe : options) {
// Option entries
if (oe.isActive() || ObjectUtils.compareEqual(oe.getValue(), currentValue)) {
// add active or current item
addSelectItem(input, textResolver, oe);
} else if (log.isDebugEnabled()) {
// not active, ignore this one
log.debug("Select item {} is not active.", oe.getValue());
}
}
}
}
Aggregations