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;
}
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;
}
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);
}
}
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();
}
Aggregations