Search in sources :

Example 16 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class TransGraphTest method testInitializeXulMenu.

@SuppressWarnings("unchecked")
@Test
public void testInitializeXulMenu() throws KettleException {
    StepMeta stepMeta = mock(StepMeta.class);
    TransGraph transGraph = mock(TransGraph.class);
    TransMeta transMeta = mock(TransMeta.class);
    Document document = mock(Document.class);
    XulMenuitem xulItem = mock(XulMenuitem.class);
    XulMenu xulMenu = mock(XulMenu.class);
    StepErrorMeta stepErrorMeta = mock(StepErrorMeta.class);
    Spoon spoon = mock(Spoon.class);
    List<StepMeta> selection = Arrays.asList(new StepMeta(), stepMeta, new StepMeta());
    doCallRealMethod().when(transGraph).setTransMeta(any(TransMeta.class));
    doCallRealMethod().when(transGraph).setSpoon(any(Spoon.class));
    transGraph.setTransMeta(transMeta);
    transGraph.setSpoon(spoon);
    when(stepMeta.getStepErrorMeta()).thenReturn(stepErrorMeta);
    when(stepMeta.isDrawn()).thenReturn(true);
    when(document.getElementById(any(String.class))).thenReturn(xulItem);
    when(document.getElementById(TransGraph.TRANS_GRAPH_ENTRY_AGAIN)).thenReturn(xulMenu);
    when(document.getElementById(TransGraph.TRANS_GRAPH_ENTRY_SNIFF)).thenReturn(xulMenu);
    doCallRealMethod().when(transGraph).initializeXulMenu(any(Document.class), any(List.class), any(StepMeta.class));
    transGraph.initializeXulMenu(document, selection, stepMeta);
    verify(transMeta).isAnySelectedStepUsedInTransHops();
}
Also used : XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) Spoon(org.pentaho.di.ui.spoon.Spoon) TransMeta(org.pentaho.di.trans.TransMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) List(java.util.List) Document(org.pentaho.ui.xul.dom.Document) StepMeta(org.pentaho.di.trans.step.StepMeta) XulMenu(org.pentaho.ui.xul.containers.XulMenu) Test(org.junit.Test)

Example 17 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class TableOutputDialog method open.

/**
 * Open the dialog.
 */
