本文整理了Java中com.haulmont.chile.core.datatypes.Datatype.format()
方法的一些代码示例,展示了Datatype.format()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datatype.format()
方法的具体详情如下:
包路径:com.haulmont.chile.core.datatypes.Datatype
类名称:Datatype
方法名:format
[英]Converts value to String. Returns an empty string for null value.
[中]将值转换为字符串。返回空值的空字符串。
代码示例来源:origin: com.haulmont.cuba/cuba-global
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
String formattedDate = dateDatatype.format(src);
return new JsonPrimitive(formattedDate);
}
}
代码示例来源:origin: com.haulmont.charts/charts-web
protected String getDateTimeFormattedValue(Object value, Locale locale) {
return Datatypes.getNN(Date.class).format(value, locale);
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
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;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
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));
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.reports/reports-core
@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);
}
}
}
代码示例来源:origin: com.haulmont.reports/reports-core
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));
}
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-web
@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));
}
代码示例来源:origin: com.haulmont.cuba/cuba-web
@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));
}
代码示例来源:origin: com.haulmont.bpm/bpm-global
@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 + ")";
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
@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);
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
/**
* 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());
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
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()));
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-gui
@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);
}
内容来源于网络,如有侵权,请联系作者删除!