Tabnine Logo
Datatypes
Code IndexAdd Tabnine to your IDE (free)

How to use
Datatypes
in
com.haulmont.chile.core.datatypes

Best Java code snippets using com.haulmont.chile.core.datatypes.Datatypes (Showing top 20 results out of 315)

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-rest-api

protected Datatype getDatatype(Class clazz) {
  if (clazz == Integer.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE) return Datatypes.get(Integer.class);
  if (clazz == Long.TYPE) return Datatypes.get(Long.class);
  if (clazz == Boolean.TYPE) return Datatypes.get(Boolean.class);
  return Datatypes.get(clazz);
}
origin: com.haulmont.cuba/cuba-gui

  @Override
  public String apply(Number value) {
    if (value == null) {
      return null;
    }
    String pattern = element != null ? element.attributeValue("format") : null;

    if (pattern == null) {
      Datatype datatype = Datatypes.getNN(value.getClass());
      return datatype.format(value, userSessionSource.getLocale());
    } else {
      if (pattern.startsWith("msg://")) {
        pattern = messages.getMainMessage(pattern.substring(6, pattern.length()));
      }
      FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale());
      if (formatStrings == null)
        throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale());
      DecimalFormat format = new DecimalFormat(pattern, formatStrings.getFormatSymbols());
      return format.format(value);
    }
  }
}
origin: com.haulmont.cuba/cuba-gui

private void loadProperties(Element element, KeyValueContainer container) {
  Element propsEl = element.element("properties");
  if (propsEl != null) {
    for (Element propEl : propsEl.elements()) {
      String name = propEl.attributeValue("name");
      String className = propEl.attributeValue("class");
      if (className != null) {
        container.addProperty(name, ReflectionHelper.getClass(className));
      } else {
        String typeName = propEl.attributeValue("datatype");
        Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName);
        container.addProperty(name, datatype);
      }
    }
    String idProperty = propsEl.attributeValue("idProperty");
    if (idProperty != null) {
      if (container.getEntityMetaClass().getProperty(idProperty) == null)
        throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty));
      container.setIdName(idProperty);
    }
  }
}
origin: com.haulmont.fts/fts-global

private Object tryDate(String value) {
  UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME);
  FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale());
  SimpleDateFormat sdf = new SimpleDateFormat(formatStrings.getDateFormat());
  try {
    Date date = sdf.parse(value);
    return date;
  } catch (ParseException e) {
    return null;
  }
}
origin: com.haulmont.cuba/cuba-core

  public String[] getAvailableBasicTypes() {
    Set<String> allAvailableTypes = Datatypes.getIds();
    TreeSet<String> availableTypes = new TreeSet<>();

    //byteArray is not supported as a GET parameter
    for (String type : allAvailableTypes)
      if (!"byteArray".equals(type))
        availableTypes.add(type);

    return availableTypes.toArray(new String[availableTypes.size()]);
  }
}
origin: com.haulmont.cuba/cuba-gui

  public static String formatParamValue(Param param, Object value) {
    //noinspection unchecked
    Datatype datatype = Datatypes.get(param.getJavaClass());
    MetaProperty property = param.getProperty();
    if (property != null) {
      TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME);
      if (tt == TemporalType.DATE) {
        datatype = Datatypes.getNN(java.sql.Date.class);
      }
    }
    if (datatype != null) {
      UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.class);
      return datatype.format(value, userSessionSource.getLocale());
    }
    return value.toString();
  }
}
origin: com.haulmont.fts/fts-global

  private Object tryNumber(String value) {
    UserSessionSource userSession = AppBeans.get(UserSessionSource.NAME);
    FormatStrings formatStrings = Datatypes.getFormatStrings(userSession.getLocale());
    char decimalSeparator = formatStrings.getFormatSymbols().getDecimalSeparator();
    char groupingSeparator = formatStrings.getFormatSymbols().getGroupingSeparator();
    if (decimalSeparator != '.')
      value = value.replace(decimalSeparator, '.');
    if (groupingSeparator != ',')
      value = value.replace(groupingSeparator, ',');

    if (!Character.isDigit(value.charAt(0)) || value.startsWith("0"))
      return null;

    try {
      Number number = new BigDecimal(value);
      return number;
    } catch (NumberFormatException e) {
      return null;
    }
  }
}
origin: com.haulmont.cuba/cuba-gui

  @Override
  public Component generateField(Datasource datasource, String propertyId) {
    LookupField lookup = AppConfig.getFactory().createComponent(LookupField.class);
    lookup.setDatasource(datasource, propertyId);
    lookup.setRequiredMessage(getMessage("datatypeMsg"));
    lookup.setRequired(true);
    lookup.setPageLength(15);
    Map<String, Object> options = new TreeMap<>();
    String mainMessagePack = AppConfig.getMessagesPack();
    for (String datatypeId : Datatypes.getIds()) {
      options.put(messages.getMessage(mainMessagePack, "Datatype." + datatypeId), datatypeId);
    }
    lookup.setOptionsMap(options);
    return lookup;
  }
}
origin: com.haulmont.cuba/cuba-rest-api

private static Object parseByDatatype(String value, Class<?> type) throws ParseException {
  Datatype datatype = Datatypes.getNN(type);
  return datatype.parse(value);
}
origin: com.haulmont.cuba/cuba-rest-api

