use of com.vaadin.data.util.ObjectProperty in project opennms by OpenNMS.
the class SelectableItem method getPropertyDescriptors.
/**
* <b>Note:</b>This method is simmilar to
* {@link com.vaadin.data.util.BeanItem#getPropertyDescriptors(java.lang.Class)
* }
* but adds an additional <code>VaadinPropertyDescriptor</codE> to support a
* "is selectable" feature. Because the earlier mentioned method is static,
* we cannot overwrite it. Therefore I decided to implement it in my own
* way.<br/>
* <br/>
*
* <b>In short:</b> It lookups all methods which fullfill the java bean
* convention of <code>clazz</code> and builds accessors for it (read
* method, write method, etc. for a field, etc. Have a look at
* {@link java.beans.Introspector}). And in addition we a new "accessor" for
* a selectable item is added.<br/>
* <br/>
*
* <b>In detail:</b><br/>
* {@link java.beans.Introspector} is used to get all PropertyDescriptors
* from the given class <code>clazz</code>. Each PropertyDescriptor is
* converted to a vaadin <code>MethodPropertyDescriptor</code>(
* {@link com.vaadin.data.util.MethodPropertyDescriptor} is created. In
* addition a VaadinPropertyDescriptor is added to provide the "select"
* feature. For this we use the <code>ObjectProperty</code> of vaadin. <br/>
* <br/>
*
* The build map is a mapping between property names and the
* <code>VaadinPropertyDescriptor</code>s, whereby
* {@link com.vaadin.data.util.VaadinPropertyDescriptor#getName()} is
* identically with the key of the returned map (and therefore represents
* the property name).
*
* @param <T>
* @param clazz
* @return
*/
protected static <T> Map<String, VaadinPropertyDescriptor> getPropertyDescriptors(Class<? super T> clazz) {
Map<String, VaadinPropertyDescriptor> mpdMap = new HashMap<String, VaadinPropertyDescriptor>();
try {
// add all available method property descriptors
for (PropertyDescriptor pd : Introspector.getBeanInfo(clazz).getPropertyDescriptors()) {
MethodPropertyDescriptor mpd = new MethodPropertyDescriptor<T>(pd.getName(), pd.getPropertyType(), pd.getReadMethod(), pd.getWriteMethod());
mpdMap.put(pd.getName(), mpd);
}
// add selected property descriptor
mpdMap.put("selected", new VaadinPropertyDescriptor<T>() {
@Override
public String getName() {
return "selected";
}
@Override
public Class<?> getPropertyType() {
return Boolean.class;
}
@Override
public com.vaadin.data.Property createProperty(T value) {
return new ObjectProperty(false, Boolean.class, false);
}
});
} catch (IntrospectionException ex) {
LOG.warn("Error while introspecting class '{}'. Will continue anyway, result may not be complete.", clazz);
}
return mpdMap;
}
Aggregations