Search in sources :

Example 11 with ExplainPlanViewer

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);
        }
    }
}
Also used : DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer)

Example 12 with ExplainPlanViewer

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);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) Point(org.eclipse.swt.graphics.Point) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Matcher(java.util.regex.Matcher) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) EFS(org.eclipse.core.filesystem.EFS) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) SQLQueryDataContainer(org.jkiss.dbeaver.model.sql.data.SQLQueryDataContainer) org.jkiss.dbeaver.ui.controls.resultset(org.jkiss.dbeaver.ui.controls.resultset) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) SWT(org.eclipse.swt.SWT) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) SimpleDateFormat(java.text.SimpleDateFormat) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) IFile(org.eclipse.core.resources.IFile) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) org.eclipse.swt.events(org.eclipse.swt.events) SQLPresentationRegistry(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationRegistry) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) SourceViewer(org.eclipse.jface.text.source.SourceViewer) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.eclipse.core.runtime(org.eclipse.core.runtime) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) GridLayout(org.eclipse.swt.layout.GridLayout) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) org.eclipse.jface.text(org.eclipse.jface.text) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) SQLPresentationPanelDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationPanelDescriptor) ModelMessages(org.jkiss.dbeaver.model.messages.ModelMessages) SQLPresentationDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationDescriptor) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) IFileState(org.eclipse.core.resources.IFileState) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) NLS(org.eclipse.osgi.util.NLS) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) org.jkiss.dbeaver.ui.controls(org.jkiss.dbeaver.ui.controls) SQLEditorMessages(org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) Pattern(java.util.regex.Pattern) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) SQLQueryJob(org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) FillLayout(org.eclipse.swt.layout.FillLayout) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) ArrayUtils(org.jkiss.utils.ArrayUtils) DataSourceUtils(org.jkiss.dbeaver.registry.DataSourceUtils) CTabItem(org.eclipse.swt.custom.CTabItem) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.ui.wizard.DataTransferWizard) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) CTabFolder(org.eclipse.swt.custom.CTabFolder) CTabItem(org.eclipse.swt.custom.CTabItem) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) Point(org.eclipse.swt.graphics.Point) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ExplainPlanViewer (org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer)12 CTabItem (org.eclipse.swt.custom.CTabItem)8 Point (org.eclipse.swt.graphics.Point)6 DBCQueryPlanner (org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner)6 DBCPlanStyle (org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle)4 java.io (java.io)2 URI (java.net.URI)2 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 EFS (org.eclipse.core.filesystem.EFS)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IFile (org.eclipse.core.resources.IFile)2 IFileState (org.eclipse.core.resources.IFileState)2 org.eclipse.core.runtime (org.eclipse.core.runtime)2 Job (org.eclipse.core.runtime.jobs.Job)2 org.eclipse.jface.action (org.eclipse.jface.action)2