Search in sources :

Example 36 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp 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 37 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class TableInputDialog 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) {
            // for prompting if dialog is simply closed
            changedInDialog = false;
            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, "TableInputDialog.TableInput"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "TableInputDialog.StepName"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
        wConnection.select(0);
    }
    wConnection.addModifyListener(lsMod);
    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wPreview = new Button(shell, SWT.PUSH);
    wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    // wHelp = createHelpButton(shell, stepMeta);
    setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, null);
    // Limit input ...
    wlLimit = new Label(shell, SWT.RIGHT);
    wlLimit.setText(BaseMessages.getString(PKG, "TableInputDialog.LimitSize"));
    props.setLook(wlLimit);
    fdlLimit = new FormData();
    fdlLimit.left = new FormAttachment(0, 0);
    fdlLimit.right = new FormAttachment(middle, -margin);
    fdlLimit.bottom = new FormAttachment(wOK, -2 * margin);
    wlLimit.setLayoutData(fdlLimit);
    wLimit = new TextVar(transMeta, 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.bottom = new FormAttachment(wOK, -2 * margin);
    wLimit.setLayoutData(fdLimit);
    // Execute for each row?
    wlEachRow = new Label(shell, SWT.RIGHT);
    wlEachRow.setText(BaseMessages.getString(PKG, "TableInputDialog.ExecuteForEachRow"));
    props.setLook(wlEachRow);
    fdlEachRow = new FormData();
    fdlEachRow.left = new FormAttachment(0, 0);
    fdlEachRow.right = new FormAttachment(middle, -margin);
    fdlEachRow.bottom = new FormAttachment(wLimit, -margin);
    wlEachRow.setLayoutData(fdlEachRow);
    wEachRow = new Button(shell, SWT.CHECK);
    props.setLook(wEachRow);
    fdEachRow = new FormData();
    fdEachRow.left = new FormAttachment(middle, 0);
    fdEachRow.right = new FormAttachment(100, 0);
    fdEachRow.bottom = new FormAttachment(wLimit, -margin);
    wEachRow.setLayoutData(fdEachRow);
    SelectionAdapter lsSelMod = new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
        }
    };
    wEachRow.addSelectionListener(lsSelMod);
    // Read date from...
    wlDatefrom = new Label(shell, SWT.RIGHT);
    wlDatefrom.setText(BaseMessages.getString(PKG, "TableInputDialog.InsertDataFromStep"));
    props.setLook(wlDatefrom);
    fdlDatefrom = new FormData();
    fdlDatefrom.left = new FormAttachment(0, 0);
    fdlDatefrom.right = new FormAttachment(middle, -margin);
    fdlDatefrom.bottom = new FormAttachment(wEachRow, -margin);
    wlDatefrom.setLayoutData(fdlDatefrom);
    wDatefrom = new CCombo(shell, SWT.BORDER);
    props.setLook(wDatefrom);
    List<StepMeta> previousSteps = transMeta.findPreviousSteps(transMeta.findStep(stepname));
    for (StepMeta stepMeta : previousSteps) {
        wDatefrom.add(stepMeta.getName());
    }
    wDatefrom.addModifyListener(lsMod);
    fdDatefrom = new FormData();
    fdDatefrom.left = new FormAttachment(middle, 0);
    fdDatefrom.right = new FormAttachment(100, 0);
    fdDatefrom.bottom = new FormAttachment(wEachRow, -margin);
    wDatefrom.setLayoutData(fdDatefrom);
    // Replace variables in SQL?
    // 
    wlVariables = new Label(shell, SWT.RIGHT);
    wlVariables.setText(BaseMessages.getString(PKG, "TableInputDialog.ReplaceVariables"));
    props.setLook(wlVariables);
    fdlVariables = new FormData();
    fdlVariables.left = new FormAttachment(0, 0);
    fdlVariables.right = new FormAttachment(middle, -margin);
    fdlVariables.bottom = new FormAttachment(wDatefrom, -margin);
    wlVariables.setLayoutData(fdlVariables);
    wVariables = new Button(shell, SWT.CHECK);
    props.setLook(wVariables);
    fdVariables = new FormData();
    fdVariables.left = new FormAttachment(middle, 0);
    fdVariables.right = new FormAttachment(100, 0);
    fdVariables.bottom = new FormAttachment(wDatefrom, -margin);
    wVariables.setLayoutData(fdVariables);
    wVariables.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
            setSQLToolTip();
        }
    });
    // Lazy conversion?
    // 
    wlLazyConversion = new Label(shell, SWT.RIGHT);
    wlLazyConversion.setText(BaseMessages.getString(PKG, "TableInputDialog.LazyConversion"));
    props.setLook(wlLazyConversion);
    fdlLazyConversion = new FormData();
    fdlLazyConversion.left = new FormAttachment(0, 0);
    fdlLazyConversion.right = new FormAttachment(middle, -margin);
    fdlLazyConversion.bottom = new FormAttachment(wVariables, -margin);
    wlLazyConversion.setLayoutData(fdlLazyConversion);
    wLazyConversion = new Button(shell, SWT.CHECK);
    props.setLook(wLazyConversion);
    fdLazyConversion = new FormData();
    fdLazyConversion.left = new FormAttachment(middle, 0);
    fdLazyConversion.right = new FormAttachment(100, 0);
    fdLazyConversion.bottom = new FormAttachment(wVariables, -margin);
    wLazyConversion.setLayoutData(fdLazyConversion);
    wLazyConversion.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
            setSQLToolTip();
        }
    });
    // Cached Row Meta conversion?
    // 
    wlCachedRowMeta = new Label(shell, SWT.RIGHT);
    wlCachedRowMeta.setText(BaseMessages.getString(PKG, "TableInputDialog.CacheRowMeta"));
    props.setLook(wlCachedRowMeta);
    fdlCachedRowMeta = new FormData();
    fdlCachedRowMeta.left = new FormAttachment(0, 0);
    fdlCachedRowMeta.right = new FormAttachment(middle, -margin);
    fdlCachedRowMeta.bottom = new FormAttachment(wLazyConversion, -margin);
    wlCachedRowMeta.setLayoutData(fdlCachedRowMeta);
    wCachedRowMeta = new Button(shell, SWT.CHECK);
    props.setLook(wCachedRowMeta);
    fdCachedRowMeta = new FormData();
    fdCachedRowMeta.left = new FormAttachment(middle, 0);
    fdCachedRowMeta.right = new FormAttachment(100, 0);
    fdCachedRowMeta.bottom = new FormAttachment(wLazyConversion, -margin);
    wCachedRowMeta.setLayoutData(fdCachedRowMeta);
    wCachedRowMeta.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            input.setChanged();
        }
    });
    wlPosition = new Label(shell, SWT.NONE);
    props.setLook(wlPosition);
    fdlPosition = new FormData();
    fdlPosition.left = new FormAttachment(0, 0);
    fdlPosition.right = new FormAttachment(100, 0);
    fdlPosition.bottom = new FormAttachment(wCachedRowMeta, -margin);
    wlPosition.setLayoutData(fdlPosition);
    // Table line...
    wlSQL = new Label(shell, SWT.NONE);
    wlSQL.setText(BaseMessages.getString(PKG, "TableInputDialog.SQL"));
    props.setLook(wlSQL);
    fdlSQL = new FormData();
    fdlSQL.left = new FormAttachment(0, 0);
    fdlSQL.top = new FormAttachment(wConnection, margin * 2);
    wlSQL.setLayoutData(fdlSQL);
    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(BaseMessages.getString(PKG, "TableInputDialog.GetSQLAndSelectStatement"));
    fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wConnection, margin * 2);
    wbTable.setLayoutData(fdbTable);
    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(wbTable, margin);
    fdSQL.right = new FormAttachment(100, -2 * margin);
    fdSQL.bottom = new FormAttachment(wlPosition, -margin);
    wSQL.setLayoutData(fdSQL);
    wSQL.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            setSQLToolTip();
            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());
    // Add listeners
    lsCancel = new Listener() {

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

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

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

        public void handleEvent(Event e) {
            getSQL();
        }
    };
    lsDatefrom = new Listener() {

        public void handleEvent(Event e) {
            setFlags();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wPreview.addListener(SWT.Selection, lsPreview);
    wOK.addListener(SWT.Selection, lsOK);
    wbTable.addListener(SWT.Selection, lsbTable);
    wDatefrom.addListener(SWT.Selection, lsDatefrom);
    wDatefrom.addListener(SWT.FocusOut, lsDatefrom);
    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) {
            checkCancel(e);
        }
    });
    getData();
    // 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) 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) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) TextVar(org.pentaho.di.ui.core.widget.TextVar) CCombo(org.eclipse.swt.custom.CCombo) 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) Display(org.eclipse.swt.widgets.Display)

