Search in sources :

Example 1 with SQLLogPanel

use of org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel in project dbeaver by serge-rider.

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) {
                curResultsContainer = (QueryResultsContainer) data;
                curQueryProcessor = curResultsContainer.queryProcessor;
                ResultSetViewer rsv = curResultsContainer.getResultSetController();
                if (rsv != null) {
                //rsv.getActivePresentation().getControl().setFocus();
                }
            } else if (data == outputViewer) {
                ((CTabItem) e.item).setImage(IMG_OUTPUT);
                outputViewer.resetNewOutput();
            }
        }
    });
    getTextViewer().getTextWidget().addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent 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);
        /*
            ToolItem planItem = new ToolItem(rsToolbar, SWT.NONE);
            planItem.setText("Plan");
            planItem.setImage(IMG_EXPLAIN_PLAN);
            planItem.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (curResultsContainer != null && curResultsContainer.query != null) {
                        explainQueryPlan(curResultsContainer.query);
                    } else {
                        UIUtils.showErrorDialog(
                            sashForm.getShell(),
                            CoreMessages.editors_sql_error_execution_plan_title,
                            "Select tab with SQL query results");
                    }
                }
            });
*/
        toolLogItem = new ToolItem(rsToolbar, SWT.CHECK);
        toolLogItem.setText("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("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.getItem(0).addListener();
    resultTabs.addListener(SWT.MouseDoubleClick, new Listener() {

        @Override
        public void handleEvent(Event 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(new IMenuListener() {

            @Override
            public void menuAboutToShow(IMenuManager manager) {
                if (sashForm.getMaximizedControl() == null) {
                    manager.add(new Action("Maximize results") {

                        @Override
                        public void run() {
                            toggleEditorMaximize();
                        }
                    });
                } else {
                    manager.add(new Action("Normalize results") {

                        @Override
                        public void run() {
                            toggleEditorMaximize();
                        }
                    });
                }
                if (resultTabs.getItemCount() > 3) {
                    manager.add(new Action("Close multiple results") {

                        @Override
                        public void run() {
                            closeExtraResultTabs(null);
                        }
                    });
                }
                final CTabItem activeTab = resultTabs.getSelection();
                if (activeTab != null && resultTabs.indexOf(activeTab) > 0 && activeTab.getData() instanceof QueryResultsContainer) {
                    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());
                            }
                        }
                    });
                }
            }
        });
        menuMgr.setRemoveAllWhenShown(true);
        resultTabs.setMenu(menu);
    }
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) IResultSetListener(org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener) SQLQueryListener(org.jkiss.dbeaver.runtime.sql.SQLQueryListener) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) CTabItem(org.eclipse.swt.custom.CTabItem) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) Point(org.eclipse.swt.graphics.Point) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) GridData(org.eclipse.swt.layout.GridData) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 DBPPreferenceListener (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)1 DBRProgressListener (org.jkiss.dbeaver.model.runtime.DBRProgressListener)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 SQLQueryListener (org.jkiss.dbeaver.runtime.sql.SQLQueryListener)1 IResultSetListener (org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener)1 ResultSetViewer (org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)1 EnterNameDialog (org.jkiss.dbeaver.ui.dialogs.EnterNameDialog)1 SQLLogPanel (org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel)1