/** * Used internally to generate the types that a widget supports. Widgets support more than what * they explicitly support, they also deal with parent types and what not, so that is what this * will figure out. * * @param set the set that we will add the types to * @param types the types that a widget supports * @return the set that was given (except it will have types added to it) */ private static Set<DataType> generateTypes(Set<DataType> set, DataType[] types) { for (DataType type : types) { if (set.add(type)) { generateTypes(set, type.getParents()); } } return set; }
/** * Returns all the widgets which support a given type. * * @param type the type to support * @return the widgets which support the given type */ public static Set<Class<? extends Widget>> getWidgetsForType(DataType type) { Set<DataType> types = generateTypes(new LinkedHashSet<DataType>(), type.getParents()); types.add(type); Set<Class<? extends Widget>> elements = new LinkedHashSet<Class<? extends Widget>>(); for (DataType t : types) { Set<Class<? extends Widget>> set = map.get(t); if (set != null) { Class<? extends Widget> priority = t.getDefault(); if (priority != null) { elements.add(priority); } } } for (DataType t : types) { Set<Class<? extends Widget>> set = map.get(t); if (set != null) { elements.addAll(set); } } return elements; }