public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    setShellImage(shell, input);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    ModifyListener lsTableMod = new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            input.setChanged();
            setTableFieldCombo();
        }
    };
    SelectionListener lsSelection = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setTableFieldCombo();
        }
    };
    backupChanged = input.hasChanged();
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "TableOutputDialog.DialogTitle"));
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    wConnection.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setFlags();
        }
    });
    wConnection.addSelectionListener(lsSelection);
    // Schema line...
    wlSchema = new Label(shell, SWT.RIGHT);
    wlSchema.setText(BaseMessages.getString(PKG, "TableOutputDialog.TargetSchema.Label"));
    props.setLook(wlSchema);
    fdlSchema = new FormData();
    fdlSchema.left = new FormAttachment(0, 0);
    fdlSchema.right = new FormAttachment(middle, -margin);
    fdlSchema.top = new FormAttachment(wConnection, margin * 2);
    wlSchema.setLayoutData(fdlSchema);
    wbSchema = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbSchema);
    wbSchema.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbSchema = new FormData();
    fdbSchema.top = new FormAttachment(wConnection, 2 * margin);
    fdbSchema.right = new FormAttachment(100, 0);
    wbSchema.setLayoutData(fdbSchema);
    wSchema = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSchema);
    wSchema.addModifyListener(lsTableMod);
    fdSchema = new FormData();
    fdSchema.left = new FormAttachment(middle, 0);
    fdSchema.top = new FormAttachment(wConnection, margin * 2);
    fdSchema.right = new FormAttachment(wbSchema, -margin);
    wSchema.setLayoutData(fdSchema);
    // Table line...
    wlTable = new Label(shell, SWT.RIGHT);
    wlTable.setText(BaseMessages.getString(PKG, "TableOutputDialog.TargetTable.Label"));
    props.setLook(wlTable);
    fdlTable = new FormData();
    fdlTable.left = new FormAttachment(0, 0);
    fdlTable.right = new FormAttachment(middle, -margin);
    fdlTable.top = new FormAttachment(wbSchema, margin);
    wlTable.setLayoutData(fdlTable);
    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wbSchema, margin);
    wbTable.setLayoutData(fdbTable);
    wTable = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTable);
    wTable.addModifyListener(lsTableMod);
    fdTable = new FormData();
    fdTable.top = new FormAttachment(wbSchema, margin);
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);
    // Commit size ...
    wlCommit = new Label(shell, SWT.RIGHT);
    wlCommit.setText(BaseMessages.getString(PKG, "TableOutputDialog.CommitSize.Label"));
    props.setLook(wlCommit);
    fdlCommit = new FormData();
    fdlCommit.left = new FormAttachment(0, 0);
    fdlCommit.right = new FormAttachment(middle, -margin);
    fdlCommit.top = new FormAttachment(wbTable, margin);
    wlCommit.setLayoutData(fdlCommit);
    wCommit = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCommit);
    wCommit.addModifyListener(lsMod);
    fdCommit = new FormData();
    fdCommit.left = new FormAttachment(middle, 0);
    fdCommit.top = new FormAttachment(wbTable, margin);
    fdCommit.right = new FormAttachment(100, 0);
    wCommit.setLayoutData(fdCommit);
    // Truncate table
    wlTruncate = new Label(shell, SWT.RIGHT);
    wlTruncate.setText(BaseMessages.getString(PKG, "TableOutputDialog.TruncateTable.Label"));
    props.setLook(wlTruncate);
    fdlTruncate = new FormData();
    fdlTruncate.left = new FormAttachment(0, 0);
    fdlTruncate.top = new FormAttachment(wCommit, margin);
    fdlTruncate.right = new FormAttachment(middle, -margin);
    wlTruncate.setLayoutData(fdlTruncate);
    wTruncate = new Button(shell, SWT.CHECK);
    props.setLook(wTruncate);
    fdTruncate = new FormData();
    fdTruncate.left = new FormAttachment(middle, 0);
    fdTruncate.top = new FormAttachment(wCommit, margin);
    fdTruncate.right = new FormAttachment(100, 0);
    wTruncate.setLayoutData(fdTruncate);
    SelectionAdapter lsSelMod = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
        }
    };
    wTruncate.addSelectionListener(lsSelMod);
    // Ignore errors
    wlIgnore = new Label(shell, SWT.RIGHT);
    wlIgnore.setText(BaseMessages.getString(PKG, "TableOutputDialog.IgnoreInsertErrors.Label"));
    props.setLook(wlIgnore);
    fdlIgnore = new FormData();
    fdlIgnore.left = new FormAttachment(0, 0);
    fdlIgnore.top = new FormAttachment(wTruncate, margin);
    fdlIgnore.right = new FormAttachment(middle, -margin);
    wlIgnore.setLayoutData(fdlIgnore);
    wIgnore = new Button(shell, SWT.CHECK);
    props.setLook(wIgnore);
    fdIgnore = new FormData();
    fdIgnore.left = new FormAttachment(middle, 0);
    fdIgnore.top = new FormAttachment(wTruncate, margin);
    fdIgnore.right = new FormAttachment(100, 0);
    wIgnore.setLayoutData(fdIgnore);
    wIgnore.addSelectionListener(lsSelMod);
    // Specify fields
    wlSpecifyFields = new Label(shell, SWT.RIGHT);
    wlSpecifyFields.setText(BaseMessages.getString(PKG, "TableOutputDialog.SpecifyFields.Label"));
    props.setLook(wlSpecifyFields);
    fdlSpecifyFields = new FormData();
    fdlSpecifyFields.left = new FormAttachment(0, 0);
    fdlSpecifyFields.top = new FormAttachment(wIgnore, margin);
    fdlSpecifyFields.right = new FormAttachment(middle, -margin);
    wlSpecifyFields.setLayoutData(fdlSpecifyFields);
    wSpecifyFields = new Button(shell, SWT.CHECK);
    props.setLook(wSpecifyFields);
    fdSpecifyFields = new FormData();
    fdSpecifyFields.left = new FormAttachment(middle, 0);
    fdSpecifyFields.top = new FormAttachment(wIgnore, margin);
    fdSpecifyFields.right = new FormAttachment(100, 0);
    wSpecifyFields.setLayoutData(fdSpecifyFields);
    wSpecifyFields.addSelectionListener(lsSelMod);
    // If the flag is off, gray out the fields tab e.g.
    wSpecifyFields.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setFlags();
        }
    });
    wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
    // ////////////////////////
    // START OF KEY TAB ///
    // /
    wMainTab = new CTabItem(wTabFolder, SWT.NONE);
    wMainTab.setText(BaseMessages.getString(PKG, "TableOutputDialog.MainTab.CTabItem"));
    FormLayout mainLayout = new FormLayout();
    mainLayout.marginWidth = 3;
    mainLayout.marginHeight = 3;
    Composite wMainComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wMainComp);
    wMainComp.setLayout(mainLayout);
    // Partitioning support
    // Use partitioning?
    wlUsePart = new Label(wMainComp, SWT.RIGHT);
    wlUsePart.setText(BaseMessages.getString(PKG, "TableOutputDialog.UsePart.Label"));
    wlUsePart.setToolTipText(BaseMessages.getString(PKG, "TableOutputDialog.UsePart.Tooltip"));
    props.setLook(wlUsePart);
    fdlUsePart = new FormData();
    fdlUsePart.left = new FormAttachment(0, 0);
    fdlUsePart.top = new FormAttachment(wSpecifyFields, margin * 5);
    fdlUsePart.right = new FormAttachment(middle, -margin);
    wlUsePart.setLayoutData(fdlUsePart);
    wUsePart = new Button(wMainComp, SWT.CHECK);
    props.setLook(wUsePart);
    fdUsePart = new FormData();
    fdUsePart.left = new FormAttachment(middle, 0);
    fdUsePart.top = new FormAttachment(wSpecifyFields, margin * 5);
    fdUsePart.right = new FormAttachment(100, 0);
    wUsePart.setLayoutData(fdUsePart);
    wUsePart.addSelectionListener(lsSelMod);
    wUsePart.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            if (wUsePart.getSelection()) {
                wNameInField.setSelection(false);
            }
            setFlags();
        }
    });
    // Partitioning field
    wlPartField = new Label(wMainComp, SWT.RIGHT);
    wlPartField.setText(BaseMessages.getString(PKG, "TableOutputDialog.PartField.Label"));
    props.setLook(wlPartField);
    fdlPartField = new FormData();
    fdlPartField.top = new FormAttachment(wUsePart, margin);
    fdlPartField.left = new FormAttachment(0, 0);
    fdlPartField.right = new FormAttachment(middle, -margin);
    wlPartField.setLayoutData(fdlPartField);
    wPartField = new ComboVar(transMeta, wMainComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wPartField);
    wPartField.addModifyListener(lsMod);
    fdPartField = new FormData();
    fdPartField.top = new FormAttachment(wUsePart, margin);
    fdPartField.left = new FormAttachment(middle, 0);
    fdPartField.right = new FormAttachment(100, 0);
    wPartField.setLayoutData(fdPartField);
    wPartField.addFocusListener(new FocusListener() {

        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
        }

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            shell.setCursor(busy);
            getFields();
            shell.setCursor(null);
            busy.dispose();
        }
    });
    // Partition per month
    wlPartMonthly = new Label(wMainComp, SWT.RIGHT);
    wlPartMonthly.setText(BaseMessages.getString(PKG, "TableOutputDialog.PartMonthly.Label"));
    wlPartMonthly.setToolTipText(BaseMessages.getString(PKG, "TableOutputDialog.PartMonthly.Tooltip"));
    props.setLook(wlPartMonthly);
    fdlPartMonthly = new FormData();
    fdlPartMonthly.left = new FormAttachment(0, 0);
    fdlPartMonthly.top = new FormAttachment(wPartField, margin);
    fdlPartMonthly.right = new FormAttachment(middle, -margin);
    wlPartMonthly.setLayoutData(fdlPartMonthly);
    wPartMonthly = new Button(wMainComp, SWT.RADIO);
    props.setLook(wPartMonthly);
    fdPartMonthly = new FormData();
    fdPartMonthly.left = new FormAttachment(middle, 0);
    fdPartMonthly.top = new FormAttachment(wPartField, margin);
    fdPartMonthly.right = new FormAttachment(100, 0);
    wPartMonthly.setLayoutData(fdPartMonthly);
    wPartMonthly.addSelectionListener(lsSelMod);
    wPartMonthly.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            wPartMonthly.setSelection(true);
            wPartDaily.setSelection(false);
        }
    });
    // Partition per month
    wlPartDaily = new Label(wMainComp, SWT.RIGHT);
    wlPartDaily.setText(BaseMessages.getString(PKG, "TableOutputDialog.PartDaily.Label"));
    wlPartDaily.setToolTipText(BaseMessages.getString(PKG, "TableOutputDialog.PartDaily.Tooltip"));
    props.setLook(wlPartDaily);
    fdlPartDaily = new FormData();
    fdlPartDaily.left = new FormAttachment(0, 0);
    fdlPartDaily.top = new FormAttachment(wPartMonthly, margin);
    fdlPartDaily.right = new FormAttachment(middle, -margin);
    wlPartDaily.setLayoutData(fdlPartDaily);
    wPartDaily = new Button(wMainComp, SWT.RADIO);
    props.setLook(wPartDaily);
    fdPartDaily = new FormData();
    fdPartDaily.left = new FormAttachment(middle, 0);
    fdPartDaily.top = new FormAttachment(wPartMonthly, margin);
    fdPartDaily.right = new FormAttachment(100, 0);
    wPartDaily.setLayoutData(fdPartDaily);
    wPartDaily.addSelectionListener(lsSelMod);
    wPartDaily.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            wPartDaily.setSelection(true);
            wPartMonthly.setSelection(false);
        }
    });
    // Batch update
    wlBatch = new Label(wMainComp, SWT.RIGHT);
    wlBatch.setText(BaseMessages.getString(PKG, "TableOutputDialog.Batch.Label"));
    props.setLook(wlBatch);
    fdlBatch = new FormData();
    fdlBatch.left = new FormAttachment(0, 0);
    fdlBatch.top = new FormAttachment(wPartDaily, 5 * margin);
    fdlBatch.right = new FormAttachment(middle, -margin);
    wlBatch.setLayoutData(fdlBatch);
    wBatch = new Button(wMainComp, SWT.CHECK);
    props.setLook(wBatch);
    fdBatch = new FormData();
    fdBatch.left = new FormAttachment(middle, 0);
    fdBatch.top = new FormAttachment(wPartDaily, 5 * margin);
    fdBatch.right = new FormAttachment(100, 0);
    wBatch.setLayoutData(fdBatch);
    wBatch.addSelectionListener(lsSelMod);
    wBatch.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setFlags();
        }
    });
    // NameInField
    wlNameInField = new Label(wMainComp, SWT.RIGHT);
    wlNameInField.setText(BaseMessages.getString(PKG, "TableOutputDialog.NameInField.Label"));
    props.setLook(wlNameInField);
    fdlNameInField = new FormData();
    fdlNameInField.left = new FormAttachment(0, 0);
    fdlNameInField.top = new FormAttachment(wBatch, margin * 5);
    fdlNameInField.right = new FormAttachment(middle, -margin);
    wlNameInField.setLayoutData(fdlNameInField);
    wNameInField = new Button(wMainComp, SWT.CHECK);
    props.setLook(wNameInField);
    fdNameInField = new FormData();
    fdNameInField.left = new FormAttachment(middle, 0);
    fdNameInField.top = new FormAttachment(wBatch, margin * 5);
    fdNameInField.right = new FormAttachment(100, 0);
    wNameInField.setLayoutData(fdNameInField);
    wNameInField.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            if (wNameInField.getSelection()) {
                wUsePart.setSelection(false);
            }
            setFlags();
        }
    });
    wNameInField.addSelectionListener(lsSelMod);
    // NameField size ...
    wlNameField = new Label(wMainComp, SWT.RIGHT);
    wlNameField.setText(BaseMessages.getString(PKG, "TableOutputDialog.NameField.Label"));
    props.setLook(wlNameField);
    fdlNameField = new FormData();
    fdlNameField.left = new FormAttachment(0, 0);
    fdlNameField.top = new FormAttachment(wNameInField, margin);
    fdlNameField.right = new FormAttachment(middle, -margin);
    wlNameField.setLayoutData(fdlNameField);
    wNameField = new ComboVar(transMeta, wMainComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wNameField);
    wNameField.addModifyListener(lsMod);
    fdNameField = new FormData();
    fdNameField.left = new FormAttachment(middle, 0);
    fdNameField.top = new FormAttachment(wNameInField, margin);
    fdNameField.right = new FormAttachment(100, 0);
    wNameField.setLayoutData(fdNameField);
    wNameField.addFocusListener(new FocusListener() {

        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
        }

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            shell.setCursor(busy);
            getFields();
            shell.setCursor(null);
            busy.dispose();
        }
    });
    // NameInTable
    wlNameInTable = new Label(wMainComp, SWT.RIGHT);
    wlNameInTable.setText(BaseMessages.getString(PKG, "TableOutputDialog.NameInTable.Label"));
    props.setLook(wlNameInTable);
    fdlNameInTable = new FormData();
    fdlNameInTable.left = new FormAttachment(0, 0);
    fdlNameInTable.top = new FormAttachment(wNameField, margin);
    fdlNameInTable.right = new FormAttachment(middle, -margin);
    wlNameInTable.setLayoutData(fdlNameInTable);
    wNameInTable = new Button(wMainComp, SWT.CHECK);
    props.setLook(wNameInTable);
    fdNameInTable = new FormData();
    fdNameInTable.left = new FormAttachment(middle, 0);
    fdNameInTable.top = new FormAttachment(wNameField, margin);
    fdNameInTable.right = new FormAttachment(100, 0);
    wNameInTable.setLayoutData(fdNameInTable);
    wNameInTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setFlags();
        }
    });
    wNameInTable.addSelectionListener(lsSelMod);
    // Return generated keys?
    wlReturnKeys = new Label(wMainComp, SWT.RIGHT);
    wlReturnKeys.setText(BaseMessages.getString(PKG, "TableOutputDialog.ReturnKeys.Label"));
    wlReturnKeys.setToolTipText(BaseMessages.getString(PKG, "TableOutputDialog.ReturnKeys.Tooltip"));
    props.setLook(wlReturnKeys);
    fdlReturnKeys = new FormData();
    fdlReturnKeys.left = new FormAttachment(0, 0);
    fdlReturnKeys.top = new FormAttachment(wNameInTable, margin * 5);
    fdlReturnKeys.right = new FormAttachment(middle, -margin);
    wlReturnKeys.setLayoutData(fdlReturnKeys);
    wReturnKeys = new Button(wMainComp, SWT.CHECK);
    props.setLook(wReturnKeys);
    fdReturnKeys = new FormData();
    fdReturnKeys.left = new FormAttachment(middle, 0);
    fdReturnKeys.top = new FormAttachment(wNameInTable, margin * 5);
    fdReturnKeys.right = new FormAttachment(100, 0);
    wReturnKeys.setLayoutData(fdReturnKeys);
    wReturnKeys.addSelectionListener(lsSelMod);
    wReturnKeys.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setFlags();
        }
    });
    // ReturnField size ...
    wlReturnField = new Label(wMainComp, SWT.RIGHT);
    wlReturnField.setText(BaseMessages.getString(PKG, "TableOutputDialog.ReturnField.Label"));
    props.setLook(wlReturnField);
    fdlReturnField = new FormData();
    fdlReturnField.left = new FormAttachment(0, 0);
    fdlReturnField.right = new FormAttachment(middle, -margin);
    fdlReturnField.top = new FormAttachment(wReturnKeys, margin);
    wlReturnField.setLayoutData(fdlReturnField);
    wReturnField = new TextVar(transMeta, wMainComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wReturnField);
    wReturnField.addModifyListener(lsMod);
    fdReturnField = new FormData();
    fdReturnField.left = new FormAttachment(middle, 0);
    fdReturnField.top = new FormAttachment(wReturnKeys, margin);
    fdReturnField.right = new FormAttachment(100, 0);
    wReturnField.setLayoutData(fdReturnField);
    fdMainComp = new FormData();
    fdMainComp.left = new FormAttachment(0, 0);
    fdMainComp.top = new FormAttachment(0, 0);
    fdMainComp.right = new FormAttachment(100, 0);
    fdMainComp.bottom = new FormAttachment(100, 0);
    wMainComp.setLayoutData(fdMainComp);
    wMainComp.layout();
    wMainTab.setControl(wMainComp);
    // 
    // Fields tab...
    // 
    wFieldsTab = new CTabItem(wTabFolder, SWT.NONE);
    wFieldsTab.setText(BaseMessages.getString(PKG, "TableOutputDialog.FieldsTab.CTabItem.Title"));
    Composite wFieldsComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wFieldsComp);
    FormLayout fieldsCompLayout = new FormLayout();
    fieldsCompLayout.marginWidth = Const.FORM_MARGIN;
    fieldsCompLayout.marginHeight = Const.FORM_MARGIN;
    wFieldsComp.setLayout(fieldsCompLayout);
    // The fields table
    wlFields = new Label(wFieldsComp, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "TableOutputDialog.InsertFields.Label"));
    props.setLook(wlFields);
    FormData fdlUpIns = new FormData();
    fdlUpIns.left = new FormAttachment(0, 0);
    fdlUpIns.top = new FormAttachment(0, margin);
    wlFields.setLayoutData(fdlUpIns);
    int tableCols = 2;
    int UpInsRows = (input.getFieldStream() != null ? input.getFieldStream().length : 1);
    ciFields = new ColumnInfo[tableCols];
    ciFields[0] = new ColumnInfo(BaseMessages.getString(PKG, "TableOutputDialog.ColumnInfo.TableField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciFields[1] = new ColumnInfo(BaseMessages.getString(PKG, "TableOutputDialog.ColumnInfo.StreamField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    tableFieldColumns.add(ciFields[0]);
    wFields = new TableView(transMeta, wFieldsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciFields, UpInsRows, lsMod, props);
    wGetFields = new Button(wFieldsComp, SWT.PUSH);
    wGetFields.setText(BaseMessages.getString(PKG, "TableOutputDialog.GetFields.Button"));
    fdGetFields = new FormData();
    fdGetFields.top = new FormAttachment(wlFields, margin);
    fdGetFields.right = new FormAttachment(100, 0);
    wGetFields.setLayoutData(fdGetFields);
    wDoMapping = new Button(wFieldsComp, SWT.PUSH);
    wDoMapping.setText(BaseMessages.getString(PKG, "TableOutputDialog.DoMapping.Button"));
    fdDoMapping = new FormData();
    fdDoMapping.top = new FormAttachment(wGetFields, margin);
    fdDoMapping.right = new FormAttachment(100, 0);
    wDoMapping.setLayoutData(fdDoMapping);
    wDoMapping.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event arg0) {
            generateMappings();
        }
    });
    FormData fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(wDoMapping, -margin);
    fdFields.bottom = new FormAttachment(100, -2 * margin);
    wFields.setLayoutData(fdFields);
    fdFieldsComp = new FormData();
    fdFieldsComp.left = new FormAttachment(0, 0);
    fdFieldsComp.top = new FormAttachment(0, 0);
    fdFieldsComp.right = new FormAttachment(100, 0);
    fdFieldsComp.bottom = new FormAttachment(100, 0);
    wFieldsComp.setLayoutData(fdFieldsComp);
    wFieldsComp.layout();
    wFieldsTab.setControl(wFieldsComp);
    // 
    // Search the fields in the background
    // 
    final Runnable runnable = new Runnable() {

        public void run() {
            StepMeta stepMeta = transMeta.findStep(stepname);
            if (stepMeta != null) {
                try {
                    RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);
                    // Remember these fields...
                    for (int i = 0; i < row.size(); i++) {
                        inputFields.put(row.getValueMeta(i).getName(), i);
                    }
                    setComboBoxes();
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCreate = new Button(shell, SWT.PUSH);
    wCreate.setText(BaseMessages.getString(PKG, "System.Button.SQL"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wCreate }, margin, null);
    fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wSpecifyFields, margin);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(wOK, -margin);
    wTabFolder.setLayoutData(fdTabFolder);
    // Add listeners
    lsOK = new Listener() {

        public void handleEvent(Event e) {
            ok();
        }
    };
    lsCreate = new Listener() {

        public void handleEvent(Event e) {
            sql();
        }
    };
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsGet = new Listener() {

        public void handleEvent(Event e) {
            get();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wCreate.addListener(SWT.Selection, lsCreate);
    wCancel.addListener(SWT.Selection, lsCancel);
    wGetFields.addListener(SWT.Selection, lsGet);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wCommit.addSelectionListener(lsDef);
    wSchema.addSelectionListener(lsDef);
    wTable.addSelectionListener(lsDef);
    wPartField.addSelectionListener(lsDef);
    wNameField.addSelectionListener(lsDef);
    wReturnField.addSelectionListener(lsDef);
    wbTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            getTableName();
        }
    });
    wbSchema.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            getSchemaNames();
        }
    });
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    wTabFolder.setSelection(0);
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    setTableFieldCombo();
    input.setChanged(backupChanged);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ComboVar(org.pentaho.di.ui.core.widget.ComboVar) CTabFolder(org.eclipse.swt.custom.CTabFolder) SelectionListener(org.eclipse.swt.events.SelectionListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Cursor(org.eclipse.swt.graphics.Cursor) CTabItem(org.eclipse.swt.custom.CTabItem) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) TextVar(org.pentaho.di.ui.core.widget.TextVar) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 18 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class TeraFastDialog method open.

