use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress 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.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class SQLEditor method explainPlanFromQuery.
private void explainPlanFromQuery(final DBCQueryPlanner planner, final SQLQuery sqlQuery) {
final String[] planQueryString = new String[1];
DBRRunnableWithProgress queryObtainTask = monitor -> {
DBCQueryPlannerConfiguration configuration = ExplainPlanViewer.makeExplainPlanConfiguration(monitor, planner);
if (configuration == null) {
return;
}
try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, "Prepare plan query")) {
DBCPlan plan = planner.planQueryExecution(session, sqlQuery.getText(), configuration);
planQueryString[0] = plan.getPlanQueryString();
} catch (Exception e) {
log.error(e);
}
};
if (RuntimeUtils.runTask(queryObtainTask, "Retrieve plan query", 5000) && !CommonUtils.isEmpty(planQueryString[0])) {
SQLQuery planQuery = new SQLQuery(getDataSource(), planQueryString[0]);
processQueries(Collections.singletonList(planQuery), false, true, false, true, null, null);
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class ObjectPropertiesEditor method makeDatabaseEditorTabs.
private void makeDatabaseEditorTabs(final IDatabaseEditor part, final List<TabbedFolderInfo> tabList) {
final DBNDatabaseNode node = part.getEditorInput() instanceof IDatabaseEditorInput ? ((IDatabaseEditorInput) part.getEditorInput()).getNavigatorNode() : null;
if (node == null) {
return;
}
final DBSObject object = node.getObject();
if (!node.getMeta().isStandaloneNode()) {
// Collect tabs from navigator tree model
DBRRunnableWithProgress tabsCollector = monitor -> collectNavigatorTabs(monitor, part, node, tabList);
try {
if (node.needsInitialization()) {
UIUtils.runInProgressService(tabsCollector);
} else {
tabsCollector.run(new VoidProgressMonitor());
}
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
} catch (InterruptedException e) {
// just go further
}
}
// Extra properties tab (show if we have extra properties only)
{
TabbedFolderPageProperties pageProperties = new TabbedFolderPageProperties(this, getEditorInput());
List<String> extraCategories = pageProperties.getExtraCategories();
if (!extraCategories.isEmpty()) {
tabList.add(new TabbedFolderInfo(PropertiesContributor.TAB_PROPERTIES, extraCategories.get(0) + (extraCategories.size() == 1 ? "" : " / ... "), DBIcon.TREE_INFO, String.join(", ", extraCategories), false, pageProperties));
}
}
// Query for entity editors
List<EntityEditorDescriptor> editors = EntityEditorsRegistry.getInstance().getEntityEditors(object, this, null);
if (!CommonUtils.isEmpty(editors)) {
for (EntityEditorDescriptor descriptor : editors) {
if (descriptor.getType() == EntityEditorDescriptor.Type.folder) {
tabList.add(new TabbedFolderInfo(descriptor.getId(), descriptor.getName(), descriptor.getIcon(), descriptor.getDescription(), descriptor.isEmbeddable(), new TabbedFolderPageEditor(this, descriptor)));
}
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class NavigatorHandlerObjectCreateCopy method pasteResource.
private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
final IResource resource = resourceNode.getResource();
final IResource targetResource = toFolder.getResource();
assert resource != null;
assert targetResource != null;
final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
try {
UIUtils.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
copyResource(monitor, resource, targetFolder);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Copy error", "Error copying resource", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class NavigatorStatePersistor method restoreState.
public void restoreState(final TreeViewer navigatorViewer, final DBNNode rootNode, int maxDepth, final IMemento memento) {
if (memento == null || ArrayUtils.isEmpty(memento.getAttributeKeys())) {
return;
}
DBRRunnableWithProgress runnable = (monitor) -> {
try {
if (memento != null) {
monitor.beginTask("Expan navigator nodes", memento.getAttributeKeys().length);
for (int i = 0; i < memento.getAttributeKeys().length; i++) {
if (monitor.isCanceled()) {
break;
}
String nodeIdentifier = memento.getString(KEY_PREFIX + i);
monitor.subTask("Expan node " + nodeIdentifier);
DBNNode node = findNode(nodeIdentifier, rootNode, 1, maxDepth, monitor);
if (node != null && !node.isDisposed()) {
UIUtils.syncExec(() -> {
navigatorViewer.setExpandedState(node, true);
});
}
}
monitor.done();
}
} catch (Exception e) {
throw new InvocationTargetException(e);
}
};
AbstractJob expandJob = new AbstractJob("Expand navigator nodes") {
{
setSystem(false);
setUser(true);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
runnable.run(monitor);
} catch (InvocationTargetException e) {
log.error(e);
} catch (InterruptedException e) {
// ignore
}
return Status.OK_STATUS;
}
};
UIUtils.asyncExec(expandJob::schedule);
}
Aggregations