use of org.jkiss.dbeaver.model.runtime.DBRProgressListener in project dbeaver by serge-rider.
the class SQLEditor method processQueries.
private void processQueries(@NotNull final List<SQLQuery> queries, final boolean newTab, final boolean export, final boolean checkSession) {
if (queries.isEmpty()) {
// Nothing to process
return;
}
final DBPDataSourceContainer container = getDataSourceContainer();
if (checkSession) {
try {
DBRProgressListener connectListener = new DBRProgressListener() {
@Override
public void onTaskFinished(IStatus status) {
if (!status.isOK() || container == null || !container.isConnected()) {
UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, null, status);
return;
}
// Make a small pause to let all UI connection listeners to finish
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// it's ok
}
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
processQueries(queries, newTab, export, false);
}
});
}
};
if (!checkSession(connectListener)) {
return;
}
} catch (DBException ex) {
ResultSetViewer viewer = getActiveResultSetViewer();
if (viewer != null) {
viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
}
UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
return;
}
}
if (sashForm.getMaximizedControl() != null) {
sashForm.setMaximizedControl(null);
}
// Save editor
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
doSave(new NullProgressMonitor());
}
final boolean isSingleQuery = (queries.size() == 1);
if (!newTab || !isSingleQuery) {
// We don't need new tab or we are executing a script - so close all extra tabs
closeExtraResultTabs(null);
}
if (newTab) {
// Execute each query in a new tab
for (int i = 0; i < queries.size(); i++) {
SQLQuery query = queries.get(i);
QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
queryProcessor.processQueries(Collections.singletonList(query), true, export);
}
} else {
// Use current tab.
// If current tab was pinned then use first tab
final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
if (firstResults.isPinned()) {
curQueryProcessor = queryProcessors.get(0);
}
closeExtraResultTabs(curQueryProcessor);
if (firstResults.tabItem != null) {
resultTabs.setSelection(firstResults.tabItem);
}
curQueryProcessor.processQueries(queries, false, export);
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressListener in project dbeaver by dbeaver.
the class SearchMetadataPage method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
initializeDialogUnits(parent);
Composite searchGroup = new Composite(parent, SWT.NONE);
searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
searchGroup.setLayout(new GridLayout(3, false));
setControl(searchGroup);
UIUtils.createControlLabel(searchGroup, CoreMessages.dialog_search_objects_label_object_name);
searchText = new Combo(searchGroup, SWT.DROP_DOWN);
searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (nameMask != null) {
searchText.setText(nameMask);
}
for (String history : searchHistory) {
searchText.add(history);
}
searchText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
nameMask = searchText.getText();
updateEnablement();
}
});
Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
GridLayout layout = new GridLayout(2, true);
layout.marginHeight = 0;
layout.marginWidth = 0;
optionsGroup.setLayout(layout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
optionsGroup.setLayoutData(gd);
{
final DBeaverCore core = DBeaverCore.getInstance();
Group sourceGroup = UIUtils.createControlGroup(optionsGroup, CoreMessages.dialog_search_objects_group_objects_source, 1, GridData.FILL_BOTH, 0);
gd = new GridData(GridData.FILL_BOTH);
// gd.heightHint = 300;
sourceGroup.setLayoutData(gd);
final DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(core.getProjectRegistry().getActiveProject());
DBNNode rootNode = projectNode == null ? core.getNavigatorModel().getRoot() : projectNode.getDatabases();
dataSourceTree = new DatabaseNavigatorTree(sourceGroup, rootNode, SWT.SINGLE);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
dataSourceTree.setLayoutData(gd);
dataSourceTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeLoadNode) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && DBSObjectContainer.class.isAssignableFrom(folderItemsClass);
}
if (element instanceof DBNLocalFolder || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && ((DBSWrapper) element).getObject() instanceof DBSObjectContainer)) {
return true;
}
}
return false;
}
});
dataSourceTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
fillObjectTypes();
updateEnablement();
IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
Object object = structSel.isEmpty() ? null : structSel.getFirstElement();
if (object instanceof DBNNode) {
for (DBNNode node = (DBNNode) object; node != null; node = node.getParentNode()) {
if (node instanceof DBNDataSource) {
DBNDataSource dsNode = (DBNDataSource) node;
dsNode.initializeNode(null, new DBRProgressListener() {
@Override
public void onTaskFinished(IStatus status) {
if (status.isOK()) {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
if (!dataSourceTree.isDisposed()) {
fillObjectTypes();
}
}
});
}
}
});
break;
}
}
}
}
});
}
{
Group settingsGroup = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_BOTH, 0);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
settingsGroup.setLayoutData(gd);
{
// new Label(searchGroup, SWT.NONE);
UIUtils.createControlLabel(settingsGroup, CoreMessages.dialog_search_objects_label_name_match);
final Combo matchCombo = new Combo(settingsGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
matchCombo.add(CoreMessages.dialog_search_objects_combo_starts_with, SearchMetadataConstants.MATCH_INDEX_STARTS_WITH);
matchCombo.add(CoreMessages.dialog_search_objects_combo_contains, SearchMetadataConstants.MATCH_INDEX_CONTAINS);
matchCombo.add(CoreMessages.dialog_search_objects_combo_like, SearchMetadataConstants.MATCH_INDEX_LIKE);
matchCombo.select(0);
matchCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (matchTypeIndex >= 0) {
matchCombo.select(matchTypeIndex);
}
matchCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
matchTypeIndex = matchCombo.getSelectionIndex();
}
});
matchCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
if (maxResults <= 0) {
maxResults = 100;
}
final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(settingsGroup, CoreMessages.dialog_search_objects_spinner_max_results, maxResults, 1, 10000);
maxResultsSpinner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
maxResultsSpinner.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
maxResults = maxResultsSpinner.getSelection();
}
});
maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
final Button caseCheckbox = UIUtils.createLabelCheckbox(settingsGroup, CoreMessages.dialog_search_objects_case_sensitive, caseSensitive);
caseCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
caseSensitive = caseCheckbox.getSelection();
}
});
caseCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
Label otLabel = UIUtils.createControlLabel(settingsGroup, CoreMessages.dialog_search_objects_group_object_types);
otLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
typesTable = new Table(settingsGroup, SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
typesTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// checkedTypes.clear();
for (TableItem item : typesTable.getItems()) {
DBSObjectType objectType = (DBSObjectType) item.getData();
if (item.getChecked()) {
checkedTypes.add(objectType);
} else {
checkedTypes.remove(objectType);
}
}
updateEnablement();
}
});
typesTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TableItem tableItem = typesTable.getSelection()[0];
tableItem.setChecked(!tableItem.getChecked());
}
});
typesTable.setLayoutData(new GridData(GridData.FILL_BOTH));
UIUtils.createTableColumn(typesTable, SWT.LEFT, CoreMessages.dialog_search_objects_column_type);
UIUtils.createTableColumn(typesTable, SWT.LEFT, CoreMessages.dialog_search_objects_column_description);
}
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
loadState();
}
});
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressListener in project dbeaver by dbeaver.
the class SQLEditor method processQueries.
private void processQueries(@NotNull final List<SQLScriptElement> queries, final boolean newTab, final boolean export, final boolean checkSession, @Nullable final SQLQueryListener queryListener) {
if (queries.isEmpty()) {
// Nothing to process
return;
}
final DBPDataSourceContainer container = getDataSourceContainer();
if (checkSession) {
try {
DBRProgressListener connectListener = status -> {
if (!status.isOK() || container == null || !container.isConnected()) {
DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_cant_obtain_session, null, status);
return;
}
updateExecutionContext(new Runnable() {
@Override
public void run() {
DBeaverUI.syncExec(() -> processQueries(queries, newTab, export, false, queryListener));
}
});
};
if (!checkSession(connectListener)) {
return;
}
} catch (DBException ex) {
ResultSetViewer viewer = getActiveResultSetViewer();
if (viewer != null) {
viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
}
DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
return;
}
}
if (dataSourceContainer == null) {
return;
}
final boolean isSingleQuery = (queries.size() == 1);
if (isSingleQuery && queries.get(0) instanceof SQLQuery) {
SQLQuery query = (SQLQuery) queries.get(0);
if (query.isDeleteUpdateDangerous()) {
String targetName = "multiple tables";
if (query.getSingleSource() != null) {
targetName = query.getSingleSource().getEntityName();
}
if (ConfirmationDialog.showConfirmDialogEx(getSite().getShell(), DBeaverPreferences.CONFIRM_DANGER_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, query.getType().name(), targetName) != IDialogConstants.OK_ID) {
return;
}
}
} else if (newTab && queries.size() > MAX_PARALLEL_QUERIES_NO_WARN) {
if (ConfirmationDialog.showConfirmDialogEx(getSite().getShell(), DBeaverPreferences.CONFIRM_MASS_PARALLEL_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, queries.size()) != IDialogConstants.OK_ID) {
return;
}
}
if (sashForm.getMaximizedControl() != null) {
sashForm.setMaximizedControl(null);
}
// Save editor
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
doSave(new NullProgressMonitor());
}
if (!newTab || !isSingleQuery) {
// We don't need new tab or we are executing a script - so close all extra tabs
closeExtraResultTabs(null);
}
if (newTab) {
// Execute each query in a new tab
for (int i = 0; i < queries.size(); i++) {
SQLScriptElement query = queries.get(i);
QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
queryProcessor.processQueries(Collections.singletonList(query), true, export, getActivePreferenceStore().getBoolean(SQLPreferenceConstants.RESULT_SET_CLOSE_ON_ERROR), queryListener);
}
} else {
// Use current tab.
// If current tab was pinned then use first tab
final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
if (firstResults.isPinned()) {
curQueryProcessor = queryProcessors.get(0);
}
closeExtraResultTabs(curQueryProcessor);
if (firstResults.tabItem != null) {
// Do not switch tab if Output tab is active
CTabItem selectedTab = resultTabs.getSelection();
if (selectedTab == null || selectedTab.getData() != outputViewer) {
resultTabs.setSelection(firstResults.tabItem);
}
}
curQueryProcessor.processQueries(queries, false, export, false, queryListener);
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressListener in project dbeaver by dbeaver.
the class BookmarksHandlerImpl method openResource.
@Override
public void openResource(@NotNull final IResource resource) throws CoreException, DBException {
if (!(resource instanceof IFile)) {
return;
}
final DBNProject projectNode = DBeaverCore.getInstance().getNavigatorModel().getRoot().getProject(resource.getProject());
if (projectNode == null) {
// $NON-NLS-2$
throw new DBException("Can't find project node for '" + resource.getProject().getName() + "'");
}
final BookmarkStorage storage = new BookmarkStorage((IFile) resource, false);
try {
final DBPDataSourceContainer dataSourceContainer = projectNode.getDatabases().getDataSourceRegistry().getDataSource(storage.getDataSourceId());
if (dataSourceContainer == null) {
// $NON-NLS-2$
throw new DBException("Can't find datasource '" + storage.getDataSourceId() + "'");
}
final DBNDataSource dsNode = (DBNDataSource) NavigatorUtils.getNodeByObject(dataSourceContainer);
if (dsNode == null) {
// $NON-NLS-2$
throw new DBException("Can't find datasource node for '" + dataSourceContainer.getName() + "'");
}
dsNode.initializeNode(null, new DBRProgressListener() {
@Override
public void onTaskFinished(IStatus status) {
if (status.isOK()) {
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
openNodeByPath(dsNode, (IFile) resource, storage);
}
});
} else {
DBUserInterface.getInstance().showError("Open bookmark", "Can't open bookmark", status);
}
}
});
} finally {
storage.dispose();
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressListener in project dbeaver by serge-rider.
the class SQLEditor method processQueries.
private boolean processQueries(@NotNull final List<SQLScriptElement> queries, final boolean forceScript, boolean newTab, final boolean export, final boolean checkSession, @Nullable final SQLQueryListener queryListener, @Nullable final SQLScriptContext context) {
if (queries.isEmpty()) {
// Nothing to process
return false;
}
final DBPDataSourceContainer container = getDataSourceContainer();
if (checkSession) {
try {
boolean finalNewTab = newTab;
DBRProgressListener connectListener = status -> {
if (!status.isOK() || container == null || !container.isConnected()) {
DBWorkbench.getPlatformUI().showError(SQLEditorMessages.editors_sql_error_cant_obtain_session, null, status);
return;
}
updateExecutionContext(() -> UIUtils.syncExec(() -> processQueries(queries, forceScript, finalNewTab, export, false, queryListener, context)));
};
if (!checkSession(connectListener)) {
return false;
}
} catch (DBException ex) {
ResultSetViewer viewer = getActiveResultSetViewer();
if (viewer != null) {
viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
}
DBWorkbench.getPlatformUI().showError(SQLEditorMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
return false;
}
}
if (dataSourceContainer == null) {
return false;
}
if (!dataSourceContainer.hasModifyPermission(DBPDataSourcePermission.PERMISSION_EXECUTE_SCRIPTS)) {
DBWorkbench.getPlatformUI().showError(SQLEditorMessages.editors_sql_error_cant_execute_query_title, "Query execution was restricted by connection configuration");
return false;
}
SQLScriptContext scriptContext = context;
if (scriptContext == null) {
scriptContext = createScriptContext();
}
final boolean isSingleQuery = !forceScript && (queries.size() == 1);
if (isSingleQuery && queries.get(0) instanceof SQLQuery) {
SQLQuery query = (SQLQuery) queries.get(0);
if (query.isDeleteUpdateDangerous()) {
String targetName = "multiple tables";
if (query.getSingleSource() != null) {
targetName = query.getSingleSource().getEntityName();
}
if (ConfirmationDialog.showConfirmDialogEx(ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME), getSite().getShell(), SQLPreferenceConstants.CONFIRM_DANGER_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, query.getType().name(), targetName) != IDialogConstants.OK_ID) {
return false;
}
}
} else if (newTab && queries.size() > MAX_PARALLEL_QUERIES_NO_WARN) {
if (ConfirmationDialog.showConfirmDialogEx(ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME), getSite().getShell(), SQLPreferenceConstants.CONFIRM_MASS_PARALLEL_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, queries.size()) != IDialogConstants.OK_ID) {
return false;
}
}
if (resultsSash.getMaximizedControl() != null) {
resultsSash.setMaximizedControl(null);
}
// Save editor
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
doSave(new NullProgressMonitor());
}
// Clear server console output
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.CLEAR_OUTPUT_BEFORE_EXECUTE)) {
outputViewer.clearOutput();
}
if (!export) {
// 2. The user is executing script that may open several result sets
if (!newTab && !isSingleQuery) {
int tabsClosed = closeExtraResultTabs(null, true, false);
if (tabsClosed == IDialogConstants.CANCEL_ID) {
return false;
} else if (tabsClosed == IDialogConstants.NO_ID) {
newTab = true;
}
}
// 3. Or current query processor has running jobs
if (newTab || queryProcessors.isEmpty() || curQueryProcessor.hasPinnedTabs() || curQueryProcessor.getRunningJobs() > 0) {
boolean foundSuitableTab = false;
// 2. The user is executing only single query
if (!newTab && isSingleQuery) {
for (QueryProcessor processor : queryProcessors) {
if (!processor.hasPinnedTabs() && processor.getRunningJobs() == 0) {
foundSuitableTab = true;
curQueryProcessor = processor;
break;
}
}
}
// Just create a new query processor
if (!foundSuitableTab) {
createQueryProcessor(true, false);
}
}
// if the user is executing only single query
if (!newTab && isSingleQuery && curQueryProcessor.getResultContainers().size() > 1) {
closeExtraResultTabs(curQueryProcessor, false, true);
}
CTabItem tabItem = curQueryProcessor.getFirstResults().getTabItem();
if (tabItem != null) {
// Do not switch tab if Output tab is active
CTabItem selectedTab = resultTabs.getSelection();
if (selectedTab == null || selectedTab.getData() != outputViewer.getControl()) {
resultTabs.setSelection(tabItem);
}
}
}
return curQueryProcessor.processQueries(scriptContext, queries, forceScript, false, export, !export && getActivePreferenceStore().getBoolean(SQLPreferenceConstants.RESULT_SET_CLOSE_ON_ERROR), queryListener);
}
Aggregations