Search in sources :

Example 1 with ExplainPlanViewer

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;
}
Also used : ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point)

Example 2 with ExplainPlanViewer

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;
}
Also used : ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point)

Example 3 with ExplainPlanViewer

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;
}
Also used : ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point)

Example 4 with ExplainPlanViewer

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;
}
Also used : ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point)

Example 5 with ExplainPlanViewer

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

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