List of usage examples for com.vaadin.ui AbstractComponent setDescription
public void setDescription(String description)
From source file:uk.co.q3c.v7.i18n.AnnotationI18NTranslator.java
License:Apache License
private void decodeAnnotation(I18NListener listener, Field field, Annotation annotation, Provider<? extends I18NAnnotationReader> provider) { // get a reader I18NAnnotationReader reader = provider.get(); // get the keys from the reader I18NKey<?> captionKey = reader.caption(annotation); I18NKey<?> descriptionKey = reader.description(annotation); I18NKey<?> valueKey = reader.value(annotation); // check for nulls. Nulls are used for caption and description so that content can be cleared. // for value, this is not the case, as it may be a bad idea String captionValue = captionKey.isNullKey() ? null : captionKey.getValue(currentLocale.getLocale()); String descriptionValue = descriptionKey.isNullKey() ? null : descriptionKey.getValue(currentLocale.getLocale()); // set caption and description field.setAccessible(true);/*from www . j a va2 s . c o m*/ try { AbstractComponent c = (AbstractComponent) field.get(listener); if (captionValue != null) { c.setCaption(captionValue); } if (descriptionValue != null) { c.setDescription(descriptionValue); } c.setLocale(currentLocale.getLocale()); } catch (IllegalArgumentException | IllegalAccessException e) { log.error("Unable to set I18N caption or description for " + field.getName(), e); } // These components have a value. Usually I18N would only be used for Label values. If no key is provided // the component value is left unchanged if (valueKey != null) { if (Property.class.isAssignableFrom(field.getType())) { try { @SuppressWarnings("unchecked") Property<String> c = (Property<String>) field.get(listener); String valueValue = valueKey.isNullKey() ? null : valueKey.getValue(currentLocale.getLocale()); if (valueValue != null) { c.setValue(valueValue); } } catch (Exception e) { log.error("Unable to set I18N value for " + field.getName(), e); } } } // Table columns need special treatment if (Table.class.isAssignableFrom(field.getType())) { try { Table table = (Table) field.get(listener); Object[] columns = table.getVisibleColumns(); List<String> headers = new ArrayList<>(); for (Object column : columns) { if (column instanceof LabelKey) { LabelKey columnid = (LabelKey) column; String header = columnid.getValue(currentLocale.getLocale()); headers.add(header); } else { headers.add(column.toString()); } } String headerArray[] = headers.toArray(new String[] {}); table.setColumnHeaders(headerArray); } catch (Exception e) { log.error("Unable to set I18N table columns headers for " + field.getName(), e); } } }
From source file:uk.q3c.krail.core.i18n.DefaultI18NProcessor.java
License:Apache License
/** * Applies annotation values to {@code component} * * @param component the component to be updated * @param annotationValues the annotation values to apply * @param annotationInfo used primarily to identify the Field, and therefore its name *//* w ww . j a va 2s . c om*/ private void applyAnnotationValues(AbstractComponent component, AnnotationValues annotationValues, AnnotationInfo annotationInfo) { // set locale first Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get() : currentLocale.getLocale(); component.setLocale(locale); // set caption, description & value if available if (annotationValues.captionKey.isPresent()) { component.setCaption(translate.from(annotationValues.captionKey.get(), locale)); } if (annotationValues.descriptionKey.isPresent()) { component.setDescription(translate.from(annotationValues.descriptionKey.get(), locale)); } if (annotationValues.valueKey.isPresent()) { if (component instanceof HasValue) { ((HasValue) component).setValue(translate.from(annotationValues.valueKey.get(), locale)); return; } else { log.warn("Field {} has a value annotation but does not implement HasValue. Annotation ignored", annotationInfo.getField().getName()); } } }
From source file:uk.q3c.krail.i18n.DefaultI18NProcessor.java
License:Apache License
/** * Applies annotation values to {@code component} * * @param component//w ww. j av a 2 s . co m * the component to be updated * @param annotationValues * the annotation values to apply * @param annotationInfo * used primarily to identify the Field, and therefore its name */ private void applyAnnotationValues(AbstractComponent component, AnnotationValues annotationValues, AnnotationInfo annotationInfo) { // set locale first Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get() : currentLocale.getLocale(); component.setLocale(locale); // set caption, description & value if available if (annotationValues.captionKey.isPresent()) { component.setCaption(translate.from(annotationValues.captionKey.get(), locale)); } if (annotationValues.descriptionKey.isPresent()) { component.setDescription(translate.from(annotationValues.descriptionKey.get(), locale)); } if (annotationValues.valueKey.isPresent()) { if (component instanceof Property) { //noinspection unchecked ((Property) component).setValue(translate.from(annotationValues.valueKey.get(), locale)); } else { log.warn("Field {} has a value annotation but does not implement Property. Annotation ignored", annotationInfo.getField().getName()); } } }