Search in sources :

Example 1 with TextVarWarning

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

the class ValidatorDialog method open.

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, input);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            input.setChanged();
        }
    };
    changed = input.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "ValidatorDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    Rectangle imageBounds = GUIResource.getInstance().getImageInfoHop().getBounds();
    // Stepname line
    // 
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "ValidatorDialog.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);
    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wNew = new Button(shell, SWT.PUSH);
    wNew.setText(BaseMessages.getString(PKG, "ValidatorDialog.NewButton.Label"));
    wClear = new Button(shell, SWT.PUSH);
    wClear.setText(BaseMessages.getString(PKG, "ValidatorDialog.ClearButton.Label"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    setButtonPositions(new Button[] { wOK, wNew, wClear, wCancel }, margin, null);
    // List of fields to the left...
    // 
    Label wlFieldList = new Label(shell, SWT.LEFT);
    wlFieldList.setText(BaseMessages.getString(PKG, "ValidatorDialog.FieldList.Label"));
    props.setLook(wlFieldList);
    FormData fdlFieldList = new FormData();
    fdlFieldList.left = new FormAttachment(0, 0);
    fdlFieldList.right = new FormAttachment(middle, -margin);
    fdlFieldList.top = new FormAttachment(wStepname, margin);
    wlFieldList.setLayoutData(fdlFieldList);
    wValidationsList = new List(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wValidationsList);
    wValidationsList.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            showSelectedValidatorField(wValidationsList.getSelection()[0]);
        }
    });
    FormData fdFieldList = new FormData();
    fdFieldList.left = new FormAttachment(0, 0);
    fdFieldList.top = new FormAttachment(wlFieldList, margin);
    fdFieldList.right = new FormAttachment(middle, -margin);
    fdFieldList.bottom = new FormAttachment(wOK, -margin * 2);
    wValidationsList.setLayoutData(fdFieldList);
    // General: an option to allow ALL the options to be checked.
    // 
    wValidateAll = new Button(shell, SWT.CHECK);
    wValidateAll.setText(BaseMessages.getString(PKG, "ValidatorDialog.ValidateAll.Label"));
    props.setLook(wValidateAll);
    FormData fdValidateAll = new FormData();
    fdValidateAll.left = new FormAttachment(middle, 0);
    fdValidateAll.right = new FormAttachment(100, 0);
    fdValidateAll.top = new FormAttachment(wStepname, margin);
    wValidateAll.setLayoutData(fdValidateAll);
    wValidateAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setFlags();
        }
    });
    // General: When validating all options, still output a single row, errors concatenated
    // 
    wConcatErrors = new Button(shell, SWT.CHECK);
    wConcatErrors.setText(BaseMessages.getString(PKG, "ValidatorDialog.ConcatErrors.Label"));
    props.setLook(wConcatErrors);
    FormData fdConcatErrors = new FormData();
    fdConcatErrors.left = new FormAttachment(middle, 0);
    fdConcatErrors.top = new FormAttachment(wValidateAll, margin);
    wConcatErrors.setLayoutData(fdConcatErrors);
    wConcatErrors.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            setFlags();
        }
    });
    // The separator
    // 
    wConcatSeparator = new TextVarWarning(transMeta, shell, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
    props.setLook(wConcatSeparator);
    FormData fdConcatSeparator = new FormData();
    fdConcatSeparator.left = new FormAttachment(wConcatErrors, margin);
    fdConcatSeparator.right = new FormAttachment(100, 0);
    fdConcatSeparator.top = new FormAttachment(wValidateAll, margin);
    wConcatSeparator.setLayoutData(fdConcatSeparator);
    // Create a scrolled composite on the right side...
    // 
    ScrolledComposite wSComp = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    props.setLook(wSComp);
    wSComp.setLayout(new FillLayout());
    FormData fdComp = new FormData();
    fdComp.left = new FormAttachment(middle, 0);
    fdComp.top = new FormAttachment(wConcatSeparator, 2 * margin);
    fdComp.right = new FormAttachment(100, 0);
    fdComp.bottom = new FormAttachment(wOK, -margin * 2);
    wSComp.setLayoutData(fdComp);
    Composite wComp = new Composite(wSComp, SWT.BORDER);
    props.setLook(wComp);
    FormLayout compLayout = new FormLayout();
    compLayout.marginWidth = 3;
    compLayout.marginHeight = 3;
    wComp.setLayout(compLayout);
    int extra = imageBounds.width;
    // Description (list key)
    // 
    wlDescription = new Label(wComp, SWT.RIGHT);
    wlDescription.setText(BaseMessages.getString(PKG, "ValidatorDialog.Description.Label"));
    props.setLook(wlDescription);
    FormData fdlDescription = new FormData();
    fdlDescription.left = new FormAttachment(0, 0);
    fdlDescription.right = new FormAttachment(middle, -margin);
    fdlDescription.top = new FormAttachment(0, 0);
    wlDescription.setLayoutData(fdlDescription);
    wDescription = new Text(wComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDescription);
    FormData fdDescription = new FormData();
    fdDescription.left = new FormAttachment(middle, margin + extra);
    fdDescription.right = new FormAttachment(100, 0);
    fdDescription.top = new FormAttachment(0, 0);
    wDescription.setLayoutData(fdDescription);
    wDescription.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            // 
            if (wValidationsList != null && wValidationsList.getItemCount() > 0 && wValidationsList.getSelection().length == 1) {
                int index = wValidationsList.getSelectionIndex();
                String description = wValidationsList.getItem(index);
                Validation validation = Validation.findValidation(selectionList, description);
                String newDescription = wDescription.getText();
                validation.setName(newDescription);
                wValidationsList.setItem(index, newDescription);
                wValidationsList.select(index);
            }
        }
    });
    // The name of the field to validate
    // 
    wlFieldName = new Label(wComp, SWT.RIGHT);
    wlFieldName.setText(BaseMessages.getString(PKG, "ValidatorDialog.FieldName.Label"));
    props.setLook(wlFieldName);
    FormData fdlFieldName = new FormData();
    fdlFieldName.left = new FormAttachment(0, 0);
    fdlFieldName.right = new FormAttachment(middle, -margin);
    fdlFieldName.top = new FormAttachment(wDescription, margin);
    wlFieldName.setLayoutData(fdlFieldName);
    wFieldName = new CCombo(wComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFieldName);
    FormData fdFieldName = new FormData();
    fdFieldName.left = new FormAttachment(middle, margin + extra);
    fdFieldName.right = new FormAttachment(100, 0);
    fdFieldName.top = new FormAttachment(wDescription, margin);
    wFieldName.setLayoutData(fdFieldName);
    // 
    try {
        inputFields = transMeta.getPrevStepFields(stepMeta);
        wFieldName.setItems(inputFields.getFieldNames());
    } catch (KettleStepException ex) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "ValidatorDialog.Exception.CantGetFieldsFromPreviousSteps.Title"), BaseMessages.getString(PKG, "ValidatorDialog.Exception.CantGetFieldsFromPreviousSteps.Message"), ex);
    }
    // ErrorCode
    // 
    wlErrorCode = new Label(wComp, SWT.RIGHT);
    wlErrorCode.setText(BaseMessages.getString(PKG, "ValidatorDialog.ErrorCode.Label"));
    props.setLook(wlErrorCode);
    FormData fdlErrorCode = new FormData();
    fdlErrorCode.left = new FormAttachment(0, 0);
    fdlErrorCode.right = new FormAttachment(middle, -margin);
    fdlErrorCode.top = new FormAttachment(wFieldName, margin);
    wlErrorCode.setLayoutData(fdlErrorCode);
    wErrorCode = new TextVarWarning(transMeta, wComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wErrorCode);
    FormData fdErrorCode = new FormData();
    fdErrorCode.left = new FormAttachment(middle, margin);
    fdErrorCode.right = new FormAttachment(100, 0);
    fdErrorCode.top = new FormAttachment(wFieldName, margin);
    wErrorCode.setLayoutData(fdErrorCode);
    addSpacesWarning(wErrorCode);
    // ErrorDescription
    // 
    wlErrorDescription = new Label(wComp, SWT.RIGHT);
    wlErrorDescription.setText(BaseMessages.getString(PKG, "ValidatorDialog.ErrorDescription.Label"));
    props.setLook(wlErrorDescription);
    FormData fdlErrorDescription = new FormData();
    fdlErrorDescription.left = new FormAttachment(0, 0);
    fdlErrorDescription.right = new FormAttachment(middle, -margin);
    fdlErrorDescription.top = new FormAttachment(wErrorCode, margin);
    wlErrorDescription.setLayoutData(fdlErrorDescription);
    wErrorDescription = new TextVarWarning(transMeta, wComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wErrorDescription);
    FormData fdErrorDescription = new FormData();
    fdErrorDescription.left = new FormAttachment(middle, margin);
    fdErrorDescription.right = new FormAttachment(100, 0);
    fdErrorDescription.top = new FormAttachment(wErrorCode, margin);
    wErrorDescription.setLayoutData(fdErrorDescription);
    addSpacesWarning(wErrorDescription);
    // Data type validations & constants masks...
    // 
    wgType = new Group(wComp, SWT.NONE);
    props.setLook(wgType);
    wgType.setText(BaseMessages.getString(PKG, "ValidatorDialog.TypeGroup.Label"));
    FormLayout typeGroupLayout = new FormLayout();
    typeGroupLayout.marginHeight = Const.FORM_MARGIN;
    typeGroupLayout.marginWidth = Const.FORM_MARGIN;
    wgType.setLayout(typeGroupLayout);
    FormData fdType = new FormData();
    fdType.left = new FormAttachment(0, 0);
    fdType.right = new FormAttachment(100, 0);
    fdType.top = new FormAttachment(wErrorDescription, margin * 2);
    wgType.setLayoutData(fdType);
    // Check for data type correctness?
    // 
    wlDataTypeVerified = new Label(wgType, SWT.RIGHT);
    wlDataTypeVerified.setText(BaseMessages.getString(PKG, "ValidatorDialog.DataTypeVerified.Label"));
    props.setLook(wlDataTypeVerified);
    FormData fdldataTypeVerified = new FormData();
    fdldataTypeVerified.left = new FormAttachment(0, 0);
    fdldataTypeVerified.right = new FormAttachment(middle, -margin);
    fdldataTypeVerified.top = new FormAttachment(0, 0);
    wlDataTypeVerified.setLayoutData(fdldataTypeVerified);
    wDataTypeVerified = new Button(wgType, SWT.CHECK);
    props.setLook(wDataTypeVerified);
    FormData fddataTypeVerified = new FormData();
    fddataTypeVerified.left = new FormAttachment(middle, margin + extra);
    fddataTypeVerified.right = new FormAttachment(100, 0);
    fddataTypeVerified.top = new FormAttachment(0, 0);
    wDataTypeVerified.setLayoutData(fddataTypeVerified);
    // Data type
    // 
    wlDataType = new Label(wgType, SWT.RIGHT);
    wlDataType.setText(BaseMessages.getString(PKG, "ValidatorDialog.DataType.Label"));
    props.setLook(wlDataType);
    FormData fdlDataType = new FormData();
    fdlDataType.left = new FormAttachment(0, 0);
    fdlDataType.right = new FormAttachment(middle, -margin);
    fdlDataType.top = new FormAttachment(wDataTypeVerified, margin);
    wlDataType.setLayoutData(fdlDataType);
    wDataType = new Combo(wgType, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wDataType.setItems(ValueMetaFactory.getValueMetaNames());
    props.setLook(wDataType);
    FormData fdDataType = new FormData();
    fdDataType.left = new FormAttachment(middle, margin + extra);
    fdDataType.right = new FormAttachment(100, 0);
    fdDataType.top = new FormAttachment(wDataTypeVerified, margin);
    wDataType.setLayoutData(fdDataType);
    // Conversion mask
    // 
    wlConversionMask = new Label(wgType, SWT.RIGHT);
    wlConversionMask.setText(BaseMessages.getString(PKG, "ValidatorDialog.ConversionMask.Label"));
    props.setLook(wlConversionMask);
    FormData fdlConversionMask = new FormData();
    fdlConversionMask.left = new FormAttachment(0, 0);
    fdlConversionMask.right = new FormAttachment(middle, -margin);
    fdlConversionMask.top = new FormAttachment(wDataType, margin);
    wlConversionMask.setLayoutData(fdlConversionMask);
    wConversionMask = new TextVarWarning(transMeta, wgType, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wConversionMask);
    FormData fdConversionMask = new FormData();
    fdConversionMask.left = new FormAttachment(middle, margin);
    fdConversionMask.right = new FormAttachment(100, 0);
    fdConversionMask.top = new FormAttachment(wDataType, margin);
    wConversionMask.setLayoutData(fdConversionMask);
    addSpacesWarning(wConversionMask);
    // Decimal Symbol
    // 
    wlDecimalSymbol = new Label(wgType, SWT.RIGHT);
    wlDecimalSymbol.setText(BaseMessages.getString(PKG, "ValidatorDialog.DecimalSymbol.Label"));
    props.setLook(wlDecimalSymbol);
    FormData fdlDecimalSymbol = new FormData();
    fdlDecimalSymbol.left = new FormAttachment(0, 0);
    fdlDecimalSymbol.right = new FormAttachment(middle, -margin);
    fdlDecimalSymbol.top = new FormAttachment(wConversionMask, margin);
    wlDecimalSymbol.setLayoutData(fdlDecimalSymbol);
    wDecimalSymbol = new TextVarWarning(transMeta, wgType, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDecimalSymbol);
    FormData fdDecimalSymbol = new FormData();
    fdDecimalSymbol.left = new FormAttachment(middle, margin);
    fdDecimalSymbol.right = new FormAttachment(100, 0);
    fdDecimalSymbol.top = new FormAttachment(wConversionMask, margin);
    wDecimalSymbol.setLayoutData(fdDecimalSymbol);
    addSpacesWarning(wDecimalSymbol);
    // Grouping Symbol
    // 
    wlGroupingSymbol = new Label(wgType, SWT.RIGHT);
    wlGroupingSymbol.setText(BaseMessages.getString(PKG, "ValidatorDialog.GroupingSymbol.Label"));
    props.setLook(wlGroupingSymbol);
    FormData fdlGroupingSymbol = new FormData();
    fdlGroupingSymbol.left = new FormAttachment(0, 0);
    fdlGroupingSymbol.right = new FormAttachment(middle, -margin);
    fdlGroupingSymbol.top = new FormAttachment(wDecimalSymbol, margin);
    wlGroupingSymbol.setLayoutData(fdlGroupingSymbol);
    wGroupingSymbol = new TextVarWarning(transMeta, wgType, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wGroupingSymbol);
    FormData fdGroupingSymbol = new FormData();
    fdGroupingSymbol.left = new FormAttachment(middle, margin);
    fdGroupingSymbol.right = new FormAttachment(100, 0);
    fdGroupingSymbol.top = new FormAttachment(wDecimalSymbol, margin);
    wGroupingSymbol.setLayoutData(fdGroupingSymbol);
    addSpacesWarning(wGroupingSymbol);
    // /////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // The data group...
    // 
    // 
    wgData = new Group(wComp, SWT.NONE);
    props.setLook(wgData);
    wgData.setText(BaseMessages.getString(PKG, "ValidatorDialog.DataGroup.Label"));
    FormLayout dataGroupLayout = new FormLayout();
    dataGroupLayout.marginHeight = Const.FORM_MARGIN;
    dataGroupLayout.marginWidth = Const.FORM_MARGIN;
    wgData.setLayout(dataGroupLayout);
    FormData fdData = new FormData();
    fdData.left = new FormAttachment(0, 0);
    fdData.right = new FormAttachment(100, 0);
    fdData.top = new FormAttachment(wgType, margin);
    wgData.setLayoutData(fdData);
    // Check for null?
    // 
    wlNullAllowed = new Label(wgData, SWT.RIGHT);
    wlNullAllowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.NullAllowed.Label"));
    props.setLook(wlNullAllowed);
    FormData fdlNullAllowed = new FormData();
    fdlNullAllowed.left = new FormAttachment(0, 0);
    fdlNullAllowed.right = new FormAttachment(middle, -margin);
    fdlNullAllowed.top = new FormAttachment(0, 0);
    wlNullAllowed.setLayoutData(fdlNullAllowed);
    wNullAllowed = new Button(wgData, SWT.CHECK);
    props.setLook(wNullAllowed);
    FormData fdNullAllowed = new FormData();
    fdNullAllowed.left = new FormAttachment(middle, margin + extra);
    fdNullAllowed.right = new FormAttachment(100, 0);
    fdNullAllowed.top = new FormAttachment(0, 0);
    wNullAllowed.setLayoutData(fdNullAllowed);
    // Only null allowed?
    // 
    wlOnlyNullAllowed = new Label(wgData, SWT.RIGHT);
    wlOnlyNullAllowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.OnlyNullAllowed.Label"));
    props.setLook(wlOnlyNullAllowed);
    FormData fdlOnlyNullAllowed = new FormData();
    fdlOnlyNullAllowed.left = new FormAttachment(0, 0);
    fdlOnlyNullAllowed.right = new FormAttachment(middle, -margin);
    fdlOnlyNullAllowed.top = new FormAttachment(wNullAllowed, margin);
    wlOnlyNullAllowed.setLayoutData(fdlOnlyNullAllowed);
    wOnlyNullAllowed = new Button(wgData, SWT.CHECK);
    props.setLook(wOnlyNullAllowed);
    FormData fdOnlyNullAllowed = new FormData();
    fdOnlyNullAllowed.left = new FormAttachment(middle, margin + extra);
    fdOnlyNullAllowed.right = new FormAttachment(100, 0);
    fdOnlyNullAllowed.top = new FormAttachment(wNullAllowed, margin);
    wOnlyNullAllowed.setLayoutData(fdOnlyNullAllowed);
    // Only numeric allowed?
    // 
    wlOnlyNumeric = new Label(wgData, SWT.RIGHT);
    wlOnlyNumeric.setText(BaseMessages.getString(PKG, "ValidatorDialog.OnlyNumeric.Label"));
    props.setLook(wlOnlyNumeric);
    FormData fdlOnlyNumeric = new FormData();
    fdlOnlyNumeric.left = new FormAttachment(0, 0);
    fdlOnlyNumeric.right = new FormAttachment(middle, -margin);
    fdlOnlyNumeric.top = new FormAttachment(wOnlyNullAllowed, margin);
    wlOnlyNumeric.setLayoutData(fdlOnlyNumeric);
    wOnlyNumeric = new Button(wgData, SWT.CHECK);
    props.setLook(wOnlyNumeric);
    FormData fdOnlyNumeric = new FormData();
    fdOnlyNumeric.left = new FormAttachment(middle, margin + extra);
    fdOnlyNumeric.right = new FormAttachment(100, 0);
    fdOnlyNumeric.top = new FormAttachment(wOnlyNullAllowed, margin);
    wOnlyNumeric.setLayoutData(fdOnlyNumeric);
    // Maximum length
    // 
    wlMaxLength = new Label(wgData, SWT.RIGHT);
    wlMaxLength.setText(BaseMessages.getString(PKG, "ValidatorDialog.MaxLength.Label"));
    props.setLook(wlMaxLength);
    FormData fdlMaxLength = new FormData();
    fdlMaxLength.left = new FormAttachment(0, 0);
    fdlMaxLength.right = new FormAttachment(middle, -margin);
    fdlMaxLength.top = new FormAttachment(wOnlyNumeric, margin);
    wlMaxLength.setLayoutData(fdlMaxLength);
    wMaxLength = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wMaxLength);
    FormData fdMaxLength = new FormData();
    fdMaxLength.left = new FormAttachment(middle, margin);
    fdMaxLength.right = new FormAttachment(100, 0);
    fdMaxLength.top = new FormAttachment(wOnlyNumeric, margin);
    wMaxLength.setLayoutData(fdMaxLength);
    addSpacesWarning(wMaxLength);
    // Minimum length
    // 
    wlMinLength = new Label(wgData, SWT.RIGHT);
    wlMinLength.setText(BaseMessages.getString(PKG, "ValidatorDialog.MinLength.Label"));
    props.setLook(wlMinLength);
    FormData fdlMinLength = new FormData();
    fdlMinLength.left = new FormAttachment(0, 0);
    fdlMinLength.right = new FormAttachment(middle, -margin);
    fdlMinLength.top = new FormAttachment(wMaxLength, margin);
    wlMinLength.setLayoutData(fdlMinLength);
    wMinLength = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wMinLength);
    FormData fdMinLength = new FormData();
    fdMinLength.left = new FormAttachment(middle, margin);
    fdMinLength.right = new FormAttachment(100, 0);
    fdMinLength.top = new FormAttachment(wMaxLength, margin);
    wMinLength.setLayoutData(fdMinLength);
    addSpacesWarning(wMinLength);
    // Maximum value
    // 
    wlMaxValue = new Label(wgData, SWT.RIGHT);
    wlMaxValue.setText(BaseMessages.getString(PKG, "ValidatorDialog.MaxValue.Label"));
    props.setLook(wlMaxValue);
    FormData fdlMaxValue = new FormData();
    fdlMaxValue.left = new FormAttachment(0, 0);
    fdlMaxValue.right = new FormAttachment(middle, -margin);
    fdlMaxValue.top = new FormAttachment(wMinLength, margin);
    wlMaxValue.setLayoutData(fdlMaxValue);
    wMaxValue = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wMaxValue);
    FormData fdMaxValue = new FormData();
    fdMaxValue.left = new FormAttachment(middle, margin);
    fdMaxValue.right = new FormAttachment(100, 0);
    fdMaxValue.top = new FormAttachment(wMinLength, margin);
    wMaxValue.setLayoutData(fdMaxValue);
    addSpacesWarning(wMaxValue);
    // Minimum value
    // 
    wlMinValue = new Label(wgData, SWT.RIGHT);
    wlMinValue.setText(BaseMessages.getString(PKG, "ValidatorDialog.MinValue.Label"));
    props.setLook(wlMinValue);
    FormData fdlMinValue = new FormData();
    fdlMinValue.left = new FormAttachment(0, 0);
    fdlMinValue.right = new FormAttachment(middle, -margin);
    fdlMinValue.top = new FormAttachment(wMaxValue, margin);
    wlMinValue.setLayoutData(fdlMinValue);
    wMinValue = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wMinValue);
    FormData fdMinValue = new FormData();
    fdMinValue.left = new FormAttachment(middle, margin);
    fdMinValue.right = new FormAttachment(100, 0);
    fdMinValue.top = new FormAttachment(wMaxValue, margin);
    wMinValue.setLayoutData(fdMinValue);
    addSpacesWarning(wMinValue);
    // Expected start string
    // 
    wlStartStringExpected = new Label(wgData, SWT.RIGHT);
    wlStartStringExpected.setText(BaseMessages.getString(PKG, "ValidatorDialog.StartStringExpected.Label"));
    props.setLook(wlStartStringExpected);
    FormData fdlStartStringExpected = new FormData();
    fdlStartStringExpected.left = new FormAttachment(0, 0);
    fdlStartStringExpected.right = new FormAttachment(middle, -margin);
    fdlStartStringExpected.top = new FormAttachment(wMinValue, margin);
    wlStartStringExpected.setLayoutData(fdlStartStringExpected);
    wStartStringExpected = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wStartStringExpected);
    FormData fdStartStringExpected = new FormData();
    fdStartStringExpected.left = new FormAttachment(middle, margin);
    fdStartStringExpected.right = new FormAttachment(100, 0);
    fdStartStringExpected.top = new FormAttachment(wMinValue, margin);
    wStartStringExpected.setLayoutData(fdStartStringExpected);
    addSpacesWarning(wStartStringExpected);
    // Expected End string
    // 
    wlEndStringExpected = new Label(wgData, SWT.RIGHT);
    wlEndStringExpected.setText(BaseMessages.getString(PKG, "ValidatorDialog.EndStringExpected.Label"));
    props.setLook(wlEndStringExpected);
    FormData fdlEndStringExpected = new FormData();
    fdlEndStringExpected.left = new FormAttachment(0, 0);
    fdlEndStringExpected.right = new FormAttachment(middle, -margin);
    fdlEndStringExpected.top = new FormAttachment(wStartStringExpected, margin);
    wlEndStringExpected.setLayoutData(fdlEndStringExpected);
    wEndStringExpected = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEndStringExpected);
    FormData fdEndStringExpected = new FormData();
    fdEndStringExpected.left = new FormAttachment(middle, margin);
    fdEndStringExpected.right = new FormAttachment(100, 0);
    fdEndStringExpected.top = new FormAttachment(wStartStringExpected, margin);
    wEndStringExpected.setLayoutData(fdEndStringExpected);
    addSpacesWarning(wEndStringExpected);
    // Disallowed start string
    // 
    wlStartStringDisallowed = new Label(wgData, SWT.RIGHT);
    wlStartStringDisallowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.StartStringDisallowed.Label"));
    props.setLook(wlStartStringDisallowed);
    FormData fdlStartStringDisallowed = new FormData();
    fdlStartStringDisallowed.left = new FormAttachment(0, 0);
    fdlStartStringDisallowed.right = new FormAttachment(middle, -margin);
    fdlStartStringDisallowed.top = new FormAttachment(wEndStringExpected, margin);
    wlStartStringDisallowed.setLayoutData(fdlStartStringDisallowed);
    wStartStringDisallowed = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wStartStringDisallowed);
    FormData fdStartStringDisallowed = new FormData();
    fdStartStringDisallowed.left = new FormAttachment(middle, margin);
    fdStartStringDisallowed.right = new FormAttachment(100, 0);
    fdStartStringDisallowed.top = new FormAttachment(wEndStringExpected, margin);
    wStartStringDisallowed.setLayoutData(fdStartStringDisallowed);
    addSpacesWarning(wStartStringDisallowed);
    // Disallowed End string
    // 
    wlEndStringDisallowed = new Label(wgData, SWT.RIGHT);
    wlEndStringDisallowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.EndStringDisallowed.Label"));
    props.setLook(wlEndStringDisallowed);
    FormData fdlEndStringDisallowed = new FormData();
    fdlEndStringDisallowed.left = new FormAttachment(0, 0);
    fdlEndStringDisallowed.right = new FormAttachment(middle, -margin);
    fdlEndStringDisallowed.top = new FormAttachment(wStartStringDisallowed, margin);
    wlEndStringDisallowed.setLayoutData(fdlEndStringDisallowed);
    wEndStringDisallowed = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wEndStringDisallowed);
    FormData fdEndStringDisallowed = new FormData();
    fdEndStringDisallowed.left = new FormAttachment(middle, margin);
    fdEndStringDisallowed.right = new FormAttachment(100, 0);
    fdEndStringDisallowed.top = new FormAttachment(wStartStringDisallowed, margin);
    wEndStringDisallowed.setLayoutData(fdEndStringDisallowed);
    addSpacesWarning(wEndStringDisallowed);
    // Expected regular expression
    // 
    wlRegExpExpected = new Label(wgData, SWT.RIGHT);
    wlRegExpExpected.setText(BaseMessages.getString(PKG, "ValidatorDialog.RegExpExpected.Label"));
    props.setLook(wlRegExpExpected);
    FormData fdlRegExpExpected = new FormData();
    fdlRegExpExpected.left = new FormAttachment(0, 0);
    fdlRegExpExpected.right = new FormAttachment(middle, -margin);
    fdlRegExpExpected.top = new FormAttachment(wEndStringDisallowed, margin);
    wlRegExpExpected.setLayoutData(fdlRegExpExpected);
    wRegExpExpected = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wRegExpExpected);
    FormData fdRegExpExpected = new FormData();
    fdRegExpExpected.left = new FormAttachment(middle, margin);
    fdRegExpExpected.right = new FormAttachment(100, 0);
    fdRegExpExpected.top = new FormAttachment(wEndStringDisallowed, margin);
    wRegExpExpected.setLayoutData(fdRegExpExpected);
    addSpacesWarning(wRegExpExpected);
    // Disallowed regular expression
    // 
    wlRegExpDisallowed = new Label(wgData, SWT.RIGHT);
    wlRegExpDisallowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.RegExpDisallowed.Label"));
    props.setLook(wlRegExpDisallowed);
    FormData fdlRegExpDisallowed = new FormData();
    fdlRegExpDisallowed.left = new FormAttachment(0, 0);
    fdlRegExpDisallowed.right = new FormAttachment(middle, -margin);
    fdlRegExpDisallowed.top = new FormAttachment(wRegExpExpected, margin);
    wlRegExpDisallowed.setLayoutData(fdlRegExpDisallowed);
    wRegExpDisallowed = new TextVarWarning(transMeta, wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wRegExpDisallowed);
    FormData fdRegExpDisallowed = new FormData();
    fdRegExpDisallowed.left = new FormAttachment(middle, margin);
    fdRegExpDisallowed.right = new FormAttachment(100, 0);
    fdRegExpDisallowed.top = new FormAttachment(wRegExpExpected, margin);
    wRegExpDisallowed.setLayoutData(fdRegExpDisallowed);
    addSpacesWarning(wRegExpDisallowed);
    // Allowed values: a list box.
    // 
    // Add an entry
    // 
    wbAddAllowed = new Button(wgData, SWT.PUSH);
    wbAddAllowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.ButtonAddAllowed.Label"));
    FormData fdbAddAllowed = new FormData();
    fdbAddAllowed.right = new FormAttachment(100, 0);
    fdbAddAllowed.top = new FormAttachment(wRegExpDisallowed, margin);
    wbAddAllowed.setLayoutData(fdbAddAllowed);
    wbAddAllowed.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addAllowedValue();
        }
    });
    // Remove an entry
    // 
    wbRemoveAllowed = new Button(wgData, SWT.PUSH);
    wbRemoveAllowed.setText(BaseMessages.getString(PKG, "ValidatorDialog.ButtonRemoveAllowed.Label"));
    FormData fdbRemoveAllowed = new FormData();
    fdbRemoveAllowed.right = new FormAttachment(100, 0);
    fdbRemoveAllowed.top = new FormAttachment(wbAddAllowed, margin);
    wbRemoveAllowed.setLayoutData(fdbRemoveAllowed);
    wbRemoveAllowed.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeAllowedValue();
        }
    });
    wlAllowedValues = new Label(wgData, SWT.RIGHT);
    wlAllowedValues.setText(BaseMessages.getString(PKG, "ValidatorDialog.AllowedValues.Label"));
    props.setLook(wlAllowedValues);
    FormData fdlAllowedValues = new FormData();
    fdlAllowedValues.left = new FormAttachment(0, 0);
    fdlAllowedValues.right = new FormAttachment(middle, -margin);
    fdlAllowedValues.top = new FormAttachment(wRegExpDisallowed, margin);
    wlAllowedValues.setLayoutData(fdlAllowedValues);
    wAllowedValues = new List(wgData, SWT.MULTI | SWT.LEFT | SWT.BORDER);
    props.setLook(wAllowedValues);
    FormData fdAllowedValues = new FormData();
    fdAllowedValues.left = new FormAttachment(middle, margin + extra);
    fdAllowedValues.right = new FormAttachment(wbRemoveAllowed, -20);
    fdAllowedValues.top = new FormAttachment(wRegExpDisallowed, margin);
    fdAllowedValues.bottom = new FormAttachment(wRegExpDisallowed, 150);
    wAllowedValues.setLayoutData(fdAllowedValues);
    // Source allowed values from another step?
    // 
    wlSourceValues = new Label(wgData, SWT.RIGHT);
    wlSourceValues.setText(BaseMessages.getString(PKG, "ValidatorDialog.SourceValues.Label"));
    props.setLook(wlSourceValues);
    FormData fdlSourceValues = new FormData();
    fdlSourceValues.left = new FormAttachment(0, 0);
    fdlSourceValues.right = new FormAttachment(middle, -margin);
    fdlSourceValues.top = new FormAttachment(wAllowedValues, margin);
    wlSourceValues.setLayoutData(fdlSourceValues);
    wSourceValues = new Button(wgData, SWT.CHECK);
    props.setLook(wSourceValues);
    FormData fdSourceValues = new FormData();
    fdSourceValues.left = new FormAttachment(middle, margin + extra);
    fdSourceValues.right = new FormAttachment(100, 0);
    fdSourceValues.top = new FormAttachment(wAllowedValues, margin);
    wSourceValues.setLayoutData(fdSourceValues);
    wSourceValues.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            enableFields();
        }
    });
    // Source allowed values : source step
    // 
    wlSourceStep = new Label(wgData, SWT.RIGHT);
    wlSourceStep.setText(BaseMessages.getString(PKG, "ValidatorDialog.SourceStep.Label"));
    props.setLook(wlSourceStep);
    FormData fdlSourceStep = new FormData();
    fdlSourceStep.left = new FormAttachment(0, margin);
    fdlSourceStep.right = new FormAttachment(middle, -margin);
    fdlSourceStep.top = new FormAttachment(wSourceValues, margin);
    wlSourceStep.setLayoutData(fdlSourceStep);
    wSourceStep = new Combo(wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSourceStep);
    FormData fdSourceStep = new FormData();
    fdSourceStep.left = new FormAttachment(middle, margin + extra);
    fdSourceStep.right = new FormAttachment(100, 0);
    fdSourceStep.top = new FormAttachment(wSourceValues, margin);
    wSourceStep.setLayoutData(fdSourceStep);
    wSourceStep.addFocusListener(new FocusAdapter() {

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            getSteps();
        }
    });
    wSourceStep.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            getSteps();
        }
    });
    // Source allowed values : source field
    // 
    wlSourceField = new Label(wgData, SWT.RIGHT);
    wlSourceField.setText(BaseMessages.getString(PKG, "ValidatorDialog.SourceField.Label"));
    props.setLook(wlSourceField);
    FormData fdlSourceField = new FormData();
    fdlSourceField.left = new FormAttachment(0, margin);
    fdlSourceField.right = new FormAttachment(middle, -margin);
    fdlSourceField.top = new FormAttachment(wSourceStep, margin);
    wlSourceField.setLayoutData(fdlSourceField);
    wSourceField = new Combo(wgData, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSourceField);
    FormData fdSourceField = new FormData();
    fdSourceField.left = new FormAttachment(middle, margin + extra);
    fdSourceField.right = new FormAttachment(100, 0);
    fdSourceField.top = new FormAttachment(wSourceStep, margin);
    wSourceField.setLayoutData(fdSourceField);
    wSourceField.addFocusListener(new FocusAdapter() {

        public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            getFields();
        }
    });
    wSourceField.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            getFields();
        }
    });
    wComp.layout();
    wComp.pack();
    Rectangle bounds = wComp.getBounds();
    wSComp.setContent(wComp);
    wSComp.setExpandHorizontal(true);
    wSComp.setExpandVertical(true);
    wSComp.setMinWidth(bounds.width);
    wSComp.setMinHeight(bounds.height);
    // 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);
    wClear.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            // Clear the validation rules for a certain field...
            // 
            int index = wValidationsList.getSelectionIndex();
            if (index >= 0) {
                selectionList.remove(index);
                selectedField = null;
                wValidationsList.remove(index);
                enableFields();
            }
        }
    });
    wNew.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            // Create a new validation rule page ...
            // 
            EnterStringDialog enterStringDialog = new EnterStringDialog(shell, "", BaseMessages.getString(PKG, "ValidatorDialog.EnterValidationRuleName.Title"), BaseMessages.getString(PKG, "ValidatorDialog.EnterValidationRuleName.Message"));
            String description = enterStringDialog.open();
            if (description != null) {
                if (Validation.findValidation(selectionList, description) != null) {
                    MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR);
                    // CHECKSTYLE:LineLength:OFF
                    messageBox.setText(BaseMessages.getString(PKG, "ValidatorDialog.ValidationRuleNameAlreadyExists.Title"));
                    messageBox.setMessage(BaseMessages.getString(PKG, "ValidatorDialog.ValidationRuleNameAlreadyExists.Message"));
                    messageBox.open();
                    return;
                }
                saveChanges();
                Validation validation = new Validation();
                validation.setName(description);
                selectionList.add(validation);
                selectedField = validation;
                refreshValidationsList();
                wValidationsList.select(selectionList.size() - 1);
                getValidatorFieldData(validation);
            }
        }
    });
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wConversionMask.addSelectionListener(lsDef);
    wGroupingSymbol.addSelectionListener(lsDef);
    wDecimalSymbol.addSelectionListener(lsDef);
    wMaxLength.addSelectionListener(lsDef);
    wMinLength.addSelectionListener(lsDef);
    wMaxValue.addSelectionListener(lsDef);
    wMinValue.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(changed);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return stepname;
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) KettleStepException(org.pentaho.di.core.exception.KettleStepException) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) CCombo(org.eclipse.swt.custom.CCombo) Combo(org.eclipse.swt.widgets.Combo) EnterStringDialog(org.pentaho.di.ui.core.dialog.EnterStringDialog) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) FormAttachment(org.eclipse.swt.layout.FormAttachment) TextVarWarning(org.pentaho.di.ui.core.widget.warning.TextVarWarning) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Validation(org.pentaho.di.trans.steps.validator.Validation) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) MessageBox(org.eclipse.swt.widgets.MessageBox) CCombo(org.eclipse.swt.custom.CCombo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

ArrayList (java.util.ArrayList)1 CCombo (org.eclipse.swt.custom.CCombo)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 FocusAdapter (org.eclipse.swt.events.FocusAdapter)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellAdapter (org.eclipse.swt.events.ShellAdapter)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1 Event (org.eclipse.swt.widgets.Event)1