Search in sources :

Example 1 with SQLValuesHighlight

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

the class JobEntryWaitForSQLDialog 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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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(JobEntryWaitForSQL.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
    wlRowsCountValue = new Label(wSuccessGroup, SWT.RIGHT);
    wlRowsCountValue.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.RowsCountValue.Label"));
    props.setLook(wlRowsCountValue);
    fdlRowsCountValue = new FormData();
    fdlRowsCountValue.left = new FormAttachment(0, -margin);
    fdlRowsCountValue.top = new FormAttachment(wSuccessCondition, margin);
    fdlRowsCountValue.right = new FormAttachment(middle, -2 * margin);
    wlRowsCountValue.setLayoutData(fdlRowsCountValue);
    wRowsCountValue = new TextVar(jobMeta, wSuccessGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER, BaseMessages.getString(PKG, "JobEntryWaitForSQL.RowsCountValue.Tooltip"));
    props.setLook(wRowsCountValue);
    wRowsCountValue.addModifyListener(lsMod);
    fdRowsCountValue = new FormData();
    fdRowsCountValue.left = new FormAttachment(middle, -margin);
    fdRowsCountValue.top = new FormAttachment(wSuccessCondition, margin);
    fdRowsCountValue.right = new FormAttachment(100, 0);
    wRowsCountValue.setLayoutData(fdRowsCountValue);
    // Maximum timeout
    wlMaximumTimeout = new Label(wSuccessGroup, SWT.RIGHT);
    wlMaximumTimeout.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.MaximumTimeout.Label"));
    props.setLook(wlMaximumTimeout);
    fdlMaximumTimeout = new FormData();
    fdlMaximumTimeout.left = new FormAttachment(0, -margin);
    fdlMaximumTimeout.top = new FormAttachment(wRowsCountValue, margin);
    fdlMaximumTimeout.right = new FormAttachment(middle, -2 * margin);
    wlMaximumTimeout.setLayoutData(fdlMaximumTimeout);
    wMaximumTimeout = new TextVar(jobMeta, wSuccessGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wMaximumTimeout);
    wMaximumTimeout.setToolTipText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.MaximumTimeout.Tooltip"));
    wMaximumTimeout.addModifyListener(lsMod);
    fdMaximumTimeout = new FormData();
    fdMaximumTimeout.left = new FormAttachment(middle, -margin);
    fdMaximumTimeout.top = new FormAttachment(wRowsCountValue, margin);
    fdMaximumTimeout.right = new FormAttachment(100, 0);
    wMaximumTimeout.setLayoutData(fdMaximumTimeout);
    // Cycle time
    wlCheckCycleTime = new Label(wSuccessGroup, SWT.RIGHT);
    wlCheckCycleTime.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.CheckCycleTime.Label"));
    props.setLook(wlCheckCycleTime);
    fdlCheckCycleTime = new FormData();
    fdlCheckCycleTime.left = new FormAttachment(0, -margin);
    fdlCheckCycleTime.top = new FormAttachment(wMaximumTimeout, margin);
    fdlCheckCycleTime.right = new FormAttachment(middle, -2 * margin);
    wlCheckCycleTime.setLayoutData(fdlCheckCycleTime);
    wCheckCycleTime = new TextVar(jobMeta, wSuccessGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCheckCycleTime);
    wCheckCycleTime.setToolTipText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.CheckCycleTime.Tooltip"));
    wCheckCycleTime.addModifyListener(lsMod);
    fdCheckCycleTime = new FormData();
    fdCheckCycleTime.left = new FormAttachment(middle, -margin);
    fdCheckCycleTime.top = new FormAttachment(wMaximumTimeout, margin);
    fdCheckCycleTime.right = new FormAttachment(100, 0);
    wCheckCycleTime.setLayoutData(fdCheckCycleTime);
    // Success on timeout
    wlSuccesOnTimeout = new Label(wSuccessGroup, SWT.RIGHT);
    wlSuccesOnTimeout.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.SuccessOnTimeout.Label"));
    props.setLook(wlSuccesOnTimeout);
    fdlSuccesOnTimeout = new FormData();
    fdlSuccesOnTimeout.left = new FormAttachment(0, -margin);
    fdlSuccesOnTimeout.top = new FormAttachment(wCheckCycleTime, margin);
    fdlSuccesOnTimeout.right = new FormAttachment(middle, -2 * margin);
    wlSuccesOnTimeout.setLayoutData(fdlSuccesOnTimeout);
    wSuccesOnTimeout = new Button(wSuccessGroup, SWT.CHECK);
    props.setLook(wSuccesOnTimeout);
    wSuccesOnTimeout.setToolTipText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.SuccessOnTimeout.Tooltip"));
    fdSuccesOnTimeout = new FormData();
    fdSuccesOnTimeout.left = new FormAttachment(middle, -margin);
    fdSuccesOnTimeout.top = new FormAttachment(wCheckCycleTime, margin);
    fdSuccesOnTimeout.right = new FormAttachment(100, -margin);
    wSuccesOnTimeout.setLayoutData(fdSuccesOnTimeout);
    wSuccesOnTimeout.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });
    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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQL.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, "JobEntryWaitForSQLDialogSize");
    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 2 with SQLValuesHighlight

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

