use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class ProgressLoaderVisualizer method overwriteMonitor.
@Override
public DBRProgressMonitor overwriteMonitor(DBRProgressMonitor monitor) {
DBRProgressMonitor progressMonitor = new ProxyProgressMonitor(monitor) {
@Override
public void subTask(String name) {
progressMessage = name;
super.subTask(name);
}
};
return progressMonitor;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class DatabaseNavigatorTree method expandNodeOnLoad.
private void expandNodeOnLoad(final DBNNode node) {
if (node instanceof DBNDataSource && DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.NAVIGATOR_EXPAND_ON_CONNECT)) {
try {
DBRRunnableWithResult<DBNNode> runnable = new DBRRunnableWithResult<DBNNode>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
result = findActiveNode(monitor, node);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
DBeaverUI.runInProgressService(runnable);
if (runnable.getResult() != null) {
showNode(runnable.getResult());
treeViewer.expandToLevel(runnable.getResult(), 1);
}
} catch (InvocationTargetException e) {
log.error("Can't expand node", e.getTargetException());
} catch (InterruptedException e) {
// skip it
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor 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;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class PostgresRolePrivilegesEditor method createPartControl.
@Override
public void createPartControl(Composite parent) {
this.boldFont = UIUtils.makeBoldFont(parent.getFont());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
UIUtils.dispose(boldFont);
}
});
this.pageControl = new PageControl(parent);
this.pageControl.createOrSubstituteProgressPanel(getSite());
this.pageControl.setDoubleClickHandler(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
final ISelection selection = pageControl.getSelectionProvider().getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
final PostgrePermission element = (PostgrePermission) ((IStructuredSelection) selection).getFirstElement();
new AbstractJob("Open target object") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final PostgreObject targetObject = element.getTargetObject(monitor);
if (targetObject != null) {
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
NavigatorHandlerObjectOpen.openEntityEditor(targetObject);
}
});
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
});
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class PostgreStructureAssistant method findTableColumnsByMask.
private void findTableColumnsByMask(JDBCSession session, @Nullable final List<PostgreSchema> schema, String columnNameMask, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
// Load constraints
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT x.attname,x.attrelid,x.atttypid,c.relnamespace " + "FROM pg_catalog.pg_attribute x, pg_catalog.pg_class c\n" + "WHERE c.oid=x.attrelid AND x.attname " + (caseSensitive ? "LIKE" : "ILIKE") + " ? " + (CommonUtils.isEmpty(schema) ? "" : " AND c.relnamespace IN (" + SQLUtils.generateParamList(schema.size()) + ")") + " ORDER BY x.attname LIMIT " + maxResults)) {
dbStat.setString(1, columnNameMask);
if (!CommonUtils.isEmpty(schema)) {
PostgreUtils.setArrayParameter(dbStat, 2, schema);
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final long schemaId = JDBCUtils.safeGetLong(dbResult, "relnamespace");
final long tableId = JDBCUtils.safeGetLong(dbResult, "attrelid");
final String attributeName = JDBCUtils.safeGetString(dbResult, "attname");
final PostgreSchema constrSchema = dataSource.getDefaultInstance().getSchema(session.getProgressMonitor(), schemaId);
if (constrSchema == null) {
log.debug("Schema '" + schemaId + "' not found");
continue;
}
objects.add(new AbstractObjectReference(attributeName, constrSchema, null, PostgreTableBase.class, RelationalObjectType.TYPE_TABLE) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
final PostgreTableBase table = PostgreUtils.getObjectById(monitor, constrSchema.tableCache, constrSchema, tableId);
if (table == null) {
throw new DBException("Table '" + tableId + "' not found in schema '" + constrSchema.getName() + "'");
}
return table.getAttribute(monitor, attributeName);
}
});
}
}
}
}
Aggregations