### Eclipse Workspace Patch 1.0 #P org.jboss.tools.modeshape.jcr.test Index: src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java =================================================================== --- src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java (revision 41509) +++ src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java (working copy) @@ -205,6 +205,16 @@ } @Test + public void emptyValueConstraintShouldBeAnError() { + // setup + final ValidationStatus status = CndValidator.validateValueConstraint(Utils.EMPTY_STRING); + + // tests + assertTrue(status.isError()); + assertTrue("Code is " + status.getCode(), status.containsCode(StatusCodes.EMPTY_VALUE_CONSTRAINT)); //$NON-NLS-1$ + } + + @Test public void invalidQualifiedNameQualifierShouldBeAnError() { // setup final QualifiedName qname = new QualifiedName(Constants.QUALIFIER1 + "Changed", Constants.UNQUALIFIED_NAME1); //$NON-NLS-1$ @@ -410,6 +420,16 @@ } @Test + public void nullValueConstraintShouldBeAnError() { + // setup + final ValidationStatus status = CndValidator.validateValueConstraint(null); + + // tests + assertTrue(status.isError()); + assertTrue("Code is " + status.getCode(), status.containsCode(StatusCodes.EMPTY_VALUE_CONSTRAINT)); //$NON-NLS-1$ + } + + @Test public void primaryItemNameWithNonMatchingQualifierShouldBeAnError() { // setup nodeTypeDefinition.setName(Constants.QUALIFIED_NAME1.get()); #P org.jboss.tools.modeshape.jcr Index: src/org/jboss/tools/modeshape/jcr/messages.properties =================================================================== --- src/org/jboss/tools/modeshape/jcr/messages.properties (revision 41509) +++ src/org/jboss/tools/modeshape/jcr/messages.properties (working copy) @@ -57,6 +57,7 @@ emptyUnqualifiedName = The {0} has an empty unqualified name. # 0 = property or attribute name of a node type definition, property definition, or child node definition emptyValue = A "{0}" value cannot be empty +emptyValueConstraint = The value constraint cannot be empty. # 0 = property definition name emptyValueConstraints = The property definition "{0}" must have at least one value constraint. # 0 = property value, 1 = property type, 2 = property name Index: src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java =================================================================== --- src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java (revision 41509) +++ src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java (working copy) @@ -1629,7 +1629,11 @@ * @return the status (never null) */ public static ValidationStatus validateValueConstraint( final String constraint ) { - Utils.verifyIsNotEmpty(constraint, "constraint"); //$NON-NLS-1$ + try { + Utils.verifyIsNotEmpty(constraint, "constraint"); //$NON-NLS-1$ + } catch (IllegalArgumentException e) { + return ValidationStatus.createErrorMessage(StatusCodes.EMPTY_VALUE_CONSTRAINT, Messages.emptyValueConstraint); + } // TODO implement validateValueConstraint to make sure constraint is property syntax return ValidationStatus.OK_STATUS; @@ -1789,6 +1793,7 @@ int EMPTY_VALUE_CONSTRAINTS = 285; int DUPLICATE_VALUE_CONSTRAINT = 290; int VALUE_CONSTRAINTS_EXIST_BUT_MARKED_AS_VARIANT = 295; + int EMPTY_VALUE_CONSTRAINT = 300; } } Index: src/org/jboss/tools/modeshape/jcr/Messages.java =================================================================== --- src/org/jboss/tools/modeshape/jcr/Messages.java (revision 41509) +++ src/org/jboss/tools/modeshape/jcr/Messages.java (working copy) @@ -163,6 +163,11 @@ public static String emptyValue; /** + * A message indicating a property definition's value constraint is empty. + */ + public static String emptyValueConstraint; + + /** * A message indicating a property definition is missing value constraints. One parameter, the property definition name, is * required. */ #P org.jboss.tools.modeshape.jcr.ui Index: src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java =================================================================== --- src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java (revision 41509) +++ src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java (working copy) @@ -57,6 +57,7 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; import org.jboss.tools.modeshape.jcr.ItemOwnerProvider; import org.jboss.tools.modeshape.jcr.Messages; +import org.jboss.tools.modeshape.jcr.MultiValidationStatus; import org.jboss.tools.modeshape.jcr.PropertyDefinition; import org.jboss.tools.modeshape.jcr.PropertyDefinition.PropertyName; import org.jboss.tools.modeshape.jcr.QualifiedName; @@ -1158,7 +1159,7 @@ void handleAddValueConstraint() { final PropertyDefinition propDefn = getPropertyDefinition(); - final Collection currentConstraints = Arrays.asList(propDefn.getValueConstraints()); + final Collection currentConstraints = new ArrayList(Arrays.asList(propDefn.getValueConstraints())); final StringValueEditorDialog dialog = new StringValueEditorDialog(getShell()) { /** @@ -1191,7 +1192,9 @@ // check for duplicate currentConstraints.add(newValue); - return CndValidator.validateValueConstraints(propDefn.getName(), currentConstraints); + MultiValidationStatus validationStatus = CndValidator.validateValueConstraints(propDefn.getName(), currentConstraints); + currentConstraints.remove(newValue); + return validationStatus; } };