Search in sources :

Example 1 with ExplainPlanViewer

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);
    }
}
Also used : StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) IResultSetListener(org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) SashForm(org.eclipse.swt.custom.SashForm) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) StyledText(org.eclipse.swt.custom.StyledText) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SQLQueryListener(org.jkiss.dbeaver.runtime.sql.SQLQueryListener) SQLQueryJob(org.jkiss.dbeaver.runtime.sql.SQLQueryJob) SQLResultsView(org.jkiss.dbeaver.ui.views.SQLResultsView) org.eclipse.jface.text(org.eclipse.jface.text) 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) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) IOUtils(org.jkiss.utils.IOUtils) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) URI(java.net.URI) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) EFS(org.eclipse.core.filesystem.EFS) ExplainPlanViewer(org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) 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) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBeaverPreferences(org.jkiss.dbeaver.DBeaverPreferences) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) DBUserInterface(org.jkiss.dbeaver.runtime.ui.DBUserInterface) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) DataSourceHandler(org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler) IProject(org.eclipse.core.resources.IProject) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IResultSetContainer(org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) IFileStore(org.eclipse.core.filesystem.IFileStore) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) org.eclipse.swt.widgets(org.eclipse.swt.widgets) ArrayUtils(org.jkiss.utils.ArrayUtils) CTabItem(org.eclipse.swt.custom.CTabItem) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.jkiss.dbeaver.core(org.jkiss.dbeaver.core) org.eclipse.core.runtime(org.eclipse.core.runtime) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) CTabFolder(org.eclipse.swt.custom.CTabFolder) CTabItem(org.eclipse.swt.custom.CTabItem) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) 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) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 2 with ExplainPlanViewer

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);
    }
}
Also used : DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) ExplainPlanViewer(org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer) CTabItem(org.eclipse.swt.custom.CTabItem)

Aggregations

CTabItem (org.eclipse.swt.custom.CTabItem)2 DBCPlanStyle (org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle)2 DBCQueryPlanner (org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner)2 ExplainPlanViewer (org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer)2 java.io (java.io)1 URI (java.net.URI)1 java.util (java.util)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EFS (org.eclipse.core.filesystem.EFS)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFile (org.eclipse.core.resources.IFile)1 IFileState (org.eclipse.core.resources.IFileState)1 IProject (org.eclipse.core.resources.IProject)1 org.eclipse.core.runtime (org.eclipse.core.runtime)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 org.eclipse.jface.action (org.eclipse.jface.action)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1