use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class SQLEditor method dumpServerOutput.
private void dumpServerOutput(@NotNull final DBCExecutionContext executionContext, @NotNull final DBCServerOutputReader outputReader) {
new AbstractJob("Dump server output") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
final StringWriter dump = new StringWriter();
try {
outputReader.readServerOutput(monitor, executionContext, new PrintWriter(dump, true));
final String dumpString = dump.toString();
if (!dumpString.isEmpty()) {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
if (outputViewer.isDisposed()) {
return;
}
try {
IOUtils.copyText(new StringReader(dumpString), outputViewer.getOutputWriter());
} catch (IOException e) {
log.error(e);
}
if (outputViewer.isHasNewOutput()) {
outputViewer.scrollToEnd();
CTabItem outputItem = UIUtils.getTabItem(resultTabs, outputViewer);
if (outputItem != null && outputItem != resultTabs.getSelection()) {
outputItem.setImage(IMG_OUTPUT_ALERT);
} else {
toolOutputItem.setImage(IMG_OUTPUT_ALERT);
}
}
}
});
}
} catch (Exception e) {
log.error(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method refreshNavigator.
public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
Job refreshJob = new AbstractJob("Refresh navigator object(s)") {
public Throwable error;
@Override
protected IStatus run(DBRProgressMonitor monitor) {
addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (error != null) {
UIUtils.showErrorDialog(null, "Refresh", "Error refreshing node", error);
}
}
});
Set<DBNNode> refreshedSet = new HashSet<>();
for (DBNNode node : refreshObjects) {
if (node.isDisposed() || node.isLocked()) {
// Skip locked nodes
continue;
}
// Check this node was already refreshed
if (!refreshedSet.isEmpty()) {
boolean skip = false;
for (DBNNode refreshed : refreshedSet) {
if (node == refreshed || node.isChildOf(refreshed)) {
skip = true;
break;
}
}
if (skip) {
continue;
}
}
setName("Refresh '" + node.getNodeName() + "'...");
try {
DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
if (refreshed != null) {
refreshedSet.add(refreshed);
}
} catch (Throwable ex) {
error = ex;
}
}
return Status.OK_STATUS;
}
};
refreshJob.setUser(true);
refreshJob.schedule();
}
use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class SpreadsheetPresentation method navigateLink.
///////////////////////////////////////////////
// Links
public void navigateLink(@NotNull GridCell cell, final int state) {
boolean recordMode = controller.isRecordMode();
final DBDAttributeBinding attr = (DBDAttributeBinding) (recordMode ? cell.row : cell.col);
final ResultSetRow row = (ResultSetRow) (recordMode ? cell.col : cell.row);
Object value = controller.getModel().getCellValue(attr, row);
if (DBUtils.isNullValue(value)) {
log.warn("Can't navigate to NULL value");
return;
}
if (!CommonUtils.isEmpty(attr.getReferrers())) {
// Navigate association
new AbstractJob("Navigate association") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
boolean ctrlPressed = (state & SWT.CTRL) == SWT.CTRL;
controller.navigateAssociation(monitor, attr, row, ctrlPressed);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
} else {
// Navigate hyperlink
String strValue = attr.getValueHandler().getValueDisplayString(attr, value, DBDDisplayFormat.UI);
UIUtils.launchProgram(strValue);
}
}
use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class MySQLExportWizardPageObjects method loadTables.
private void loadTables(final MySQLCatalog catalog) {
if (catalog != null) {
curCatalog = catalog;
}
if (curCatalog == null) {
return;
}
final boolean isCatalogChecked = isChecked(curCatalog);
final Set<MySQLTableBase> checkedObjects = this.checkedObjects.get(curCatalog);
new AbstractJob("Load '" + curCatalog.getName() + "' tables") {
{
setUser(true);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<MySQLTableBase> objects = new ArrayList<>();
objects.addAll(curCatalog.getTables(monitor));
if (wizard.showViews) {
objects.addAll(curCatalog.getViews(monitor));
}
Collections.sort(objects, DBUtils.nameComparator());
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
tablesTable.removeAll();
for (MySQLTableBase table : objects) {
TableItem item = new TableItem(tablesTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(table.isView() ? DBIcon.TREE_VIEW : DBIcon.TREE_TABLE));
item.setText(0, table.getName());
item.setData(table);
item.setChecked(isCatalogChecked && (checkedObjects == null || checkedObjects.contains(table)));
}
}
});
} catch (DBException e) {
UIUtils.showErrorDialog(null, "Table list", "Can't read table list", e);
}
return Status.OK_STATUS;
}
}.schedule();
}
use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class PostgreCreateSchemaDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
final Composite composite = super.createDialogArea(parent);
final Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(2, false));
final Text nameText = UIUtils.createLabelText(group, "Schema name", "");
nameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
name = nameText.getText();
getButton(IDialogConstants.OK_ID).setEnabled(!name.isEmpty());
}
});
final Combo userCombo = UIUtils.createLabelCombo(group, "Owner", SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
userCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
owner = allUsers.get(userCombo.getSelectionIndex());
}
});
new AbstractJob("Load users") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<String> userNames = new ArrayList<>();
allUsers = new ArrayList<>(database.getUsers(monitor));
final PostgreRole dba = database.getDBA(monitor);
final String defUserName = dba == null ? "" : dba.getName();
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
for (PostgreRole authId : allUsers) {
String name = authId.getName();
userCombo.add(name);
if (name.equals(defUserName)) {
owner = authId;
}
}
userCombo.setText(defUserName);
}
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
return composite;
}
Aggregations