Search in sources :

Example 1 with ResultsTab

use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.

the class SQLEditor method createResultsTab.

/**
 * Allocates a new tab for an AbstractSQLExecution; the tab and it's contents are completely undefined
 *
 * @param sqlExec
 * @return
 */
public ResultsTab createResultsTab(AbstractSQLExecution job) {
    if (tabFolder.isDisposed()) {
        return null;
    }
    // Create the new tab, make it second to last (IE keep the messages tab
    // always at the end) and set the new tab's title to the 1-based index
    CTabItem tabItem = new CTabItem(tabFolder, SWT.CLOSE, tabFolder.getItems().length - 1);
    tabItem.setText(Integer.toString(tabFolder.getItems().length - 1));
    tabFolder.setSelection(tabItem);
    // Make sure we can track the execution
    tabItem.setData(job);
    // Create a composite to add all controls to
    Composite composite = new Composite(tabFolder, SWT.NONE);
    tabItem.setControl(composite);
    // Make sure we're visible
    getSite().getPage().bringToTop(this);
    return new ResultsTab(this, tabItem, composite);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ResultsTab(net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 2 with ResultsTab

use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.

the class SQLExecution method displayResults.

/**
 * Display SQL Results in result pane
 * @param sqlResult the results of the query
 */
protected void displayResults(final SQLResult sqlResult) {
    // Switch to the UI thread to execute this
    getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            ResultsTab resultsTab = allocateResultsTab(sqlResult.getQuery());
            if (resultsTab == null)
                return;
            String caption = sqlResult.getDataSet().getCaption();
            if (caption != null)
                resultsTab.getTabItem().setText(caption);
            try {
                // set initial message
                setProgressMessage(Messages.getString("SQLResultsView.ConnectionWait"));
                Composite composite = resultsTab.getParent();
                GridLayout gLayout = new GridLayout();
                gLayout.numColumns = 2;
                gLayout.marginLeft = 0;
                gLayout.horizontalSpacing = 0;
                gLayout.verticalSpacing = 0;
                gLayout.marginWidth = 0;
                gLayout.marginHeight = 0;
                composite.setLayout(gLayout);
                int resultCount = sqlResult.getDataSet().getRows().length;
                String statusMessage = Messages.getString("SQLResultsView.Time.Prefix") + " " + sqlResult.getExecutionTimeMillis() + " " + Messages.getString("SQLResultsView.Time.Postfix");
                getEditor().setMessage(statusMessage);
                if (resultCount > 0)
                    statusMessage = statusMessage + "  " + Messages.getString("SQLResultsView.Count.Prefix") + " " + resultCount;
                Query sql = sqlResult.getQuery();
                int lineNo = sql.getLineNo();
                lineNo = getQueryParser().adjustLineNo(lineNo);
                getEditor().addMessage(new Message(Message.Status.SUCCESS, lineNo, 0, sql.getQuerySql(), statusMessage));
                new DataSetTable(composite, sqlResult.getDataSet(), statusMessage);
                composite.setData("parenttab", resultsTab.getTabItem());
                composite.layout();
                composite.redraw();
                // reset to start message in case F5 will be used
                setProgressMessage(Messages.getString("SQLResultsView.ConnectionWait"));
            } catch (Exception e) {
                // add message
                if (resultsTab != null) {
                    String message = e.getMessage();
                    Label errorLabel = new Label(resultsTab.getParent(), SWT.FILL);
                    errorLabel.setText(message);
                    errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
                }
                SQLExplorerPlugin.error("Error creating result tab", e);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Query(net.sourceforge.sqlexplorer.parsers.Query) Message(net.sourceforge.sqlexplorer.plugin.editors.Message) DataSetTable(net.sourceforge.sqlexplorer.dataset.DataSetTable) ResultsTab(net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SQLException(java.sql.SQLException)

Example 3 with ResultsTab

use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.

the class AbstractSQLExecution method allocateResultsTab.

/**
 * Creates a new tab for the results in SQLEditor
 * @return
 */
protected ResultsTab allocateResultsTab(Query query) {
    ResultsTab resultsTab = _editor.createResultsTab(this);
    if (resultsTab == null)
        return null;
    boolean longCaptions = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.USE_LONG_CAPTIONS_ON_RESULTS);
    if (longCaptions) {
        String caption = resultsTab.getTabItem().getText() + " [" + TextUtil.compressWhitespace(query.getQuerySql(), MAX_CAPTION_LENGTH) + "]";
        resultsTab.getTabItem().setText(caption);
    }
    return resultsTab;
}
Also used : ResultsTab(net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab)

Example 4 with ResultsTab

use of net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab in project tdq-studio-se by Talend.

the class ExplainExecution method displayResults.

private void displayResults(final ExplainNode node, final Query query) {
    getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            ResultsTab resultsTab = allocateResultsTab(query);
            try {
                Composite composite = resultsTab.getParent();
                GridLayout gLayout = new GridLayout();
                gLayout.numColumns = 2;
                gLayout.marginLeft = 0;
                gLayout.horizontalSpacing = 0;
                gLayout.verticalSpacing = 0;
                gLayout.marginWidth = 0;
                gLayout.marginHeight = 0;
                composite.setLayout(gLayout);
                composite.setData("parenttab", resultsTab.getTabItem());
                Composite pp = new Composite(composite, 0);
                pp.setLayout(new FillLayout());
                pp.setLayoutData(new GridData(1808));
                TableTreeViewer tv = new TableTreeViewer(pp, 0x10800);
                Table table = tv.getTableTree().getTable();
                table.setLinesVisible(true);
                table.setHeaderVisible(true);
                TableColumn tc = new TableColumn(table, 0);
                tc.setText("");
                tc = new TableColumn(table, 0);
                tc.setText("Cost");
                tc = new TableColumn(table, 0);
                tc.setText("Cardinality");
                TableLayout tableLayout = new TableLayout();
                tableLayout.addColumnData(new ColumnWeightData(6, 150, true));
                tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
                tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
                table.setLayout(tableLayout);
                tv.setContentProvider(new ITreeContentProvider() {

                    public void dispose() {
                    }

                    public Object[] getChildren(Object parentElement) {
                        return ((ExplainNode) parentElement).getChildren();
                    }

                    public Object[] getElements(Object inputElement) {
                        ExplainNode nd = (ExplainNode) inputElement;
                        return nd.getChildren();
                    }

                    public Object getParent(Object element) {
                        return ((ExplainNode) element).getParent();
                    }

                    public boolean hasChildren(Object element) {
                        return ((ExplainNode) element).getChildren().length > 0;
                    }

                    public void inputChanged(Viewer viewer1, Object obj, Object obj1) {
                    }
                });
                tv.setLabelProvider(new TreeLabelProvider() {
                });
                tv.setInput(node);
                tv.refresh();
                tv.expandAll();
                for (int i = 0; i < table.getColumnCount(); i++) table.getColumn(i).pack();
                final ExplainPlanActionGroup actionGroup = new ExplainPlanActionGroup(tv, node.getChildren()[0]);
                MenuManager menuManager = new MenuManager("ExplainPlanContextMenu");
                menuManager.setRemoveAllWhenShown(true);
                org.eclipse.swt.widgets.Menu contextMenu = menuManager.createContextMenu(table);
                tv.getControl().setMenu(contextMenu);
                menuManager.addMenuListener(new IMenuListener() {

                    public void menuAboutToShow(IMenuManager manager) {
                        actionGroup.fillContextMenu(manager);
                    }
                });
                composite.layout();
                composite.redraw();
            } catch (Exception e) {
                if (resultsTab != null) {
                    Composite composite = resultsTab.getParent();
                    String message = e.getMessage();
                    Label errorLabel = new Label(composite, 4);
                    errorLabel.setText(message);
                    errorLabel.setLayoutData(new GridData(4, 128, true, false));
                }
                SQLExplorerPlugin.error("Error creating explain tab", e);
            }
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Label(org.eclipse.swt.widgets.Label) TableTreeViewer(org.eclipse.jface.viewers.TableTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableTreeViewer(org.eclipse.jface.viewers.TableTreeViewer) ExplainPlanActionGroup(net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainPlanActionGroup) GridLayout(org.eclipse.swt.layout.GridLayout) ResultsTab(net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab) TableLayout(org.eclipse.jface.viewers.TableLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ExplainNode(net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainNode) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) IMenuListener(org.eclipse.jface.action.IMenuListener) SQLException(java.sql.SQLException) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager)

Aggregations

ResultsTab (net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab)4 Composite (org.eclipse.swt.widgets.Composite)3 SQLException (java.sql.SQLException)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Label (org.eclipse.swt.widgets.Label)2 DataSetTable (net.sourceforge.sqlexplorer.dataset.DataSetTable)1 ExplainNode (net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainNode)1 ExplainPlanActionGroup (net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainPlanActionGroup)1 Query (net.sourceforge.sqlexplorer.parsers.Query)1 Message (net.sourceforge.sqlexplorer.plugin.editors.Message)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 TableLayout (org.eclipse.jface.viewers.TableLayout)1 TableTreeViewer (org.eclipse.jface.viewers.TableTreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 CTabItem (org.eclipse.swt.custom.CTabItem)1