Example usage for com.jgoodies.validation.util PropertyValidationSupport getResult

List of usage examples for com.jgoodies.validation.util PropertyValidationSupport getResult

Introduction

In this page you can find the example usage for com.jgoodies.validation.util PropertyValidationSupport getResult.

Prototype

public final ValidationResult getResult() 

Source Link

Document

Returns the default ValidationResult .

Usage

From source file:org.openthinclient.console.nodes.views.DirObjectEditor.java

License:Open Source License

public ValidationResult validate() {
    model.triggerCommit();//from   w w w.j av  a2 s.  c o m

    if (oldName == null)
        oldName = dirObject.getName();

    final PropertyValidationSupport support = new PropertyValidationSupport(dirObject,
            dirObject.getClass().getSimpleName()); //$NON-NLS-1$

    final ValidateNames validate = new ValidateNames();
    final String name = dirObject.getName();
    final Class<? extends DirectoryObject> dirObjectClass = dirObject.getClass();
    final String result = validate.validate(name, dirObjectClass);

    if (result != null)
        support.addError("name", result);

    if (existingNames == null) {
        existingNames = new ArrayList<String>();

        try {
            final DirContext ctx = getContext(realm);
            try {
                final String ouName = realm.getDirectory().getMapping().getTypes().get(dirObjectClass)
                        .getBaseRDN();

                if (ouName != null) {
                    final Attributes att = new BasicAttributes(true);
                    att.put(new BasicAttribute("cn"));

                    final NamingEnumeration ne = ctx.search(ouName, att);

                    while (ne.hasMoreElements()) {
                        final SearchResult sr = (SearchResult) ne.next();
                        final Attributes srName = sr.getAttributes();
                        existingNames.add(srName.get("cn").get().toString());
                    }
                }
            } catch (final DirectoryException e) {
                e.printStackTrace();
                ErrorManager.getDefault().notify(e);
            } finally {
                ctx.close();
            }
        } catch (final NamingException e) {
            e.printStackTrace();
            ErrorManager.getDefault().notify(e);
        }
    }

    if (existingNames.contains(name) && !name.equals(oldName))
        support.addError("name", Messages.getString("DirObjectEditor.name.exists"));

    return support.getResult();
}

From source file:salomon.engine.controller.gui.domain.SolutionValidator.java

License:Open Source License

/**
 * Method is responsible for solution validation.
 * /*  w  ww  . j  ava  2 s .c o m*/
 * @see com.jgoodies.validation.Validator#validate()
 */
public ValidationResult validate() {
    LOGGER.debug("SolutionValidator.validate()");
    PropertyValidationSupport support = new PropertyValidationSupport(_solutionInfo, "Solution");

    // solution name validation !!!
    String currentSolutioName = _solutionModel.getSolutionName();
    // not validate if the name is not changed - second validation fails as the name exists in DB
    // this may happen when editing solution
    if (!_solutionInfo.getName().equals(currentSolutioName)) {
        if (ValidationUtils.isBlank(currentSolutioName)) {
            support.addError("Solution Name", "is mandatory");
        } else {
            try {
                boolean exists = _domainManager.exists(currentSolutioName);
                if (exists) {
                    support.addError("Solution Name", "already exists");
                }
            } catch (PlatformException e) {
                LOGGER.fatal("", e);
                support.addError("Solution Name", "INTERNAL ERROR");
            }
        }
    }
    return support.getResult();
}

From source file:salomon.engine.controller.gui.project.ProjectValidator.java

License:Open Source License

/**
 * Method is responsible for project validation.
 * //w  w w  . j  av  a  2s. c o m
 * @see com.jgoodies.validation.Validator#validate()
 */
public ValidationResult validate() {
    LOGGER.debug("ProjectValidator.validate()");
    PropertyValidationSupport support = new PropertyValidationSupport(_projectInfo, "Project");

    String currentProjectName = _projectModel.getProjectName();
    // name validatation if it has changed
    String projectName = _projectInfo.getName();
    if (projectName == null || !projectName.equals(currentProjectName)) {
        if (ValidationUtils.isBlank(currentProjectName)) {
            support.addError("Project Name", "is mandatory");
        } else {
            try {
                boolean exists = _projectManager.exists(currentProjectName);
                if (exists) {
                    support.addError("Project Name", "already exists");
                }
            } catch (PlatformException e) {
                LOGGER.fatal("", e);
                support.addError("Project Name", "INTERNAL ERROR");
            }
        }
    }
    return support.getResult();
}

From source file:salomon.engine.controller.gui.solution.SolutionValidator.java

License:Open Source License

/**
 * Method is responsible for solution validation.
 * /*from  w  w  w  .j a  va2 s . c  om*/
 * @see com.jgoodies.validation.Validator#validate()
 */
public ValidationResult validate() {
    LOGGER.debug("SolutionValidator.validate()");
    PropertyValidationSupport support = new PropertyValidationSupport(_solutionInfo, "Solution");

    // solution name validation !!!
    String currentSolutioName = _solutionModel.getSolutionName();
    // not validate if the name is not changed - second validation fails as the name exists in DB
    // this may happen when editing solution
    if (!_solutionInfo.getName().equals(currentSolutioName)) {
        if (ValidationUtils.isBlank(currentSolutioName)) {
            support.addError("Solution Name", "is mandatory");
        } else {
            try {
                boolean exists = _solutionManager.exists(currentSolutioName);
                if (exists) {
                    support.addError("Solution Name", "already exists");
                }
            } catch (PlatformException e) {
                LOGGER.fatal("", e);
                support.addError("Solution Name", "INTERNAL ERROR");
            }
        }
    }
    return support.getResult();
}

From source file:salomon.util.gui.validation.attributeset.AttributeSetValidator.java

License:Open Source License

/**
 * Method is responsible for dataset validation.
 * //from  w  ww.java  2 s . co  m
 * @see com.jgoodies.validation.Validator#validate()
 */
public ValidationResult validate() {
    PropertyValidationSupport support = new PropertyValidationSupport(_attributeSet, "AttributeSet");

    // here whole validation !!!
    if (ValidationUtils.isBlank(_attributeSet.getAttributeSetName())) {
        support.addError("AttributeSet Name", "is mandatory");
    } else {
        try {
            boolean exists = exists(_attributeSet);
            if (exists) {
                support.addError("AttributeSet Name", "already exists");
            }
        } catch (PlatformException e) {
            LOGGER.fatal("", e);
            support.addError("AttributeSet Name", "INTERNAL ERROR");
        }
    }
    return support.getResult();
}

From source file:salomon.util.gui.validation.dataset.DataSetValidator.java

License:Open Source License

/**
 * Method is responsible for dataset validation.
 * /*from   w ww.ja va 2s.c  o  m*/
 * @see com.jgoodies.validation.Validator#validate()
 */
public ValidationResult validate() {
    PropertyValidationSupport support = new PropertyValidationSupport(_dataSet, "DataSet");

    // here whole validation !!!
    if (ValidationUtils.isBlank(_dataSet.getDataSetName())) {
        support.addError("DataSet Name", "is mandatory");
    } else {
        try {
            boolean exists = exists(_dataSet);
            if (exists) {
                support.addError("DataSet Name", "already exists");
            }
        } catch (PlatformException e) {
            LOGGER.fatal("", e);
            support.addError("DataSet Name", "INTERNAL ERROR");
        }
    }
    return support.getResult();
}