Author: elvisisking
Date: 2012-05-31 09:38:00 -0400 (Thu, 31 May 2012)
New Revision: 41577
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/messages.properties
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java
Log:
JBIDE-12056 Exception Adding/Editing Property Definition's Value Constraint In CND
Editor. Exception caused by trying to add an element to an unmodifiable list. Also fixed
an exception thrown by validator when removing all text.
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java 2012-05-31
13:29:00 UTC (rev 41576)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java 2012-05-31
13:38:00 UTC (rev 41577)
@@ -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.
*/
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java 2012-05-31
13:29:00 UTC (rev 41576)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java 2012-05-31
13:38:00 UTC (rev 41577)
@@ -1629,7 +1629,11 @@
* @return the status (never <code>null</code>)
*/
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;
}
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/messages.properties
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/messages.properties 2012-05-31
13:29:00 UTC (rev 41576)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/messages.properties 2012-05-31
13:38:00 UTC (rev 41577)
@@ -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
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java 2012-05-31
13:29:00 UTC (rev 41576)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java 2012-05-31
13:38:00 UTC (rev 41577)
@@ -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<String> currentConstraints =
Arrays.asList(propDefn.getValueConstraints());
+ final Collection<String> currentConstraints = new
ArrayList<String>(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;
}
};
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java 2012-05-31
13:29:00 UTC (rev 41576)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java 2012-05-31
13:38:00 UTC (rev 41577)
@@ -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());
Show replies by date