Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » EditableGridExample(EditableGridExample Error Message Not Working)
EditableGridExample [message #1778401] Wed, 13 December 2017 20:43 Go to next message
Gus Mata is currently offline Gus MataFriend
Messages: 2
Registered: February 2017
Junior Member
I was trying to following the example for registering my own data validator and have a Error Decoration when the data is invalid. I ran the EditableGridExample but the ISIN validator is not showing the correct Error. It is showing "Error whilst validating cell value" instead of "Security Id must be 3 alpha characters optionally followed by numbers". Does someone have an example of working Error Decoration? The code below doesn't work properly in the example.

private static void registerISINValidator(IConfigRegistry configRegistry) {

TextCellEditor textCellEditor = new TextCellEditor();
textCellEditor.setErrorDecorationEnabled(true);
textCellEditor.setErrorDecorationText(
"Security Id must be 3 alpha characters optionally followed by numbers");
textCellEditor.setDecorationPositionOverride(SWT.LEFT | SWT.TOP);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR, textCellEditor,
DisplayMode.NORMAL, SECURITY_ID_EDITOR);

configRegistry.registerConfigAttribute(
EditConfigAttributes.DATA_VALIDATOR, getSecurtityIdValidator(),
DisplayMode.EDIT, SECURITY_ID_CONFIG_LABEL);
}


Re: EditableGridExample [message #1778419 is a reply to message #1778401] Thu, 14 December 2017 06:27 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2624
Registered: July 2012
Senior Member
The validation concept in combination with the decoration provider was overhauled some years ago. Looks like we missed to at least deprecate the method setErrorDecorationText().

In the old concept it was not possible to be more specific in the error text. It was not possible to distinguish whether it was a conversion error or a validation error, or what concrete validation failed. There was only one general error decoration for all cases.
The new concept allows you to be more specific by throwing a ValidationFailedException or a ConversionFailedException with a specific message instead of returning only false. Returning false only results in a general message, and without a decoration or an error dialog this is sufficient.

If you change the IDataValidator to something like the following snippet, it works again as expected and can be customized to become even more specific:
    private static IDataValidator getSecurtityIdValidator() {
        return new DataValidator() {

            @Override
            public boolean validate(int columnIndex, int rowIndex, Object newValue) {
                boolean valid = false;

                if (newValue != null) {
                    String value = (String) newValue;
                    if (value.length() > 3) {
                        String alphabeticPart = value.substring(0, 2);
                        String numericPart = value.substring(3, value.length());
                        valid = isAlpha(alphabeticPart)
                                && isNumeric(numericPart);
                    } else {
                        String alphabeticPart = value.substring(0, value.length());
                        valid = isAlpha(alphabeticPart);
                    }
                }

                if (!valid) {
                    throw new ValidationFailedException("Security Id must be 3 alpha characters optionally followed by numbers");
                }

                return valid;
            }

            private boolean isAlpha(String str) {
                for (int i = 0; i < str.length(); i++) {
                    if (!Character.isLetter(str.charAt(i)))
                        return false;
                }
                return true;
            }

            private boolean isNumeric(String str) {
                for (int i = 0; i < str.length(); i++) {
                    if (!Character.isDigit(str.charAt(i)))
                        return false;
                }
                return true;
            }
        };
    }
Previous Topic:Row selection with spanning
Next Topic:define the hot key for copy // select all // paste
Goto Forum:
  


Current Time: Fri Nov 16 00:50:16 GMT 2018

Powered by FUDForum. Page generated in 0.02185 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top