protected Datatype getDatatype(Class clazz) {
  if (clazz == Integer.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE) return Datatypes.get(Integer.class);
  if (clazz == Long.TYPE) return Datatypes.get(Long.class);
  if (clazz == Boolean.TYPE) return Datatypes.get(Boolean.class);
  return Datatypes.get(clazz);
}
origin: com.haulmont.cuba/cuba-gui

private void loadProperties(Element element, ValueDatasource datasource) {
  Element propsEl = element.element("properties");
  if (propsEl != null) {
    for (Element propEl : Dom4j.elements(propsEl)) {
      String name = propEl.attributeValue("name");
      String className = propEl.attributeValue("class");
      if (className != null) {
        datasource.addProperty(name, ReflectionHelper.getClass(className));
      } else {
        String typeName = propEl.attributeValue("datatype");
        Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName);
        datasource.addProperty(name, datatype);
      }
    }
    String idProperty = propsEl.attributeValue("idProperty");
    if (idProperty != null) {
      if (datasource.getMetaClass().getProperty(idProperty) == null)
        throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty));
      datasource.setIdName(idProperty);
    }
  }
}
origin: com.haulmont.cuba/cuba-gui

String type = element.attributeValue("type");
if (type != null) {
  FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale());
  if (formatStrings == null)
    throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale());
origin: com.haulmont.cuba/cuba-gui

protected String formatSingleValue(Object v) {
  switch (type) {
    case ENTITY:
      if (v instanceof UUID)
        return v.toString();
      else if (v instanceof Entity)
        return ((Entity) v).getId().toString();
    case ENUM:
      return ((Enum) v).name();
    case RUNTIME_ENUM:
    case DATATYPE:
    case UNARY:
      if (isDateInterval) return (String) v;
      //noinspection unchecked
      Datatype<Object> datatype = Datatypes.getNN(javaClass);
      return datatype.format(v);
    default:
      throw new IllegalStateException("Param type unknown");
  }
}
origin: com.haulmont.cuba/cuba-global

public DateSerializer() {
  dateDatatype = Datatypes.get(Date.class);
}
origin: com.haulmont.charts/charts-web

FormatStrings formatStrings = Datatypes.getFormatStrings(locale);
origin: com.haulmont.cuba/cuba-rest-api

if (Integer.class == clazz || Integer.TYPE == clazz
    || Byte.class == clazz || Byte.TYPE == clazz
    || Short.class == clazz || Short.TYPE == clazz) return Datatypes.getNN(Integer.class).parse(value);
if (Date.class == clazz) {
  try {
    return Datatypes.getNN(Date.class).parse(value);
  } catch (ParseException e) {
    try {
      return Datatypes.getNN(java.sql.Date.class).parse(value);
    } catch (ParseException e1) {
      return Datatypes.getNN(Time.class).parse(value);
if (BigDecimal.class == clazz) return Datatypes.getNN(BigDecimal.class).parse(value);
if (Boolean.class == clazz || Boolean.TYPE == clazz) return Datatypes.getNN(Boolean.class).parse(value);
if (Long.class == clazz || Long.TYPE == clazz) return Datatypes.getNN(Long.class).parse(value);
if (Double.class == clazz || Double.TYPE == clazz
    || Float.class == clazz || Float.TYPE == clazz) return Datatypes.getNN(Double.class).parse(value);
if (UUID.class == clazz) return UUID.fromString(value);
throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported");
origin: com.haulmont.cuba/cuba-global

public DateDeserializer() {
  dateDatatype = Datatypes.get(Date.class);
}
origin: com.haulmont.charts/charts-web

protected void setupFormatStrings(List<StockPanel> panels) {
  FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale());
  if (formatStrings != null) {
    for (StockPanel panel : panels) {
      DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
      if (panel.getPrecision() == null) {
        panel.setPrecision(-1);
      }
      if (panel.getPercentPrecision() == null) {
        panel.setPercentPrecision(2);
      }
      if (panel.getDecimalSeparator() == null) {
        panel.setDecimalSeparator(Character.toString(formatSymbols.getDecimalSeparator()));
      }
      if (panel.getThousandsSeparator() == null) {
        panel.setThousandsSeparator(Character.toString(formatSymbols.getGroupingSeparator()));
      }
    }
  }
}
origin: com.haulmont.cuba/cuba-rest-api

  || Byte.class == clazz || Byte.TYPE == clazz
  || Short.class == clazz || Short.TYPE == clazz) {
return Datatypes.getNN(Integer.class).parse(value);
  return Datatypes.getNN(Date.class).parse(value);
} catch (ParseException e) {
  try {
    return Datatypes.getNN(java.sql.Date.class).parse(value);
  } catch (ParseException e1) {
    return Datatypes.getNN(Time.class).parse(value);
return Datatypes.getNN(BigDecimal.class).parse(value);
return Datatypes.getNN(Boolean.class).parse(value);
return Datatypes.getNN(Long.class).parse(value);
return Datatypes.getNN(Double.class).parse(value);
com.haulmont.chile.core.datatypesDatatypes

Javadoc

Utility class for accessing datatypes and format strings. Consider using DatatypeRegistry and FormatStringsRegistry beans directly.

Most used methods

  • getNN
    Get Datatype instance by the corresponding Java class. This method tries to find matching supertype
  • get
    Get Datatype instance by its unique name
  • getFormatStrings
    Returns localized format strings.
  • getIds
  • getDatatypeRegistry
  • getFormatStringsRegistry

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • getSharedPreferences (Context)
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • JPanel (javax.swing)
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now