use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.
the class CursorViewDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
final IValueController valueController = getValueController();
value = (DBDCursor) valueController.getValue();
Composite dialogGroup = (Composite) super.createDialogArea(parent);
if (value != null) {
DBPPreferenceStore globalPreferenceStore = DBeaverCore.getGlobalPreferenceStore();
if (!globalPreferenceStore.getBoolean(DBeaverPreferences.KEEP_STATEMENT_OPEN)) {
if (ConfirmationDialog.showConfirmDialog(getShell(), DBeaverPreferences.CONFIRM_KEEP_STATEMENT_OPEN, ConfirmationDialog.QUESTION) == IDialogConstants.YES_ID) {
globalPreferenceStore.setValue(DBeaverPreferences.KEEP_STATEMENT_OPEN, true);
if (valueController.getValueSite().getPart() instanceof IResultSetContainer) {
IResultSetController rsv = ((IResultSetContainer) valueController.getValueSite().getPart()).getResultSetController();
if (rsv != null) {
rsv.refresh();
}
}
}
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
close();
}
});
}
}
resultSetViewer = new ResultSetViewer(dialogGroup, valueController.getValueSite(), this);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.grabExcessVerticalSpace = true;
resultSetViewer.getControl().setLayoutData(gd);
resultSetViewer.refresh();
return dialogGroup;
}
use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer 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.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.
the class SQLEditor method onDataSourceChange.
private void onDataSourceChange() {
updateExecutionContext();
if (sashForm == null || sashForm.isDisposed()) {
reloadSyntaxRules();
return;
}
DatabaseEditorUtils.setPartBackground(this, sashForm);
DBCExecutionContext executionContext = getExecutionContext();
if (syntaxLoaded && lastExecutionContext == executionContext) {
return;
}
for (QueryProcessor queryProcessor : queryProcessors) {
for (QueryResultsContainer resultsProvider : queryProcessor.getResultContainers()) {
ResultSetViewer rsv = resultsProvider.getResultSetController();
if (rsv != null) {
if (executionContext == null) {
rsv.setStatus(CoreMessages.editors_sql_status_not_connected_to_database);
} else {
//$NON-NLS-2$
rsv.setStatus(CoreMessages.editors_sql_staus_connected_to + executionContext.getDataSource().getContainer().getName() + "'");
}
}
}
}
// Update command states
SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXECUTE);
SQLEditorPropertyTester.firePropertyChange(SQLEditorPropertyTester.PROP_CAN_EXPLAIN);
reloadSyntaxRules();
if (getDataSourceContainer() == null) {
sashForm.setMaximizedControl(editorControl);
} else {
sashForm.setMaximizedControl(null);
}
lastExecutionContext = executionContext;
syntaxLoaded = true;
}
use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.
the class ValueViewCommandHandler method execute.
@Nullable
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ResultSetViewer rsv = (ResultSetViewer) ResultSetCommandHandler.getActiveResultSet(HandlerUtil.getActivePart(event));
if (rsv == null) {
return null;
}
String actionId = event.getCommand().getId();
IResultSetPanel visiblePanel = rsv.getVisiblePanel();
if (visiblePanel instanceof ViewValuePanel) {
switch(actionId) {
case ITextEditorActionDefinitionIds.SMART_ENTER:
case CoreCommands.CMD_EXECUTE_STATEMENT:
case CMD_SAVE_VALUE:
((ViewValuePanel) visiblePanel).saveValue();
break;
}
}
return null;
}
use of org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer in project dbeaver by serge-rider.
the class DatabaseDataEditor method createResultSetView.
private void createResultSetView() {
if (resultSetView == null) {
resultSetView = new ResultSetViewer(parent, getSite(), this);
resultSetView.addListener(this);
parent.layout();
resultSetView.getControl().setFocus();
// Set selection provider from resultset
getSite().setSelectionProvider(resultSetView);
}
}
Aggregations