Example 38 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class ScriptValuesModDialog method test.

private boolean test(boolean getvars, boolean popup) {
    boolean retval = true;
    StyledTextComp wScript = getStyledTextComp();
    String scr = wScript.getText();
    KettleException testException = null;
    Context jscx;
    Scriptable jsscope;
    // Script jsscript;
    // Making Refresh to get Active Script State
    refreshScripts();
    jscx = ContextFactory.getGlobal().enterContext();
    jscx.setOptimizationLevel(-1);
    jsscope = jscx.initStandardObjects(null, false);
    // Adding the existing Scripts to the Context
    for (int i = 0; i < folder.getItemCount(); i++) {
        StyledTextComp sItem = getStyledTextComp(folder.getItem(i));
        Scriptable jsR = Context.toObject(sItem.getText(), jsscope);
        jsscope.put(folder.getItem(i).getText(), jsscope, jsR);
    }
    // Adding the Name of the Transformation to the Context
    jsscope.put("_TransformationName_", jsscope, this.stepname);
    try {
        RowMetaInterface rowMeta = transMeta.getPrevStepFields(stepname);
        if (rowMeta != null) {
            ScriptValuesModDummy dummyStep = new ScriptValuesModDummy(rowMeta, transMeta.getStepFields(stepname));
            Scriptable jsvalue = Context.toObject(dummyStep, jsscope);
            jsscope.put("_step_", jsscope, jsvalue);
            // Modification for Additional Script parsing
            try {
                if (input.getAddClasses() != null) {
                    for (int i = 0; i < input.getAddClasses().length; i++) {
                        Object jsOut = Context.javaToJS(input.getAddClasses()[i].getAddObject(), jsscope);
                        ScriptableObject.putProperty(jsscope, input.getAddClasses()[i].getJSName(), jsOut);
                    }
                }
            } catch (Exception e) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddToContext", e.toString()));
                retval = false;
            }
            // Adding some default JavaScriptFunctions to the System
            try {
                Context.javaToJS(ScriptValuesAddedFunctions.class, jsscope);
                ((ScriptableObject) jsscope).defineFunctionProperties(jsFunctionList, ScriptValuesAddedFunctions.class, ScriptableObject.DONTENUM);
            } catch (Exception ex) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddDefaultFunctions", ex.toString()));
                retval = false;
            }
            // Adding some Constants to the JavaScript
            try {
                jsscope.put("SKIP_TRANSFORMATION", jsscope, Integer.valueOf(SKIP_TRANSFORMATION));
                jsscope.put("ABORT_TRANSFORMATION", jsscope, Integer.valueOf(ABORT_TRANSFORMATION));
                jsscope.put("ERROR_TRANSFORMATION", jsscope, Integer.valueOf(ERROR_TRANSFORMATION));
                jsscope.put("CONTINUE_TRANSFORMATION", jsscope, Integer.valueOf(CONTINUE_TRANSFORMATION));
            } catch (Exception ex) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddTransformationConstants", ex.toString()));
                retval = false;
            }
            try {
                Object[] row = new Object[rowMeta.size()];
                Scriptable jsRowMeta = Context.toObject(rowMeta, jsscope);
                jsscope.put("rowMeta", jsscope, jsRowMeta);
                for (int i = 0; i < rowMeta.size(); i++) {
                    ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
                    Object valueData = null;
                    // 
                    if (valueMeta.isDate()) {
                        valueData = new Date();
                    }
                    if (valueMeta.isString()) {
                        valueData = "test value test value test value test value test value " + "test value test value test value test value test value";
                    }
                    if (valueMeta.isInteger()) {
                        valueData = Long.valueOf(0L);
                    }
                    if (valueMeta.isNumber()) {
                        valueData = new Double(0.0);
                    }
                    if (valueMeta.isBigNumber()) {
                        valueData = BigDecimal.ZERO;
                    }
                    if (valueMeta.isBoolean()) {
                        valueData = Boolean.TRUE;
                    }
                    if (valueMeta.isBinary()) {
                        valueData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                    }
                    if (valueMeta.isStorageBinaryString()) {
                        valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
                    }
                    row[i] = valueData;
                    if (wCompatible.getSelection()) {
                        Value value = valueMeta.createOriginalValue(valueData);
                        Scriptable jsarg = Context.toObject(value, jsscope);
                        jsscope.put(valueMeta.getName(), jsscope, jsarg);
                    } else {
                        Scriptable jsarg = Context.toObject(valueData, jsscope);
                        jsscope.put(valueMeta.getName(), jsscope, jsarg);
                    }
                }
                // OK, for these input values, we're going to allow the user to edit the default values...
                // We are displaying a
                // 2)
                // Add support for Value class (new Value())
                Scriptable jsval = Context.toObject(Value.class, jsscope);
                jsscope.put("Value", jsscope, jsval);
                // 
                if (wCompatible.getSelection()) {
                    Row v2Row = RowMeta.createOriginalRow(rowMeta, row);
                    Scriptable jsV2Row = Context.toObject(v2Row, jsscope);
                    jsscope.put("row", jsscope, jsV2Row);
                } else {
                    Scriptable jsRow = Context.toObject(row, jsscope);
                    jsscope.put("row", jsscope, jsRow);
                }
            } catch (Exception ev) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddInputFields", ev.toString()));
                retval = false;
            }
            try {
                // Checking for StartScript
                if (strActiveStartScript != null && !folder.getSelection().getText().equals(strActiveStartScript) && strActiveStartScript.length() > 0) {
                    String strStartScript = getStyledTextComp(folder.getItem(getCTabPosition(strActiveStartScript))).getText();
                    /* Object startScript = */
                    jscx.evaluateString(jsscope, strStartScript, "trans_Start", 1, null);
                }
            } catch (Exception e) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldProcessStartScript", e.toString()));
                retval = false;
            }
            try {
                Script evalScript = jscx.compileString(scr, "script", 1, null);
                evalScript.exec(jscx, jsscope);
                if (getvars) {
                    ScriptNode tree = parseVariables(jscx, jsscope, scr, "script", 1, null);
                    for (int i = 0; i < tree.getParamAndVarCount(); i++) {
                        String varname = tree.getParamOrVarName(i);
                        if (!varname.equalsIgnoreCase("row") && !varname.equalsIgnoreCase("trans_Status")) {
                            int type = ValueMetaInterface.TYPE_STRING;
                            int length = -1, precision = -1;
                            Object result = jsscope.get(varname, jsscope);
                            if (result != null) {
                                String classname = result.getClass().getName();
                                if (classname.equalsIgnoreCase("java.lang.Byte")) {
                                    // MAX = 127
                                    type = ValueMetaInterface.TYPE_INTEGER;
                                    length = 3;
                                    precision = 0;
                                } else if (classname.equalsIgnoreCase("java.lang.Integer")) {
                                    // MAX = 2147483647
                                    type = ValueMetaInterface.TYPE_INTEGER;
                                    length = 9;
                                    precision = 0;
                                } else if (classname.equalsIgnoreCase("java.lang.Long")) {
                                    // MAX = 9223372036854775807
                                    type = ValueMetaInterface.TYPE_INTEGER;
                                    length = 18;
                                    precision = 0;
                                } else if (classname.equalsIgnoreCase("java.lang.Double")) {
                                    type = ValueMetaInterface.TYPE_NUMBER;
                                    length = 16;
                                    precision = 2;
                                } else if (classname.equalsIgnoreCase("org.mozilla.javascript.NativeDate") || classname.equalsIgnoreCase("java.util.Date")) {
                                    type = ValueMetaInterface.TYPE_DATE;
                                } else if (classname.equalsIgnoreCase("java.lang.Boolean")) {
                                    type = ValueMetaInterface.TYPE_BOOLEAN;
                                }
                            }
                            TableItem ti = new TableItem(wFields.table, SWT.NONE);
                            ti.setText(1, varname);
                            ti.setText(2, "");
                            ti.setText(3, ValueMetaFactory.getValueMetaName(type));
                            ti.setText(4, length >= 0 ? ("" + length) : "");
                            ti.setText(5, precision >= 0 ? ("" + precision) : "");
                            // If the variable name exists in the input, suggest to replace the value
                            // 
                            ti.setText(6, (rowMeta.indexOfValue(varname) >= 0) ? YES_NO_COMBO[1] : YES_NO_COMBO[0]);
                        }
                    }
                    wFields.removeEmptyRows();
                    wFields.setRowNums();
                    wFields.optWidth(true);
                }
            // End Script!
            } catch (EvaluatorException e) {
                String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
                String message = BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotExecuteScript", position);
                testException = new KettleException(message, e);
                retval = false;
            } catch (JavaScriptException e) {
                String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
                String message = BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotExecuteScript", position);
                testException = new KettleException(message, e);
                retval = false;
            } catch (Exception e) {
                testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotExecuteScript2"), e);
                retval = false;
            }
        } else {
            testException = new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotGetFields"));
            retval = false;
        }
        if (popup) {
            if (retval) {
                if (!getvars) {
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                    mb.setMessage(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ScriptCompilationOK") + Const.CR);
                    mb.setText("OK");
                    mb.open();
                }
            } else {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogMessage"), testException);
            }
        }
    } catch (KettleException ke) {
        retval = false;
        new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogMessage"), ke);
    } finally {
        if (jscx != null) {
            Context.exit();
        }
    }
    return retval;
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) KettleException(org.pentaho.di.core.exception.KettleException) TableItem(org.eclipse.swt.widgets.TableItem) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) EvaluatorException(org.mozilla.javascript.EvaluatorException) Context(org.mozilla.javascript.Context) ScriptValuesScript(org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesScript) Script(org.mozilla.javascript.Script) ScriptableObject(org.mozilla.javascript.ScriptableObject) ScriptValuesModDummy(org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesModDummy) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Scriptable(org.mozilla.javascript.Scriptable) ScriptNode(org.mozilla.javascript.ast.ScriptNode) Point(org.eclipse.swt.graphics.Point) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) KettleException(org.pentaho.di.core.exception.KettleException) Date(java.util.Date) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) JavaScriptException(org.mozilla.javascript.JavaScriptException) MessageBox(org.eclipse.swt.widgets.MessageBox) Value(org.pentaho.di.compatibility.Value) ScriptableObject(org.mozilla.javascript.ScriptableObject) Row(org.pentaho.di.compatibility.Row)

