Search in sources :

Example 1 with PropertySourceDelegate

use of org.jkiss.dbeaver.ui.properties.PropertySourceDelegate in project dbeaver by dbeaver.

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)) {
        if (adaptableObject instanceof DBNDatabaseFolder) {
            adaptableObject = ((DBNDatabaseFolder) adaptableObject).getParentObject();
        }
        DBPObject object = null;
        if (adaptableObject instanceof DBSWrapper) {
            object = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            object = (DBPObject) adaptableObject;
        }
        if (object instanceof DBSObject) {
            object = DBUtils.getPublicObject((DBSObject) object);
        }
        if (object != null && adapterType.isAssignableFrom(object.getClass())) {
            return adapterType.cast(object);
        }
    // } else if (IProject.class == adapterType) {
    // DBPProject project = null;
    // if (adaptableObject instanceof DBNNode) {
    // project = ((DBNNode) adaptableObject).getOwnerProject();
    // }
    // return project == null ? null : adapterType.cast(project.getEclipseProject());
    } 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, ModelMessages.model_navigator_Name, meta.getName());
                // $NON-NLS-1$
                props.addProperty(null, "desc", ModelMessages.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) 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) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) WorkbenchAdapter(org.eclipse.ui.model.WorkbenchAdapter) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource)

Example 2 with PropertySourceDelegate

use of org.jkiss.dbeaver.ui.properties.PropertySourceDelegate in project dbeaver by dbeaver.

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)

Example 3 with PropertySourceDelegate

use of org.jkiss.dbeaver.ui.properties.PropertySourceDelegate in project dbeaver by serge-rider.

the class SpreadsheetPresentation method getAdapter.

@Override
public <T> T getAdapter(Class<T> adapter) {
    if (adapter == IPropertySheetPage.class) {
        // Show cell properties
        PropertyPageStandard page = new PropertyPageStandard();
        page.setPropertySourceProvider(object -> {
            if (object instanceof GridCell) {
                GridCell cell = (GridCell) object;
                boolean recordMode = controller.isRecordMode();
                final DBDAttributeBinding attr = (DBDAttributeBinding) (recordMode ? cell.row : cell.col);
                final ResultSetRow row = (ResultSetRow) (recordMode ? cell.col : cell.row);
                final SpreadsheetValueController valueController = new SpreadsheetValueController(controller, attr, row, IValueController.EditType.NONE, null);
                PropertyCollector props = new PropertyCollector(valueController.getBinding().getAttribute(), false);
                props.collectProperties();
                valueController.getValueManager().contributeProperties(props, valueController);
                return new PropertySourceDelegate(props);
            }
            return null;
        });
        return adapter.cast(page);
    } else if (adapter == IFindReplaceTarget.class) {
        return adapter.cast(findReplaceTarget);
    }
    return null;
}
Also used : PropertyPageStandard(org.jkiss.dbeaver.ui.controls.PropertyPageStandard) PropertySourceDelegate(org.jkiss.dbeaver.ui.properties.PropertySourceDelegate) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget)

Example 4 with PropertySourceDelegate

use of org.jkiss.dbeaver.ui.properties.PropertySourceDelegate 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)

Example 5 with PropertySourceDelegate

use of org.jkiss.dbeaver.ui.properties.PropertySourceDelegate 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)) {
        if (adaptableObject instanceof DBNDatabaseFolder) {
            adaptableObject = ((DBNDatabaseFolder) adaptableObject).getParentObject();
        }
        DBPObject object = null;
        if (adaptableObject instanceof DBSWrapper) {
            object = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            object = (DBPObject) adaptableObject;
        }
        if (object instanceof DBSObject) {
            object = DBUtils.getPublicObject((DBSObject) object);
        }
        if (object != null && adapterType.isAssignableFrom(object.getClass())) {
            return adapterType.cast(object);
        }
    // } else if (IProject.class == adapterType) {
    // DBPProject project = null;
    // if (adaptableObject instanceof DBNNode) {
    // project = ((DBNNode) adaptableObject).getOwnerProject();
    // }
    // return project == null ? null : adapterType.cast(project.getEclipseProject());
    } 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, ModelMessages.model_navigator_Name, meta.getName());
                // $NON-NLS-1$
                props.addProperty(null, "desc", ModelMessages.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) 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) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) WorkbenchAdapter(org.eclipse.ui.model.WorkbenchAdapter) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource)

Aggregations

PropertySourceDelegate (org.jkiss.dbeaver.ui.properties.PropertySourceDelegate)6 PropertyCollector (org.jkiss.dbeaver.runtime.properties.PropertyCollector)4 Collection (java.util.Collection)2 Map (java.util.Map)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 IWorkbenchAdapter (org.eclipse.ui.model.IWorkbenchAdapter)2 WorkbenchAdapter (org.eclipse.ui.model.WorkbenchAdapter)2 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)2 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)2 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)2 DBPPropertySource (org.jkiss.dbeaver.model.preferences.DBPPropertySource)2 PropertySourceCollection (org.jkiss.dbeaver.runtime.properties.PropertySourceCollection)2 PropertySourceMap (org.jkiss.dbeaver.runtime.properties.PropertySourceMap)2 PropertyPageStandard (org.jkiss.dbeaver.ui.controls.PropertyPageStandard)2