/**
 * {@inheritDoc}
 *
 * @see org.pentaho.di.trans.step.StepDialogInterface#open()
 */
public String open() {
    this.changed = this.meta.hasChanged();
    final Shell parent = getParent();
    final Display display = parent.getDisplay();
    this.shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    this.props.setLook(this.shell);
    setShellImage(this.shell, this.meta);
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    this.shell.setLayout(formLayout);
    this.shell.setText(BaseMessages.getString(PKG, "TeraFastDialog.Shell.Title"));
    buildUi();
    assignChangeListener();
    listeners();
    // 
    // Search the fields in the background
    // 
    final Runnable runnable = new Runnable() {

        public void run() {
            final StepMeta stepMetaSearchFields = TeraFastDialog.this.transMeta.findStep(TeraFastDialog.this.stepname);
            if (stepMetaSearchFields == null) {
                return;
            }
            try {
                final RowMetaInterface row = TeraFastDialog.this.transMeta.getPrevStepFields(stepMetaSearchFields);
                // Remember these fields...
                for (int i = 0; i < row.size(); i++) {
                    TeraFastDialog.this.inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i));
                }
                setComboBoxes();
            } catch (KettleException e) {
                TeraFastDialog.this.logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
            }
        }
    };
    new Thread(runnable).start();
    // 
    // // Set the shell size, based upon previous time...
    setSize();
    getData();
    this.meta.setChanged(this.changed);
    disableInputs();
    this.shell.open();
    while (!this.shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return this.stepname;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) KettleException(org.pentaho.di.core.exception.KettleException) Shell(org.eclipse.swt.widgets.Shell) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Display(org.eclipse.swt.widgets.Display)

