use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by serge-rider.
the class SQLEditor method closeExtraResultTabs.
private int closeExtraResultTabs(@Nullable QueryProcessor queryProcessor, boolean confirmClose, boolean keepFirstTab) {
List<CTabItem> tabsToClose = new ArrayList<>();
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof QueryResultsContainer && item.getShowClose()) {
QueryResultsContainer resultsProvider = (QueryResultsContainer) item.getData();
if (queryProcessor != null && queryProcessor != resultsProvider.queryProcessor) {
continue;
}
if (queryProcessor != null && queryProcessor.resultContainers.size() < 2 && keepFirstTab) {
// Do not remove first tab for this processor
continue;
}
tabsToClose.add(item);
} else if (item.getData() instanceof ExplainPlanViewer) {
tabsToClose.add(item);
}
}
if (tabsToClose.size() > 1 || (tabsToClose.size() == 1 && keepFirstTab)) {
int confirmResult = IDialogConstants.YES_ID;
if (confirmClose) {
confirmResult = ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME), getSite().getShell(), SQLPreferenceConstants.CONFIRM_RESULT_TABS_CLOSE, ConfirmationDialog.QUESTION_WITH_CANCEL, tabsToClose.size());
if (confirmResult == IDialogConstants.CANCEL_ID || confirmResult < 0) {
return IDialogConstants.CANCEL_ID;
}
}
if (confirmResult == IDialogConstants.YES_ID) {
for (int i = 0; i < tabsToClose.size(); i++) {
if (i == 0 && keepFirstTab) {
continue;
}
tabsToClose.get(i).dispose();
}
}
return confirmResult;
}
// No need to close anything
return IDialogConstants.IGNORE_ID;
}
use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by serge-rider.
the class SQLEditor method getPlanView.
private ExplainPlanViewer getPlanView(SQLQuery sqlQuery, DBCQueryPlanner planner) {
if (planner == null) {
DBWorkbench.getPlatformUI().showError("Execution plan", "Execution plan explain isn't supported by current datasource");
return null;
}
// Transform query parameters
if (sqlQuery != null) {
if (!transformQueryWithParameters(sqlQuery)) {
return null;
}
}
ExplainPlanViewer planView = null;
if (sqlQuery != null) {
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof ExplainPlanViewer) {
ExplainPlanViewer pv = (ExplainPlanViewer) item.getData();
if (pv.getQuery() != null && pv.getQuery().equals(sqlQuery)) {
resultTabs.setSelection(item);
planView = pv;
break;
}
}
}
}
if (planView == null) {
int maxPlanNumber = 0;
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof ExplainPlanViewer) {
maxPlanNumber = Math.max(maxPlanNumber, ((ExplainPlanViewer) item.getData()).getPlanNumber());
}
}
maxPlanNumber++;
planView = new ExplainPlanViewer(this, this, resultTabs, maxPlanNumber);
final CTabItem item = new CTabItem(resultTabs, SWT.CLOSE);
item.setControl(planView.getControl());
item.setText(SQLEditorMessages.editors_sql_error_execution_plan_title + " - " + maxPlanNumber);
if (sqlQuery != null) {
item.setToolTipText(sqlQuery.getText());
}
item.setImage(IMG_EXPLAIN_PLAN);
item.setData(planView);
item.addDisposeListener(resultTabDisposeListener);
UIUtils.disposeControlOnItemDispose(item);
resultTabs.setSelection(item);
}
return planView;
}
use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by dbeaver.
the class SQLEditor method closeExtraResultTabs.
private int closeExtraResultTabs(@Nullable QueryProcessor queryProcessor, boolean confirmClose, boolean keepFirstTab) {
List<CTabItem> tabsToClose = new ArrayList<>();
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof QueryResultsContainer && item.getShowClose()) {
QueryResultsContainer resultsProvider = (QueryResultsContainer) item.getData();
if (queryProcessor != null && queryProcessor != resultsProvider.queryProcessor) {
continue;
}
if (queryProcessor != null && queryProcessor.resultContainers.size() < 2 && keepFirstTab) {
// Do not remove first tab for this processor
continue;
}
tabsToClose.add(item);
} else if (item.getData() instanceof ExplainPlanViewer) {
tabsToClose.add(item);
}
}
if (tabsToClose.size() > 1 || (tabsToClose.size() == 1 && keepFirstTab)) {
int confirmResult = IDialogConstants.YES_ID;
if (confirmClose) {
confirmResult = ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME), getSite().getShell(), SQLPreferenceConstants.CONFIRM_RESULT_TABS_CLOSE, ConfirmationDialog.QUESTION_WITH_CANCEL, tabsToClose.size());
if (confirmResult == IDialogConstants.CANCEL_ID || confirmResult < 0) {
return IDialogConstants.CANCEL_ID;
}
}
if (confirmResult == IDialogConstants.YES_ID) {
for (int i = 0; i < tabsToClose.size(); i++) {
if (i == 0 && keepFirstTab) {
continue;
}
tabsToClose.get(i).dispose();
}
}
return confirmResult;
}
// No need to close anything
return IDialogConstants.IGNORE_ID;
}
use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by dbeaver.
the class SQLEditor method getPlanView.
private ExplainPlanViewer getPlanView(SQLQuery sqlQuery, DBCQueryPlanner planner) {
if (planner == null) {
DBWorkbench.getPlatformUI().showError("Execution plan", "Execution plan explain isn't supported by current datasource");
return null;
}
// Transform query parameters
if (sqlQuery != null) {
if (!transformQueryWithParameters(sqlQuery)) {
return null;
}
}
ExplainPlanViewer planView = null;
if (sqlQuery != null) {
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof ExplainPlanViewer) {
ExplainPlanViewer pv = (ExplainPlanViewer) item.getData();
if (pv.getQuery() != null && pv.getQuery().equals(sqlQuery)) {
resultTabs.setSelection(item);
planView = pv;
break;
}
}
}
}
if (planView == null) {
int maxPlanNumber = 0;
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof ExplainPlanViewer) {
maxPlanNumber = Math.max(maxPlanNumber, ((ExplainPlanViewer) item.getData()).getPlanNumber());
}
}
maxPlanNumber++;
planView = new ExplainPlanViewer(this, this, resultTabs, maxPlanNumber);
final CTabItem item = new CTabItem(resultTabs, SWT.CLOSE);
item.setControl(planView.getControl());
item.setText(SQLEditorMessages.editors_sql_error_execution_plan_title + " - " + maxPlanNumber);
if (sqlQuery != null) {
item.setToolTipText(sqlQuery.getText());
}
item.setImage(IMG_EXPLAIN_PLAN);
item.setData(planView);
item.addDisposeListener(resultTabDisposeListener);
UIUtils.disposeControlOnItemDispose(item);
resultTabs.setSelection(item);
}
return planView;
}
use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by serge-rider.
the class SQLEditor method loadQueryPlan.
public void loadQueryPlan() {
DBCQueryPlanner planner = GeneralUtils.adapt(getDataSource(), DBCQueryPlanner.class);
ExplainPlanViewer planView = getPlanView(null, planner);
if (planView != null) {
if (!planView.loadQueryPlan(planner, planView)) {
closeActiveTab();
}
}
}
Aggregations