Search in sources :

Example 6 with SQLValuesHighlight

use of org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight in project pentaho-kettle by pentaho.

the class JobEntryEvalTableContentDialog method open.

public JobEntryInterface open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, props.getJobsDialogStyle());
    props.setLook(shell);
    JobDialog.setShellImage(shell, jobEntry);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            jobEntry.setChanged();
        }
    };
    changed = jobEntry.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    FormData fd = new FormData();
    fd.right = new FormAttachment(50, -10);
    fd.bottom = new FormAttachment(100, 0);
    fd.width = 100;
    wOK.setLayoutData(fd);
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    fd = new FormData();
    fd.left = new FormAttachment(50, 10);
    fd.bottom = new FormAttachment(100, 0);
    fd.width = 100;
    wCancel.setLayoutData(fd);
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, null);
    // Filename line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Name.Label"));
    props.setLook(wlName);
    fdlName = new FormData();
    fdlName.left = new FormAttachment(0, 0);
    fdlName.right = new FormAttachment(middle, -margin);
    fdlName.top = new FormAttachment(0, margin);
    wlName.setLayoutData(fdlName);
    wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wName);
    wName.addModifyListener(lsMod);
    fdName = new FormData();
    fdName.left = new FormAttachment(middle, 0);
    fdName.top = new FormAttachment(0, margin);
    fdName.right = new FormAttachment(100, 0);
    wName.setLayoutData(fdName);
    // Connection line
    wConnection = addConnectionLine(shell, wName, middle, margin);
    if (jobEntry.getDatabase() == null && jobMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // Schema name line
    wlSchemaname = new Label(shell, SWT.RIGHT);
    wlSchemaname.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Schemaname.Label"));
    props.setLook(wlSchemaname);
    fdlSchemaname = new FormData();
    fdlSchemaname.left = new FormAttachment(0, 0);
    fdlSchemaname.right = new FormAttachment(middle, 0);
    fdlSchemaname.top = new FormAttachment(wConnection, margin);
    wlSchemaname.setLayoutData(fdlSchemaname);
    wSchemaname = new TextVar(jobMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSchemaname);
    wSchemaname.setToolTipText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Schemaname.Tooltip"));
    wSchemaname.addModifyListener(lsMod);
    fdSchemaname = new FormData();
    fdSchemaname.left = new FormAttachment(middle, 0);
    fdSchemaname.top = new FormAttachment(wConnection, margin);
    fdSchemaname.right = new FormAttachment(100, 0);
    wSchemaname.setLayoutData(fdSchemaname);
    // Table name line
    wlTablename = new Label(shell, SWT.RIGHT);
    wlTablename.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Tablename.Label"));
    props.setLook(wlTablename);
    fdlTablename = new FormData();
    fdlTablename.left = new FormAttachment(0, 0);
    fdlTablename.right = new FormAttachment(middle, 0);
    fdlTablename.top = new FormAttachment(wSchemaname, margin);
    wlTablename.setLayoutData(fdlTablename);
    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    FormData fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wSchemaname, margin / 2);
    wbTable.setLayoutData(fdbTable);
    wbTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            getTableName();
        }
    });
    wTablename = new TextVar(jobMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTablename);
    wTablename.setToolTipText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Tablename.Tooltip"));
    wTablename.addModifyListener(lsMod);
    fdTablename = new FormData();
    fdTablename.left = new FormAttachment(middle, 0);
    fdTablename.top = new FormAttachment(wSchemaname, margin);
    fdTablename.right = new FormAttachment(wbTable, -margin);
    wTablename.setLayoutData(fdTablename);
    // ////////////////////////
    // START OF Success GROUP///
    // ///////////////////////////////
    wSuccessGroup = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wSuccessGroup);
    wSuccessGroup.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.SuccessGroup.Group.Label"));
    FormLayout SuccessGroupLayout = new FormLayout();
    SuccessGroupLayout.marginWidth = 10;
    SuccessGroupLayout.marginHeight = 10;
    wSuccessGroup.setLayout(SuccessGroupLayout);
    // Success Condition
    wlSuccessCondition = new Label(wSuccessGroup, SWT.RIGHT);
    wlSuccessCondition.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.SuccessCondition.Label"));
    props.setLook(wlSuccessCondition);
    fdlSuccessCondition = new FormData();
    fdlSuccessCondition.left = new FormAttachment(0, -margin);
    fdlSuccessCondition.right = new FormAttachment(middle, -2 * margin);
    fdlSuccessCondition.top = new FormAttachment(0, margin);
    wlSuccessCondition.setLayoutData(fdlSuccessCondition);
    wSuccessCondition = new CCombo(wSuccessGroup, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
    wSuccessCondition.setItems(JobEntryEvalTableContent.successConditionsDesc);
    // +1: starts at -1
    wSuccessCondition.select(0);
    props.setLook(wSuccessCondition);
    fdSuccessCondition = new FormData();
    fdSuccessCondition.left = new FormAttachment(middle, -margin);
    fdSuccessCondition.top = new FormAttachment(0, margin);
    fdSuccessCondition.right = new FormAttachment(100, 0);
    wSuccessCondition.setLayoutData(fdSuccessCondition);
    wSuccessCondition.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
        // activeSuccessCondition();
        }
    });
    // Success when number of errors less than
    wlLimit = new Label(wSuccessGroup, SWT.RIGHT);
    wlLimit.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Limit.Label"));
    props.setLook(wlLimit);
    fdlLimit = new FormData();
    fdlLimit.left = new FormAttachment(0, -margin);
    fdlLimit.top = new FormAttachment(wSuccessCondition, margin);
    fdlLimit.right = new FormAttachment(middle, -2 * margin);
    wlLimit.setLayoutData(fdlLimit);
    wLimit = new TextVar(jobMeta, wSuccessGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER, BaseMessages.getString(PKG, "JobEntryEvalTableContent.Limit.Tooltip"));
    props.setLook(wLimit);
    wLimit.addModifyListener(lsMod);
    fdLimit = new FormData();
    fdLimit.left = new FormAttachment(middle, -margin);
    fdLimit.top = new FormAttachment(wSuccessCondition, margin);
    fdLimit.right = new FormAttachment(100, -margin);
    wLimit.setLayoutData(fdLimit);
    fdSuccessGroup = new FormData();
    fdSuccessGroup.left = new FormAttachment(0, margin);
    fdSuccessGroup.top = new FormAttachment(wbTable, margin);
    fdSuccessGroup.right = new FormAttachment(100, -margin);
    wSuccessGroup.setLayoutData(fdSuccessGroup);
    // ///////////////////////////////////////////////////////////
    // / END OF SuccessGroup GROUP
    // ///////////////////////////////////////////////////////////
    // ////////////////////////
    // START OF Custom GROUP///
    // ///////////////////////////////
    wCustomGroup = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wCustomGroup);
    wCustomGroup.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.CustomGroup.Group.Label"));
    FormLayout CustomGroupLayout = new FormLayout();
    CustomGroupLayout.marginWidth = 10;
    CustomGroupLayout.marginHeight = 10;
    wCustomGroup.setLayout(CustomGroupLayout);
    // custom SQL?
    wlcustomSQL = new Label(wCustomGroup, SWT.RIGHT);
    wlcustomSQL.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.customSQL.Label"));
    props.setLook(wlcustomSQL);
    fdlcustomSQL = new FormData();
    fdlcustomSQL.left = new FormAttachment(0, -margin);
    fdlcustomSQL.top = new FormAttachment(wSuccessGroup, margin);
    fdlcustomSQL.right = new FormAttachment(middle, -2 * margin);
    wlcustomSQL.setLayoutData(fdlcustomSQL);
    wcustomSQL = new Button(wCustomGroup, SWT.CHECK);
    props.setLook(wcustomSQL);
    wcustomSQL.setToolTipText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.customSQL.Tooltip"));
    fdcustomSQL = new FormData();
    fdcustomSQL.left = new FormAttachment(middle, -margin);
    fdcustomSQL.top = new FormAttachment(wSuccessGroup, margin);
    fdcustomSQL.right = new FormAttachment(100, 0);
    wcustomSQL.setLayoutData(fdcustomSQL);
    wcustomSQL.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            setCustomerSQL();
            jobEntry.setChanged();
        }
    });
    // use Variable substitution?
    wlUseSubs = new Label(wCustomGroup, SWT.RIGHT);
    wlUseSubs.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.UseVariableSubst.Label"));
    props.setLook(wlUseSubs);
    fdlUseSubs = new FormData();
    fdlUseSubs.left = new FormAttachment(0, -margin);
    fdlUseSubs.top = new FormAttachment(wcustomSQL, margin);
    fdlUseSubs.right = new FormAttachment(middle, -2 * margin);
    wlUseSubs.setLayoutData(fdlUseSubs);
    wUseSubs = new Button(wCustomGroup, SWT.CHECK);
    props.setLook(wUseSubs);
    wUseSubs.setToolTipText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.UseVariableSubst.Tooltip"));
    fdUseSubs = new FormData();
    fdUseSubs.left = new FormAttachment(middle, -margin);
    fdUseSubs.top = new FormAttachment(wcustomSQL, margin);
    fdUseSubs.right = new FormAttachment(100, 0);
    wUseSubs.setLayoutData(fdUseSubs);
    wUseSubs.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });
    // clear result rows ?
    wlClearResultList = new Label(wCustomGroup, SWT.RIGHT);
    wlClearResultList.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ClearResultList.Label"));
    props.setLook(wlClearResultList);
    fdlClearResultList = new FormData();
    fdlClearResultList.left = new FormAttachment(0, -margin);
    fdlClearResultList.top = new FormAttachment(wUseSubs, margin);
    fdlClearResultList.right = new FormAttachment(middle, -2 * margin);
    wlClearResultList.setLayoutData(fdlClearResultList);
    wClearResultList = new Button(wCustomGroup, SWT.CHECK);
    props.setLook(wClearResultList);
    wClearResultList.setToolTipText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ClearResultList.Tooltip"));
    fdClearResultList = new FormData();
    fdClearResultList.left = new FormAttachment(middle, -margin);
    fdClearResultList.top = new FormAttachment(wUseSubs, margin);
    fdClearResultList.right = new FormAttachment(100, 0);
    wClearResultList.setLayoutData(fdClearResultList);
    wClearResultList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });
    // add rows to result?
    wlAddRowsToResult = new Label(wCustomGroup, SWT.RIGHT);
    wlAddRowsToResult.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.AddRowsToResult.Label"));
    props.setLook(wlAddRowsToResult);
    fdlAddRowsToResult = new FormData();
    fdlAddRowsToResult.left = new FormAttachment(0, -margin);
    fdlAddRowsToResult.top = new FormAttachment(wClearResultList, margin);
    fdlAddRowsToResult.right = new FormAttachment(middle, -2 * margin);
    wlAddRowsToResult.setLayoutData(fdlAddRowsToResult);
    wAddRowsToResult = new Button(wCustomGroup, SWT.CHECK);
    props.setLook(wAddRowsToResult);
    wAddRowsToResult.setToolTipText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.AddRowsToResult.Tooltip"));
    fdAddRowsToResult = new FormData();
    fdAddRowsToResult.left = new FormAttachment(middle, -margin);
    fdAddRowsToResult.top = new FormAttachment(wClearResultList, margin);
    fdAddRowsToResult.right = new FormAttachment(100, 0);
    wAddRowsToResult.setLayoutData(fdAddRowsToResult);
    wAddRowsToResult.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });
    wlPosition = new Label(wCustomGroup, SWT.NONE);
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.right = new FormAttachment(100, 0);
    // fdlPosition.top= new FormAttachment(wSQL , 0);
    fdlPosition.bottom = new FormAttachment(100, -margin);
    wlPosition.setLayoutData(fdlPosition);
    // Script line
    wlSQL = new Label(wCustomGroup, SWT.NONE);
    wlSQL.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.Script.Label"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wAddRowsToResult, margin);
    wlSQL.setLayoutData(fdlSQL);
    wbSQLTable = new Button(wCustomGroup, SWT.PUSH | SWT.CENTER);
    props.setLook(wbSQLTable);
    wbSQLTable.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.GetSQLAndSelectStatement"));
    FormData fdbSQLTable = new FormData();
    fdbSQLTable.right = new FormAttachment(100, 0);
    fdbSQLTable.top = new FormAttachment(wAddRowsToResult, margin);
    wbSQLTable.setLayoutData(fdbSQLTable);
    wSQL = new StyledTextComp(jobEntry, wCustomGroup, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wSQL, Props.WIDGET_STYLE_FIXED);
    wSQL.addModifyListener(lsMod);
    fdSQL = new FormData();
    fdSQL.left = new FormAttachment(0, 0);
    fdSQL.top = new FormAttachment(wbSQLTable, margin);
    fdSQL.right = new FormAttachment(100, -10);
    fdSQL.bottom = new FormAttachment(wlPosition, -margin);
    wSQL.setLayoutData(fdSQL);
    wSQL.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setPosition();
        }
    });
    wSQL.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            setPosition();
        }

        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    wSQL.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            setPosition();
        }

        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    wSQL.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            setPosition();
        }

        public void mouseDown(MouseEvent e) {
            setPosition();
        }

        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    wSQL.addModifyListener(lsMod);
    // Text Higlighting
    wSQL.addLineStyleListener(new SQLValuesHighlight());
    fdCustomGroup = new FormData();
    fdCustomGroup.left = new FormAttachment(0, margin);
    fdCustomGroup.top = new FormAttachment(wSuccessGroup, margin);
    fdCustomGroup.right = new FormAttachment(100, -margin);
    fdCustomGroup.bottom = new FormAttachment(wOK, -margin);
    wCustomGroup.setLayoutData(fdCustomGroup);
    // ///////////////////////////////////////////////////////////
    // / END OF CustomGroup GROUP
    // ///////////////////////////////////////////////////////////
    // Add listeners
    lsCancel = new Listener() {

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

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

        public void handleEvent(Event e) {
            getSQL();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wbSQLTable.addListener(SWT.Selection, lsbSQLTable);
    wName.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    getData();
    setCustomerSQL();
    BaseStepDialog.setSize(shell);
    shell.open();
    props.setDialogSize(shell, "JobEntryEvalTableContentDialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) 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) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) TextVar(org.pentaho.di.ui.core.widget.TextVar) CCombo(org.eclipse.swt.custom.CCombo) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) Display(org.eclipse.swt.widgets.Display)

Example 7 with SQLValuesHighlight

use of org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight in project pentaho-kettle by pentaho.

the class SQLEditor method open.

public void open() {
    shell = new Shell(parentShell, style);
    props.setLook(shell);
    shell.setImage(GUIResource.getInstance().getImageConnection());
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "SQLEditor.Title"));
    int margin = Const.MARGIN;
    // Script line
    wlScript = new Label(shell, SWT.NONE);
    wlScript.setText(BaseMessages.getString(PKG, "SQLEditor.Editor.Label"));
    props.setLook(wlScript);
    fdlScript = new FormData();
    fdlScript.left = new FormAttachment(0, 0);
    fdlScript.top = new FormAttachment(0, 0);
    wlScript.setLayoutData(fdlScript);
    wScript = new StyledTextComp(this.variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    wScript.setText("");
    props.setLook(wScript, Props.WIDGET_STYLE_FIXED);
    fdScript = new FormData();
    fdScript.left = new FormAttachment(0, 0);
    fdScript.top = new FormAttachment(wlScript, margin);
    fdScript.right = new FormAttachment(100, -10);
    fdScript.bottom = new FormAttachment(100, -70);
    wScript.setLayoutData(fdScript);
    wScript.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setPosition();
        }
    });
    wScript.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            setPosition();
        }

        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    wScript.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            setPosition();
        }

        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    wScript.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            setPosition();
        }

        public void mouseDown(MouseEvent e) {
            setPosition();
        }

        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    // SQL Higlighting
    highlight = new SQLValuesHighlight();
    highlight.addKeyWords(connection.getReservedWords());
    wScript.addLineStyleListener(highlight);
    wlPosition = new Label(shell, SWT.NONE);
    wlPosition.setText(BaseMessages.getString(PKG, "SQLEditor.LineNr.Label", "0"));
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.top = new FormAttachment(wScript, margin);
    fdlPosition.right = new FormAttachment(100, 0);
    wlPosition.setLayoutData(fdlPosition);
    wExec = new Button(shell, SWT.PUSH);
    wExec.setText(BaseMessages.getString(PKG, "SQLEditor.Button.Execute"));
    wClear = new Button(shell, SWT.PUSH);
    wClear.setText(BaseMessages.getString(PKG, "SQLEditor.Button.ClearCache"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Close"));
    wClear.setToolTipText(BaseMessages.getString(PKG, "SQLEditor.Button.ClearCache.Tooltip"));
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wExec, wClear, wCancel }, margin, null);
    // Add listeners
    lsCancel = new Listener() {

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

        public void handleEvent(Event e) {
            clearCache();
        }
    };
    lsExec = new Listener() {

        public void handleEvent(Event e) {
            try {
                exec();
            } catch (Exception ge) {
            // Ignore errors
            }
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wClear.addListener(SWT.Selection, lsClear);
    wExec.addListener(SWT.Selection, lsExec);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    BaseStepDialog.setSize(shell);
    getData();
    shell.open();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ShellAdapter(org.eclipse.swt.events.ShellAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ShellEvent(org.eclipse.swt.events.ShellEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 8 with SQLValuesHighlight

use of org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight in project pentaho-kettle by pentaho.

the class ExecSQLDialog 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) {
            changedInDialog = true;
            input.setChanged();
        }
    };
    SelectionAdapter lsSel = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    };
    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, "ExecSQLDialog.Shell.Label"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "ExecSQLDialog.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);
    // Table line...
    wlSQL = new Label(shell, SWT.LEFT);
    wlSQL.setText(BaseMessages.getString(PKG, "ExecSQLDialog.SQL.Label"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wConnection, margin * 2);
    wlSQL.setLayoutData(fdlSQL);
    wSQL = new StyledTextComp(transMeta, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wSQL, Props.WIDGET_STYLE_FIXED);
    wSQL.addModifyListener(lsMod);
    wSQL.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setPosition();
        }
    });
    wSQL.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            setPosition();
        }

        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    wSQL.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            setPosition();
        }

        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    wSQL.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            setPosition();
        }

        public void mouseDown(MouseEvent e) {
            setPosition();
        }

        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    // Text Higlighting
    wSQL.addLineStyleListener(new SQLValuesHighlight());
    // Some buttons
    // 
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "ExecSQLDialog.GetFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
    // Build it up from the bottom up...
    // Read field
    // 
    wlReadField = new Label(shell, SWT.RIGHT);
    wlReadField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.ReadField.Label"));
    props.setLook(wlReadField);
    fdlReadField = new FormData();
    fdlReadField.left = new FormAttachment(middle, margin);
    fdlReadField.right = new FormAttachment(middle * 2, -margin);
    fdlReadField.bottom = new FormAttachment(wOK, -3 * margin);
    wlReadField.setLayoutData(fdlReadField);
    wReadField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wReadField);
    wReadField.addModifyListener(lsMod);
    fdReadField = new FormData();
    fdReadField.left = new FormAttachment(middle * 2, 0);
    fdReadField.bottom = new FormAttachment(wOK, -3 * margin);
    fdReadField.right = new FormAttachment(100, 0);
    wReadField.setLayoutData(fdReadField);
    // Delete field
    // 
    wlDeleteField = new Label(shell, SWT.RIGHT);
    wlDeleteField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.DeleteField.Label"));
    props.setLook(wlDeleteField);
    fdlDeleteField = new FormData();
    fdlDeleteField.left = new FormAttachment(middle, margin);
    fdlDeleteField.right = new FormAttachment(middle * 2, -margin);
    fdlDeleteField.bottom = new FormAttachment(wReadField, -margin);
    wlDeleteField.setLayoutData(fdlDeleteField);
    wDeleteField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDeleteField);
    wDeleteField.addModifyListener(lsMod);
    fdDeleteField = new FormData();
    fdDeleteField.left = new FormAttachment(middle * 2, 0);
    fdDeleteField.bottom = new FormAttachment(wReadField, -margin);
    fdDeleteField.right = new FormAttachment(100, 0);
    wDeleteField.setLayoutData(fdDeleteField);
    // Update field
    // 
    wlUpdateField = new Label(shell, SWT.RIGHT);
    wlUpdateField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.UpdateField.Label"));
    props.setLook(wlUpdateField);
    fdlUpdateField = new FormData();
    fdlUpdateField.left = new FormAttachment(middle, margin);
    fdlUpdateField.right = new FormAttachment(middle * 2, -margin);
    fdlUpdateField.bottom = new FormAttachment(wDeleteField, -margin);
    wlUpdateField.setLayoutData(fdlUpdateField);
    wUpdateField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wUpdateField);
    wUpdateField.addModifyListener(lsMod);
    fdUpdateField = new FormData();
    fdUpdateField.left = new FormAttachment(middle * 2, 0);
    fdUpdateField.bottom = new FormAttachment(wDeleteField, -margin);
    fdUpdateField.right = new FormAttachment(100, 0);
    wUpdateField.setLayoutData(fdUpdateField);
    // insert field
    // 
    wlInsertField = new Label(shell, SWT.RIGHT);
    wlInsertField.setText(BaseMessages.getString(PKG, "ExecSQLDialog.InsertField.Label"));
    props.setLook(wlInsertField);
    fdlInsertField = new FormData();
    fdlInsertField.left = new FormAttachment(middle, margin);
    fdlInsertField.right = new FormAttachment(middle * 2, -margin);
    fdlInsertField.bottom = new FormAttachment(wUpdateField, -margin);
    wlInsertField.setLayoutData(fdlInsertField);
    wInsertField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wInsertField);
    wInsertField.addModifyListener(lsMod);
    fdInsertField = new FormData();
    fdInsertField.left = new FormAttachment(middle * 2, 0);
    fdInsertField.bottom = new FormAttachment(wUpdateField, -margin);
    fdInsertField.right = new FormAttachment(100, 0);
    wInsertField.setLayoutData(fdInsertField);
    // Setup the "Parameters" label
    // 
    wlFields = new Label(shell, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "ExecSQLDialog.Fields.Label"));
    props.setLook(wlFields);
    fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.right = new FormAttachment(middle, 0);
    fdlFields.bottom = new FormAttachment(wInsertField, -25);
    wlFields.setLayoutData(fdlFields);
    // Parameter fields...
    // 
    final int FieldsRows = input.getArguments().length;
    colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "ExecSQLDialog.ColumnInfo.ArgumentFieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false) };
    wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props);
    fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlFields, margin);
    fdFields.right = new FormAttachment(middle, 0);
    fdFields.bottom = new FormAttachment(wOK, -3 * margin);
    wFields.setLayoutData(fdFields);
    // For the "execute for each row" and "variable substitution" labels,
    // find their maximum width
    // and use that in the alignment
    // 
    wlEachRow = new Label(shell, SWT.RIGHT);
    wlEachRow.setText(BaseMessages.getString(PKG, "ExecSQLDialog.EachRow.Label"));
    wlEachRow.pack();
    wlSingleStatement = new Label(shell, SWT.RIGHT);
    wlSingleStatement.setText(BaseMessages.getString(PKG, "ExecSQLDialog.SingleStatement.Label"));
    wlSingleStatement.pack();
    wlVariables = new Label(shell, SWT.RIGHT);
    wlVariables.setText(BaseMessages.getString(PKG, "ExecSQLDialog.ReplaceVariables"));
    wlVariables.pack();
    wlQuoteString = new Label(shell, SWT.RIGHT);
    wlQuoteString.setText(BaseMessages.getString(PKG, "ExecSQLDialog.QuoteString.Label"));
    wlQuoteString.pack();
    Rectangle rEachRow = wlEachRow.getBounds();
    Rectangle rSingleStatement = wlSingleStatement.getBounds();
    Rectangle rVariables = wlVariables.getBounds();
    Rectangle rQuoteString = wlQuoteString.getBounds();
    int width = Math.max(Math.max(Math.max(rEachRow.width, rSingleStatement.width), rVariables.width), rQuoteString.width) + 30;
    // Setup the "Quote String" label and checkbox
    // 
    props.setLook(wlQuoteString);
    fdlQuoteString = new FormData();
    fdlQuoteString.left = new FormAttachment(0, margin);
    fdlQuoteString.right = new FormAttachment(0, width);
    fdlQuoteString.bottom = new FormAttachment(wlFields, -2 * margin);
    wlQuoteString.setLayoutData(fdlQuoteString);
    wQuoteString = new Button(shell, SWT.CHECK);
    props.setLook(wQuoteString);
    wQuoteString.setToolTipText(BaseMessages.getString(PKG, "ExecSQLDialog.QuoteString.Tooltip"));
    fdQuoteString = new FormData();
    fdQuoteString.left = new FormAttachment(wlQuoteString, margin);
    fdQuoteString.bottom = new FormAttachment(wlFields, -2 * margin);
    fdQuoteString.right = new FormAttachment(middle, 0);
    wQuoteString.setLayoutData(fdQuoteString);
    wQuoteString.addSelectionListener(lsSel);
    // Setup the "Bind parameters" label and checkbox
    // 
    wlSetParams = new Label(this.shell, SWT.RIGHT);
    wlSetParams.setText(BaseMessages.getString(PKG, "ExecSQLDialog.SetParams.Label"));
    props.setLook(this.wlSetParams);
    fdlSetParams = new FormData();
    fdlSetParams.left = new FormAttachment(0, margin);
    fdlSetParams.bottom = new FormAttachment(wQuoteString, -margin);
    fdlSetParams.right = new FormAttachment(0, width);
    wlSetParams.setLayoutData(this.fdlSetParams);
    wSetParams = new Button(shell, SWT.CHECK);
    props.setLook(this.wSetParams);
    wSetParams.setToolTipText(BaseMessages.getString(PKG, "ExecSQLDialog.SetParams.Tooltip"));
    fdSetParams = new FormData();
    fdSetParams.left = new FormAttachment(wlSetParams, margin);
    fdSetParams.bottom = new FormAttachment(wQuoteString, -margin);
    fdSetParams.right = new FormAttachment(middle, 0);
    wSetParams.setLayoutData(fdSetParams);
    wSetParams.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            setExecutedSetParams();
            input.setChanged();
        }
    });
    // Setup the "variable substitution" label and checkbox
    // 
    props.setLook(wlVariables);
    fdlVariables = new FormData();
    fdlVariables.left = new FormAttachment(0, margin);
    fdlVariables.right = new FormAttachment(0, width);
    fdlVariables.bottom = new FormAttachment(wSetParams, -margin);
    wlVariables.setLayoutData(fdlVariables);
    wVariables = new Button(shell, SWT.CHECK);
    props.setLook(wVariables);
    fdVariables = new FormData();
    fdVariables.left = new FormAttachment(wlVariables, margin);
    fdVariables.bottom = new FormAttachment(wSetParams, -margin);
    fdVariables.right = new FormAttachment(middle, 0);
    wVariables.setLayoutData(fdVariables);
    wVariables.addSelectionListener(lsSel);
    // Setup the "Single statement" label and checkbox
    // 
    props.setLook(wlSingleStatement);
    FormData fdlSingleStatement = new FormData();
    fdlSingleStatement.left = new FormAttachment(0, margin);
    fdlSingleStatement.right = new FormAttachment(0, width);
    fdlSingleStatement.bottom = new FormAttachment(wVariables, -margin);
    wlSingleStatement.setLayoutData(fdlSingleStatement);
    wSingleStatement = new Button(shell, SWT.CHECK);
    props.setLook(wSingleStatement);
    FormData fdSingleStatement = new FormData();
    fdSingleStatement.left = new FormAttachment(wlEachRow, margin);
    fdSingleStatement.bottom = new FormAttachment(wVariables, -margin);
    fdSingleStatement.right = new FormAttachment(middle, 0);
    wSingleStatement.setLayoutData(fdSingleStatement);
    wSingleStatement.addSelectionListener(lsSel);
    // Setup the "execute for each row" label and checkbox
    // 
    props.setLook(wlEachRow);
    FormData fdlEachRow = new FormData();
    fdlEachRow.left = new FormAttachment(0, margin);
    fdlEachRow.right = new FormAttachment(0, width);
    fdlEachRow.bottom = new FormAttachment(wSingleStatement, -margin);
    wlEachRow.setLayoutData(fdlEachRow);
    wEachRow = new Button(shell, SWT.CHECK);
    props.setLook(wEachRow);
    FormData fdEachRow = new FormData();
    fdEachRow.left = new FormAttachment(wlEachRow, margin);
    fdEachRow.bottom = new FormAttachment(wSingleStatement, -margin);
    fdEachRow.right = new FormAttachment(middle, 0);
    wEachRow.setLayoutData(fdEachRow);
    wEachRow.addSelectionListener(lsSel);
    // Position label under the SQL editor
    // 
    wlPosition = new Label(shell, SWT.NONE);
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.right = new FormAttachment(100, 0);
    // 2 times since we deal with bottom instead of
    fdlPosition.bottom = new FormAttachment(wEachRow, -2 * margin);
    // top
    wlPosition.setLayoutData(fdlPosition);
    // Finally, the SQL editor takes up all other space between the position and the SQL label
    // 
    fdSQL = new FormData();
    fdSQL.left = new FormAttachment(0, 0);
    fdSQL.top = new FormAttachment(wlSQL, margin);
    fdSQL.right = new FormAttachment(100, -2 * margin);
    fdSQL.bottom = new FormAttachment(wlPosition, -margin);
    wSQL.setLayoutData(fdSQL);
    // 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(), Integer.valueOf(i));
                    }
                    setComboBoxes();
                } catch (KettleException e) {
                    logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
                }
            }
        }
    };
    new Thread(runnable).start();
    // Add listeners
    // 
    lsCancel = new Listener() {

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

        public void handleEvent(Event e) {
            get();
        }
    };
    lsOK = new Listener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wEachRow.addSelectionListener(new SelectionAdapter() {

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

        public void shellClosed(ShellEvent e) {
            checkCancel(e);
        }
    });
    getData();
    setExecutedEachInputRow();
    setExecutedSetParams();
    // for prompting if dialog is simply closed
    changedInDialog = false;
    input.setChanged(changed);
    // Set the shell size, based upon previous time...
    setSize();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) FocusAdapter(org.eclipse.swt.events.FocusAdapter) KettleException(org.pentaho.di.core.exception.KettleException) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) 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) KeyEvent(org.eclipse.swt.events.KeyEvent) 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) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) Display(org.eclipse.swt.widgets.Display)

