@Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { String formattedDate = dateDatatype.format(src); return new JsonPrimitive(formattedDate); } }
protected String getDateTimeFormattedValue(Object value, Locale locale) { return Datatypes.getNN(Date.class).format(value, locale); }
/** * Format Date (date without time) using {@code dateFormat} string specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatDate(@Nullable Date value) { return datatypeRegistry.getNN(java.sql.Date.class).format(value, uss.getLocale()); }
protected JsonArray serializeSimpleCollection(Collection fieldValue, MetaProperty property) { JsonArray jsonArray = new JsonArray(); fieldValue.stream() .forEach(item -> { if (item instanceof Number) { jsonArray.add((Number) item); } else if (item instanceof Boolean) { jsonArray.add((Boolean) item); } else { Datatype datatype = property.getRange().asDatatype(); jsonArray.add(datatype.format(item)); } }); return jsonArray; } }
/** * Format Date (time without date) using {@code timeFormat} string specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatTime(@Nullable Date value) { return datatypeRegistry.getNN(Time.class).format(value, uss.getLocale()); }
/** * Format BigDecimal using {@code decimalFormat} string specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatBigDecimal(@Nullable BigDecimal value) { return datatypeRegistry.getNN(BigDecimal.class).format(value, uss.getLocale()); }
/** * Format Boolean using {@code trueString} and {@code falseString} strings specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatBoolean(@Nullable Boolean value) { return datatypeRegistry.getNN(Boolean.class).format(value, uss.getLocale()); }
/** * Format Long using {@code integerFormat} string specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatLong(@Nullable Long value) { return datatypeRegistry.getNN(Long.class).format(value, uss.getLocale()); }
protected void writeSimpleProperty(JsonObject jsonObject, @NotNull Object fieldValue, MetaProperty property) { String propertyName = property.getName(); if (fieldValue instanceof Number) { jsonObject.addProperty(propertyName, (Number) fieldValue); } else if (fieldValue instanceof Boolean) { jsonObject.addProperty(propertyName, (Boolean) fieldValue); } else { Datatype datatype = property.getRange().asDatatype(); jsonObject.addProperty(propertyName, datatype.format(fieldValue)); } }
/** * Format Double using {@code doubleFormat} string specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatDouble(@Nullable Double value) { return datatypeRegistry.getNN(Double.class).format(value, uss.getLocale()); }
/** * Format Integer using {@code integerFormat} string specified in the main message pack. * @return string representation or empty string if the value is null */ public String formatInteger(@Nullable Integer value) { return datatypeRegistry.getNN(Integer.class).format(value, uss.getLocale()); }
@Override public String convertToString(Class parameterClass, Object paramValue) { if (paramValue == null) { return null; } else if (String.class.isAssignableFrom(parameterClass)) { return (String) paramValue; } else if (Entity.class.isAssignableFrom(parameterClass)) { return EntityLoadInfo.create((Entity) paramValue).toString(); } else { Datatype datatype = Datatypes.get(parameterClass); if (datatype != null) { return datatype.format(paramValue); } else { return String.valueOf(paramValue); } } }
protected void writeSimpleProperty(JsonWriter out, Entity entity, MetaProperty property) throws IOException { Object value = entity.getValue(property.getName()); if (value != null) { out.name(property.getName()); Datatype datatype = Datatypes.get(property.getJavaType()); if (datatype != null) { out.value(datatype.format(value)); } else { out.value(String.valueOf(value)); } } }
@Override protected String convertToPresentation(V modelValue) throws ConversionException { // Vaadin TextField does not permit `null` value if (datatype != null) { return nullToEmpty(datatype.format(modelValue, locale)); } if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) { EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource(); Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype(); return nullToEmpty(propertyDataType.format(modelValue)); } return nullToEmpty(super.convertToPresentation(modelValue)); }
@Override protected String convertToPresentation(V modelValue) throws ConversionException { Datatype<V> datatype = getDatatypeInternal(); // Vaadin TextField does not permit `null` value if (datatype != null) { return nullToEmpty(datatype.format(modelValue, locale)); } if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) { EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource(); Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype(); return nullToEmpty(propertyDataType.format(modelValue, locale)); } return nullToEmpty(super.convertToPresentation(modelValue)); }
@MetaProperty public String getCaption() { Locale defaultLocale = AppBeans.get(MessageTools.class).getDefaultLocale(); String formattedDeploymentDate = Datatypes.getNN(Date.class).format(deploymentDate, defaultLocale); return this.name + " (" + this.code + " - " + formattedDeploymentDate + ")"; } }
@MetaProperty(related = {"snapshotDate,author"}) public String getLabel() { String name = ""; if (author != null && StringUtils.isNotEmpty(this.author.getCaption())) { name += this.author.getCaption() + " "; } Datatype datatype = Datatypes.getNN(Date.class); UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME); if (userSessionSource != null && userSessionSource.checkCurrentUserSession()) { name += datatype.format(snapshotDate, userSessionSource.getLocale()); } return StringUtils.trim(name); }
/** * Format Date (date and time) using {@code dateTimeFormat} string specified in the main message pack. * <p>Takes into account time zone if it is set for the current user session.</p> * @return string representation or empty string if the value is null */ public String formatDateTime(@Nullable Date value) { TimeZone timeZone = uss.getUserSession().getTimeZone(); Datatype<Date> datatype = datatypeRegistry.getNN(Date.class); if (datatype instanceof DateTimeDatatype) { return ((DateTimeDatatype) datatype).format(value, uss.getLocale(), timeZone); } return datatype.format(value, uss.getLocale()); }
protected void writeIdField(Entity entity, JsonObject jsonObject) { MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(entity.getMetaClass()); if (primaryKeyProperty == null) { primaryKeyProperty = entity.getMetaClass().getProperty("id"); } if (primaryKeyProperty == null) throw new EntitySerializationException("Primary key property not found for entity " + entity.getMetaClass()); if (metadataTools.hasCompositePrimaryKey(entity.getMetaClass())) { JsonObject serializedIdEntity = serializeEntity((Entity) entity.getId(), null, Collections.emptySet()); jsonObject.add("id", serializedIdEntity); } else { Datatype idDatatype = Datatypes.getNN(primaryKeyProperty.getJavaType()); jsonObject.addProperty("id", idDatatype.format(entity.getId())); } }
@Override public void init(Map<String, Object> params) { super.init(params); sessionsTable.setTextSelectionEnabled(true); sessionsDs.addCollectionChangeListener(e -> { String time = Datatypes.getNN(Date.class).format(sessionsDs.getUpdateTs(), userSessionSource.getLocale()); lastUpdateTsLab.setValue(time); }); addAction(refreshAction); }