Search in sources :

Example 6 with DBPPropertyDescriptor

use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor 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)

Example 7 with DBPPropertyDescriptor

use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.

the class WMIPropertySource method getPropertyDescriptors2.

@Override
public DBPPropertyDescriptor[] getPropertyDescriptors2() {
    try {
        WMIQualifiedObject qualifiedObject = getQualifiedObject();
        if (qualifiedObject == null) {
            return EMPTY_PROPERTIES;
        }
        Collection<WMIQualifier> qualifiers = qualifiedObject.getQualifiers();
        DBPPropertyDescriptor[] result = new DBPPropertyDescriptor[qualifiers.size()];
        int index = 0;
        for (WMIQualifier qualifier : qualifiers) {
            String name = qualifier.getName();
            PropertyDescriptor prop = new PropertyDescriptor("WMI", name, name, null, null, false, null, null, false);
            result[index++] = prop;
        }
        return result;
    } catch (WMIException e) {
        log.error(e);
        return EMPTY_PROPERTIES;
    }
}
Also used : WMIException(org.jkiss.wmi.service.WMIException) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) PropertyDescriptor(org.jkiss.dbeaver.model.impl.PropertyDescriptor) WMIQualifiedObject(org.jkiss.wmi.service.WMIQualifiedObject) WMIQualifier(org.jkiss.wmi.service.WMIQualifier) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 8 with DBPPropertyDescriptor

use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.

the class PropertyDescriptor method extractProperties.

public static List<DBPPropertyDescriptor> extractProperties(IConfigurationElement config) {
    String category = NAME_UNDEFINED;
    if (TAG_PROPERTY_GROUP.equals(config.getName())) {
        category = config.getAttribute(ATTR_LABEL);
        if (CommonUtils.isEmpty(category)) {
            category = NAME_UNDEFINED;
        }
    }
    List<DBPPropertyDescriptor> properties = new ArrayList<>();
    IConfigurationElement[] propElements = config.getChildren(PropertyDescriptor.TAG_PROPERTY);
    for (IConfigurationElement prop : propElements) {
        properties.add(new PropertyDescriptor(category, prop));
    }
    return properties;
}
Also used : DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 9 with DBPPropertyDescriptor

use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.

the class AttributeEditPage method createPageContents.

@Override
protected Control createPageContents(Composite parent) {
    Composite propsGroup = new Composite(parent, SWT.NONE);
    propsGroup.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    propsGroup.setLayoutData(gd);
    //$NON-NLS-2$
    final Text nameText = UIUtils.createLabelText(propsGroup, "Name", attribute.getName());
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (attribute instanceof DBPNamedObject2) {
                ((DBPNamedObject2) attribute).setName(nameText.getText());
            }
        }
    });
    UIUtils.createControlLabel(propsGroup, "Properties").setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    propertyViewer.getControl().setLayoutData(gd);
    propertyViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
        }
    });
    PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute) {

        @Override
        public void setPropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object newValue) throws IllegalArgumentException {
            super.setPropertyValue(monitor, editableValue, prop, newValue);
        /*
                if (prop.getId().equals("dataType")) {
                    newValue = getPropertyValue(monitor, editableValue, prop);
                    if (newValue instanceof DBSDataType) {
                        DBPPropertyDescriptor lengthProp = getProperty("maxLength");
                        if (lengthProp instanceof ObjectPropertyDescriptor) {
                            DBPDataKind dataKind = ((DBSDataType) newValue).getDataKind();
                            if (dataKind == DBPDataKind.STRING) {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, 100);
                            } else {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, null);
                            }
                            propertyViewer.update(lengthProp, null);
                        }
                    }
                }
*/
        }
    };
    pc.collectProperties();
    for (DBPPropertyDescriptor prop : pc.getProperties()) {
        if (prop instanceof ObjectPropertyDescriptor) {
            if (((ObjectPropertyDescriptor) prop).isEditPossible() && !((ObjectPropertyDescriptor) prop).isNameProperty()) {
                continue;
            }
        }
        pc.removeProperty(prop);
    }
    propertyViewer.loadProperties(pc);
    return propsGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) Text(org.eclipse.swt.widgets.Text) Viewer(org.eclipse.jface.viewers.Viewer) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) GridData(org.eclipse.swt.layout.GridData) PropertySourceAbstract(org.jkiss.dbeaver.runtime.properties.PropertySourceAbstract) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Nullable(org.jkiss.code.Nullable)

Example 10 with DBPPropertyDescriptor

use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.

the class PropertySourceAbstract method collectProperties.

public boolean collectProperties() {
    lazyValues.clear();
    props.clear();
    propValues.clear();
    final Object editableValue = getEditableValue();
    IPropertyFilter filter;
    if (editableValue instanceof DBSObject) {
        filter = new DataSourcePropertyFilter(((DBSObject) editableValue).getDataSource());
    } else if (editableValue instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editableValue).getExecutionContext();
        filter = context == null ? new DataSourcePropertyFilter() : new DataSourcePropertyFilter(context.getDataSource());
    } else {
        filter = new DataSourcePropertyFilter();
    }
    List<ObjectPropertyDescriptor> annoProps = ObjectAttributeDescriptor.extractAnnotations(this, editableValue.getClass(), filter);
    for (final ObjectPropertyDescriptor desc : annoProps) {
        addProperty(desc);
    }
    if (editableValue instanceof DBPPropertySource) {
        DBPPropertySource ownPropSource = (DBPPropertySource) editableValue;
        DBPPropertyDescriptor[] ownProperties = ownPropSource.getPropertyDescriptors2();
        if (!ArrayUtils.isEmpty(ownProperties)) {
            for (DBPPropertyDescriptor prop : ownProperties) {
                props.add(prop);
                propValues.put(prop.getId(), ownPropSource.getPropertyValue(null, prop.getId()));
            }
        }
    }
    return !props.isEmpty();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBPPropertySource(org.jkiss.dbeaver.model.preferences.DBPPropertySource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Aggregations

DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)14 PropertyDescriptor (org.jkiss.dbeaver.model.impl.PropertyDescriptor)4 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2 DBPSystemObject (org.jkiss.dbeaver.model.DBPSystemObject)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DriverPropertyInfo (java.sql.DriverPropertyInfo)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1