Search in sources :

Example 1 with DBPPropertySource

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

Example 2 with DBPPropertySource

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

the class NavigatorAdapterFactory method getAdapter.

@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType == DBPDataSourceContainer.class) {
        if (adaptableObject instanceof DBNDataSource) {
            return adapterType.cast(((DBNDataSource) adaptableObject).getDataSourceContainer());
        }
        DBSObject object = DBUtils.getFromObject(adaptableObject);
        if (object == null) {
            return null;
        }
        if (object instanceof DBPDataSourceContainer) {
            return adapterType.cast(object);
        }
        DBPDataSource dataSource = object.getDataSource();
        return dataSource == null ? null : adapterType.cast(dataSource.getContainer());
    } else if (DBPObject.class.isAssignableFrom(adapterType)) {
        DBPObject object = null;
        if (adaptableObject instanceof DBSWrapper) {
            object = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            object = (DBPObject) adaptableObject;
        }
        if (object != null && adapterType.isAssignableFrom(object.getClass())) {
            return adapterType.cast(object);
        }
    } else if (IResource.class.isAssignableFrom(adapterType)) {
        if (adaptableObject instanceof DBNResource) {
            return ((DBNResource) adaptableObject).getAdapter(adapterType);
        }
    } else if (adapterType == IPropertySource.class) {
        DBPObject dbObject = null;
        if (adaptableObject instanceof DBSWrapper) {
            dbObject = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            dbObject = (DBPObject) adaptableObject;
        }
        if (dbObject instanceof IPropertySource) {
            return adapterType.cast(dbObject);
        }
        if (dbObject instanceof DBPPropertySource) {
            return adapterType.cast(new PropertySourceDelegate((DBPPropertySource) dbObject));
        }
        if (dbObject instanceof IAdaptable) {
            Object adapter = ((IAdaptable) dbObject).getAdapter(IPropertySource.class);
            if (adapter != null) {
                return adapterType.cast(adapter);
            }
            adapter = ((IAdaptable) dbObject).getAdapter(DBPPropertySource.class);
            if (adapter != null) {
                return adapterType.cast(new PropertySourceDelegate((DBPPropertySource) adapter));
            }
        }
        if (dbObject != null) {
            PropertyCollector props = new PropertyCollector(adaptableObject, dbObject, true);
            props.collectProperties();
            if (props.isEmpty() && adaptableObject instanceof DBSObject) {
                // Add default properties
                DBSObject meta = (DBSObject) adaptableObject;
                //$NON-NLS-1$
                props.addProperty(null, DBConstants.PROP_ID_NAME, CoreMessages.model_navigator_Name, meta.getName());
                //$NON-NLS-1$
                props.addProperty(null, "desc", CoreMessages.model_navigator_Description, meta.getDescription());
            }
            return adapterType.cast(new PropertySourceDelegate(props));
        }
    } else if (adapterType == IWorkbenchAdapter.class) {
        // Workbench adapter
        if (adaptableObject instanceof DBNNode) {
            final DBNNode node = (DBNNode) adaptableObject;
            WorkbenchAdapter workbenchAdapter = new WorkbenchAdapter() {

                @Override
                public ImageDescriptor getImageDescriptor(Object object) {
                    return DBeaverIcons.getImageDescriptor(node.getNodeIconDefault());
                }

                @Override
                public String getLabel(Object o) {
                    return node.getNodeName();
                }

                @Override
                public Object getParent(Object o) {
                    return node.getParentNode();
                }
            };
            return adapterType.cast(workbenchAdapter);
        } else {
            return null;
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) PropertySourceDelegate(org.jkiss.dbeaver.ui.properties.PropertySourceDelegate) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPPropertySource(org.jkiss.dbeaver.model.preferences.DBPPropertySource) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) WorkbenchAdapter(org.eclipse.ui.model.WorkbenchAdapter) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

DBPPropertySource (org.jkiss.dbeaver.model.preferences.DBPPropertySource)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IWorkbenchAdapter (org.eclipse.ui.model.IWorkbenchAdapter)1 WorkbenchAdapter (org.eclipse.ui.model.WorkbenchAdapter)1 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)1 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)1 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)1 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)1 PropertyCollector (org.jkiss.dbeaver.runtime.properties.PropertyCollector)1 PropertySourceDelegate (org.jkiss.dbeaver.ui.properties.PropertySourceDelegate)1