the class DynamicSQLRowDialog 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, "DynamicSQLRowDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.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);
    // SQLFieldName field
    wlSQLFieldName = new Label(shell, SWT.RIGHT);
    wlSQLFieldName.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.SQLFieldName.Label"));
    props.setLook(wlSQLFieldName);
    fdlSQLFieldName = new FormData();
    fdlSQLFieldName.left = new FormAttachment(0, 0);
    fdlSQLFieldName.right = new FormAttachment(middle, -margin);
    fdlSQLFieldName.top = new FormAttachment(wConnection, 2 * margin);
    wlSQLFieldName.setLayoutData(fdlSQLFieldName);
    wSQLFieldName = new CCombo(shell, SWT.BORDER | SWT.READ_ONLY);
    wSQLFieldName.setEditable(true);
    props.setLook(wSQLFieldName);
    wSQLFieldName.addModifyListener(lsMod);
    fdSQLFieldName = new FormData();
    fdSQLFieldName.left = new FormAttachment(middle, 0);
    fdSQLFieldName.top = new FormAttachment(wConnection, 2 * margin);
    fdSQLFieldName.right = new FormAttachment(100, -margin);
    wSQLFieldName.setLayoutData(fdSQLFieldName);
    wSQLFieldName.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);
            get();
            shell.setCursor(null);
            busy.dispose();
        }
    });
    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wCancel }, margin, null);
    // Limit the number of lines returns
    wlLimit = new Label(shell, SWT.RIGHT);
    wlLimit.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.Limit.Label"));
    props.setLook(wlLimit);
    fdlLimit = new FormData();
    fdlLimit.left = new FormAttachment(0, 0);
    fdlLimit.right = new FormAttachment(middle, -margin);
    fdlLimit.top = new FormAttachment(wSQLFieldName, 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(wSQLFieldName, margin);
    wLimit.setLayoutData(fdLimit);
    // Outer join?
    wlOuter = new Label(shell, SWT.RIGHT);
    wlOuter.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.Outerjoin.Label"));
    wlOuter.setToolTipText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.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, "DynamicSQLRowDialog.useVarsjoin.Label"));
    wluseVars.setToolTipText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.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();
        }
    });
    // queryOnlyOnChange ?
    wlqueryOnlyOnChange = new Label(shell, SWT.RIGHT);
    wlqueryOnlyOnChange.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.queryOnlyOnChangejoin.Label"));
    wlqueryOnlyOnChange.setToolTipText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.queryOnlyOnChangejoin.Tooltip"));
    props.setLook(wlqueryOnlyOnChange);
    fdlqueryOnlyOnChange = new FormData();
    fdlqueryOnlyOnChange.left = new FormAttachment(0, 0);
    fdlqueryOnlyOnChange.right = new FormAttachment(middle, -margin);
    fdlqueryOnlyOnChange.top = new FormAttachment(wuseVars, margin);
    wlqueryOnlyOnChange.setLayoutData(fdlqueryOnlyOnChange);
    wqueryOnlyOnChange = new Button(shell, SWT.CHECK);
    props.setLook(wqueryOnlyOnChange);
    wqueryOnlyOnChange.setToolTipText(wlqueryOnlyOnChange.getToolTipText());
    fdqueryOnlyOnChange = new FormData();
    fdqueryOnlyOnChange.left = new FormAttachment(middle, 0);
    fdqueryOnlyOnChange.top = new FormAttachment(wuseVars, margin);
    wqueryOnlyOnChange.setLayoutData(fdqueryOnlyOnChange);
    wqueryOnlyOnChange.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            input.setChanged();
        }
    });
    // SQL editor...
    wlSQL = new Label(shell, SWT.NONE);
    wlSQL.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.SQL.Label"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wqueryOnlyOnChange, margin);
    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);
    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(wOK, -4 * 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());
    wlPosition = new Label(shell, SWT.NONE);
    // wlPosition.setText(BaseMessages.getString(PKG, "DynamicSQLRowDialog.Position.Label"));
    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);
    // Add listeners
    lsOK = new Listener() {

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

        public void handleEvent(Event e) {
            cancel();
        }
    };
    wOK.addListener(SWT.Selection, lsOK);
    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) FocusListener(org.eclipse.swt.events.FocusListener) 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) Cursor(org.eclipse.swt.graphics.Cursor) 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) 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) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display)

