Exemple #1
0
 public static Class getNestedPropertyType(DynaClass bean, String name)
     throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
         ClassNotFoundException, NoSuchFieldException {
   // Resolve nested references
   while (resolver.hasNested(name)) {
     String next = resolver.next(name);
     if (resolver.isIndexed(next) || resolver.isMapped(next)) {
       String property = resolver.getProperty(next);
       Class<?> clazz = Class.forName(bean.getName());
       Class<?> detectTypeParameter =
           detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1);
       bean = WrapDynaClass.createDynaClass(detectTypeParameter);
       return getNestedPropertyType(bean, resolver.remove(name));
     }
     DynaProperty db = bean.getDynaProperty(next);
     bean = WrapDynaClass.createDynaClass(db.getType());
     name = resolver.remove(name);
   }
   if (resolver.isMapped(name) || resolver.isIndexed(name)) {
     String property = resolver.getProperty(name);
     Class<?> clazz = Class.forName(bean.getName());
     return detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1);
   }
   Class<?> type = bean.getDynaProperty(name).getType();
   return type;
 }
Exemple #2
0
 @Override
 public Collection<?> getSortableContainerPropertyIds() {
   if (backingList instanceof SortableLazyList) {
     // Assume SortableLazyList can sort by any Comparable property
   } else if (backingList instanceof LazyList) {
     // When using LazyList, don't support sorting by default
     // as the sorting should most probably be done at backend call level
     return Collections.emptySet();
   }
   final ArrayList<String> props = new ArrayList<String>();
   for (Object a : getContainerPropertyIds()) {
     DynaProperty db = getDynaClass().getDynaProperty(a.toString());
     if (db != null
         && db.getType() != null
         && (db.getType().isPrimitive() || Comparable.class.isAssignableFrom(db.getType()))) {
       props.add(db.getName());
     }
   }
   return props;
 }
Exemple #3
0
 @Override
 public Collection<String> getContainerPropertyIds() {
   if (properties == null) {
     if (getDynaClass() != null) {
       ArrayList<String> props = new ArrayList<String>();
       for (DynaProperty db : getDynaClass().getDynaProperties()) {
         if (db.getType() != null) {
           props.add(db.getName());
         } else {
           // type may be null in some cases
           Logger.getLogger(ListContainer.class.getName())
               .log(Level.FINE, "Type not detected for property {0}", db.getName());
         }
       }
       props.remove("class");
       properties = props;
     } else {
       return Collections.EMPTY_LIST;
     }
   }
   return properties;
 }
Exemple #4
0
 @Override
 public Class<?> getType(Object propertyId) {
   final String pName = propertyId.toString();
   try {
     final DynaProperty dynaProperty = getDynaClass().getDynaProperty(pName);
     final Class<?> type = dynaProperty.getType();
     if (type.isPrimitive()) {
       // Vaadin can't handle primitive types in _all_ places, so use
       // wrappers instead. FieldGroup works, but e.g. Table in _editable_
       // mode fails for some reason
       return ClassUtils.primitiveToWrapper(type);
     }
     return type;
   } catch (Exception e) {
     // If type can't be found via dynaClass, it is most likely
     // nested/indexed/mapped property
     try {
       return getNestedPropertyType(getDynaClass(), pName);
     } catch (Exception ex) {
       throw new RuntimeException(ex);
     }
   }
 }