Search in sources :

Example 1 with SelectElement

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());
        }
    }
}
Also used : SelectElement(org.asqatasun.webapp.form.SelectElement) OptionElement(org.asqatasun.webapp.entity.option.OptionElement)

Example 2 with SelectElement

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);
            }
        }
    }
}
Also used : SelectElement(org.asqatasun.webapp.form.SelectElement)

Example 3 with SelectElement

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;
}
Also used : SelectElement(org.asqatasun.webapp.form.SelectElement) TextualFormField(org.asqatasun.webapp.form.TextualFormField) List(java.util.List) SelectFormField(org.asqatasun.webapp.form.SelectFormField) FormField(org.asqatasun.webapp.form.FormField) TextualFormField(org.asqatasun.webapp.form.TextualFormField) Map(java.util.Map) ContractSortCommand(org.asqatasun.webapp.command.ContractSortCommand) SelectFormField(org.asqatasun.webapp.form.SelectFormField)

Example 4 with SelectElement

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;
}
Also used : SelectElement(org.asqatasun.webapp.form.SelectElement) SelectElementImpl(org.asqatasun.webapp.form.SelectElementImpl)

Aggregations

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