Search in sources :

Example 1 with PropertySourceCollection

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;
}
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)

Example 2 with PropertySourceCollection

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);
}
Also used : PropertySourceDelegate(org.jkiss.dbeaver.ui.properties.PropertySourceDelegate) Collection(java.util.Collection) PropertySourceCollection(org.jkiss.dbeaver.runtime.properties.PropertySourceCollection) PropertySourceMap(org.jkiss.dbeaver.runtime.properties.PropertySourceMap) PropertySourceMap(org.jkiss.dbeaver.runtime.properties.PropertySourceMap) Map(java.util.Map) PropertySourceCollection(org.jkiss.dbeaver.runtime.properties.PropertySourceCollection)

Aggregations

PropertySourceCollection (org.jkiss.dbeaver.runtime.properties.PropertySourceCollection)2 Collection (java.util.Collection)1 Map (java.util.Map)1 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 PropertySourceMap (org.jkiss.dbeaver.runtime.properties.PropertySourceMap)1 PropertySourceDelegate (org.jkiss.dbeaver.ui.properties.PropertySourceDelegate)1