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;
}
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);
}
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);
}
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));
}
}
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));
}
}
Aggregations