@Override protected ValidationResult compute() { String projectName = projectNameField.getValue(); if (projectName == null) { return error("Project name is undefined"); } else if ("".equals(projectName)) { return error("Project name is empty"); } else if (projectName.indexOf(' ') >= 0) { return error("Project name contains spaces"); } else if (existsInWorkspace(projectName)) { return error("A project with name '" + projectName + "' already exists in the workspace."); } else { for (int i = 0; i < projectName.length(); i++) { char c = projectName.charAt(i); if (!isAllowedChar(c)) { return error("Project name contains forbidden character '" + c + "'"); } } } return ValidationResult.OK; }
public ProjectNameValidator(LiveExpression<String> projectNameField) { this.projectNameField = projectNameField; projectNameField.addListener(this); }