use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView || (navigatorView instanceof ProjectNavigatorView && activeEditor instanceof ITextEditor)) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull DBSObject activeObject = null;
if (dsContainer != null) {
if (activeEditor instanceof DBPContextProvider) {
DBCExecutionContext executionContext = ((DBPContextProvider) activeEditor).getExecutionContext();
if (executionContext != null) {
DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
if (contextDefaults != null) {
activeObject = contextDefaults.getDefaultSchema();
if (activeObject == null) {
activeObject = contextDefaults.getDefaultCatalog();
}
}
}
}
if (activeObject == null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource.getDefaultInstance());
} else {
activeObject = dsContainer;
}
}
DBSObject objectToSelect = activeObject;
final NavigatorViewBase view = navigatorView;
UIUtils.runInUI(activePage.getWorkbenchWindow(), monitor -> {
DBSObject showObject = objectToSelect;
if (showObject instanceof DBSInstance && !(showObject instanceof DBPDataSourceContainer)) {
showObject = objectToSelect.getParentObject();
}
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
});
}
}
activePage.activate(navigatorView);
return null;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class NavigatorHandlerSetDefaultObject method markObjectAsActive.
@SuppressWarnings("unchecked")
private void markObjectAsActive(final DBNDatabaseNode databaseNode, IEditorPart activeEditor) {
DBNNode parentNode = databaseNode.getParentNode();
if (parentNode instanceof DBNDatabaseItem) {
markObjectAsActive((DBNDatabaseItem) parentNode, activeEditor);
return;
}
DBSObject object = databaseNode.getObject();
DBPDataSource dataSource = object.getDataSource();
final DBCExecutionContext editorContext;
if (activeEditor instanceof DBPContextProvider) {
editorContext = ((DBPContextProvider) activeEditor).getExecutionContext();
} else {
editorContext = null;
}
TasksJob.runTask("Change default object", monitor -> {
try {
DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
try {
DBCExecutionContext defaultContext = dataSource.getDefaultInstance().getDefaultContext(monitor, false);
DBCExecutionContext[] contextsToChange;
if (editorContext != null && editorContext != defaultContext && editorContext.getDataSource() == defaultContext.getDataSource()) {
contextsToChange = new DBCExecutionContext[] { defaultContext, editorContext };
} else {
contextsToChange = new DBCExecutionContext[] { defaultContext };
}
for (DBCExecutionContext executionContext : contextsToChange) {
DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
if (contextDefaults != null) {
if (object instanceof DBSCatalog && contextDefaults.supportsCatalogChange()) {
contextDefaults.setDefaultCatalog(monitor, (DBSCatalog) object, null);
} else if (object instanceof DBSSchema && contextDefaults.supportsSchemaChange()) {
contextDefaults.setDefaultSchema(monitor, (DBSSchema) object);
} else {
throw new DBCException("Internal error: active object change not supported");
}
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (Exception e) {
throw new InvocationTargetException(e);
}
});
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class PropertySourceAbstract method collectProperties.
public boolean collectProperties() {
lazyValues.clear();
props.clear();
propValues.clear();
final Object editableValue = getEditableValue();
if (editableValue != null) {
IPropertyFilter filter;
if (isEnableFilters()) {
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();
}
} else {
filter = null;
}
List<ObjectPropertyDescriptor> annoProps = ObjectAttributeDescriptor.extractAnnotations(this, editableValue.getClass(), filter, locale);
for (final ObjectPropertyDescriptor desc : annoProps) {
if (desc.isPropertyVisible(editableValue, editableValue)) {
addProperty(desc);
}
}
if (editableValue instanceof DBPPropertySource) {
DBPPropertySource ownPropSource = (DBPPropertySource) editableValue;
DBPPropertyDescriptor[] ownProperties = ownPropSource.getProperties();
if (!ArrayUtils.isEmpty(ownProperties)) {
for (DBPPropertyDescriptor prop : ownProperties) {
props.add(prop);
propValues.put(prop.getId(), ownPropSource.getPropertyValue(null, prop.getId()));
}
}
}
}
return !props.isEmpty();
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class ResultSetValueController method getColumnId.
@NotNull
@Override
public String getColumnId() {
DBCExecutionContext context = getExecutionContext();
DBSAttributeBase metaAttribute = binding.getMetaAttribute();
if (metaAttribute == null) {
metaAttribute = binding.getAttribute();
}
if (metaAttribute == null) {
return binding.getName();
}
return DBUtils.getSimpleQualifiedName(context == null ? null : context.getDataSource().getContainer().getName(), metaAttribute instanceof DBCAttributeMetaData ? ((DBCAttributeMetaData) metaAttribute).getEntityName() : "", metaAttribute.getName());
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class AbstractDataEditor method openNewContainer.
@Override
public void openNewContainer(DBRProgressMonitor monitor, @NotNull DBSDataContainer dataContainer, @NotNull DBDDataFilter newFilter) {
final DBCExecutionContext executionContext = getExecutionContext();
if (executionContext == null) {
log.error("Can't open new container - not execution context found");
return;
}
final DBNDatabaseNode targetNode = executionContext.getDataSource().getContainer().getPlatform().getNavigatorModel().getNodeByObject(monitor, dataContainer, false);
if (targetNode == null) {
UIUtils.showMessageBox(null, "Open link", "Can't navigate to '" + DBUtils.getObjectFullName(dataContainer, DBPEvaluationContext.UI) + "' - navigator node not found", SWT.ICON_ERROR);
return;
}
openNewDataEditor(targetNode, newFilter);
}
Aggregations