Example 39 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class ScriptValuesModDialog method treeDblClick.

/*
   * private void rebuildInputFieldsTree(){ try{ String itemName = BaseMessages.getString(PKG,
   * "ScriptValuesDialogMod.InputFields.Label");
   *
   * RowMetaInterface r = transMeta.getPrevStepFields(stepname); if (r!=null){ TreeItem item = null; for (TreeItem look
   * : wTree.getItems()) { if (look.getText().equals(itemName)) { // This is the rebuild part! for (TreeItem child :
   * look.getItems()) child.dispose(); // clear the children. item=look; break; } } if (item==null) item = new
   * TreeItem(wTree, SWT.NULL); item.setText(itemName); String strItemToAdd=""; for (int i=0;i<r.size();i++){
   * ValueMetaInterface v = r.getValueMeta(i); if (wCompatible.getSelection()) { switch(v.getType()){ case
   * ValueMetaInterface.TYPE_STRING : strItemToAdd=v.getName()+".getString()"; break; case
   * ValueMetaInterface.TYPE_NUMBER : strItemToAdd=v.getName()+".getNumber()"; break; case
   * ValueMetaInterface.TYPE_INTEGER: strItemToAdd=v.getName()+".getInteger()"; break; case ValueMetaInterface.TYPE_DATE
   * : strItemToAdd=v.getName()+".getDate()"; break; case ValueMetaInterface.TYPE_BOOLEAN:
   * strItemToAdd=v.getName()+".getBoolean()"; break; case ValueMetaInterface.TYPE_BIGNUMBER:
   * strItemToAdd=v.getName()+".getBigNumber()"; break; case ValueMetaInterface.TYPE_BINARY:
   * strItemToAdd=v.getName()+".getBytes()"; break; case ValueMetaInterface.TYPE_SERIALIZABLE:
   * strItemToAdd=v.getName()+".getSerializable()"; break; default: strItemToAdd=v.getName(); break; } } else {
   * strItemToAdd=v.getName(); } TreeItem itemInputFields = new TreeItem(item, SWT.NULL);
   * itemInputFields.setText(strItemToAdd); itemInputFields.setData(strItemToAdd); } } }catch(KettleException ke){ new
   * ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptValuesDialogMod.FailedToGetFields.DialogTitle"),
   * BaseMessages.getString(PKG, "ScriptValuesDialogMod.FailedToGetFields.DialogMessage"), ke); } }
   */
