use of org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer in project dbeaver by dbeaver.
the class SQLEditor method createResultTabs.
private void createResultTabs() {
resultTabs = new CTabFolder(sashForm, SWT.TOP | SWT.FLAT);
resultTabs.setLayoutData(new GridData(GridData.FILL_BOTH));
resultTabs.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Object data = e.item.getData();
if (data instanceof QueryResultsContainer) {
setActiveResultsContainer((QueryResultsContainer) data);
}
}
});
this.resultTabs.addListener(SWT.Resize, event -> {
if (!sashForm.isDisposed()) {
int[] weights = sashForm.getWeights();
IPreferenceStore prefs = getPreferenceStore();
if (prefs != null) {
prefs.setValue(SQLPreferenceConstants.RESULTS_PANEL_RATIO, weights[0] + "-" + weights[1]);
}
}
});
String resultsPanelRatio = getPreferenceStore().getString(SQLPreferenceConstants.RESULTS_PANEL_RATIO);
if (!CommonUtils.isEmpty(resultsPanelRatio)) {
String[] weights = resultsPanelRatio.split("-");
if (weights.length > 1) {
sashForm.setWeights(new int[] { Integer.parseInt(weights[0]), Integer.parseInt(weights[1]) });
}
}
getTextViewer().getTextWidget().addTraverseListener(e -> {
if (e.detail == SWT.TRAVERSE_PAGE_NEXT) {
ResultSetViewer viewer = getActiveResultSetViewer();
if (viewer != null && viewer.getActivePresentation().getControl().isVisible()) {
viewer.getActivePresentation().getControl().setFocus();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
}
});
resultTabs.setSimple(true);
// resultTabs.setMRUVisible(true);
{
ToolBar rsToolbar = new ToolBar(resultTabs, SWT.HORIZONTAL | SWT.RIGHT | SWT.WRAP);
toolLogItem = new ToolItem(rsToolbar, SWT.CHECK);
toolLogItem.setText(CoreMessages.sql_editor_resultset_tool_item_log);
toolLogItem.setToolTipText(ActionUtils.findCommandDescription(CoreCommands.CMD_SQL_SHOW_LOG, getSite(), false));
toolLogItem.setImage(IMG_LOG);
toolLogItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showExecutionLogPanel();
}
});
toolOutputItem = new ToolItem(rsToolbar, SWT.CHECK);
toolOutputItem.setText(CoreMessages.sql_editor_resultset_tool_item_output);
toolOutputItem.setToolTipText(ActionUtils.findCommandDescription(CoreCommands.CMD_SQL_SHOW_OUTPUT, getSite(), false));
toolOutputItem.setImage(IMG_OUTPUT);
toolOutputItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
toolOutputItem.setImage(IMG_OUTPUT);
showOutputPanel();
}
});
resultTabs.setTopRight(rsToolbar);
}
resultTabs.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
if (e.button == 2) {
CTabItem item = resultTabs.getItem(new Point(e.x, e.y));
if (item != null && item.getShowClose()) {
item.dispose();
}
}
}
});
resultTabs.addListener(SWT.MouseDoubleClick, event -> {
if (event.button != 1) {
return;
}
CTabItem selectedItem = resultTabs.getItem(new Point(event.getBounds().x, event.getBounds().y));
if (selectedItem != null && selectedItem == resultTabs.getSelection()) {
toggleEditorMaximize();
}
});
// Extra views
// planView = new ExplainPlanViewer(this, resultTabs);
logViewer = new SQLLogPanel(resultTabs, this);
outputViewer = new SQLEditorOutputViewer(getSite(), resultTabs, SWT.NONE);
// Create results tab
createQueryProcessor(true);
{
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(resultTabs);
menuMgr.addMenuListener(manager -> {
manager.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_SQL_EDITOR_MAXIMIZE_PANEL));
if (resultTabs.getItemCount() > 1) {
manager.add(new Action("Close multiple results") {
@Override
public void run() {
closeExtraResultTabs(null);
}
});
}
final CTabItem activeTab = resultTabs.getSelection();
if (activeTab != null && activeTab.getData() instanceof QueryResultsContainer) {
if (resultTabs.indexOf(activeTab) > 0) {
final QueryResultsContainer resultsContainer = (QueryResultsContainer) activeTab.getData();
manager.add(new Separator());
final boolean isPinned = resultsContainer.isPinned();
manager.add(new Action(isPinned ? "Unpin tab" : "Pin tab") {
@Override
public void run() {
resultsContainer.setPinned(!isPinned);
}
});
}
manager.add(new Action("Set tab title") {
@Override
public void run() {
EnterNameDialog dialog = new EnterNameDialog(resultTabs.getShell(), "Tab title", activeTab.getText());
if (dialog.open() == IDialogConstants.OK_ID) {
activeTab.setText(dialog.getResult());
}
}
});
}
if (activeTab != null && activeTab.getShowClose()) {
manager.add(ActionUtils.makeCommandContribution(getSite(), CoreCommands.CMD_SQL_EDITOR_CLOSE_TAB));
}
});
menuMgr.setRemoveAllWhenShown(true);
resultTabs.setMenu(menu);
}
}
use of org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer in project dbeaver by dbeaver.
the class SQLEditor method explainQueryPlan.
private void explainQueryPlan(SQLQuery sqlQuery) {
// 1. Determine whether planner supports plan extraction
DBCQueryPlanner planner = DBUtils.getAdapter(DBCQueryPlanner.class, getDataSource());
if (planner == null) {
DBUserInterface.getInstance().showError("Execution plan", "Execution plan explain isn't supported by current datasource");
return;
}
DBCPlanStyle planStyle = planner.getPlanStyle();
if (planStyle == DBCPlanStyle.QUERY) {
explainPlanFromQuery(planner, sqlQuery);
return;
}
ExplainPlanViewer planView = 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) {
planView = new ExplainPlanViewer(this, resultTabs);
final CTabItem item = new CTabItem(resultTabs, SWT.CLOSE);
item.setControl(planView.getControl());
item.setText("Exec. Plan");
item.setToolTipText("Execution plan for\n" + sqlQuery.getText());
item.setImage(IMG_EXPLAIN_PLAN);
item.setData(planView);
UIUtils.disposeControlOnItemDispose(item);
resultTabs.setSelection(item);
}
try {
planView.explainQueryPlan(getExecutionContext(), sqlQuery);
} catch (DBCException e) {
DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_execution_plan_title, CoreMessages.editors_sql_error_execution_plan_message, e);
}
}
Aggregations