use of org.jkiss.dbeaver.model.DBPContextProvider in project dbeaver by serge-rider.
the class DataSourceTransactionLogHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell activeShell = HandlerUtil.getActiveShell(event);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
DBCExecutionContext context = null;
if (editor instanceof DBPContextProvider) {
context = ((DBPContextProvider) editor).getExecutionContext();
}
TransactionLogDialog.showDialog(activeShell, context);
return null;
}
use of org.jkiss.dbeaver.model.DBPContextProvider in project dbeaver by serge-rider.
the class SQLAttributeResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext == null) {
return super.resolveAll(context);
}
TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
if (!CommonUtils.isEmpty(tableName)) {
final List<DBSEntityAttribute> attributes = new ArrayList<>();
DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<DBSEntity> entities = new ArrayList<>();
SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
if (!CommonUtils.isEmpty(entities)) {
DBSEntity table = DBUtils.findObject(entities, tableName);
if (table != null) {
attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
if (!CommonUtils.isEmpty(attributes)) {
String[] result = new String[attributes.size()];
for (int i = 0; i < attributes.size(); i++) {
DBSEntityAttribute entity = attributes.get(i);
result[i] = entity.getName();
}
return result;
}
}
return super.resolveAll(context);
}
use of org.jkiss.dbeaver.model.DBPContextProvider in project dbeaver by serge-rider.
the class SQLDataTypeResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext == null) {
return super.resolveAll(context);
}
DBPDataTypeProvider dataTypeProvider = DBUtils.getAdapter(DBPDataTypeProvider.class, executionContext.getDataSource());
if (dataTypeProvider != null) {
final Collection<? extends DBSDataType> localDataTypes = dataTypeProvider.getLocalDataTypes();
if (!CommonUtils.isEmpty(localDataTypes)) {
String[] result = new String[localDataTypes.size()];
int index = 0;
for (DBSDataType dataType : localDataTypes) {
result[index++] = dataType.getName();
}
return result;
}
}
return super.resolveAll(context);
}
use of org.jkiss.dbeaver.model.DBPContextProvider in project dbeaver by serge-rider.
the class SQLObjectResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final List<T> entities = new ArrayList<>();
if (context instanceof DBPContextProvider) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext != null) {
RuntimeUtils.runTask(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
resolveObjects(monitor, executionContext, context, entities);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
}, "Resolve object references", 1000);
}
}
if (!CommonUtils.isEmpty(entities)) {
String[] result = new String[entities.size()];
for (int i = 0; i < entities.size(); i++) {
T entity = entities.get(i);
result[i] = entity.getName();
}
return result;
}
return super.resolveAll(context);
}
use of org.jkiss.dbeaver.model.DBPContextProvider in project dbeaver by serge-rider.
the class NavigatorHandlerObjectGoto method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBCExecutionContext context = null;
DBSObject container = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof DBPContextProvider) {
context = ((DBPContextProvider) activePart).getExecutionContext();
} else if (activePart instanceof INavigatorModelView) {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) element).getObject();
if (object != null) {
container = object;
while (container instanceof DBSFolder) {
container = container.getParentObject();
}
DBPDataSource dataSource = object.getDataSource();
if (dataSource != null) {
context = dataSource.getDefaultContext(true);
}
}
}
}
}
if (context == null) {
DBUserInterface.getInstance().showError("Go to object", "No active datasource");
return null;
}
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
dialog.open();
Object[] objectsToOpen = dialog.getResult();
if (!ArrayUtils.isEmpty(objectsToOpen)) {
Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
for (DBNDatabaseNode node : nodes) {
NavigatorUtils.openNavigatorNode(node, workbenchWindow);
}
}
return null;
}
Aggregations