All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.grails.scaffolding.registry.input.CurrencyInputRenderer.groovy Maven / Gradle / Ivy

The newest version!
package org.grails.scaffolding.registry.input

import org.grails.scaffolding.model.property.DomainProperty
import org.grails.scaffolding.registry.DomainInputRenderer
import groovy.transform.CompileStatic

/**
 * The default renderer for rendering {@link Currency} properties
 *
 * @author James Kleeh
 */
@CompileStatic
class CurrencyInputRenderer implements MapToSelectInputRenderer {

    String getOptionValue(Currency currency) {
        currency.currencyCode
    }

    String getOptionKey(Currency currency) {
        currency.currencyCode
    }

    protected List getDefaultCurrencyCodes() {
        ['EUR', 'XCD', 'USD', 'XOF', 'NOK', 'AUD',
         'XAF', 'NZD', 'MAD', 'DKK', 'GBP', 'CHF',
         'XPF', 'ILS', 'ROL', 'TRL']
    }

    Map getOptions() {
        defaultCurrencyCodes.collectEntries {
            Currency currency = Currency.getInstance(it)
            [(getOptionKey(currency)): getOptionValue(currency)]
        }
    }

    Currency getDefaultOption() {
        Currency.getInstance(Locale.default)
    }

    @Override
    boolean supports(DomainProperty property) {
        property.type in Currency
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy