Search in sources :

Example 6 with DBPContextProvider

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

the class AbstractDataSourceHandler method getExecutionContext.

protected DBCExecutionContext getExecutionContext(ExecutionEvent event, boolean useEditor) {
    if (useEditor) {
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        if (editor instanceof DBPContextProvider) {
            return ((DBPContextProvider) editor).getExecutionContext();
        }
        return null;
    }
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DBPContextProvider) {
        return ((DBPContextProvider) activePart).getExecutionContext();
    }
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        DBSObject selectedObject = NavigatorUtils.getSelectedObject((IStructuredSelection) selection);
        if (selectedObject != null) {
            DBPDataSource dataSource = selectedObject.getDataSource();
            if (dataSource != null) {
                return dataSource.getDefaultContext(false);
            }
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 7 with DBPContextProvider

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

the class DataSourcePropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof DBPContextProvider)) {
        return false;
    }
    DBPContextProvider contextProvider = (DBPContextProvider) receiver;
    @Nullable DBCExecutionContext context = contextProvider.getExecutionContext();
    switch(property) {
        case PROP_CONNECTED:
            boolean isConnected;
            if (context != null) {
                isConnected = context.getDataSource().getContainer().isConnected();
            } else if (receiver instanceof IDataSourceContainerProvider) {
                DBPDataSourceContainer container = ((IDataSourceContainerProvider) receiver).getDataSourceContainer();
                isConnected = container != null && container.isConnected();
            } else {
                isConnected = false;
            }
            boolean checkConnected = Boolean.TRUE.equals(expectedValue);
            return checkConnected ? isConnected : !isConnected;
        case PROP_TRANSACTIONAL:
            if (context == null) {
                return false;
            }
            if (!context.isConnected()) {
                return Boolean.FALSE.equals(expectedValue);
            }
            DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
            try {
                return txnManager != null && Boolean.valueOf(!txnManager.isAutoCommit()).equals(expectedValue);
            } catch (DBCException e) {
                log.debug("Error checking auto-commit state", e);
                return false;
            }
        case PROP_TRANSACTION_ACTIVE:
            if (context != null && context.isConnected()) {
                boolean active = QMUtils.isTransactionActive(context);
                return Boolean.valueOf(active).equals(expectedValue);
            }
            return Boolean.FALSE.equals(expectedValue);
    }
    return false;
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) Nullable(org.jkiss.code.Nullable)

Example 8 with DBPContextProvider

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

the class DatabaseEditorUtils method setPartBackground.

public static void setPartBackground(IEditorPart editor, Composite composite) {
    CTabFolder tabFolder = null;
    Composite rootComposite = null;
    for (Composite c = composite; c != null; c = c.getParent()) {
        if (c.getParent() instanceof CTabFolder) {
            tabFolder = (CTabFolder) c.getParent();
            rootComposite = c;
            break;
        }
    }
    if (tabFolder == null) {
        return;
    }
    tabFolder.setBorderVisible(false);
    Color bgColor = null;
    if (editor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
        if (container != null) {
            bgColor = UIUtils.getConnectionColor(container.getConnectionConfiguration());
        }
    } else if (editor instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
        if (context != null) {
            bgColor = UIUtils.getConnectionColor(context.getDataSource().getContainer().getConnectionConfiguration());
        }
    }
    if (bgColor == null) {
        rootComposite.setBackground(null);
    } else {
        rootComposite.setBackground(bgColor);
    }
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) Color(org.eclipse.swt.graphics.Color) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 9 with DBPContextProvider

use of org.jkiss.dbeaver.model.DBPContextProvider 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

DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)9 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)7 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 Color (org.eclipse.swt.graphics.Color)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1