Search in sources :

Example 1 with IPropertySourceEditable

use of org.jkiss.dbeaver.runtime.properties.IPropertySourceEditable in project dbeaver by serge-rider.

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;
}
Also used : IPropertySourceEditable(org.jkiss.dbeaver.runtime.properties.IPropertySourceEditable) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) PropertySourceCollection(org.jkiss.dbeaver.runtime.properties.PropertySourceCollection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPObject(org.jkiss.dbeaver.model.DBPObject) PropertySourceCollection(org.jkiss.dbeaver.runtime.properties.PropertySourceCollection) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Aggregations

DBPObject (org.jkiss.dbeaver.model.DBPObject)1 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 IPropertySourceEditable (org.jkiss.dbeaver.runtime.properties.IPropertySourceEditable)1 PropertyCollector (org.jkiss.dbeaver.runtime.properties.PropertyCollector)1 PropertySourceCollection (org.jkiss.dbeaver.runtime.properties.PropertySourceCollection)1