@Override public Class<?> getType() { return propertyDataSource.getType(); }
@Override public Object parse(String formattedValue) throws Exception { if ("".equals(formattedValue)){ return null; } return ConvertUtils.convert(formattedValue, map.get(newDataSource.getType())); } };
/** * Construct a new formatter that is connected to given data source. Calls * {@link #format(Object)} which can be a problem if the formatter has not * yet been initialized. * * @param propertyDataSource * to connect this property to. */ public PropertyConverter(Property propertyDataSource) { setPropertyDataSource(propertyDataSource); propertyClass = (Class<? extends PC>) propertyDataSource.getType(); }//new
if (newDataSource.getType().isPrimitive() && newDataSource instanceof ObjectProperty) { try { Field[] fields = newDataSource.getClass().getSuperclass().getDeclaredFields();
private synchronized void loadPropertiesIfNull() { if (m_properties == null) { m_properties = new TreeMap<Object,Class<?>>(); BeanItem<T> item = null; try { item = new BeanItem<T>(m_datasource.createInstance(m_itemClass)); } catch (InstantiationException e) { LoggerFactory.getLogger(getClass()).error("Class {} does not have a default constructor. Cannot create an instance.", getItemClass()); } catch (IllegalAccessException e) { LoggerFactory.getLogger(getClass()).error("Class {} does not have a public default constructor. Cannot create an instance.", getItemClass()); } for (Object key : item.getItemPropertyIds()) { m_properties.put(key, item.getItemProperty(key).getType()); } } } }
private synchronized void loadPropertiesIfNull() { if (m_properties == null) { m_properties = new TreeMap<Object,Class<?>>(); BeanItem<T> item = null; try { item = new BeanItem<T>(m_datasource.createInstance(m_itemClass)); } catch (InstantiationException e) { LoggerFactory.getLogger(getClass()).error("Class {} does not have a default constructor. Cannot create an instance.", getItemClass()); } catch (IllegalAccessException e) { LoggerFactory.getLogger(getClass()).error("Class {} does not have a public default constructor. Cannot create an instance.", getItemClass()); } for (Object key : item.getItemPropertyIds()) { m_properties.put(key, item.getItemProperty(key).getType()); } } } }
/** * Expands nested bean properties by replacing a top-level property with * some or all of its sub-properties. The expansion is not recursive. * * @param propertyId * property id for the property whose sub-properties are to be * expanded, * @param subPropertyIds * sub-properties to expand, all sub-properties are expanded if * not specified */ public void expandProperty(final String propertyId, final String... subPropertyIds) { Set<String> subPropertySet = new HashSet<String>( Arrays.asList(subPropertyIds)); if (0 == subPropertyIds.length) { // Enumerate all sub-properties Class<?> propertyType = getItemProperty(propertyId).getType(); Map<String, ?> pds = getPropertyDescriptors(propertyType); subPropertySet.addAll(pds.keySet()); } for (String subproperty : subPropertySet) { String qualifiedPropertyId = propertyId + "." + subproperty; addNestedProperty(qualifiedPropertyId); } }
@Override public Object generateCell(Table source, Object itemId, Object columnId) { Property property = source.getContainerProperty(itemId, columnId); if (property == null || property.getValue() == null) { return null; } String formattedValue; if(property.getType().equals(Instant.class)){ formattedValue = timeformatService.format((Instant) property.getValue(), UserTimeZoneExtractor.extractUserTimeZoneIdOrNull()); } else if(property.getType().equals(Date.class)){ formattedValue = timeformatService.format((Date) property.getValue(), UserTimeZoneExtractor.extractUserTimeZoneIdOrNull()); } else { formattedValue = property.toString(); } return formattedValue; } }
protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) { // Format by property type Formatter formatter = FormatterFactory.getFormatter(property.getType()); if (formatter != null) { // setColumnAlignment(colId, Table.ALIGN_RIGHT); return formatter.format(property.getValue()); } return super.formatPropertyValue(rowId, colId, property); }
@Override public Field createField(Item item, Object propertyId, Component uiContext) { Class<?> type = item.getItemProperty(propertyId).getType(); Field field = createFieldByPropertyType(type); field.setCaption(createCaptionByPropertyId(propertyId)); return field; }
protected String formatPropertyValue(Object rowId, Object colId, Property property) { // Format by property type Formatter formatter = FormatterFactory.getFormatter(property.getType()); if (formatter != null) { // setColumnAlignment(colId, Table.ALIGN_RIGHT); return formatter.format(property.getValue()); } return super.formatPropertyValue(rowId, colId, property); }
@SuppressWarnings("unchecked") @Override public void setPropertyDataSource(@SuppressWarnings("rawtypes") Property newDataSource) { // Stops listening the old data source changes if (dataSource != null && Property.ValueChangeNotifier.class.isAssignableFrom(dataSource.getClass())) { ((Property.ValueChangeNotifier) dataSource).removeValueChangeListener(this); } // Check if the current converter is compatible. if (newDataSource != null && !ConverterUtil.canConverterPossiblyHandle(getConverter(), getType(), newDataSource.getType())) { // There is no converter set or there is no way the current converter can be compatible Converter<T, Object> c = ConverterUtil.getConverter(getType(), newDataSource.getType(), getSession()); setConverter(c); } dataSource = newDataSource; if (dataSource != null) { // Update value from the data source updateValueFromDataSource(); } // Listens the new data source if (dataSource != null && Property.ValueChangeNotifier.class.isAssignableFrom(dataSource.getClass())) { ((Property.ValueChangeNotifier) dataSource).addValueChangeListener(this); } markAsDirty(); }
component.setReadOnly(false); if (Date.class.isAssignableFrom(component.getType())) { DateWidgetElement dwe = Lang2.assumeType(element, DateWidgetElement.class); Date v = new SimpleDateFormat(dwe.getFormat()).parse(String.valueOf(value)); component.setValue(v); } else if (String.class.isAssignableFrom(component.getType())) { component.setValue(nvl(value, "")); } else if (component instanceof Container && component.getType().isAssignableFrom(value.getClass())) { if (((Container) component).containsId(value)) { component.setValue(value);
Class<?> componentPropertyType = property.getType(); @SuppressWarnings( "unchecked" ) Converter<Object, Object> setValueConverter = (Converter<Object, Object>) getConverter( toInspectPropertyType, componentPropertyType );
Converter<Object, Object> getValueConverter = (Converter<Object, Object>) getConverter( property.getType(), toInspectPropertyType );
@Override public Field createField(Item item, Object propertyId, Component uiContext) { Property property = item.getItemProperty(propertyId); Class<?> cls = property.getType(); Class[] supported = new Class[]{String.class, Boolean.class, Integer.class}; if (!Arrays.asList(supported).contains(cls)) {