// Adds the Current item to the current Position
private void treeDblClick(Event event) {
    StyledTextComp wScript = getStyledTextComp();
    Point point = new Point(event.x, event.y);
    TreeItem item = wTree.getItem(point);
    // Qualifikation where the Click comes from
    if (item != null && item.getParentItem() != null) {
        if (item.getParentItem().equals(wTreeScriptsItem)) {
            setActiveCtab(item.getText());
        } else if (!item.getData().equals("Function")) {
            int iStart = wScript.getCaretOffset();
            // this selection will be replaced by wScript.insert
            int selCount = wScript.getSelectionCount();
            // when a selection is already there we need to subtract the position
            iStart = iStart - selCount;
            if (iStart < 0) {
                // just safety
                iStart = 0;
            }
            String strInsert = (String) item.getData();
            if (strInsert.equals("jsFunction")) {
                strInsert = item.getText();
            }
            wScript.insert(strInsert);
            wScript.setSelection(iStart, iStart + strInsert.length());
        }
    }
/*
     * if (item != null && item.getParentItem()!=null && !item.getData().equals("Function")) { int iStart =
     * wScript.getCaretOffset(); String strInsert =(String)item.getData(); if(strInsert.equals("jsFunction")) strInsert
     * = (String)item.getText(); wScript.insert(strInsert); wScript.setSelection(iStart,iStart+strInsert.length()); }
     */
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point)

