Search in sources :

Example 1 with SelectElement

use of org.asqatasun.webapp.ui.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(ff.getI18nKey(), ff.getValue());
        }
    }
    contractDisplayCommand.setUserId(userId);
    return contractDisplayCommand;
}
Also used : SelectElement(org.asqatasun.webapp.ui.form.SelectElement) TextualFormField(org.asqatasun.webapp.ui.form.TextualFormField) List(java.util.List) FormField(org.asqatasun.webapp.ui.form.FormField) TextualFormField(org.asqatasun.webapp.ui.form.TextualFormField) SelectFormField(org.asqatasun.webapp.ui.form.SelectFormField) Map(java.util.Map) ContractSortCommand(org.asqatasun.webapp.command.ContractSortCommand) SelectFormField(org.asqatasun.webapp.ui.form.SelectFormField)

Example 2 with SelectElement

use of org.asqatasun.webapp.ui.form.SelectElement in project Asqatasun by Asqatasun.

the class SelectElementBuilderImpl method build.

@Override
public SelectElement build() {
    SelectElement formField = new SelectElement();
    formField.setErrorI18nKey(getErrorI18nKey());
    formField.setI18nKey(getI18nKey());
    formField.setValue(getValue());
    formField.setDefault(isDefaultElement);
    formField.setDefaultCode(defaultCode);
    formField.setEnabled(isEnabled);
    return formField;
}
Also used : SelectElement(org.asqatasun.webapp.ui.form.SelectElement)

Example 3 with SelectElement

use of org.asqatasun.webapp.ui.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 selElementMap
 */
private 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);
            }
        }
    }
}
Also used : SelectElement(org.asqatasun.webapp.ui.form.SelectElement)

Example 4 with SelectElement

use of org.asqatasun.webapp.ui.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 void activateSelectFormField(SelectFormField selectFormField, Collection<OptionElementImpl> optionElementSet) {
    boolean enableElements = true;
    OptionElementImpl 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());
        }
    }
}
Also used : SelectElement(org.asqatasun.webapp.ui.form.SelectElement) OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl)

Aggregations

SelectElement (org.asqatasun.webapp.ui.form.SelectElement)4 List (java.util.List)1 Map (java.util.Map)1 OptionElementImpl (org.asqatasun.entity.option.OptionElementImpl)1 ContractSortCommand (org.asqatasun.webapp.command.ContractSortCommand)1 FormField (org.asqatasun.webapp.ui.form.FormField)1 SelectFormField (org.asqatasun.webapp.ui.form.SelectFormField)1 TextualFormField (org.asqatasun.webapp.ui.form.TextualFormField)1