Example 19 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class MySQLBulkLoaderDialog method open.

public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    setShellImage(shell, input);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    FocusListener lsFocusLost = new FocusAdapter() {

        public void focusLost(FocusEvent arg0) {
            setTableFieldCombo();
        }
    };
    changed = input.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // Schema line...
    wlSchema = new Label(shell, SWT.RIGHT);
    wlSchema.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.TargetSchema.Label"));
    props.setLook(wlSchema);
    fdlSchema = new FormData();
    fdlSchema.left = new FormAttachment(0, 0);
    fdlSchema.right = new FormAttachment(middle, -margin);
    fdlSchema.top = new FormAttachment(wConnection, margin * 2);
    wlSchema.setLayoutData(fdlSchema);
    wSchema = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSchema);
    wSchema.addModifyListener(lsMod);
    wSchema.addFocusListener(lsFocusLost);
    fdSchema = new FormData();
    fdSchema.left = new FormAttachment(middle, 0);
    fdSchema.top = new FormAttachment(wConnection, margin * 2);
    fdSchema.right = new FormAttachment(100, 0);
    wSchema.setLayoutData(fdSchema);
    // Table line...
    wlTable = new Label(shell, SWT.RIGHT);
    wlTable.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.TargetTable.Label"));
    props.setLook(wlTable);
    fdlTable = new FormData();
    fdlTable.left = new FormAttachment(0, 0);
    fdlTable.right = new FormAttachment(middle, -margin);
    fdlTable.top = new FormAttachment(wSchema, margin);
    wlTable.setLayoutData(fdlTable);
    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Browse.Button"));
    fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wSchema, margin);
    wbTable.setLayoutData(fdbTable);
    wTable = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTable);
    wTable.addModifyListener(lsMod);
    wTable.addFocusListener(lsFocusLost);
    fdTable = new FormData();
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.top = new FormAttachment(wSchema, margin);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);
    // FifoFile line...
    wlFifoFile = new Label(shell, SWT.RIGHT);
    wlFifoFile.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.FifoFile.Label"));
    props.setLook(wlFifoFile);
    fdlFifoFile = new FormData();
    fdlFifoFile.left = new FormAttachment(0, 0);
    fdlFifoFile.right = new FormAttachment(middle, -margin);
    fdlFifoFile.top = new FormAttachment(wTable, margin);
    wlFifoFile.setLayoutData(fdlFifoFile);
    wFifoFile = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFifoFile);
    wFifoFile.addModifyListener(lsMod);
    fdFifoFile = new FormData();
    fdFifoFile.left = new FormAttachment(middle, 0);
    fdFifoFile.top = new FormAttachment(wTable, margin);
    fdFifoFile.right = new FormAttachment(100, 0);
    wFifoFile.setLayoutData(fdFifoFile);
    // Delimiter line...
    wlDelimiter = new Label(shell, SWT.RIGHT);
    wlDelimiter.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Delimiter.Label"));
    props.setLook(wlDelimiter);
    fdlDelimiter = new FormData();
    fdlDelimiter.left = new FormAttachment(0, 0);
    fdlDelimiter.right = new FormAttachment(middle, -margin);
    fdlDelimiter.top = new FormAttachment(wFifoFile, margin);
    wlDelimiter.setLayoutData(fdlDelimiter);
    wbDelimiter = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbDelimiter);
    wbDelimiter.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Delimiter.Button"));
    FormData fdbDelimiter = new FormData();
    fdbDelimiter.top = new FormAttachment(wFifoFile, margin);
    fdbDelimiter.right = new FormAttachment(100, 0);
    wbDelimiter.setLayoutData(fdbDelimiter);
    wDelimiter = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDelimiter);
    wDelimiter.addModifyListener(lsMod);
    fdDelimiter = new FormData();
    fdDelimiter.left = new FormAttachment(middle, 0);
    fdDelimiter.top = new FormAttachment(wFifoFile, margin);
    fdDelimiter.right = new FormAttachment(wbDelimiter, -margin);
    wDelimiter.setLayoutData(fdDelimiter);
    // Allow the insertion of tabs as separator...
    wbDelimiter.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            Text t = wDelimiter.getTextWidget();
            if (t != null) {
                t.insert("\t");
            }
        }
    });
    // Enclosure line...
    wlEnclosure = new Label(shell, SWT.RIGHT);
    wlEnclosure.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Enclosure.Label"));
    props.setLook(wlEnclosure);
    fdlEnclosure = new FormData();
    fdlEnclosure.left = new FormAttachment(0, 0);
    fdlEnclosure.right = new FormAttachment(middle, -margin);
    fdlEnclosure.top = new FormAttachment(wDelimiter, margin);
    wlEnclosure.setLayoutData(fdlEnclosure);
    wEnclosure = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEnclosure);
    wEnclosure.addModifyListener(lsMod);
    fdEnclosure = new FormData();
    fdEnclosure.left = new FormAttachment(middle, 0);
    fdEnclosure.top = new FormAttachment(wDelimiter, margin);
    fdEnclosure.right = new FormAttachment(100, 0);
    wEnclosure.setLayoutData(fdEnclosure);
    // EscapeChar line...
    wlEscapeChar = new Label(shell, SWT.RIGHT);
    wlEscapeChar.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.EscapeChar.Label"));
    props.setLook(wlEscapeChar);
    fdlEscapeChar = new FormData();
    fdlEscapeChar.left = new FormAttachment(0, 0);
    fdlEscapeChar.right = new FormAttachment(middle, -margin);
    fdlEscapeChar.top = new FormAttachment(wEnclosure, margin);
    wlEscapeChar.setLayoutData(fdlEscapeChar);
    wEscapeChar = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEscapeChar);
    wEscapeChar.addModifyListener(lsMod);
    fdEscapeChar = new FormData();
    fdEscapeChar.left = new FormAttachment(middle, 0);
    fdEscapeChar.top = new FormAttachment(wEnclosure, margin);
    fdEscapeChar.right = new FormAttachment(100, 0);
    wEscapeChar.setLayoutData(fdEscapeChar);
    // CharSet line...
    wlCharSet = new Label(shell, SWT.RIGHT);
    wlCharSet.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.CharSet.Label"));
    props.setLook(wlCharSet);
    fdlCharSet = new FormData();
    fdlCharSet.left = new FormAttachment(0, 0);
    fdlCharSet.right = new FormAttachment(middle, -margin);
    fdlCharSet.top = new FormAttachment(wEscapeChar, margin);
    wlCharSet.setLayoutData(fdlCharSet);
    wCharSet = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCharSet);
    wCharSet.addModifyListener(lsMod);
    fdCharSet = new FormData();
    fdCharSet.left = new FormAttachment(middle, 0);
    fdCharSet.top = new FormAttachment(wEscapeChar, margin);
    fdCharSet.right = new FormAttachment(100, 0);
    wCharSet.setLayoutData(fdCharSet);
    // BulkSize line...
    wlBulkSize = new Label(shell, SWT.RIGHT);
    wlBulkSize.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.BulkSize.Label"));
    props.setLook(wlBulkSize);
    fdlBulkSize = new FormData();
    fdlBulkSize.left = new FormAttachment(0, 0);
    fdlBulkSize.right = new FormAttachment(middle, -margin);
    fdlBulkSize.top = new FormAttachment(wCharSet, margin);
    wlBulkSize.setLayoutData(fdlBulkSize);
    wBulkSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wBulkSize);
    wBulkSize.addModifyListener(lsMod);
    fdBulkSize = new FormData();
    fdBulkSize.left = new FormAttachment(middle, 0);
    fdBulkSize.top = new FormAttachment(wCharSet, margin);
    fdBulkSize.right = new FormAttachment(100, 0);
    wBulkSize.setLayoutData(fdBulkSize);
    // Replace line...
    wlReplace = new Label(shell, SWT.RIGHT);
    wlReplace.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Replace.Label"));
    props.setLook(wlReplace);
    fdlReplace = new FormData();
    fdlReplace.left = new FormAttachment(0, 0);
    fdlReplace.right = new FormAttachment(middle, -margin);
    fdlReplace.top = new FormAttachment(wBulkSize, margin * 2);
    wlReplace.setLayoutData(fdlReplace);
    wReplace = new Button(shell, SWT.CHECK | SWT.LEFT);
    props.setLook(wReplace);
    fdReplace = new FormData();
    fdReplace.left = new FormAttachment(middle, 0);
    fdReplace.top = new FormAttachment(wBulkSize, margin * 2);
    fdReplace.right = new FormAttachment(100, 0);
    wReplace.setLayoutData(fdReplace);
    wReplace.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (wReplace.getSelection()) {
                wIgnore.setSelection(false);
            }
            input.setChanged();
        }
    });
    // Ignore line...
    wlIgnore = new Label(shell, SWT.RIGHT);
    wlIgnore.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Ignore.Label"));
    props.setLook(wlIgnore);
    fdlIgnore = new FormData();
    fdlIgnore.left = new FormAttachment(0, 0);
    fdlIgnore.right = new FormAttachment(middle, -margin);
    fdlIgnore.top = new FormAttachment(wReplace, margin * 2);
    wlIgnore.setLayoutData(fdlIgnore);
    wIgnore = new Button(shell, SWT.CHECK | SWT.LEFT);
    props.setLook(wIgnore);
    fdIgnore = new FormData();
    fdIgnore.left = new FormAttachment(middle, 0);
    fdIgnore.top = new FormAttachment(wReplace, margin * 2);
    fdIgnore.right = new FormAttachment(100, 0);
    wIgnore.setLayoutData(fdIgnore);
    wIgnore.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (wIgnore.getSelection()) {
                wReplace.setSelection(false);
            }
            input.setChanged();
        }
    });
    // Local line...
    wlLocal = new Label(shell, SWT.RIGHT);
    wlLocal.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Local.Label"));
    props.setLook(wlLocal);
    fdlLocal = new FormData();
    fdlLocal.left = new FormAttachment(0, 0);
    fdlLocal.right = new FormAttachment(middle, -margin);
    fdlLocal.top = new FormAttachment(wIgnore, margin * 2);
    wlLocal.setLayoutData(fdlLocal);
    wLocal = new Button(shell, SWT.CHECK | SWT.LEFT);
    props.setLook(wLocal);
    fdLocal = new FormData();
    fdLocal.left = new FormAttachment(middle, 0);
    fdLocal.top = new FormAttachment(wIgnore, margin * 2);
    fdLocal.right = new FormAttachment(100, 0);
    wLocal.setLayoutData(fdLocal);
    wLocal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
        }
    });
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wSQL = new Button(shell, SWT.PUSH);
    wSQL.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.SQL.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wSQL }, margin, null);
    // The field Table
    wlReturn = new Label(shell, SWT.NONE);
    wlReturn.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.Fields.Label"));
    props.setLook(wlReturn);
    fdlReturn = new FormData();
    fdlReturn.left = new FormAttachment(0, 0);
    fdlReturn.top = new FormAttachment(wLocal, margin);
    wlReturn.setLayoutData(fdlReturn);
    int UpInsCols = 3;
    int UpInsRows = (input.getFieldTable() != null ? input.getFieldTable().length : 1);
    ciReturn = new ColumnInfo[UpInsCols];
    ciReturn[0] = new ColumnInfo(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.ColumnInfo.TableField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[1] = new ColumnInfo(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.ColumnInfo.StreamField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciReturn[2] = new ColumnInfo(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.ColumnInfo.FormatOK"), ColumnInfo.COLUMN_TYPE_CCOMBO, MySQLBulkLoaderMeta.getFieldFormatTypeDescriptions(), true);
    tableFieldColumns.add(ciReturn[0]);
    wReturn = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciReturn, UpInsRows, lsMod, props);
    wGetLU = new Button(shell, SWT.PUSH);
    wGetLU.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.GetFields.Label"));
    fdGetLU = new FormData();
    fdGetLU.top = new FormAttachment(wlReturn, margin);
    fdGetLU.right = new FormAttachment(100, 0);
    wGetLU.setLayoutData(fdGetLU);
    wDoMapping = new Button(shell, SWT.PUSH);
    wDoMapping.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.EditMapping.Label"));
    fdDoMapping = new FormData();
    fdDoMapping.top = new FormAttachment(wGetLU, margin);
    fdDoMapping.right = new FormAttachment(100, 0);
    wDoMapping.setLayoutData(fdDoMapping);
    wDoMapping.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event arg0) {
            generateMappings();
        }
    });
    fdReturn = new FormData();
    fdReturn.left = new FormAttachment(0, 0);
    fdReturn.top = new FormAttachment(wlReturn, margin);
    fdReturn.right = new FormAttachment(wDoMapping, -margin);
    fdReturn.bottom = new FormAttachment(wOK, -2 * margin);
    wReturn.setLayoutData(fdReturn);
    // 
    // Search the fields in the background
    // 
    final Runnable runnable = new Runnable() {

        public void run() {
            StepMeta stepMeta = transMeta.findStep(stepname);
            if (stepMeta != null) {
                try {
                    RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);
                    // Remember these fields...
                    for (int i = 0; i < row.size(); i++) {
                        inputFields.put(row.getValueMeta(i).getName(), i);
                    }
                    setComboBoxes();
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // Add listeners
    lsOK = new Listener() {

        public void handleEvent(Event e) {
            ok();
        }
    };
    lsGetLU = new Listener() {

        public void handleEvent(Event e) {
            getUpdate();
        }
    };
    lsSQL = new Listener() {

        public void handleEvent(Event e) {
            create();
        }
    };
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    wGetLU.addListener(SWT.Selection, lsGetLU);
    wSQL.addListener(SWT.Selection, lsSQL);
    wCancel.addListener(SWT.Selection, lsCancel);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wSchema.addSelectionListener(lsDef);
    wFifoFile.addSelectionListener(lsDef);
    wTable.addSelectionListener(lsDef);
    wDelimiter.addSelectionListener(lsDef);
    wEnclosure.addSelectionListener(lsDef);
    wCharSet.addSelectionListener(lsDef);
    wBulkSize.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    wbTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            getTableName();
        }
    });
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    setTableFieldCombo();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ShellEvent(org.eclipse.swt.events.ShellEvent) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) FocusEvent(org.eclipse.swt.events.FocusEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) TextVar(org.pentaho.di.ui.core.widget.TextVar) FocusEvent(org.eclipse.swt.events.FocusEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display)

