Search in sources :

Example 1 with ExplainPlanActionGroup

use of net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainPlanActionGroup 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

SQLException (java.sql.SQLException)1 ExplainNode (net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainNode)1 ExplainPlanActionGroup (net.sourceforge.sqlexplorer.oracle.actions.explain.ExplainPlanActionGroup)1 ResultsTab (net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab)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 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1