Example 9 with SQLValuesHighlight

use of org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight in project pentaho-kettle by pentaho.

the class DatabaseJoinDialog 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();
        }
    };
    backupChanged = input.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.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);
    // SQL editor...
    wlSQL = new Label(shell, SWT.NONE);
    wlSQL.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.SQL.Label"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wConnection, margin * 2);
    wlSQL.setLayoutData(fdlSQL);
    wSQL = new StyledTextComp(transMeta, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wSQL, Props.WIDGET_STYLE_FIXED);
    wSQL.addModifyListener(lsMod);
    fdSQL = new FormData();
    fdSQL.left = new FormAttachment(0, 0);
    fdSQL.top = new FormAttachment(wlSQL, margin);
    fdSQL.right = new FormAttachment(100, -2 * margin);
    fdSQL.bottom = new FormAttachment(60, 0);
    wSQL.setLayoutData(fdSQL);
    wSQL.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setPosition();
        }
    });
    wSQL.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            setPosition();
        }

        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    wSQL.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            setPosition();
        }

        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    wSQL.addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent e) {
            setPosition();
        }

        public void mouseDown(MouseEvent e) {
            setPosition();
        }

        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    // SQL Higlighting
    wSQL.addLineStyleListener(new SQLValuesHighlight());
    wlPosition = new Label(shell, SWT.NONE);
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.top = new FormAttachment(wSQL, margin);
    fdlPosition.right = new FormAttachment(100, 0);
    wlPosition.setLayoutData(fdlPosition);
    // Limit the number of lines returns
    wlLimit = new Label(shell, SWT.RIGHT);
    wlLimit.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.Limit.Label"));
    props.setLook(wlLimit);
    fdlLimit = new FormData();
    fdlLimit.left = new FormAttachment(0, 0);
    fdlLimit.right = new FormAttachment(middle, -margin);
    fdlLimit.top = new FormAttachment(wlPosition, margin);
    wlLimit.setLayoutData(fdlLimit);
    wLimit = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wLimit);
    wLimit.addModifyListener(lsMod);
    fdLimit = new FormData();
    fdLimit.left = new FormAttachment(middle, 0);
    fdLimit.right = new FormAttachment(100, 0);
    fdLimit.top = new FormAttachment(wlPosition, margin);
    wLimit.setLayoutData(fdLimit);
    // Outer join?
    wlOuter = new Label(shell, SWT.RIGHT);
    wlOuter.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.Outerjoin.Label"));
    wlOuter.setToolTipText(BaseMessages.getString(PKG, "DatabaseJoinDialog.Outerjoin.Tooltip"));
    props.setLook(wlOuter);
    fdlOuter = new FormData();
    fdlOuter.left = new FormAttachment(0, 0);
    fdlOuter.right = new FormAttachment(middle, -margin);
    fdlOuter.top = new FormAttachment(wLimit, margin);
    wlOuter.setLayoutData(fdlOuter);
    wOuter = new Button(shell, SWT.CHECK);
    props.setLook(wOuter);
    wOuter.setToolTipText(wlOuter.getToolTipText());
    fdOuter = new FormData();
    fdOuter.left = new FormAttachment(middle, 0);
    fdOuter.top = new FormAttachment(wLimit, margin);
    wOuter.setLayoutData(fdOuter);
    wOuter.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    // useVars ?
    wluseVars = new Label(shell, SWT.RIGHT);
    wluseVars.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.useVarsjoin.Label"));
    wluseVars.setToolTipText(BaseMessages.getString(PKG, "DatabaseJoinDialog.useVarsjoin.Tooltip"));
    props.setLook(wluseVars);
    fdluseVars = new FormData();
    fdluseVars.left = new FormAttachment(0, 0);
    fdluseVars.right = new FormAttachment(middle, -margin);
    fdluseVars.top = new FormAttachment(wOuter, margin);
    wluseVars.setLayoutData(fdluseVars);
    wuseVars = new Button(shell, SWT.CHECK);
    props.setLook(wuseVars);
    wuseVars.setToolTipText(wluseVars.getToolTipText());
    fduseVars = new FormData();
    fduseVars.left = new FormAttachment(middle, 0);
    fduseVars.top = new FormAttachment(wOuter, margin);
    wuseVars.setLayoutData(fduseVars);
    wuseVars.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.GetFields.Button"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
    // The parameters
    wlParam = new Label(shell, SWT.NONE);
    wlParam.setText(BaseMessages.getString(PKG, "DatabaseJoinDialog.Param.Label"));
    props.setLook(wlParam);
    fdlParam = new FormData();
    fdlParam.left = new FormAttachment(0, 0);
    fdlParam.top = new FormAttachment(wuseVars, margin);
    wlParam.setLayoutData(fdlParam);
    int nrKeyCols = 2;
    int nrKeyRows = (input.getParameterField() != null ? input.getParameterField().length : 1);
    ciKey = new ColumnInfo[nrKeyCols];
    ciKey[0] = new ColumnInfo(BaseMessages.getString(PKG, "DatabaseJoinDialog.ColumnInfo.ParameterFieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
    ciKey[1] = new ColumnInfo(BaseMessages.getString(PKG, "DatabaseJoinDialog.ColumnInfo.ParameterType"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames());
    wParam = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciKey, nrKeyRows, lsMod, props);
    fdParam = new FormData();
    fdParam.left = new FormAttachment(0, 0);
    fdParam.top = new FormAttachment(wlParam, margin);
    fdParam.right = new FormAttachment(100, 0);
    fdParam.bottom = new FormAttachment(wOK, -2 * margin);
    wParam.setLayoutData(fdParam);
    // 
    // 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(), Integer.valueOf(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();
        }
    };
    lsGet = new Listener() {

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

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

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wLimit.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    // Set the shell size, based upon previous time...
    setSize();
    getData();
    input.setChanged(backupChanged);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) FocusAdapter(org.eclipse.swt.events.FocusAdapter) KettleException(org.pentaho.di.core.exception.KettleException) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) 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) KeyEvent(org.eclipse.swt.events.KeyEvent) 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) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) Display(org.eclipse.swt.widgets.Display)