Example 20 with StepMeta

use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.

the class MySQLBulkLoaderDialog method create.

// Generate code for create table...
// Conversions done by Database
private void create() {
    try {
        MySQLBulkLoaderMeta info = new MySQLBulkLoaderMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.StepMeta.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
        if (!sql.hasError()) {
            if (sql.hasSQL()) {
                SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                sqledit.open();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "MySQLBulkLoaderDialog.CouldNotBuildSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) MySQLBulkLoaderMeta(org.pentaho.di.trans.steps.mysqlbulkloader.MySQLBulkLoaderMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)637 TransMeta (org.pentaho.di.trans.TransMeta)228 KettleException (org.pentaho.di.core.exception.KettleException)174 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)167 Test (org.junit.Test)162 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)147 TransHopMeta (org.pentaho.di.trans.TransHopMeta)128 Trans (org.pentaho.di.trans.Trans)119 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)113 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)107 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)106 StepInterface (org.pentaho.di.trans.step.StepInterface)92 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)79 Point (org.pentaho.di.core.gui.Point)79 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 FormData (org.eclipse.swt.layout.FormData)76 FormLayout (org.eclipse.swt.layout.FormLayout)76 Label (org.eclipse.swt.widgets.Label)76 Shell (org.eclipse.swt.widgets.Shell)76 Button (org.eclipse.swt.widgets.Button)75