Example 40 with StyledTextComp

use of org.pentaho.di.ui.core.widget.StyledTextComp in project pentaho-kettle by pentaho.

the class UserDefinedJavaClassDialog method addCtab.

private void addCtab(String tabName, String tabCode, TabAddActions tabType) {
    CTabItem item = new CTabItem(folder, SWT.CLOSE);
    switch(tabType) {
        case ADD_DEFAULT:
            item.setText(tabName);
            break;
        default:
            item.setText(getNextName(tabName));
            break;
    }
    StyledTextComp wScript = new StyledTextComp(transMeta, item.getParent(), SWT.MULTI | SWT.LEFT | SWT.H_SCROLL | SWT.V_SCROLL, item.getText(), false);
    if ((tabCode != null) && tabCode.length() > 0) {
        wScript.setText(tabCode);
    } else {
        wScript.setText(snippitsHelper.getDefaultCode());
    }
    item.setImage(imageInactiveScript);
    props.setLook(wScript, Props.WIDGET_STYLE_FIXED);
    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();
        }
    });
    wScript.addModifyListener(lsMod);
    // Text Higlighting
    wScript.addLineStyleListener(new UserDefinedJavaClassHighlight());
    item.setControl(wScript);
    // Adding new Item to Tree
    modifyTabTree(item, TabActions.ADD_ITEM);
}
Also used : StyledTextComp(org.pentaho.di.ui.core.widget.StyledTextComp) KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) CTabItem(org.eclipse.swt.custom.CTabItem) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

StyledTextComp (org.pentaho.di.ui.core.widget.StyledTextComp)41 Event (org.eclipse.swt.widgets.Event)28 Listener (org.eclipse.swt.widgets.Listener)28 ModifyEvent (org.eclipse.swt.events.ModifyEvent)27 ModifyListener (org.eclipse.swt.events.ModifyListener)27 ShellEvent (org.eclipse.swt.events.ShellEvent)27 SelectionEvent (org.eclipse.swt.events.SelectionEvent)26 FormAttachment (org.eclipse.swt.layout.FormAttachment)25 FormData (org.eclipse.swt.layout.FormData)25 FormLayout (org.eclipse.swt.layout.FormLayout)25 Button (org.eclipse.swt.widgets.Button)25 Label (org.eclipse.swt.widgets.Label)25 Shell (org.eclipse.swt.widgets.Shell)25 ShellAdapter (org.eclipse.swt.events.ShellAdapter)24 Display (org.eclipse.swt.widgets.Display)24 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)23 FocusEvent (org.eclipse.swt.events.FocusEvent)19 KeyEvent (org.eclipse.swt.events.KeyEvent)19 MouseEvent (org.eclipse.swt.events.MouseEvent)19 Text (org.eclipse.swt.widgets.Text)19