use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by dbeaver.
the class SQLEditor method explainQueryPlan.
private void explainQueryPlan(SQLQuery sqlQuery) {
DBCQueryPlanner planner = GeneralUtils.adapt(getDataSource(), DBCQueryPlanner.class);
DBCPlanStyle planStyle = planner.getPlanStyle();
if (planStyle == DBCPlanStyle.QUERY) {
explainPlanFromQuery(planner, sqlQuery);
} else if (planStyle == DBCPlanStyle.OUTPUT) {
explainPlanFromQuery(planner, sqlQuery);
showOutputPanel();
} else {
ExplainPlanViewer planView = getPlanView(sqlQuery, planner);
if (planView != null) {
planView.explainQueryPlan(sqlQuery, planner);
}
}
}
use of org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer in project dbeaver by dbeaver.
the class SQLEditor method createResultTabs.
private void createResultTabs() {
resultTabs = new CTabFolder(resultsSash, SWT.TOP | SWT.FLAT);
CSSUtils.setCSSClass(resultTabs, DBStyles.COLORED_BY_CONNECTION_TYPE);
resultTabsReorder = new TabFolderReorder(resultTabs);
resultTabs.setLayoutData(new GridData(GridData.FILL_BOTH));
resultTabs.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (extraPresentationCurrentPanel != null) {
extraPresentationCurrentPanel.deactivatePanel();
}
extraPresentationCurrentPanel = null;
Object data = e.item.getData();
if (data instanceof QueryResultsContainer) {
setActiveResultsContainer((QueryResultsContainer) data);
} else if (data instanceof SQLEditorPresentationPanel) {
extraPresentationCurrentPanel = ((SQLEditorPresentationPanel) data);
extraPresentationCurrentPanel.activatePanel();
} else if (data instanceof ExplainPlanViewer) {
SQLQuery planQuery = ((ExplainPlanViewer) data).getQuery();
if (planQuery != null) {
getSelectionProvider().setSelection(new TextSelection(planQuery.getOffset(), 0));
}
}
}
});
this.resultTabs.addListener(SWT.Resize, event -> {
if (!resultsSash.isDisposed()) {
int[] weights = resultsSash.getWeights();
IPreferenceStore prefs = getPreferenceStore();
if (prefs != null && weights.length == 2) {
prefs.setValue(SQLPreferenceConstants.RESULTS_PANEL_RATIO, weights[0] + "-" + weights[1]);
}
}
});
this.resultTabs.addListener(TabFolderReorder.ITEM_MOVE_EVENT, event -> {
CTabItem item = (CTabItem) event.item;
if (item.getData() instanceof QueryResultsContainer) {
((QueryResultsContainer) item.getData()).resultsTab = item;
}
});
String resultsPanelRatio = getPreferenceStore().getString(SQLPreferenceConstants.RESULTS_PANEL_RATIO);
if (!CommonUtils.isEmpty(resultsPanelRatio)) {
String[] weights = resultsPanelRatio.split("-");
if (weights.length > 1) {
resultsSash.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.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 SQLEditorOutputConsoleViewer(getSite(), resultTabs, SWT.NONE);
// Create results tab
createQueryProcessor(true, true);
{
resultTabs.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
activeResultsTab = resultTabs.getItem(new Point(e.x, e.y));
}
});
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(resultTabs);
menuMgr.addMenuListener(manager -> {
int pinnedTabsCount = 0;
int resultTabsCount = 0;
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof QueryResultsContainer) {
resultTabsCount++;
if (((QueryResultsContainer) item.getData()).isPinned()) {
pinnedTabsCount++;
}
}
}
final CTabItem activeTab = getActiveResultsTab();
if (activeTab != null && activeTab.getData() instanceof QueryResultsContainer) {
{
final QueryResultsContainer resultsContainer = (QueryResultsContainer) activeTab.getData();
if (resultsContainer.getResultSetController().hasData()) {
final boolean isPinned = resultsContainer.isPinned();
manager.add(new Action(isPinned ? SQLEditorMessages.action_result_tabs_unpin_tab : SQLEditorMessages.action_result_tabs_pin_tab) {
@Override
public void run() {
resultsContainer.setPinned(!isPinned);
CTabItem currTabItem = activeTab;
CTabItem nextTabItem;
if (isPinned) {
for (int i = resultTabs.indexOf(activeTab) + 1; i < resultTabs.getItemCount(); i++) {
nextTabItem = resultTabs.getItem(i);
if (nextTabItem.getShowClose()) {
break;
}
resultTabsReorder.swapTabs(currTabItem, nextTabItem);
currTabItem = nextTabItem;
}
} else {
for (int i = resultTabs.indexOf(activeTab) - 1; i >= 0; i--) {
nextTabItem = resultTabs.getItem(i);
if (!nextTabItem.getShowClose()) {
break;
}
resultTabsReorder.swapTabs(currTabItem, nextTabItem);
currTabItem = nextTabItem;
}
}
}
});
}
}
manager.add(new Action(SQLEditorMessages.action_result_tabs_set_name) {
@Override
public void run() {
EnterNameDialog dialog = new EnterNameDialog(resultTabs.getShell(), SQLEditorMessages.action_result_tabs_set_name_title, activeTab.getText());
if (dialog.open() == IDialogConstants.OK_ID) {
if (activeTab.getData() instanceof QueryResultsContainer) {
final QueryResultsContainer resultsContainer = (QueryResultsContainer) activeTab.getData();
resultsContainer.setTabName(dialog.getResult());
}
}
}
});
}
if (pinnedTabsCount > 1 || resultTabsCount > 1 || (activeTab != null && activeTab.getShowClose())) {
manager.add(new Separator());
if (pinnedTabsCount > 1 && !activeTab.getShowClose()) {
manager.add(new Separator());
manager.add(new Action(SQLEditorMessages.action_result_tabs_unpin_all_tabs) {
@Override
public void run() {
for (CTabItem item : resultTabs.getItems()) {
if (item.getData() instanceof QueryResultsContainer) {
if (((QueryResultsContainer) item.getData()).isPinned()) {
((QueryResultsContainer) item.getData()).setPinned(false);
}
}
}
}
});
}
if (resultTabsCount - pinnedTabsCount > 1 && activeTab != null && activeTab.getShowClose() && activeTab.getData() instanceof QueryResultsContainer) {
manager.add(new Action(SQLEditorMessages.action_result_tabs_close_all_tabs) {
@Override
public void run() {
closeExtraResultTabs(null, false, false);
}
});
manager.add(new Action(SQLEditorMessages.action_result_tabs_close_query_tabs) {
@Override
public void run() {
QueryProcessor processor = ((QueryResultsContainer) activeTab.getData()).queryProcessor;
List<CTabItem> tabsToRemove = new ArrayList<>();
for (QueryResultsContainer container : processor.getResultContainers()) {
CTabItem tab = container.getTabItem();
if (tab.getShowClose() && container.queryProcessor == processor) {
tabsToRemove.add(tab);
}
}
for (CTabItem tab : tabsToRemove) {
tab.dispose();
}
}
});
manager.add(new Action(SQLEditorMessages.action_result_tabs_close_other_tabs) {
@Override
public void run() {
List<CTabItem> tabsToRemove = new ArrayList<>();
for (CTabItem tab : resultTabs.getItems()) {
if (tab.getShowClose() && tab != activeTab) {
tabsToRemove.add(tab);
}
}
for (CTabItem tab : tabsToRemove) {
tab.dispose();
}
setActiveResultsContainer((QueryResultsContainer) activeTab.getData());
}
});
}
if (activeTab != null && activeTab.getShowClose()) {
manager.add(ActionUtils.makeCommandContribution(getSite(), SQLEditorCommands.CMD_SQL_EDITOR_CLOSE_TAB));
}
}
manager.add(new Separator());
manager.add(ActionUtils.makeCommandContribution(getSite(), SQLEditorCommands.CMD_SQL_EDITOR_MAXIMIZE_PANEL));
});
menuMgr.setRemoveAllWhenShown(true);
resultTabs.setMenu(menu);
}
}
Aggregations