Search in sources :

Example 6 with PropertyCollector

use of org.jkiss.dbeaver.runtime.properties.PropertyCollector 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 7 with PropertyCollector

use of org.jkiss.dbeaver.runtime.properties.PropertyCollector in project dbeaver by dbeaver.

the class SessionManagerViewer method showPlanNode.

private void showPlanNode() {
    detailsItem.setText("Plan Details");
    ISelection selection = planViewer.getSelection();
    if (selection.isEmpty()) {
        sessionProps.clearProperties();
    } else if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element != selectedPlanElement) {
            PropertyCollector propertySource = new PropertyCollector(element, true);
            propertySource.collectProperties();
            sessionProps.loadProperties(propertySource);
            selectedPlanElement = element;
        }
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) DBPObject(org.jkiss.dbeaver.model.DBPObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 8 with PropertyCollector

use of org.jkiss.dbeaver.runtime.properties.PropertyCollector in project dbeaver by dbeaver.

the class DataSourceAuthModelDescriptor method createCredentialsSource.

@NotNull
@Override
public DBPPropertySource createCredentialsSource(DBPDataSourceContainer dataSource, DBPConnectionConfiguration configuration) {
    DBAAuthModel instance = getInstance();
    DBAAuthCredentials credentials = dataSource == null || configuration == null ? instance.createCredentials() : instance.loadCredentials(dataSource, configuration);
    PropertyCollector propertyCollector = new PropertyCollector(credentials, false);
    propertyCollector.collectProperties();
    return propertyCollector;
}
Also used : DBAAuthCredentials(org.jkiss.dbeaver.model.auth.DBAAuthCredentials) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) DBAAuthModel(org.jkiss.dbeaver.model.auth.DBAAuthModel) NotNull(org.jkiss.code.NotNull)

Example 9 with PropertyCollector

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

the class ColumnInfoPanel method createPanel.

protected void createPanel(IAttributeController valueController) {
    PropertyCollector infoItem = new PropertyCollector(valueController.getBinding().getMetaAttribute(), false);
    infoItem.collectProperties();
    valueController.getValueManager().contributeProperties(infoItem, valueController);
    DBDRowIdentifier rowIdentifier = valueController.getRowIdentifier();
    if (rowIdentifier != null) {
        infoItem.addProperty(null, "Key", CoreMessages.controls_column_info_panel_property_key, new CellKeyInfo(valueController.getRowController(), rowIdentifier));
    }
    this.setLayout(new FillLayout());
    {
        PropertyTreeViewer propViewer = new PropertyTreeViewer(this, SWT.H_SCROLL | SWT.V_SCROLL);
        propViewer.loadProperties(infoItem);
    }
}
Also used : PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 10 with PropertyCollector

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

the class SessionManagerViewer method onSessionSelect.

protected void onSessionSelect(DBAServerSession session) {
    curSession = session;
    updateSQL();
    if (session == null) {
        sessionProps.clearProperties();
    } else {
        PropertyCollector propCollector = new PropertyCollector(session, true);
        propCollector.collectProperties();
        sessionProps.loadProperties(propCollector);
    }
}
Also used : PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector)

Aggregations

PropertyCollector (org.jkiss.dbeaver.runtime.properties.PropertyCollector)22 FillLayout (org.eclipse.swt.layout.FillLayout)4 DBPObject (org.jkiss.dbeaver.model.DBPObject)4 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)4 PropertySourceDelegate (org.jkiss.dbeaver.ui.properties.PropertySourceDelegate)4 PropertyTreeViewer (org.jkiss.dbeaver.ui.properties.PropertyTreeViewer)4 DBDRowIdentifier (org.jkiss.dbeaver.model.data.DBDRowIdentifier)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 CTabItem (org.eclipse.swt.custom.CTabItem)2 StyledText (org.eclipse.swt.custom.StyledText)2 IWorkbenchAdapter (org.eclipse.ui.model.IWorkbenchAdapter)2 WorkbenchAdapter (org.eclipse.ui.model.WorkbenchAdapter)2 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)2 NotNull (org.jkiss.code.NotNull)2 Nullable (org.jkiss.code.Nullable)2