Search in sources :

Example 1 with DialogClosedListener

use of org.pentaho.di.ui.core.dialog.DialogClosedListener in project pentaho-kettle by pentaho.

the class TransGraph method sniff.

public void sniff(final boolean input, final boolean output, final boolean error) {
    StepMeta stepMeta = getCurrentStep();
    if (stepMeta == null || trans == null) {
        return;
    }
    final StepInterface runThread = trans.findRunThread(stepMeta.getName());
    if (runThread != null) {
        List<Object[]> rows = new ArrayList<>();
        final PreviewRowsDialog dialog = new PreviewRowsDialog(shell, trans, SWT.NONE, stepMeta.getName(), null, rows);
        dialog.setDynamic(true);
        // Add a row listener that sends the rows over to the dialog...
        // 
        final RowListener rowListener = new RowListener() {

            @Override
            public void rowReadEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                if (input) {
                    try {
                        dialog.addDataRow(rowMeta, rowMeta.cloneRow(row));
                    } catch (KettleValueException e) {
                        throw new KettleStepException(e);
                    }
                }
            }

            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                if (output) {
                    try {
                        dialog.addDataRow(rowMeta, rowMeta.cloneRow(row));
                    } catch (KettleValueException e) {
                        throw new KettleStepException(e);
                    }
                }
            }

            @Override
            public void errorRowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                if (error) {
                    try {
                        dialog.addDataRow(rowMeta, rowMeta.cloneRow(row));
                    } catch (KettleValueException e) {
                        throw new KettleStepException(e);
                    }
                }
            }
        };
        // When the dialog is closed, make sure to remove the listener!
        // 
        dialog.addDialogClosedListener(new DialogClosedListener() {

            @Override
            public void dialogClosed() {
                runThread.removeRowListener(rowListener);
            }
        });
        // Open the dialog in a separate thread to make sure it doesn't block
        // 
        getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                dialog.open();
            }
        });
        runThread.addRowListener(rowListener);
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) EnterPreviewRowsDialog(org.pentaho.di.ui.spoon.dialog.EnterPreviewRowsDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) KettleValueException(org.pentaho.di.core.exception.KettleValueException) StepMeta(org.pentaho.di.trans.step.StepMeta) RowListener(org.pentaho.di.trans.step.RowListener) DialogClosedListener(org.pentaho.di.ui.core.dialog.DialogClosedListener)

Aggregations

ArrayList (java.util.ArrayList)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 RowListener (org.pentaho.di.trans.step.RowListener)1 StepInterface (org.pentaho.di.trans.step.StepInterface)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 DialogClosedListener (org.pentaho.di.ui.core.dialog.DialogClosedListener)1 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)1 EnterPreviewRowsDialog (org.pentaho.di.ui.spoon.dialog.EnterPreviewRowsDialog)1