Example 10 with SQLValuesHighlight

use of org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight in project pentaho-kettle by pentaho.

the class LucidDBStreamingLoaderDialog 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();
        }
    };
    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, "LucidDBStreamingLoaderDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.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, "LucidDBStreamingLoaderDialog.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);
    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, "LucidDBStreamingLoaderDialog.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, "LucidDBStreamingLoaderDialog.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);
    fdTable = new FormData();
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.top = new FormAttachment(wSchema, margin);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);
    // Auto create table check.
    lAutoCreateTable = new Label(shell, SWT.RIGHT);
    props.setLook(lAutoCreateTable);
    fdlAutoCreateTable = new FormData();
    fdlAutoCreateTable.left = new FormAttachment(0, 0);
    fdlAutoCreateTable.top = new FormAttachment(wTable, margin);
    fdlAutoCreateTable.right = new FormAttachment(middle, -margin);
    lAutoCreateTable.setLayoutData(fdlAutoCreateTable);
    fdbAutoCreateTable = new FormData();
    fdbAutoCreateTable.left = new FormAttachment(lAutoCreateTable, 10);
    fdbAutoCreateTable.top = new FormAttachment(wTable, margin);
    // Host
    wlHost = new Label(shell, SWT.RIGHT);
    wlHost.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Host.Label"));
    props.setLook(wlHost);
    fdlHost = new FormData();
    fdlHost.left = new FormAttachment(0, 0);
    fdlHost.top = new FormAttachment(lAutoCreateTable, margin);
    fdlHost.right = new FormAttachment(middle, -margin);
    wlHost.setLayoutData(fdlHost);
    wHost = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wHost);
    wHost.addModifyListener(lsMod);
    fdHost = new FormData();
    fdHost.left = new FormAttachment(middle, 0);
    fdHost.top = new FormAttachment(lAutoCreateTable, margin);
    fdHost.right = new FormAttachment(100, 0);
    wHost.setLayoutData(fdHost);
    // Port line
    wlPort = new Label(shell, SWT.RIGHT);
    wlPort.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Port.Label"));
    props.setLook(wlPort);
    fdlPort = new FormData();
    fdlPort.left = new FormAttachment(0, 0);
    fdlPort.top = new FormAttachment(wHost, margin);
    fdlPort.right = new FormAttachment(middle, -margin);
    wlPort.setLayoutData(fdlPort);
    wPort = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wPort);
    wPort.addModifyListener(lsMod);
    fdPort = new FormData();
    fdPort.left = new FormAttachment(middle, 0);
    fdPort.top = new FormAttachment(wHost, margin);
    fdPort.right = new FormAttachment(100, 0);
    wPort.setLayoutData(fdPort);
    // Operation line:
    wlOperation = new Label(shell, SWT.RIGHT);
    wlOperation.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.Label"));
    props.setLook(wlOperation);
    fdlOperation = new FormData();
    fdlOperation.left = new FormAttachment(0, 0);
    fdlOperation.top = new FormAttachment(wPort, margin);
    fdlOperation.right = new FormAttachment(middle, -margin);
    wlOperation.setLayoutData(fdlOperation);
    wOperation = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wOperation);
    wOperation.addModifyListener(lsMod);
    fdOperation = new FormData();
    fdOperation.top = new FormAttachment(wPort, margin);
    fdOperation.left = new FormAttachment(middle, 0);
    fdOperation.right = new FormAttachment(100, 0);
    wOperation.setLayoutData(fdOperation);
    final String[] operations = new String[] { BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item1"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item2"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item3"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Operation.CCombo.Item4") };
    wOperation.setItems(operations);
    wOperation.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            CCombo mycc = (CCombo) event.widget;
            // MERGE
            if (operations[0].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wKeysTab);
                wKeysTab.getControl().setEnabled(true);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(false);
                wFieldsTb.table.getColumn(3).setWidth(80);
            // INSERT
            } else if (operations[1].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wFieldsTab);
                wKeysTab.getControl().setEnabled(false);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(false);
                wFieldsTb.table.getColumn(3).setWidth(0);
            // UPDATE
            } else if (operations[2].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wKeysTab);
                wKeysTab.getControl().setEnabled(true);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(false);
                // grey out update field in Field TabelView
                wFieldsTb.table.getColumn(3).setWidth(80);
            // CUSTOM
            } else if (operations[3].equals(mycc.getItem(mycc.getSelectionIndex()))) {
                wKeysTb.table.removeAll();
                wKeysTb.table.setItemCount(1);
                wKeysTb.setRowNums();
                wFieldsTb.table.removeAll();
                wFieldsTb.table.setItemCount(1);
                wFieldsTb.setRowNums();
                wCustomTb.setText("");
                wTabFolder.setSelection(wKeysTab);
                wKeysTab.getControl().setEnabled(true);
                wFieldsTab.getControl().setEnabled(true);
                wCustomTab.getControl().setEnabled(true);
                wFieldsTb.table.getColumn(3).setWidth(80);
            }
        }
    });
    // TabFolder
    wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
    wTabFolder.setSimple(false);
    fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wlOperation, margin);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(100, -50);
    wTabFolder.setLayoutData(fdTabFolder);
    wKeysTab = new CTabItem(wTabFolder, SWT.NONE);
    wKeysTab.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.KeyTab.TabTitle"));
    FormLayout fieldsLayout = new FormLayout();
    fieldsLayout.marginWidth = Const.FORM_MARGIN;
    fieldsLayout.marginHeight = Const.FORM_MARGIN;
    // TabItem: Keys
    wKeysComp = new Composite(wTabFolder, SWT.NONE);
    wKeysComp.setLayout(fieldsLayout);
    props.setLook(wKeysComp);
    wlKeysTb = new Label(wKeysComp, SWT.LEFT);
    wlKeysTb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.KeyTab.Label"));
    fdlKeysTb = new FormData();
    fdlKeysTb.left = new FormAttachment(0, 0);
    fdlKeysTb.top = new FormAttachment(0, 0);
    fdlKeysTb.right = new FormAttachment(100, 0);
    wlKeysTb.setLayoutData(fdlKeysTb);
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Key.Column1"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Key.Column2"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
    wKeysTb = new TableView(transMeta, wKeysComp, SWT.FULL_SELECTION | SWT.MULTI, colinf, 0, lsMod, props);
    fdKeysTb = new FormData();
    fdKeysTb.left = new FormAttachment(0, 0);
    fdKeysTb.top = new FormAttachment(wlKeysTb, margin);
    fdKeysTb.right = new FormAttachment(100, 0);
    fdKeysTb.bottom = new FormAttachment(95, -margin);
    wKeysTb.setLayoutData(fdKeysTb);
    fdKeysComp = new FormData();
    fdKeysComp.left = new FormAttachment(0, 0);
    fdKeysComp.top = new FormAttachment(0, 0);
    fdKeysComp.right = new FormAttachment(100, 0);
    fdKeysComp.bottom = new FormAttachment(100, 0);
    wKeysComp.setLayoutData(fdKeysComp);
    wGetFieldsForKeys = new Button(wKeysComp, SWT.PUSH);
    wGetFieldsForKeys.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.GetFields.Label"));
    fdGetFieldsForKeys = new FormData();
    fdGetFieldsForKeys.top = new FormAttachment(wKeysTb, margin);
    fdGetFieldsForKeys.left = new FormAttachment(0, margin);
    wGetFieldsForKeys.setLayoutData(fdGetFieldsForKeys);
    wGetFieldsForKeys.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getFields(wKeysTab.getText());
        }
    });
    wDoMappingForKeys = new Button(wKeysComp, SWT.PUSH);
    wDoMappingForKeys.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.EditMapping.Label"));
    fdDoMappingForKeys = new FormData();
    fdDoMappingForKeys.top = new FormAttachment(wKeysTb, margin);
    fdDoMappingForKeys.left = new FormAttachment(wGetFieldsForKeys, margin);
    wDoMappingForKeys.setLayoutData(fdDoMappingForKeys);
    wDoMappingForKeys.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            generateMappings(wKeysTab.getText());
        }
    });
    wKeysComp.layout();
    wKeysTab.setControl(wKeysComp);
    // TabItem: Fields
    wFieldsTab = new CTabItem(wTabFolder, SWT.NONE);
    wFieldsTab.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.FieldsTab.TabTitle"));
    wFieldsComp = new Composite(wTabFolder, SWT.NONE);
    wFieldsComp.setLayout(fieldsLayout);
    props.setLook(wFieldsComp);
    wlFieldsTb = new Label(wFieldsComp, SWT.LEFT);
    wlFieldsTb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.FieldTab.Label"));
    fdlFieldsTb = new FormData();
    fdlFieldsTb.left = new FormAttachment(0, 0);
    fdlFieldsTb.top = new FormAttachment(0, 0);
    fdlFieldsTb.right = new FormAttachment(100, 0);
    wlFieldsTb.setLayoutData(fdlFieldsTb);
    ColumnInfo[] colinf1 = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Field.Column1"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Field.Column2"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.Field.Column3"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "Y", "N" }, true) };
    wFieldsTb = new TableView(transMeta, wFieldsComp, SWT.FULL_SELECTION | SWT.MULTI, colinf1, 0, lsMod, props);
    fdFieldsTb = new FormData();
    fdFieldsTb.left = new FormAttachment(0, 0);
    fdFieldsTb.top = new FormAttachment(wlFieldsTb, margin);
    fdFieldsTb.right = new FormAttachment(100, 0);
    fdFieldsTb.bottom = new FormAttachment(95, -margin);
    wFieldsTb.setLayoutData(fdFieldsTb);
    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);
    wGetFieldsForFields = new Button(wFieldsComp, SWT.PUSH);
    wGetFieldsForFields.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.GetFields.Label"));
    fdGetFieldsForFields = new FormData();
    fdGetFieldsForFields.top = new FormAttachment(wFieldsTb, margin);
    fdGetFieldsForFields.left = new FormAttachment(0, margin);
    wGetFieldsForFields.setLayoutData(fdGetFieldsForFields);
    wGetFieldsForFields.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getFields(wFieldsTab.getText());
        }
    });
    wDoMappingForFields = new Button(wFieldsComp, SWT.PUSH);
    wDoMappingForFields.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.EditMapping.Label"));
    fdDoMappingForFields = new FormData();
    fdDoMappingForFields.top = new FormAttachment(wFieldsTb, margin);
    fdDoMappingForFields.left = new FormAttachment(wGetFieldsForFields, margin);
    wDoMappingForFields.setLayoutData(fdDoMappingForFields);
    wDoMappingForFields.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            generateMappings(wFieldsTab.getText());
        }
    });
    wFieldsComp.layout();
    wFieldsTab.setControl(wFieldsComp);
    // TabItem: Custom disable Custom tab
    wCustomTab = new CTabItem(wTabFolder, SWT.NONE);
    wCustomTab.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.CustomTab.TabTitle"));
    wCustomComp = new Composite(wTabFolder, SWT.NONE);
    wCustomComp.setLayout(fieldsLayout);
    props.setLook(wCustomComp);
    wlCustomTb = new Label(wCustomComp, SWT.LEFT);
    wlCustomTb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.CustomTab.Label"));
    fdlCustomTb = new FormData();
    fdlCustomTb.left = new FormAttachment(0, 0);
    fdlCustomTb.top = new FormAttachment(0, 0);
    fdlCustomTb.right = new FormAttachment(100, 0);
    wlCustomTb.setLayoutData(fdlCustomTb);
    wCustomTb = new StyledTextComp(transMeta, wCustomComp, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    props.setLook(wCustomTb, Props.WIDGET_STYLE_FIXED);
    wCustomTb.addModifyListener(lsMod);
    fdCustomTb = new FormData();
    fdCustomTb.left = new FormAttachment(0, 0);
    fdCustomTb.top = new FormAttachment(wlCustomTb, margin);
    fdCustomTb.right = new FormAttachment(100, -2 * margin);
    fdCustomTb.bottom = new FormAttachment(100, -margin);
    wCustomTb.setLayoutData(fdCustomTb);
    // Text Higlighting
    SQLValuesHighlight lineStyler = new SQLValuesHighlight();
    wCustomTb.addLineStyleListener(lineStyler);
    fdCustomComp = new FormData();
    fdCustomComp.left = new FormAttachment(0, 0);
    fdCustomComp.top = new FormAttachment(0, 0);
    fdCustomComp.right = new FormAttachment(100, 0);
    fdCustomComp.bottom = new FormAttachment(100, 0);
    wCustomComp.setLayoutData(fdCustomComp);
    wCustomComp.layout();
    wCustomTab.setControl(wCustomComp);
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString("System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString("System.Button.Cancel"));
    wSQL = new Button(shell, SWT.PUSH);
    wSQL.setText(BaseMessages.getString("System.Button.SQL"));
    setButtonPositions(new Button[] { wOK, wSQL, wCancel }, margin, null);
    // Add listeners
    lsOK = new Listener() {

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

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

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    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);
    wTable.addSelectionListener(lsDef);
    wPort.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();
    input.setChanged(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) CTabFolder(org.eclipse.swt.custom.CTabFolder) SelectionListener(org.eclipse.swt.events.SelectionListener) 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) 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) TextVar(org.pentaho.di.ui.core.widget.TextVar) CCombo(org.eclipse.swt.custom.CCombo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) Display(org.eclipse.swt.widgets.Display) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ModifyEvent (org.eclipse.swt.events.ModifyEvent)10 ModifyListener (org.eclipse.swt.events.ModifyListener)10 ShellAdapter (org.eclipse.swt.events.ShellAdapter)10 ShellEvent (org.eclipse.swt.events.ShellEvent)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)10 FormData (org.eclipse.swt.layout.FormData)10 FormLayout (org.eclipse.swt.layout.FormLayout)10 Button (org.eclipse.swt.widgets.Button)10 Event (org.eclipse.swt.widgets.Event)10 Label (org.eclipse.swt.widgets.Label)10 Listener (org.eclipse.swt.widgets.Listener)10 Shell (org.eclipse.swt.widgets.Shell)10 StyledTextComp (org.pentaho.di.ui.core.widget.StyledTextComp)10 SQLValuesHighlight (org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Display (org.eclipse.swt.widgets.Display)9 FocusAdapter (org.eclipse.swt.events.FocusAdapter)8 FocusEvent (org.eclipse.swt.events.FocusEvent)8 KeyAdapter (org.eclipse.swt.events.KeyAdapter)8