Search in sources :

Example 6 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class FileMultiUploadFieldImpl method getFileSizeLimitString.

protected String getFileSizeLimitString() {
    String fileSizeLimitString;
    if (fileSizeLimit > 0) {
        if (fileSizeLimit % BYTES_IN_MEGABYTE == 0) {
            fileSizeLimitString = String.valueOf(fileSizeLimit / BYTES_IN_MEGABYTE);
        } else {
            DatatypeRegistry datatypeRegistry = applicationContext.getBean(DatatypeRegistry.class);
            Datatype<Double> doubleDatatype = datatypeRegistry.get(Double.class);
            double fileSizeInMb = fileSizeLimit / ((double) BYTES_IN_MEGABYTE);
            CurrentAuthentication currentAuthentication = applicationContext.getBean(CurrentAuthentication.class);
            fileSizeLimitString = doubleDatatype.format(fileSizeInMb, currentAuthentication.getLocale());
        }
    } else {
        fileSizeLimitString = String.valueOf(componentProperties.getUploadFieldMaxUploadSizeMb());
    }
    return fileSizeLimitString;
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) DatatypeRegistry(io.jmix.core.metamodel.datatype.DatatypeRegistry)

Example 7 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class CalendarImpl method initComponent.

protected void initComponent(JmixCalendar component) {
    Messages messages = applicationContext.getBean(Messages.class);
    String[] monthNamesShort = new String[12];
    monthNamesShort[0] = messages.getMessage("calendar.januaryCaption");
    monthNamesShort[1] = messages.getMessage("calendar.februaryCaption");
    monthNamesShort[2] = messages.getMessage("calendar.marchCaption");
    monthNamesShort[3] = messages.getMessage("calendar.aprilCaption");
    monthNamesShort[4] = messages.getMessage("calendar.mayCaption");
    monthNamesShort[5] = messages.getMessage("calendar.juneCaption");
    monthNamesShort[6] = messages.getMessage("calendar.julyCaption");
    monthNamesShort[7] = messages.getMessage("calendar.augustCaption");
    monthNamesShort[8] = messages.getMessage("calendar.septemberCaption");
    monthNamesShort[9] = messages.getMessage("calendar.octoberCaption");
    monthNamesShort[10] = messages.getMessage("calendar.novemberCaption");
    monthNamesShort[11] = messages.getMessage("calendar.decemberCaption");
    component.setMonthNamesShort(monthNamesShort);
    String[] dayNamesShort = new String[7];
    dayNamesShort[0] = messages.getMessage("calendar.sundayCaption");
    dayNamesShort[1] = messages.getMessage("calendar.mondayCaption");
    dayNamesShort[2] = messages.getMessage("calendar.tuesdayCaption");
    dayNamesShort[3] = messages.getMessage("calendar.wednesdayCaption");
    dayNamesShort[4] = messages.getMessage("calendar.thursdayCaption");
    dayNamesShort[5] = messages.getMessage("calendar.fridayCaption");
    dayNamesShort[6] = messages.getMessage("calendar.saturdayCaption");
    component.setDayNamesShort(dayNamesShort);
    if (TIME_FORMAT_12H.equals(messages.getMessage("calendar.timeFormat"))) {
        setTimeFormat(TimeFormat.FORMAT_12H);
    } else if (TIME_FORMAT_24H.equals(messages.getMessage("calendar.timeFormat"))) {
        setTimeFormat(TimeFormat.FORMAT_24H);
    } else {
        throw new IllegalStateException(String.format("Can't set time format '%s'", messages.getMessage("calendar.timeFormat")));
    }
    CurrentAuthentication currentAuthentication = applicationContext.getBean(CurrentAuthentication.class);
    TimeZone userTimeZone = currentAuthentication.getTimeZone();
    setTimeZone(userTimeZone);
    setNavigationButtonsStyle(navigationButtonsVisible);
}
Also used : Messages(io.jmix.core.Messages) CurrentAuthentication(io.jmix.core.security.CurrentAuthentication)

Example 8 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class TimeFieldImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    CurrentAuthentication currentAuthentication = applicationContext.getBean(CurrentAuthentication.class);
    FormatStringsRegistry formatStringsRegistry = applicationContext.getBean(FormatStringsRegistry.class);
    String timeFormat = formatStringsRegistry.getFormatStrings(currentAuthentication.getLocale()).getTimeFormat();
    setFormat(timeFormat);
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) FormatStringsRegistry(io.jmix.core.metamodel.datatype.FormatStringsRegistry)

Example 9 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class DateValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    if (value == null)
        return;
    boolean result;
    if (value instanceof String) {
        try {
            Datatype datatype = Datatypes.getNN(java.sql.Date.class);
            CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
            datatype.parse((String) value, currentAuthentication.getLocale());
            result = true;
        } catch (ParseException e) {
            result = false;
        }
    } else {
        result = value instanceof Date;
    }
    if (!result) {
        String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ValidationException(io.jmix.ui.component.ValidationException) ParseException(java.text.ParseException) Date(java.util.Date) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 10 with CurrentAuthentication

use of io.jmix.core.security.CurrentAuthentication in project jmix by jmix-framework.

the class DoubleValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    if (value == null) {
        return;
    }
    boolean result;
    if (value instanceof String) {
        try {
            Datatype<Double> datatype = Datatypes.getNN(Double.class);
            CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
            Double num = datatype.parse((String) value, currentAuthentication.getLocale());
            result = checkDoubleOnPositive(num);
        } catch (ParseException e) {
            result = false;
        }
    } else {
        result = (value instanceof Double && checkDoubleOnPositive((Double) value)) || (value instanceof BigDecimal && checkBigDecimalOnPositive((BigDecimal) value));
    }
    if (!result) {
        String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) ValidationException(io.jmix.ui.component.ValidationException) ParseException(java.text.ParseException) BigDecimal(java.math.BigDecimal)

Aggregations

CurrentAuthentication (io.jmix.core.security.CurrentAuthentication)10 ValidationException (io.jmix.ui.component.ValidationException)4 ParseException (java.text.ParseException)4 DatatypeRegistry (io.jmix.core.metamodel.datatype.DatatypeRegistry)2 FormatStringsRegistry (io.jmix.core.metamodel.datatype.FormatStringsRegistry)2 Messages (io.jmix.core.Messages)1 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 AppUI (io.jmix.ui.AppUI)1 TimeZoneIndicatorSupport (io.jmix.ui.component.mainwindow.TimeZoneIndicatorSupport)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1