Search in sources :

Example 1 with IValidateContentDescriptor

use of org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor in project scout.rt by eclipse.

the class TableFieldTest method testErrorColumn_Visible.

/**
 * Tests that an invisible displayable column is shown, if there is an error.
 */
@Test
public void testErrorColumn_Visible() {
    P_TableField tableField = createTableField(false);
    tableField.getTable().addRowByArray(TEST_ROW);
    Cell cell = (Cell) tableField.getTable().getCell(0, 1);
    cell.setEditable(true);
    tableField.getTable().getStringColumn().setVisible(false);
    cell.addErrorStatus("ErrorX");
    IValidateContentDescriptor desc = tableField.validateContent();
    assertTrue(tableField.getTable().getStringColumn().isVisible());
}
Also used : IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) Cell(org.eclipse.scout.rt.client.ui.basic.cell.Cell) Test(org.junit.Test)

Example 2 with IValidateContentDescriptor

use of org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor in project scout.rt by eclipse.

the class AbstractForm method validateForm.

@Override
public void validateForm() {
    if (!interceptCheckFields()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
    if (!getHandler().onCheckFields()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
    // check all fields that might be invalid
    final ArrayList<String> invalidTexts = new ArrayList<String>();
    final ArrayList<String> mandatoryTexts = new ArrayList<String>();
    P_AbstractCollectingFieldVisitor<IValidateContentDescriptor> v = new P_AbstractCollectingFieldVisitor<IValidateContentDescriptor>() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            IValidateContentDescriptor desc = f.validateContent();
            if (desc != null) {
                if (desc.getErrorStatus() != null) {
                    invalidTexts.add(desc.getDisplayText() + ": " + desc.getErrorStatus().getMessage());
                } else {
                    mandatoryTexts.add(desc.getDisplayText());
                }
                if (getCollectionCount() == 0) {
                    collect(desc);
                }
            }
            return true;
        }
    };
    visitFields(v);
    if (v.getCollectionCount() > 0) {
        IValidateContentDescriptor firstProblem = v.getCollection().get(0);
        if (LOG.isInfoEnabled()) {
            LOG.info("there are fields with errors");
        }
        if (firstProblem != null) {
            firstProblem.activateProblemLocation();
        }
        throw new VetoException().withHtmlMessage(createValidationMessageBoxHtml(invalidTexts, mandatoryTexts));
    }
    if (!interceptValidate()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
    if (!getHandler().onValidate()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) ArrayList(java.util.ArrayList)

Example 3 with IValidateContentDescriptor

use of org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor in project scout.rt by eclipse.

the class TableFieldTest method testOkErrorStatus_ErrorText.

/**
 * Tests that there is an error on the field, when a table field with errors is validated.
 */
@Test
public void testOkErrorStatus_ErrorText() {
    P_TableField tableField = createTableField(false);
    tableField.getTable().addRowByArray(TEST_ROW);
    Cell cell = (Cell) tableField.getTable().getCell(0, 1);
    cell.setEditable(true);
    cell.addErrorStatus("ErrorX");
    IValidateContentDescriptor desc = tableField.validateContent();
    assertNotNull(desc);
    assertTrue(desc.getDisplayText().contains(tableField.getTable().getStringColumn().getClass().getSimpleName()));
}
Also used : IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) Cell(org.eclipse.scout.rt.client.ui.basic.cell.Cell) Test(org.junit.Test)

Example 4 with IValidateContentDescriptor

use of org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor in project scout.rt by eclipse.

the class TableFieldTest method testMandatory_ErrorText.

/**
 * Tests that there is an error on the field, when a mandatory table is not filled.
 */
@Test
public void testMandatory_ErrorText() {
    P_TableField tableField = createTableField(false);
    tableField.getTable().addRowByArray(new Object[] { 1, null, false });
    Cell cell = (Cell) tableField.getTable().getCell(0, 1);
    cell.setEditable(true);
    cell.setMandatory(true);
    IValidateContentDescriptor desc = tableField.validateContent();
    assertNotNull(desc);
    assertNull(desc.getErrorStatus());
    assertTrue(desc.getDisplayText().contains(tableField.getTable().getStringColumn().getClass().getSimpleName()));
}
Also used : IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) Cell(org.eclipse.scout.rt.client.ui.basic.cell.Cell) Test(org.junit.Test)

Example 5 with IValidateContentDescriptor

use of org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor in project scout.rt by eclipse.

the class TableFieldTest method testOkErrorStatus_NoError.

/**
 * Tests that there is no error when adding a {@link Status#OK_STATUS} to a cell.
 */
@Test
public void testOkErrorStatus_NoError() {
    P_TableField tableField = createTableField(false);
    tableField.getTable().addRowByArray(TEST_ROW);
    Cell cell = (Cell) tableField.getTable().getCell(0, 1);
    cell.setEditable(true);
    cell.addErrorStatus(Status.OK_STATUS);
    IValidateContentDescriptor desc = tableField.validateContent();
    assertNull(desc);
}
Also used : IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) Cell(org.eclipse.scout.rt.client.ui.basic.cell.Cell) Test(org.junit.Test)

Aggregations

IValidateContentDescriptor (org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor)6 Cell (org.eclipse.scout.rt.client.ui.basic.cell.Cell)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)1 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)1