Example 3 with SQLValuesHighlight

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

the class JobEntrySQLDialog 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, "JobSQL.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, null);
    // Filename line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobSQL.Name.Label"));
    props.setLook(wlName);
    fdlName = new FormData();
    fdlName.left = new FormAttachment(0, 0);
    fdlName.right = new FormAttachment(middle, 0);
    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);
    // SQL from file?
    wlSQLFromFile = new Label(shell, SWT.RIGHT);
    wlSQLFromFile.setText(BaseMessages.getString(PKG, "JobSQL.SQLFromFile.Label"));
    props.setLook(wlSQLFromFile);
    fdlSQLFromFile = new FormData();
    fdlSQLFromFile.left = new FormAttachment(0, 0);
    fdlSQLFromFile.top = new FormAttachment(wConnection, 2 * margin);
    fdlSQLFromFile.right = new FormAttachment(middle, -margin);
    wlSQLFromFile.setLayoutData(fdlSQLFromFile);
    wSQLFromFile = new Button(shell, SWT.CHECK);
    props.setLook(wSQLFromFile);
    wSQLFromFile.setToolTipText(BaseMessages.getString(PKG, "JobSQL.SQLFromFile.Tooltip"));
    fdSQLFromFile = new FormData();
    fdSQLFromFile.left = new FormAttachment(middle, 0);
    fdSQLFromFile.top = new FormAttachment(wConnection, 2 * margin);
    fdSQLFromFile.right = new FormAttachment(100, 0);
    wSQLFromFile.setLayoutData(fdSQLFromFile);
    wSQLFromFile.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            activeSQLFromFile();
            jobEntry.setChanged();
        }
    });
    // Filename line
    wlFilename = new Label(shell, SWT.RIGHT);
    wlFilename.setText(BaseMessages.getString(PKG, "JobSQL.Filename.Label"));
    props.setLook(wlFilename);
    fdlFilename = new FormData();
    fdlFilename.left = new FormAttachment(0, 0);
    fdlFilename.top = new FormAttachment(wSQLFromFile, margin);
    fdlFilename.right = new FormAttachment(middle, -margin);
    wlFilename.setLayoutData(fdlFilename);
    wbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbFilename);
    wbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbFilename = new FormData();
    fdbFilename.right = new FormAttachment(100, 0);
    fdbFilename.top = new FormAttachment(wSQLFromFile, margin);
    wbFilename.setLayoutData(fdbFilename);
    wFilename = new TextVar(jobMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFilename);
    wFilename.setToolTipText(BaseMessages.getString(PKG, "JobSQL.Filename.Tooltip"));
    wFilename.addModifyListener(lsMod);
    fdFilename = new FormData();
    fdFilename.left = new FormAttachment(middle, 0);
    fdFilename.top = new FormAttachment(wSQLFromFile, margin);
    fdFilename.right = new FormAttachment(wbFilename, -margin);
    wFilename.setLayoutData(fdFilename);
    // Whenever something changes, set the tooltip to the expanded version:
    wFilename.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            wFilename.setToolTipText(jobMeta.environmentSubstitute(wFilename.getText()));
        }
    });
    wbFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.sql", "*.txt", "*" });
            if (wFilename.getText() != null) {
                dialog.setFileName(jobMeta.environmentSubstitute(wFilename.getText()));
            }
            dialog.setFilterNames(FILETYPES);
            if (dialog.open() != null) {
                wFilename.setText(dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName());
            }
        }
    });
    // Send one SQL Statement?
    wlUseOneStatement = new Label(shell, SWT.RIGHT);
    wlUseOneStatement.setText(BaseMessages.getString(PKG, "JobSQL.SendOneStatement.Label"));
    props.setLook(wlUseOneStatement);
    fdlUseOneStatement = new FormData();
    fdlUseOneStatement.left = new FormAttachment(0, 0);
    fdlUseOneStatement.top = new FormAttachment(wbFilename, margin);
    fdlUseOneStatement.right = new FormAttachment(middle, -margin);
    wlUseOneStatement.setLayoutData(fdlUseOneStatement);
    wSendOneStatement = new Button(shell, SWT.CHECK);
    props.setLook(wSendOneStatement);
    wSendOneStatement.setToolTipText(BaseMessages.getString(PKG, "JobSQL.SendOneStatement.Tooltip"));
    fdUseOneStatement = new FormData();
    fdUseOneStatement.left = new FormAttachment(middle, 0);
    fdUseOneStatement.top = new FormAttachment(wbFilename, margin);
    fdUseOneStatement.right = new FormAttachment(100, 0);
    wSendOneStatement.setLayoutData(fdUseOneStatement);
    wSendOneStatement.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });
    // Use variable substitution?
    wlUseSubs = new Label(shell, SWT.RIGHT);
    wlUseSubs.setText(BaseMessages.getString(PKG, "JobSQL.UseVariableSubst.Label"));
    props.setLook(wlUseSubs);
    fdlUseSubs = new FormData();
    fdlUseSubs.left = new FormAttachment(0, 0);
    fdlUseSubs.top = new FormAttachment(wSendOneStatement, margin);
    fdlUseSubs.right = new FormAttachment(middle, -margin);
    wlUseSubs.setLayoutData(fdlUseSubs);
    wUseSubs = new Button(shell, SWT.CHECK);
    props.setLook(wUseSubs);
    wUseSubs.setToolTipText(BaseMessages.getString(PKG, "JobSQL.UseVariableSubst.Tooltip"));
    fdUseSubs = new FormData();
    fdUseSubs.left = new FormAttachment(middle, 0);
    fdUseSubs.top = new FormAttachment(wSendOneStatement, margin);
    fdUseSubs.right = new FormAttachment(100, 0);
    wUseSubs.setLayoutData(fdUseSubs);
    wUseSubs.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            jobEntry.setUseVariableSubstitution(!jobEntry.getUseVariableSubstitution());
            jobEntry.setChanged();
        }
    });
    wlPosition = new Label(shell, SWT.NONE);
    wlPosition.setText(BaseMessages.getString(PKG, "JobSQL.LineNr.Label", "0"));
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.right = new FormAttachment(100, 0);
    fdlPosition.bottom = new FormAttachment(wOK, -margin);
    wlPosition.setLayoutData(fdlPosition);
    // Script line
    wlSQL = new Label(shell, SWT.NONE);
    wlSQL.setText(BaseMessages.getString(PKG, "JobSQL.Script.Label"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wUseSubs, margin);
    wlSQL.setLayoutData(fdlSQL);
    wSQL = new StyledTextComp(jobEntry, 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, -10);
    fdSQL.bottom = new FormAttachment(wlPosition, -margin);
    wSQL.setLayoutData(fdSQL);
    // Add listeners
    lsCancel = new Listener() {

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

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

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

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    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());
    getData();
    activeSQLFromFile();
    BaseStepDialog.setSize(shell);
    shell.open();
    props.setDialogSize(shell, "JobSQLDialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) 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) 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) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 4 with SQLValuesHighlight

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

the class CassandraInputDialog method open.

@Override
public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    props.setLook(shell);
    setShellImage(shell, m_currentMeta);
    // used to listen to a text field (m_wStepname)
    ModifyListener lsMod = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            m_currentMeta.setChanged();
        }
    };
    changed = m_currentMeta.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    // $NON-NLS-1$
    shell.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    m_stepnameLabel = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    m_stepnameLabel.setText(BaseMessages.getString(PKG, "CassandraInputDialog.StepName.Label"));
    props.setLook(m_stepnameLabel);
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(middle, -margin);
    fd.top = new FormAttachment(0, margin);
    m_stepnameLabel.setLayoutData(fd);
    m_stepnameText = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    m_stepnameText.setText(stepname);
    props.setLook(m_stepnameText);
    m_stepnameText.addModifyListener(lsMod);
    // format the text field
    fd = new FormData();
    fd.left = new FormAttachment(middle, 0);
    fd.top = new FormAttachment(0, margin);
    fd.right = new FormAttachment(100, 0);
    m_stepnameText.setLayoutData(fd);
    // host line
    m_hostLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_hostLab);
    // $NON-NLS-1$
    m_hostLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Hostname.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_stepnameText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_hostLab.setLayoutData(fd);
    m_hostText = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_hostText);
    m_hostText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            m_hostText.setToolTipText(transMeta.environmentSubstitute(m_hostText.getText()));
        }
    });
    m_hostText.addModifyListener(lsMod);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_stepnameText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_hostText.setLayoutData(fd);
    // port line
    m_portLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_portLab);
    // $NON-NLS-1$
    m_portLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Port.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_hostText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_portLab.setLayoutData(fd);
    m_portText = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_portText);
    m_portText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            m_portText.setToolTipText(transMeta.environmentSubstitute(m_portText.getText()));
        }
    });
    m_portText.addModifyListener(lsMod);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_hostText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_portText.setLayoutData(fd);
    // timeout line
    m_timeoutLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_timeoutLab);
    // $NON-NLS-1$
    m_timeoutLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Timeout.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_portText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_timeoutLab.setLayoutData(fd);
    m_timeoutText = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_timeoutText);
    m_timeoutText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            m_timeoutText.setToolTipText(transMeta.environmentSubstitute(m_timeoutText.getText()));
        }
    });
    m_timeoutText.addModifyListener(lsMod);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_portText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_timeoutText.setLayoutData(fd);
    // max length line
    m_maxLengthLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_maxLengthLab);
    m_maxLengthLab.setText(// $NON-NLS-1$
    BaseMessages.getString(PKG, "CassandraInputDialog.TransportMaxLength.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_timeoutText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_maxLengthLab.setLayoutData(fd);
    m_maxLengthText = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_maxLengthText);
    m_maxLengthText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            m_maxLengthText.setToolTipText(transMeta.environmentSubstitute(m_maxLengthText.getText()));
        }
    });
    m_maxLengthText.addModifyListener(lsMod);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_timeoutText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_maxLengthText.setLayoutData(fd);
    // username line
    m_userLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_userLab);
    // $NON-NLS-1$
    m_userLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.User.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_maxLengthText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_userLab.setLayoutData(fd);
    m_userText = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_userText);
    m_userText.addModifyListener(lsMod);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_maxLengthText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_userText.setLayoutData(fd);
    // password line
    m_passLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_passLab);
    // $NON-NLS-1$
    m_passLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Password.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_userText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_passLab.setLayoutData(fd);
    m_passText = new PasswordTextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_passText);
    m_passText.addModifyListener(lsMod);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_userText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_passText.setLayoutData(fd);
    // keyspace line
    m_keyspaceLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_keyspaceLab);
    // $NON-NLS-1$
    m_keyspaceLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Keyspace.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_passText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_keyspaceLab.setLayoutData(fd);
    m_keyspaceText = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_keyspaceText);
    m_keyspaceText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            m_keyspaceText.setToolTipText(transMeta.environmentSubstitute(m_keyspaceText.getText()));
        }
    });
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.top = new FormAttachment(m_passText, margin);
    fd.left = new FormAttachment(middle, 0);
    m_keyspaceText.setLayoutData(fd);
    // compression check box
    m_compressionLab = new Label(shell, SWT.RIGHT);
    props.setLook(m_compressionLab);
    m_compressionLab.setText(// $NON-NLS-1$
    BaseMessages.getString(PKG, "CassandraInputDialog.UseCompression.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_keyspaceText, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_compressionLab.setLayoutData(fd);
    m_useCompressionBut = new Button(shell, SWT.CHECK);
    props.setLook(m_useCompressionBut);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.left = new FormAttachment(middle, 0);
    fd.top = new FormAttachment(m_keyspaceText, margin);
    m_useCompressionBut.setLayoutData(fd);
    m_useCompressionBut.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            m_currentMeta.setChanged();
        }
    });
    // execute for each row
    Label executeForEachLab = new Label(shell, SWT.RIGHT);
    props.setLook(executeForEachLab);
    executeForEachLab.setText(// $NON-NLS-1$
    BaseMessages.getString(PKG, "CassandraInputDialog.ExecuteForEachRow.Label"));
    fd = new FormData();
    fd.right = new FormAttachment(middle, -margin);
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_useCompressionBut, margin);
    executeForEachLab.setLayoutData(fd);
    m_executeForEachRowBut = new Button(shell, SWT.CHECK);
    props.setLook(m_executeForEachRowBut);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.left = new FormAttachment(middle, 0);
    fd.top = new FormAttachment(m_useCompressionBut, margin);
    m_executeForEachRowBut.setLayoutData(fd);
    // Buttons inherited from BaseStepDialog
    wOK = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wPreview = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
    wCancel = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, m_cqlText);
    // position label
    m_positionLab = new Label(shell, SWT.NONE);
    props.setLook(m_positionLab);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(middle, -margin);
    fd.bottom = new FormAttachment(wOK, -margin);
    m_positionLab.setLayoutData(fd);
    m_showSchemaBut = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    m_showSchemaBut.setText(BaseMessages.getString(PKG, "CassandraInputDialog.Schema.Button"));
    props.setLook(m_showSchemaBut);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(wOK, -margin);
    m_showSchemaBut.setLayoutData(fd);
    m_showSchemaBut.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            popupSchemaInfo();
        }
    });
    // cql stuff
    m_cqlLab = new Label(shell, SWT.NONE);
    props.setLook(m_cqlLab);
    // $NON-NLS-1$
    m_cqlLab.setText(BaseMessages.getString(PKG, "CassandraInputDialog.CQL.Label"));
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_executeForEachRowBut, margin);
    fd.right = new FormAttachment(middle, -margin);
    m_cqlLab.setLayoutData(fd);
    m_cqlText = new StyledTextComp(transMeta, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, // $NON-NLS-1$
    "");
    props.setLook(m_cqlText, PropsUI.WIDGET_STYLE_FIXED);
    m_cqlText.addModifyListener(lsMod);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_cqlLab, margin);
    fd.right = new FormAttachment(100, -2 * margin);
    fd.bottom = new FormAttachment(m_showSchemaBut, -margin);
    m_cqlText.setLayoutData(fd);
    m_cqlText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            setPosition();
            m_cqlText.setToolTipText(transMeta.environmentSubstitute(m_cqlText.getText()));
        }
    });
    // Text Highlighting
    m_cqlText.addLineStyleListener(new SQLValuesHighlight());
    m_cqlText.addKeyListener(new KeyAdapter() {

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

        @Override
        public void keyReleased(KeyEvent e) {
            setPosition();
        }
    });
    m_cqlText.addFocusListener(new FocusAdapter() {

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

        @Override
        public void focusLost(FocusEvent e) {
            setPosition();
        }
    });
    m_cqlText.addMouseListener(new MouseAdapter() {

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

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

        @Override
        public void mouseUp(MouseEvent e) {
            setPosition();
        }
    });
    // Add listeners
    lsCancel = new Listener() {

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

        @Override
        public void handleEvent(Event e) {
            ok();
        }
    };
    lsPreview = new Listener() {

        @Override
        public void handleEvent(Event e) {
            preview();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    wPreview.addListener(SWT.Selection, lsPreview);
    lsDef = new SelectionAdapter() {

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

        @Override
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    setSize();
    getData();
    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) 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) PasswordTextVar(org.pentaho.di.ui.core.widget.PasswordTextVar) PasswordTextVar(org.pentaho.di.ui.core.widget.PasswordTextVar) 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 5 with SQLValuesHighlight

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

the class EnterCQLDialog method open.

public String open() {
    Display display = m_parent.getDisplay();
    m_shell = new Shell(m_parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN | SWT.APPLICATION_MODAL);
    m_props.setLook(m_shell);
    m_shell.setImage(GUIResource.getInstance().getImageSpoon());
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    m_shell.setLayout(formLayout);
    m_shell.setText(m_title);
    int margin = Const.MARGIN;
    int middle = Const.MIDDLE_PCT;
    Label dontComplainLab = new Label(m_shell, SWT.RIGHT);
    m_props.setLook(dontComplainLab);
    // $NON-NLS-1$
    dontComplainLab.setText(BaseMessages.getString(this.getClass(), "EnterCQLDialog.DontComplainIfCQLFails.Label"));
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.right = new FormAttachment(middle, -margin);
    fd.bottom = new FormAttachment(100, -50);
    dontComplainLab.setLayoutData(fd);
    m_dontComplainAboutAprioriCQLFailing = new Button(m_shell, SWT.CHECK);
    m_props.setLook(m_dontComplainAboutAprioriCQLFailing);
    fd = new FormData();
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, -50);
    fd.left = new FormAttachment(middle, 0);
    m_dontComplainAboutAprioriCQLFailing.setLayoutData(fd);
    m_dontComplainAboutAprioriCQLFailing.setSelection(m_dontComplain);
    m_dontComplainAboutAprioriCQLFailing.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            m_dontComplain = m_dontComplainAboutAprioriCQLFailing.getSelection();
        }
    });
    m_cqlText = // $NON-NLS-1$
    new StyledTextComp(m_transMeta, m_shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, "");
    m_props.setLook(m_cqlText, m_props.WIDGET_STYLE_FIXED);
    m_cqlText.setText(m_originalCQL);
    m_currentCQL = m_originalCQL;
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, -2 * margin);
    fd.bottom = new FormAttachment(m_dontComplainAboutAprioriCQLFailing, -margin);
    m_cqlText.setLayoutData(fd);
    m_cqlText.addModifyListener(m_lsMod);
    m_cqlText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            m_cqlText.setToolTipText(m_transMeta.environmentSubstitute(m_cqlText.getText()));
        }
    });
    // Text Highlighting
    m_cqlText.addLineStyleListener(new SQLValuesHighlight());
    // Some buttons
    m_ok = new Button(m_shell, SWT.PUSH);
    // $NON-NLS-1$
    m_ok.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    m_cancel = new Button(m_shell, SWT.PUSH);
    // $NON-NLS-1$
    m_cancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    BaseStepDialog.positionBottomButtons(m_shell, new Button[] { m_ok, m_cancel }, margin, null);
    // Add listeners
    m_lsCancel = new Listener() {

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

        public void handleEvent(Event e) {
            ok();
        }
    };
    m_ok.addListener(SWT.Selection, m_lsOK);
    m_cancel.addListener(SWT.Selection, m_lsCancel);
    // Detect [X] or ALT-F4 or something that kills this window...
    m_shell.addShellListener(new ShellAdapter() {

        @Override
        public void shellClosed(ShellEvent e) {
            checkCancel(e);
        }
    });
    BaseStepDialog.setSize(m_shell);
    m_shell.open();
    while (!m_shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return m_currentCQL;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLValuesHighlight(org.pentaho.di.ui.trans.steps.tableinput.SQLValuesHighlight) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display)

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