@Inject public void setDatatypeRegistry(DatatypeRegistry datatypeRegistry) { //noinspection unchecked this.defaultDatatype = (Datatype<V>) datatypeRegistry.get(BigDecimal.class); }
public String getDatatypesJson() { JsonArray jsonArray = new JsonArray(); try { for (String id : datatypes.getIds()) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", id); jsonObject.addProperty("name", id); // for backward compatibility Datatype datatype = datatypes.get(id); if (datatype instanceof ParameterizedDatatype) { Map<String, Object> parameters = ((ParameterizedDatatype) datatype).getParameters(); for (Map.Entry<String, Object> entry : parameters.entrySet()) { jsonObject.addProperty(entry.getKey(), entry.getValue().toString()); } } jsonArray.add(jsonObject); } } catch (Exception e) { log.error("Fail to get datatype settings", e); throw new RestAPIException("Fail to get datatype settings", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, e); } return jsonArray.toString(); } }
Datatype<?> datatype = datatypes.get(returnType); if (datatype != null) entity.setDataTypeName(datatypes.getId(datatype));
datatypeRegistry.getNN(String.class) : datatypeRegistry.get(item.getDataTypeName());
/** * Get Datatype instance by the corresponding Java class. This method tries to find matching supertype too. * @return Datatype instance or null if not found */ @Nullable public static <T> Datatype<T> get(Class<T> clazz) { return getDatatypeRegistry().get(clazz); }
/** * Get Datatype instance by its unique name * @return Datatype instance * @throws IllegalArgumentException if no datatype with the given name found */ @Nonnull public static Datatype get(String name) { return getDatatypeRegistry().get(name); }
@Nullable protected Datatype getAdaptiveDatatype(AnnotatedElement annotatedElement) { com.haulmont.chile.core.annotations.MetaProperty annotation = annotatedElement.getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class); return annotation != null && !annotation.datatype().equals("") ? datatypes.get(annotation.datatype()) : null; }
@SuppressWarnings("unchecked") @Override public <T extends Component> T create(TypeToken<T> type) { T t = (T) create((Class) type.getRawType()); if (t instanceof HasDatatype) { Type[] actualTypeArguments = ((ParameterizedType) type.getType()).getActualTypeArguments(); if (actualTypeArguments.length == 1 && actualTypeArguments[0] instanceof Class) { Class actualTypeArgument = (Class) actualTypeArguments[0]; ((HasDatatype) t).setDatatype(datatypeRegistry.get(actualTypeArgument)); } } return t; }
protected void initTextField(String dataType) { textField.setDatatype(dataType == null ? null : datatypes.get(dataType)); textField.setVisible(true); }
protected String getFormattedValue(Column<E> column, Object value) { String cellText; if (value == null) { cellText = ""; } else { if (value instanceof String) { cellText = (String) value; } else { Function<Object, String> formatter = column.getFormatter(); if (formatter != null) { cellText = formatter.apply(value); } else { Datatype datatype = datatypeRegistry.get(value.getClass()); if (datatype != null) { cellText = datatype.format(value, this.locale); } else { cellText = value.toString(); } } } } return cellText; }
protected Object getXmlAnnotationAttributeValue(String value, String className, String datatypeName) { if (className == null && datatypeName == null) return inferMetaAnnotationType(value); if (className != null) { Class aClass = ReflectionHelper.getClass(className); if (aClass.isEnum()) { //noinspection unchecked return Enum.valueOf(aClass, value); } else { throw new UnsupportedOperationException("Class " + className + " is not Enum"); } } else { try { return datatypes.get(datatypeName).parse(value); } catch (ParseException e) { throw new RuntimeException("Unable to parse XML meta-annotation value", e); } } }
/** * Formats a value according to the value type. * * @param value object to format * @return formatted value as string */ public String format(@Nullable Object value) { if (value == null) { return ""; } else if (value instanceof Instance) { return getInstanceName((Instance) value); } else if (value instanceof Enum) { return messages.getMessage((Enum) value, userSessionSource.getLocale()); } else if (value instanceof Collection) { //noinspection unchecked return ((Collection<Object>) value).stream() .map(this::format) .collect(Collectors.joining(", ")); } else { Datatype datatype = datatypeRegistry.get(value.getClass()); if (datatype != null) { return datatype.format(value, userSessionSource.getLocale()); } return value.toString(); } }
datatype = datatypes.get(type);
protected Component createTimeField(Class javaClass, final ValueProperty valueProperty) { TimeField<Object> timeField = componentsFactory.createComponent(TimeField.NAME); timeField.setDatatype(datatypeRegistry.get(javaClass)); String formatStr = messages.getMainMessage("timeFormat"); timeField.setFormat(formatStr); timeField.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty)); timeField.setValue(_getValue(valueProperty)); timeField.setWidth(theme.get("cuba.gui.filter.Param.timeComponent.width")); return timeField; }
dateField.setDatatype(datatypeRegistry.get(javaClass));