Search in sources :

Example 1 with AbstractSQLExecution

use of org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution in project tdi-studio-se by Talend.

the class SQLResultComposite method createTabItem.

/**
     * 
     * DOC dev Comment method "createTabItem".
     * 
     * @throws Exception throw all exception
     */
private void createTabItem() throws Exception {
    lastTabNumber = lastTabNumber + 1;
    final CTabItem tabItem = new CTabItem(tabFolder, SWT.NULL);
    String labelText = Messages.getString("SQLResultComposite.Result") + ": " + lastTabNumber;
    tabItem.setText(labelText);
    //$NON-NLS-1$
    tabItem.setData("tabLabel", labelText);
    tabItem.setToolTipText(TextUtil.getWrappedText(sqlExecution.getSqlStatement()));
    Composite composite = new Composite(tabFolder, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginLeft = 0;
    layout.marginTop = 0;
    layout.marginBottom = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    tabItem.setControl(composite);
    tabItem.setData(sqlExecution);
    tabItem.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(final DisposeEvent e) {
            BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                public void run() {
                    CTabItem tabItem = (CTabItem) e.getSource();
                    AbstractSQLExecution sqlExe = (AbstractSQLExecution) tabItem.getData();
                    sqlExe.stop();
                    tabItem.setData(null);
                    if (tabFolder != null && !tabFolder.isDisposed()) {
                        if (tabFolder.getItemCount() == 0) {
                            // this is last tab..
                            clearParent();
                            setDefaultMessage();
                        }
                    } else if (tabFolder.isDisposed()) {
                        clearParent();
                        setDefaultMessage();
                    }
                }
            });
        }
    });
    createHeaderComposite(composite, tabItem);
    createDetailComposite(composite, tabItem);
    // refresh view
    composite.layout();
    tabFolder.layout();
    tabFolder.redraw();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) AbstractSQLExecution(org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 2 with AbstractSQLExecution

use of org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution in project tdi-studio-se by Talend.

the class DB2ExplainPlanExecution method displayResults.

private void displayResults(final ExplainNode node) {
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        @SuppressWarnings("deprecation")
        public void run() {
            clearCanvas();
            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);
            try {
                //$NON-NLS-1$
                composite.setData("parenttab", parentTab);
                Composite pp = new Composite(composite, SWT.NULL);
                pp.setLayout(new FillLayout());
                pp.setLayoutData(new GridData(GridData.FILL_BOTH));
                TreeViewer tv = new TreeViewer(pp, SWT.BORDER | SWT.FULL_SELECTION);
                Tree tree = tv.getTree();
                tree.setLinesVisible(true);
                tree.setHeaderVisible(true);
                TreeColumn tc = new TreeColumn(tree, SWT.NULL);
                //$NON-NLS-1$
                tc.setText("");
                tc = new TreeColumn(tree, SWT.NULL);
                //$NON-NLS-1$
                tc.setText(Messages.getString("DB2ExplainPlanExecution.tableColumnText1"));
                tc = new TreeColumn(tree, SWT.NULL);
                //$NON-NLS-1$
                tc.setText(Messages.getString("DB2ExplainPlanExecution.tableColumnText2"));
                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));
                tree.setLayout(tableLayout);
                tv.setContentProvider(new ITreeContentProvider() {

                    @Override
                    public void dispose() {
                    }

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

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

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

                    @Override
                    public boolean hasChildren(Object element) {
                        if (((ExplainNode) element).getChildren().length > 0) {
                            return true;
                        }
                        return false;
                    }

                    @Override
                    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
                    }
                });
                tv.setLabelProvider(new TreeLabelProvider() {
                });
                tv.setInput(node);
                tv.refresh();
                tv.expandAll();
                // make columns full size
                for (int i = 0; i < tree.getColumnCount(); i++) {
                    tree.getColumn(i).pack();
                }
                final Composite parent = composite;
                tree.addKeyListener(new KeyAdapter() {

                    @Override
                    public void keyReleased(KeyEvent e) {
                        switch(e.keyCode) {
                            case SWT.F5:
                                // refresh SQL Results
                                try {
                                    //$NON-NLS-1$
                                    Object o = parent.getData("parenttab");
                                    if (o != null) {
                                        AbstractSQLExecution sqlExec = (AbstractSQLExecution) ((TabItem) o).getData();
                                        if (sqlExec != null) {
                                            sqlExec.startExecution();
                                        }
                                    }
                                } catch (Exception e1) {
                                    //$NON-NLS-1$
                                    SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanExecution.logMessageError1"), e1);
                                }
                                break;
                            default:
                                return;
                        }
                    }
                });
            } catch (Exception e) {
                // add message
                String message = e.getMessage();
                Label errorLabel = new Label(composite, SWT.FILL);
                errorLabel.setText(message);
                errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanExecution.logMessageError2"), e);
            }
            composite.layout();
            composite.redraw();
        }

        ;
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FillLayout(org.eclipse.swt.layout.FillLayout) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AbstractSQLExecution(org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 3 with AbstractSQLExecution

use of org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution in project tdi-studio-se by Talend.

the class OracleExplainPlanExecution method displayResults.

private void displayResults(final ExplainNode node) {
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        @SuppressWarnings("deprecation")
        public void run() {
            clearCanvas();
            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);
            try {
                //$NON-NLS-1$
                composite.setData("parenttab", parentTab);
                Composite pp = new Composite(composite, SWT.NULL);
                pp.setLayout(new FillLayout());
                pp.setLayoutData(new GridData(GridData.FILL_BOTH));
                TreeViewer tv = new TreeViewer(pp, SWT.BORDER | SWT.FULL_SELECTION);
                Tree tree = tv.getTree();
                tree.setLinesVisible(true);
                tree.setHeaderVisible(true);
                TreeColumn tc = new TreeColumn(tree, SWT.NULL);
                //$NON-NLS-1$
                tc.setText("");
                tc = new TreeColumn(tree, SWT.NULL);
                //$NON-NLS-1$
                tc.setText(Messages.getString("OracleExplainPlanExecution.tableColumnText1"));
                tc = new TreeColumn(tree, SWT.NULL);
                //$NON-NLS-1$
                tc.setText(Messages.getString("OracleExplainPlanExecution.tableColumnText2"));
                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));
                tree.setLayout(tableLayout);
                tv.setContentProvider(new ITreeContentProvider() {

                    @Override
                    public void dispose() {
                    }

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

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

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

                    @Override
                    public boolean hasChildren(Object element) {
                        if (((ExplainNode) element).getChildren().length > 0) {
                            return true;
                        }
                        return false;
                    }

                    @Override
                    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
                    }
                });
                tv.setLabelProvider(new TreeLabelProvider() {
                });
                tv.setInput(node);
                tv.refresh();
                tv.expandAll();
                // make columns full size
                for (int i = 0; i < tree.getColumnCount(); i++) {
                    tree.getColumn(i).pack();
                }
                final Composite parent = composite;
                tree.addKeyListener(new KeyAdapter() {

                    @Override
                    public void keyReleased(KeyEvent e) {
                        switch(e.keyCode) {
                            case SWT.F5:
                                // refresh SQL Results
                                try {
                                    //$NON-NLS-1$
                                    Object o = parent.getData("parenttab");
                                    if (o != null) {
                                        AbstractSQLExecution sqlExec = (AbstractSQLExecution) ((TabItem) o).getData();
                                        if (sqlExec != null) {
                                            sqlExec.startExecution();
                                        }
                                    }
                                } catch (Exception e1) {
                                    //$NON-NLS-1$
                                    SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanExecution.logMessage1"), e1);
                                }
                                break;
                            default:
                                return;
                        }
                    }
                });
            } catch (Exception e) {
                // add message
                String message = e.getMessage();
                Label errorLabel = new Label(composite, SWT.FILL);
                errorLabel.setText(message);
                errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanExecution.logMessage2"), e);
            }
            composite.layout();
            composite.redraw();
        }

        ;
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FillLayout(org.eclipse.swt.layout.FillLayout) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AbstractSQLExecution(org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) TableLayout(org.eclipse.jface.viewers.TableLayout)

Aggregations

GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 AbstractSQLExecution (org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution)3 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 TableLayout (org.eclipse.jface.viewers.TableLayout)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Viewer (org.eclipse.jface.viewers.Viewer)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Label (org.eclipse.swt.widgets.Label)2 Tree (org.eclipse.swt.widgets.Tree)2 TreeColumn (org.eclipse.swt.widgets.TreeColumn)2 CTabItem (org.eclipse.swt.custom.CTabItem)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1