use of org.jkiss.dbeaver.runtime.properties.PropertySourceCollection in project dbeaver by dbeaver.
the class PropertyTreeViewer method loadTreeNodes.
private Map<String, TreeNode> loadTreeNodes(@Nullable DBRProgressMonitor monitor, TreeNode parent, DBPPropertySource propertySource) {
Map<String, TreeNode> categories = new LinkedHashMap<>();
final DBPPropertyDescriptor[] props = propertySource.getPropertyDescriptors2();
for (DBPPropertyDescriptor prop : props) {
String categoryName = prop.getCategory();
if (CommonUtils.isEmpty(categoryName)) {
categoryName = CATEGORY_GENERAL;
}
TreeNode category = (parent != null ? parent : categories.get(categoryName));
if (category == null) {
category = new TreeNode(null, propertySource, categoryName);
categories.put(categoryName, category);
}
TreeNode propNode = new TreeNode(category, propertySource, prop);
// Load nested object's properties
if (!(propertySource instanceof IPropertySourceEditable)) {
Class<?> propType = ((DBPPropertyDescriptor) prop).getDataType();
if (propType != null) {
if (DBPObject.class.isAssignableFrom(propType)) {
Object propertyValue = propertySource.getPropertyValue(monitor, prop.getId());
if (propertyValue != null) {
PropertyCollector nestedCollector = new PropertyCollector(propertyValue, true);
if (nestedCollector.collectProperties()) {
categories.putAll(loadTreeNodes(monitor, propNode, nestedCollector));
}
}
} else if (BeanUtils.isCollectionType(propType)) {
Object propertyValue = propertySource.getPropertyValue(monitor, prop.getId());
if (propertyValue != null) {
Collection<?> collection;
if (BeanUtils.isArrayType(propType)) {
collection = Arrays.asList((Object[]) propertyValue);
} else {
collection = (Collection<?>) propertyValue;
}
PropertySourceCollection psc = new PropertySourceCollection(collection);
for (DBPPropertyDescriptor pd : psc.getPropertyDescriptors2()) {
new TreeNode(propNode, psc, pd);
}
}
}
}
}
}
return categories;
}
use of org.jkiss.dbeaver.runtime.properties.PropertySourceCollection in project dbeaver by serge-rider.
the class PropertyPageStandard method getPropertySource.
@Override
public IPropertySource getPropertySource(Object object) {
if (object == null || object.getClass().isPrimitive() || object instanceof CharSequence || object instanceof Number || object instanceof Boolean) {
// Just for better performance
return null;
}
// (get prop source from adapter, load props, load lazy props -> refresh -> get prop source from adapter, etc).
if (!ArrayUtils.isEmpty(curSelection)) {
for (PropertySourceCache cache : curSelection) {
if (cache.object == object) {
if (!cache.cached) {
cache.propertySource = RuntimeUtils.getObjectAdapter(object, IPropertySource.class);
cache.cached = true;
}
return cache.propertySource;
}
}
}
if (object instanceof Collection) {
return new PropertySourceDelegate(new PropertySourceCollection((Collection<?>) object));
} else if (object instanceof Map) {
return new PropertySourceDelegate(new PropertySourceMap((Map<String, ?>) object));
}
return RuntimeUtils.getObjectAdapter(object, IPropertySource.class);
}
Aggregations