use of org.asqatasun.webapp.form.SelectElement in project Asqatasun by Asqatasun.
the class AuditSetUpFormFieldHelper method activateSelectFormField.
/**
* This method enables/disables a select form field element regarding the
* activation / restriction strategy. If a SelectFormField is set as enabled
* by default and has a set restrictionCode, it can be disabled. If a
* SelectFormField is set as disabled by default and has a set
* activationCode, it can be enabled.
*
* @param selectFormField
* @param optionElementSet
*/
private static void activateSelectFormField(SelectFormField selectFormField, Collection<OptionElement> optionElementSet) {
boolean enableElements = true;
OptionElement optionElement = null;
if (StringUtils.isNotEmpty(selectFormField.getRestrictionCode())) {
optionElement = getOptionFromOptionSet(optionElementSet, selectFormField.getRestrictionCode());
enableElements = false;
} else if (StringUtils.isNotEmpty(selectFormField.getActivationCode())) {
optionElement = getOptionFromOptionSet(optionElementSet, selectFormField.getActivationCode());
}
if (optionElement != null) {
String[] optionValues = optionElement.getValue().split(";");
boolean isSelectFormFieldHasDefault = false;
for (String optionValue : optionValues) {
List<SelectElement> sel = selectFormField.getSelectElementMap().get(optionValue);
for (SelectElement se : sel) {
se.setEnabled(enableElements);
// By option mechanism, we can set an SelectElement as default.
if (!isSelectFormFieldHasDefault) {
isSelectFormFieldHasDefault = setSelectElementAsDefault(se, optionElementSet);
}
}
}
// is set as default
if (!isSelectFormFieldHasDefault) {
setFirstSelectElementAsDefault(selectFormField.getSelectElementMap());
}
}
}
use of org.asqatasun.webapp.form.SelectElement in project Asqatasun by Asqatasun.
the class AuditSetUpFormFieldHelper method setFirstSelectElementAsDefault.
/**
* When no SelectElement is defined as default from a list whole list, we
* set the first element of the list as default.
*
* @param sel
*/
private static void setFirstSelectElementAsDefault(Map<String, List<SelectElement>> selElementMap) {
boolean firstEnabledElementEncountered = false;
for (List<SelectElement> seList : selElementMap.values()) {
for (SelectElement se : seList) {
if (!firstEnabledElementEncountered && se.getEnabled()) {
se.setDefault(true);
firstEnabledElementEncountered = true;
} else {
se.setDefault(false);
}
}
}
}
use of org.asqatasun.webapp.form.SelectElement in project Asqatasun by Asqatasun.
the class ContractSortCommandFactory method getInitialisedContractDisplayCommand.
/**
*
* @param userId
* @param formFieldList
* @return
* An initialised auditCommand object for the given contract. This object
* handles the last values selected by the user
*/
public ContractSortCommand getInitialisedContractDisplayCommand(Long userId, List<FormField> formFieldList) {
ContractSortCommand contractDisplayCommand = new ContractSortCommand();
for (FormField ff : formFieldList) {
if (ff instanceof SelectFormField) {
for (Map.Entry<String, List<SelectElement>> entry : ((SelectFormField) ff).getSelectElementMap().entrySet()) {
for (SelectElement se : entry.getValue()) {
if (se.getDefaultElement() && se.getEnabled()) {
contractDisplayCommand.getSortOptionMap().put(entry.getKey(), se.getValue());
}
}
}
} else if (ff instanceof TextualFormField) {
contractDisplayCommand.getSortOptionMap().put(((TextualFormField) ff).getI18nKey(), ((TextualFormField) ff).getValue());
}
}
contractDisplayCommand.setUserId(userId);
return contractDisplayCommand;
}
use of org.asqatasun.webapp.form.SelectElement in project Asqatasun by Asqatasun.
the class SelectElementBuilderImpl method build.
@Override
public SelectElement build() {
SelectElement formField = new SelectElementImpl();
formField.setErrorI18nKey(getErrorI18nKey());
formField.setI18nKey(getI18nKey());
formField.setValue(getValue());
formField.setDefault(isDefaultElement);
formField.setDefaultCode(defaultCode);
formField.setEnabled(isEnabled);
return formField;
}
Aggregations