Author: elvisisking
Date: 2012-03-27 16:03:21 -0400 (Tue, 27 Mar 2012)
New Revision: 39856
Added:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ItemDefinition.java
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiUtils.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditorPage.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java
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/QualifiedNameEditor.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties
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/ValidationStatus.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.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/cnd/NamespaceMapping.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItem.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/messages.properties
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/ErrorMessage.java
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/NamespaceMappingTest.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItemTest.java
Log:
JBIDE-10702 Editor for JCR Compact Node Definition (CND) files. Work on saving and
restoring editor state, saving file and file save as, primary item, residual names, and
editor validation. Also added more tests.
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-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/Messages.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -215,7 +215,8 @@
public static String localNameEqualToSelfOrParent;
/**
- * A message indicating a with invalid characters was found. One parameter, a string
identifying the name, is required.
+ * A message indicating a with invalid characters was found. Two parameters, the name
of the owner object and a string
+ * identifying the type of name, are required.
*/
public static String localNameHasInvalidCharacters;
@@ -262,7 +263,7 @@
* A message used for the node type definition name property.
*/
public static String nodeTypeDefinitionName;
-
+
/**
* A message indicating a <code>null</code> was found. One parameter, a
string identifying the object, is required.
*/
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ValidationStatus.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ValidationStatus.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ValidationStatus.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -132,6 +132,25 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || !getClass().equals(obj.getClass())) {
+ return false;
+ }
+
+ ValidationStatus that = (ValidationStatus)obj;
+ return (this.severity.equals(that.severity) &&
this.message.equals(that.message));
+ }
+
+ /**
* @return the message pertaining to the worse validation severity (never
<code>null</code>)
*/
public String getMessage() {
@@ -141,11 +160,21 @@
/**
* @return the status severity (never <code>null</code>)
*/
- protected Severity getSeverity() {
+ public Severity getSeverity() {
return this.severity;
}
/**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return Utils.hashCode(this.severity, this.message);
+ }
+
+ /**
* @return <code>true</code> if the validation status has an error
severity
*/
public boolean isError() {
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinition.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -28,7 +28,7 @@
/**
*
*/
-public class ChildNodeDefinition implements CndElement, Comparable,
NodeDefinitionTemplate {
+public class ChildNodeDefinition implements ItemDefinition, Comparable,
NodeDefinitionTemplate {
/**
* The prefix used in CND notation before the property definition.
@@ -361,8 +361,11 @@
}
/**
- * @return the qualified name (never <code>null</code>)
+ * {@inheritDoc}
+ *
+ * @see org.jboss.tools.modeshape.jcr.cnd.ItemDefinition#getQualifiedName()
*/
+ @Override
public QualifiedName getQualifiedName() {
return this.name;
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -83,7 +83,7 @@
map.put(Preference.NAMESPACE_MAPPING_DELIMITER, "\n"); //$NON-NLS-1$
map.put(Preference.NAMESPACE_MAPPING_SECTION_END_DELIMITER, "\n");
//$NON-NLS-1$
map.put(Preference.CHILD_NODE_ATTRIBUTES_DELIMITER, Utils.SPACE_STRING);
- map.put(Preference.NODE_TYPE_DEFINITION_ATTRIBUTES_END_DELIMITER,
"\n"); //$NON-NLS-1$
+ map.put(Preference.NODE_TYPE_DEFINITION_ATTRIBUTES_END_DELIMITER,
Utils.SPACE_STRING);
map.put(Preference.NODE_TYPE_DEFINITION_DELIMITER, "\n");
//$NON-NLS-1$
map.put(Preference.NODE_TYPE_DEFINITION_NAME_END_DELIMITER, Utils.SPACE_STRING);
map.put(Preference.NODE_TYPE_DEFINITION_SECTION_END_DELIMITER, "\n");
//$NON-NLS-1$
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-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -205,10 +205,10 @@
for (final ChildNodeDefinition childNodeDefn : childNodeDefinitions) {
validateChildNodeDefinition(childNodeDefn, null, status);
- { // ERROR - Duplicate child node definition names
+ { // ERROR - Duplicate child node definition names (allow duplicate residual
names)
final String childNodeName = childNodeDefn.getName();
- if (!Utils.isEmpty(childNodeName)) {
+ if (!Utils.isEmpty(childNodeName) &&
!ItemDefinition.RESIDUAL_NAME.equals(childNodeName)) {
if (childNodeNames.contains(childNodeName)) {
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateChildNodeDefinitionName,
nodeTypeName, childNodeName)));
@@ -271,7 +271,7 @@
if (Utils.isEmpty(nodeTypeDefinitions)) {
noNodeTypeDefinitions = true;
} else {
- validateNodeTypeDefinitions(nodeTypeDefinitions, status);
+ validateNodeTypeDefinitions(nodeTypeDefinitions, true, status);
}
}
@@ -398,20 +398,21 @@
/**
* @param localName the local name being validated (cannot be
<code>null</code>)
- * @param propertyName the name to use in the validation message (cannot be
<code>null</code>)
+ * @param messagePrefix the text that will print before the message indicating the
local name is invalid (cannot be
+ * <code>null</code>)
* @return the status (never <code>null</code>)
*/
public static ValidationStatus validateLocalName( final String localName,
- final String propertyName ) {
- Utils.verifyIsNotEmpty(propertyName, propertyName);
+ final String messagePrefix ) {
+ Utils.verifyIsNotEmpty(messagePrefix, messagePrefix);
if (Utils.isEmpty(localName)) {
- return ValidationStatus.createErrorMessage(NLS.bind(Messages.emptyLocalName,
propertyName));
+ return ValidationStatus.createErrorMessage(NLS.bind(Messages.emptyLocalName,
messagePrefix));
}
// ERROR Local name cannot be self or parent
if (localName.equals(".") || localName.equals("..")) {
//$NON-NLS-1$ //$NON-NLS-2$
- return
ValidationStatus.createErrorMessage(NLS.bind(Messages.localNameEqualToSelfOrParent,
propertyName));
+ return
ValidationStatus.createErrorMessage(NLS.bind(Messages.localNameEqualToSelfOrParent,
messagePrefix));
}
for (final char c : localName.toCharArray()) {
@@ -423,7 +424,8 @@
case '|':
case '*':
// ERROR invalid character
- return
ValidationStatus.createErrorMessage(NLS.bind(Messages.localNameHasInvalidCharacters,
propertyName));
+ return
ValidationStatus.createErrorMessage(NLS.bind(Messages.localNameHasInvalidCharacters,
messagePrefix,
+ localName));
default:
continue;
}
@@ -467,12 +469,17 @@
public static void validateName( final ChildNodeDefinition childNodeDefinition,
final Collection<QualifiedName>
existingChildNodeNames,
final MultiValidationStatus status ) {
- // ERROR - Empty or invalid child node definition name
- validateQualifiedName(childNodeDefinition.getQualifiedName(),
Messages.childDefinitionName, status);
+ Utils.verifyIsNotNull(childNodeDefinition, "childNodeDefinition");
//$NON-NLS-1$
- if (!Utils.isEmpty(existingChildNodeNames) &&
existingChildNodeNames.contains(childNodeDefinition.getQualifiedName())) {
-
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateChildNodeDefinitionName,
-
childNodeDefinition.getName())));
+ // allow residual name
+ if (!ItemDefinition.RESIDUAL_NAME.equals(childNodeDefinition.getName())) {
+ // ERROR - Empty or invalid child node definition name
+ validateQualifiedName(childNodeDefinition.getQualifiedName(),
Messages.childDefinitionName, status);
+
+ if (!Utils.isEmpty(existingChildNodeNames) &&
existingChildNodeNames.contains(childNodeDefinition.getQualifiedName())) {
+
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateChildNodeDefinitionName,
+
childNodeDefinition.getName())));
+ }
}
}
@@ -525,12 +532,17 @@
public static void validateName( final PropertyDefinition propertyDefinition,
final Collection<QualifiedName>
existingPropertyNames,
final MultiValidationStatus status ) {
- // ERROR - Empty or invalid child node definition name
- validateQualifiedName(propertyDefinition.getQualifiedName(),
Messages.propertyDefinitionName, status);
+ Utils.verifyIsNotNull(propertyDefinition, "propertyDefinition");
//$NON-NLS-1$
- if (!Utils.isEmpty(existingPropertyNames) &&
existingPropertyNames.contains(propertyDefinition.getQualifiedName())) {
-
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicatePropertyDefinitionName,
-
propertyDefinition.getName())));
+ // allow residual name
+ if (!ItemDefinition.RESIDUAL_NAME.equals(propertyDefinition.getName())) {
+ // ERROR - Empty or invalid child node definition name
+ validateQualifiedName(propertyDefinition.getQualifiedName(),
Messages.propertyDefinitionName, status);
+
+ if (!Utils.isEmpty(existingPropertyNames) &&
existingPropertyNames.contains(propertyDefinition.getQualifiedName())) {
+
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicatePropertyDefinitionName,
+
propertyDefinition.getName())));
+ }
}
}
@@ -703,10 +715,12 @@
/**
* @param nodeTypeDefinition the node type definition being validated (cannot be
<code>null</code>)
* @param existingNodeTypeNames the existing node type names used to check for a
duplicate (can be <code>null</code> or empty)
+ * @param validateEachPropertyAndChildNode indicates if property definition and child
node definition validation should be done
* @return the status (never <code>null</code>)
*/
public static MultiValidationStatus validateNodeTypeDefinition( final
NodeTypeDefinition nodeTypeDefinition,
- final
Collection<QualifiedName> existingNodeTypeNames ) {
+ final
Collection<QualifiedName> existingNodeTypeNames,
+ final boolean
validateEachPropertyAndChildNode ) {
Utils.verifyIsNotNull(nodeTypeDefinition, "nodeTypeDefinition");
//$NON-NLS-1$
/**
@@ -736,7 +750,7 @@
}
{ // super types
- final String[] superTypeNames =
nodeTypeDefinition.getDeclaredSupertypeNames();
+ final Collection<QualifiedName> superTypeNames =
nodeTypeDefinition.getSupertypes();
if (Utils.isEmpty(superTypeNames)) {
if
(nodeTypeDefinition.getState(NodeTypeDefinition.PropertyName.SUPERTYPES) == Value.IS) {
@@ -749,12 +763,12 @@
}
{ // primary item
- final String primaryItemName = nodeTypeDefinition.getPrimaryItemName();
+ final QualifiedName primaryItemName = nodeTypeDefinition.getPrimaryItem();
if (nodeTypeDefinition.getState(NodeTypeDefinition.PropertyName.PRIMARY_ITEM)
== Value.IS) {
// ERROR - Empty or invalid primary item name
- validateLocalName(primaryItemName, Messages.primaryItemName, status);
- } else if (!Utils.isEmpty(primaryItemName)) {
+ validateQualifiedName(primaryItemName, Messages.primaryItemName,
status);
+ } else if (!Utils.isEmpty(primaryItemName.get())) {
// ERROR Cannot have a primary item name when the primary item node type
attribute is marked as a variant
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.primaryItemExistsButMarkedAsVariant,
nodeTypeDefinitionName)));
@@ -764,29 +778,35 @@
boolean noPropertyDefinitions = false;
boolean noChildNodeDefinitions = false;
- { // property definitions
- final Collection<PropertyDefinition> propertyDefinitions =
nodeTypeDefinition.getPropertyDefinitions();
+ if (validateEachPropertyAndChildNode) {
+ { // property definitions
+ final Collection<PropertyDefinition> propertyDefinitions =
nodeTypeDefinition.getPropertyDefinitions();
- if (Utils.isEmpty(propertyDefinitions)) {
- noPropertyDefinitions = true;
- } else {
- validatePropertyDefinitions(nodeTypeDefinitionName, propertyDefinitions,
status);
+ if (Utils.isEmpty(propertyDefinitions)) {
+ noPropertyDefinitions = true;
+ } else {
+ validatePropertyDefinitions(nodeTypeDefinitionName,
propertyDefinitions, status);
+ }
}
- }
- { // child node definitions
- final Collection<ChildNodeDefinition> childNodeDefinitions =
nodeTypeDefinition.getChildNodeDefinitions();
+ { // child node definitions
+ final Collection<ChildNodeDefinition> childNodeDefinitions =
nodeTypeDefinition.getChildNodeDefinitions();
- if (Utils.isEmpty(childNodeDefinitions)) {
- noChildNodeDefinitions = true;
- } else {
- validateChildNodeDefinitions(nodeTypeDefinitionName,
childNodeDefinitions, status);
+ if (Utils.isEmpty(childNodeDefinitions)) {
+ noChildNodeDefinitions = true;
+ } else {
+ validateChildNodeDefinitions(nodeTypeDefinitionName,
childNodeDefinitions, status);
+ }
}
+ } else {
+ noPropertyDefinitions =
nodeTypeDefinition.getPropertyDefinitions().isEmpty();
+ noChildNodeDefinitions =
nodeTypeDefinition.getChildNodeDefinitions().isEmpty();
}
// WARNING - No property definitions or child node definitions exist
if (noPropertyDefinitions && noChildNodeDefinitions) {
-
status.add(ValidationStatus.createWarningMessage(Messages.nodeTypeDefinitionHasNoPropertyDefinitionsOrChildNodeDefinitions));
+
status.add(ValidationStatus.createWarningMessage(NLS.bind(Messages.nodeTypeDefinitionHasNoPropertyDefinitionsOrChildNodeDefinitions,
+
nodeTypeDefinitionName)));
}
return status;
@@ -795,12 +815,15 @@
/**
* @param nodeTypeDefinition the node type definition being validated (cannot be
<code>null</code>)
* @param existingNodeTypeNames the existing node type names used to check for a
duplicate (can be <code>null</code> or empty)
+ * @param validateEachPropertyAndChildNode indicates if property definition and child
node definition validation should be done
* @param status the status to add the new status to (never
<code>null</code>)
*/
public static void validateNodeTypeDefinition( final NodeTypeDefinition
nodeTypeDefinition,
final Collection<QualifiedName>
existingNodeTypeNames,
+ final boolean
validateEachPropertyAndChildNode,
final MultiValidationStatus status )
{
- final ValidationStatus newStatus = validateNodeTypeDefinition(nodeTypeDefinition,
existingNodeTypeNames);
+ final ValidationStatus newStatus = validateNodeTypeDefinition(nodeTypeDefinition,
existingNodeTypeNames,
+
validateEachPropertyAndChildNode);
if (!newStatus.isOk()) {
status.add(newStatus);
@@ -809,9 +832,11 @@
/**
* @param nodeTypeDefinitions the collection of namespace mappings to validate (can
be <code>null</code> or empty)
+ * @param validateEachPropertyAndChildNode indicates if property definition and child
node definition validation should be done
* @return the status (never <code>null</code>)
*/
- public static MultiValidationStatus validateNodeTypeDefinitions( final
Collection<NodeTypeDefinition> nodeTypeDefinitions ) {
+ public static MultiValidationStatus validateNodeTypeDefinitions( final
Collection<NodeTypeDefinition> nodeTypeDefinitions,
+ final boolean
validateEachPropertyAndChildNode ) {
/**
* <pre>
* ERROR - Duplicate node type definition names
@@ -827,7 +852,7 @@
final Collection<String> names = new
ArrayList<String>(nodeTypeDefinitions.size());
for (final NodeTypeDefinition nodeTypeDefinition : nodeTypeDefinitions) {
- validateNodeTypeDefinition(nodeTypeDefinition, null, status);
+ validateNodeTypeDefinition(nodeTypeDefinition, null,
validateEachPropertyAndChildNode, status);
{ // ERROR - Duplicate node type definition names
final String name = nodeTypeDefinition.getName();
@@ -847,11 +872,13 @@
/**
* @param nodeTypeDefinitions the collection of namespace mappings to validate (can
be <code>null</code> or empty)
+ * @param validateEachPropertyAndChildNode indicates if property definition and child
node definition validation should be done
* @param status the status to add the new status to (never
<code>null</code>)
*/
public static void validateNodeTypeDefinitions( final
Collection<NodeTypeDefinition> nodeTypeDefinitions,
+ final boolean
validateEachPropertyAndChildNode,
final MultiValidationStatus status )
{
- final ValidationStatus newStatus =
validateNodeTypeDefinitions(nodeTypeDefinitions);
+ final ValidationStatus newStatus =
validateNodeTypeDefinitions(nodeTypeDefinitions, validateEachPropertyAndChildNode);
if (!newStatus.isOk()) {
status.add(newStatus);
@@ -987,10 +1014,10 @@
for (final PropertyDefinition propertyDefn : propertyDefinitions) {
validatePropertyDefinition(propertyDefn, null, status);
- { // ERROR - Duplicate property definition names
+ { // ERROR - Duplicate property definition names (allow duplicate residual
names)
final String propName = propertyDefn.getName();
- if (!Utils.isEmpty(propName)) {
+ if (!Utils.isEmpty(propName) &&
!ItemDefinition.RESIDUAL_NAME.equals(propName)) {
if (propNames.contains(propName)) {
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicatePropertyDefinitionName,
nodeTypeName, propName)));
@@ -1222,12 +1249,13 @@
/**
* @param nodeTypeDefinitionName the node type name whose supertypes are being
checked (cannot be <code>null</code> or empty)
* @param superTypesState the supertypes property state (cannot be
<code>null</code>)
- * @param superTypeNames the collection of a node type definition's supertypes to
validate (can be <code>null</code> or empty)
+ * @param superTypeNames the collection of a node type definition's supertype
names to validate (can be <code>null</code> or
+ * empty)
* @return the status (never <code>null</code>)
*/
public static MultiValidationStatus validateSuperTypes( final String
nodeTypeDefinitionName,
final Value superTypesState,
- final String[] superTypeNames
) {
+ final
Collection<QualifiedName> superTypeNames ) {
Utils.verifyIsNotEmpty(nodeTypeDefinitionName,
"nodeTypeDefinitionName"); //$NON-NLS-1$
Utils.verifyIsNotNull(superTypesState, "superTypesState");
//$NON-NLS-1$
@@ -1245,13 +1273,13 @@
}
final MultiValidationStatus status = new MultiValidationStatus();
- final Collection<String> names = new
ArrayList<String>(superTypeNames.length);
+ final Collection<QualifiedName> names = new
ArrayList<QualifiedName>(superTypeNames.size());
- for (final String superTypeName : superTypeNames) {
+ for (final QualifiedName superTypeName : superTypeNames) {
// ERROR - Invalid super type name
- validateLocalName(superTypeName, Messages.superTypeName, status);
+ validateQualifiedName(superTypeName, Messages.superTypeName, status);
- if (!Utils.isEmpty(superTypeName)) {
+ if (!Utils.isEmpty(superTypeName.get())) {
// ERROR - Duplicate super type name
if (names.contains(superTypeName)) {
status.add(ValidationStatus.createErrorMessage(NLS.bind(Messages.duplicateSuperType,
nodeTypeDefinitionName,
@@ -1274,12 +1302,13 @@
/**
* @param nodeTypeDefinitionName the node type name whose supertypes are being
checked (cannot be <code>null</code> or empty)
* @param superTypesState the supertypes property state (cannot be
<code>null</code>)
- * @param superTypeNames the collection of a node type definition's supertypes to
validate (can be <code>null</code> or empty)
+ * @param superTypeNames the collection of a node type definition's supertype
names to validate (can be <code>null</code> or
+ * empty)
* @param status the status to add the new status to (never
<code>null</code>)
*/
public static void validateSuperTypes( final String nodeTypeDefinitionName,
final Value superTypesState,
- final String[] superTypeNames,
+ final Collection<QualifiedName>
superTypeNames,
final MultiValidationStatus status ) {
final MultiValidationStatus newStatus =
validateSuperTypes(nodeTypeDefinitionName, superTypesState, superTypeNames);
Added:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ItemDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ItemDefinition.java
(rev 0)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ItemDefinition.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -0,0 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * See the LEGAL.txt file distributed with this work for information regarding copyright
ownership and licensing.
+ *
+ * See the AUTHORS.txt file distributed with this work for a full listing of individual
contributors.
+ */
+package org.jboss.tools.modeshape.jcr.cnd;
+
+/**
+ * An interface for property definitions and child node definitions.
+ */
+public interface ItemDefinition extends CndElement {
+
+ /**
+ * Defines a residual set of child items.
+ */
+ String RESIDUAL_NAME = "*"; //$NON-NLS-1$
+
+ /**
+ * @return the qualified name (never <code>null</code>)
+ */
+ QualifiedName getQualifiedName();
+}
Property changes on:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/ItemDefinition.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMapping.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -225,9 +225,11 @@
public String toCndNotation( final NotationType notationType ) {
final StringBuilder builder = new StringBuilder();
builder.append(NOTATION_PREFIX);
- builder.append(this.prefix.toCndNotation(notationType));
+ builder.append(this.prefix.get());
builder.append(NOTATION_DELIMITER);
- builder.append(this.uri.toCndNotation(notationType));
+ builder.append(LocalName.Mode.SINGLE_QUOTED); // the CND parser seems to require
URI surrounded by quotes
+ builder.append(this.uri.get());
+ builder.append(LocalName.Mode.SINGLE_QUOTED);
builder.append(NOTATION_SUFFIX);
return builder.toString();
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinition.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -467,13 +467,20 @@
}
/**
+ * @return the qualified primary item name (never <code>null</code>)
+ */
+ public QualifiedName getPrimaryItem() {
+ return this.attributes.getPrimaryItem().getPrimaryItem();
+ }
+
+ /**
* {@inheritDoc}
*
* @see javax.jcr.nodetype.NodeTypeDefinition#getPrimaryItemName()
*/
@Override
public String getPrimaryItemName() {
- final String primaryItem = this.attributes.getPrimaryItem().getPrimaryItem();
+ final String primaryItem =
this.attributes.getPrimaryItem().getPrimaryItem().get();
// API states to return null
if (Utils.isEmpty(primaryItem)) {
@@ -804,7 +811,7 @@
*/
@Override
public void setPrimaryItemName( final String newPrimaryItem ) {
- final String oldName = this.attributes.getPrimaryItem().getPrimaryItem();
+ final String oldName = this.attributes.getPrimaryItem().getPrimaryItem().get();
if (this.attributes.getPrimaryItem().setPrimaryItem(newPrimaryItem)) {
notifyChangeListeners(PropertyName.PRIMARY_ITEM, oldName, newPrimaryItem);
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinition.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -33,7 +33,7 @@
/**
* The <code>PropertyDefinition</code> class represents node type property
definition.
*/
-public class PropertyDefinition implements CndElement, Comparable,
PropertyDefinitionTemplate {
+public class PropertyDefinition implements ItemDefinition, Comparable,
PropertyDefinitionTemplate {
/**
* The prefix used in CND notation before the property definition.
@@ -409,7 +409,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see javax.jcr.nodetype.ItemDefinition#getName()
*/
@Override
@@ -437,8 +437,11 @@
}
/**
- * @return the qualified name (never <code>null</code>)
+ * {@inheritDoc}
+ *
+ * @see org.jboss.tools.modeshape.jcr.cnd.ItemDefinition#getQualifiedName()
*/
+ @Override
public QualifiedName getQualifiedName() {
return this.name;
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItem.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItem.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItem.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -9,7 +9,7 @@
import org.jboss.tools.modeshape.jcr.Utils;
import org.jboss.tools.modeshape.jcr.cnd.CndElement;
-import org.jboss.tools.modeshape.jcr.cnd.LocalName;
+import org.jboss.tools.modeshape.jcr.cnd.QualifiedName;
/**
* The primary item attribute used by node type definitions. This primary item may be a
child node or a property.
@@ -21,7 +21,7 @@
*/
public static final String[] NOTATION = new String[] { "primaryitem",
"!", "!" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- private final LocalName primaryItem = new LocalName();
+ private final QualifiedName primaryItem = new QualifiedName();
/**
* {@inheritDoc}
@@ -74,10 +74,10 @@
}
/**
- * @return the primary item (can be <code>null</code> or empty)
+ * @return the primary item (never <code>null</code>)
*/
- public String getPrimaryItem() {
- return this.primaryItem.get();
+ public QualifiedName getPrimaryItem() {
+ return this.primaryItem;
}
/**
@@ -102,7 +102,7 @@
*/
public boolean setPrimaryItem( final String newPrimaryItem ) {
if (this.primaryItem.set(newPrimaryItem)) {
- if (Utils.isEmpty(newPrimaryItem) && !isVariant()) {
+ if (Utils.isEmpty(this.primaryItem.get()) && !isVariant()) {
super.set(Value.IS_NOT);
} else {
super.set(Value.IS);
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-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/messages.properties 2012-03-27
20:03:21 UTC (rev 39856)
@@ -76,8 +76,8 @@
# 0 = a name
localNameEqualToSelfOrParent = The "{0}" cannot be equal to self (dot) or
parent (dot dot).
# 0 = property or attribute name
-localNameHasInvalidCharacters = The "{0}" contains invalid characters.
-missingName = <missing name>
+localNameHasInvalidCharacters = The {0} of "{1}" contains invalid characters.
+missingName = <empty name>
# 0 = property definition name
multipleDefaultValuesForSingleValuedProperty = The single-valued property definition
"{0}" cannot have multiple default values.
# 0 = CND line number, 1 = CND column number
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiConstants.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -40,6 +40,22 @@
}
/**
+ * The file extensions for JCR-related files.
+ */
+ interface FileExtensions {
+
+ /**
+ * File extension for Compact Node Definition (CND) files.
+ */
+ String CND = "cnd"; //$NON-NLS-1$
+
+ /**
+ * File extension for Compact Node Definition (CND) files prefixed with a dot.
+ */
+ String DOT_CND = '.' + CND;
+ }
+
+ /**
* The image paths.
*/
interface Images {
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiUtils.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiUtils.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/JcrUiUtils.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -7,8 +7,10 @@
*/
package org.jboss.tools.modeshape.jcr.ui;
+import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.modeshape.jcr.Utils;
import org.jboss.tools.modeshape.jcr.ValidationStatus;
import org.jboss.tools.modeshape.ui.forms.ErrorMessage;
@@ -41,6 +43,33 @@
}
/**
+ * @param status the validation status whose severity is being converted to a form
message area message type
+ * @return the message type
+ */
+ public static int getMessageType( final ValidationStatus status ) {
+ Utils.verifyIsNotNull(status, "status"); //$NON-NLS-1$
+
+ if (status.isOk()) {
+ return IMessageProvider.NONE;
+ }
+
+ if (status.isError()) {
+ return IMessageProvider.ERROR;
+ }
+
+ if (status.isWarning()) {
+ return IMessageProvider.WARNING;
+ }
+
+ if (status.isInfo()) {
+ return IMessageProvider.INFORMATION;
+ }
+
+ assert false : "Unexpected severity type"; //$NON-NLS-1$
+ return IMessageProvider.ERROR;
+ }
+
+ /**
* @return the generic new toolbar/menu icon (never <code>null</code>)
*/
public static ImageDescriptor getNewImageDescriptor() {
@@ -52,9 +81,8 @@
* @param status the status being used to set the message (cannot be
<code>null</code>)
* @param message the message being set (cannot be <code>null</code>)
*/
- public static void setMessage( ValidationStatus status,
- ErrorMessage message ) {
- // TODO need to figure out how to get all the MultiValidationStatus errors to
display
+ public static void setMessage( final ValidationStatus status,
+ final ErrorMessage message ) {
if (status.isError()) {
message.setErrorMessage(status.getMessage());
} else if (status.isWarning()) {
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditor.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -9,6 +9,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -18,14 +20,19 @@
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
@@ -37,6 +44,7 @@
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableEditor;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.dialogs.SaveAsDialog;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.forms.IManagedForm;
@@ -44,6 +52,8 @@
import org.eclipse.ui.forms.editor.SharedHeaderFormEditor;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.modeshape.jcr.cnd.CndElement.NotationType;
import org.jboss.tools.modeshape.jcr.cnd.CndImporter;
import org.jboss.tools.modeshape.jcr.cnd.CompactNodeTypeDefinition;
import org.jboss.tools.modeshape.jcr.ui.Activator;
@@ -58,27 +68,22 @@
public final class CndEditor extends SharedHeaderFormEditor implements
IPersistableEditor, IResourceChangeListener,
PropertyChangeListener {
- /**
- * The memento key for the index of the selected editor.
- */
- private static final String SELECTED_PAGE = "SELECTED_PAGE"; //$NON-NLS-1$
+ private CompactNodeTypeDefinition cndBeingEdited;
private boolean dirty = false;
- private boolean readOnly = false;
+ private final FileDocumentProvider documentProvider = new FileDocumentProvider();
+ private final CndEditorPage formsPage;
+
private IMemento memento;
+ private long modificationStamp = 0;
+ private CompactNodeTypeDefinition originalCnd;
- private final FileDocumentProvider documentProvider = new FileDocumentProvider();
- private long modificationStamp = 0;
+ private boolean readOnly = false;
private Listener refreshListener;
- private CompactNodeTypeDefinition originalCnd;
- private CompactNodeTypeDefinition cndBeingEdited;
-
private ScrolledForm scrolledForm;
- private final CndEditorPage formsPage;
-
/**
* Constructs a CND editor.
*/
@@ -105,7 +110,8 @@
try {
addPage(0, this.formsPage); // Page 0: Forms Editor Page
- TextEditor sourceEditor = new TextEditor() {
+ final TextEditor sourceEditor = new TextEditor() {
+
/**
* {@inheritDoc}
*
@@ -142,7 +148,7 @@
int selectedPageNum = 0;
if (this.memento != null) {
- final int value = this.memento.getInteger(SELECTED_PAGE);
+ final int value = this.memento.getInteger(MementoKeys.SELECTED_PAGE);
if (value != -1) {
selectedPageNum = value;
@@ -156,6 +162,33 @@
}
}
+ private void createCnd() throws Exception {
+ final CndImporter importer = new CndImporter();
+ final List<Throwable> errors = new ArrayList<Throwable>();
+ this.originalCnd = importer.importFrom(getFile().getContents(), errors,
getFile().getName());
+
+ // check for parse errors
+ if (!errors.isEmpty()) {
+ final Throwable t = errors.iterator().next();
+
+ if (t.getCause() == null) {
+ throw new RuntimeException(t);
+ }
+
+ throw new RuntimeException(t.getCause());
+ }
+
+ // unhook lstening to current CND being edited
+ if (this.cndBeingEdited != null) {
+ this.cndBeingEdited.removeListener(this);
+ }
+
+ // copy over CND
+ this.cndBeingEdited = CompactNodeTypeDefinition.copy(this.originalCnd);
+ this.cndBeingEdited.addListener(this);
+ this.formsPage.handleCndReloaded();
+ }
+
//
// private void contributeToMenu( IMenuManager menuMgr ) {
// menuMgr.add(this.updateRegisteryAction);
@@ -187,24 +220,6 @@
// this.showRegistryViewAction = new ShowModelExtensionRegistryViewAction();
// }
- private void createCnd() throws Exception {
- // TODO implement createCnd
- CndImporter importer = new CndImporter();
- List<Throwable> errors = new ArrayList<Throwable>();
- this.originalCnd = importer.importFrom(getFile().getContents(), errors,
getFile().getName());
-
- // TODO process parse errors here
-
- // unhook lstening to current CND being edited
- if (this.cndBeingEdited != null) {
- this.cndBeingEdited.removeListener(this);
- }
-
- // copy over CND
- this.cndBeingEdited = CompactNodeTypeDefinition.copy(this.originalCnd);
- this.cndBeingEdited.addListener(this);
- }
-
/**
* {@inheritDoc}
*
@@ -227,6 +242,17 @@
/**
* {@inheritDoc}
*
+ * @see org.eclipse.ui.forms.editor.SharedHeaderFormEditor#dispose()
+ */
+ @Override
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ super.dispose();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
@@ -241,51 +267,50 @@
*/
@Override
public void doSaveAs() {
- // TODO implement doSaveAs
-// final IProgressMonitor progressMonitor = getProgressMonitor();
- // SaveAsDialog dialog = new SaveAsDialog(getShell());
- // dialog.setOriginalFile(getFile());
- // dialog.create();
- //
- // // dialog was canceled
- // if (dialog.open() == Window.CANCEL) {
- // if (progressMonitor != null) {
- // progressMonitor.setCanceled(true);
- // }
- //
- // return;
- // }
- //
- // // dialog OK'd
- // IPath filePath = dialog.getResult();
- //
- // // make sure that file has the right extension
- // if (!ExtensionConstants.MED_EXTENSION.equals(filePath.getFileExtension())) {
- // filePath = filePath.addFileExtension(ExtensionConstants.MED_EXTENSION);
- // }
- //
- // IWorkspace workspace = ResourcesPlugin.getWorkspace();
- // IFile file = workspace.getRoot().getFile(filePath);
- //
- // try {
- // // create set new editor input file
- // InputStream emptyStream = new ByteArrayInputStream(new byte[0]);
- // file.create(emptyStream, true, progressMonitor);
- // setInput(new FileEditorInput(file));
- //
- // // save MED in new file
- // internalSave(progressMonitor);
- // } catch (Exception e) {
- // IStatus status = null;
- //
- // if (!(e instanceof CoreException)) {
- // status = new Status(IStatus.ERROR, JcrUiConstants.PLUGIN_ID,
e.getLocalizedMessage());
- // } else {
- // status = ((CoreException)e).getStatus();
- // }
- //
- // ErrorDialog.openError(getShell(), UiMessages.errorDialogTitle,
CndMessages.cndEditorSaveError, status);
- // }
+ final IProgressMonitor progressMonitor = getProgressMonitor();
+ final SaveAsDialog dialog = new SaveAsDialog(getShell());
+ dialog.setOriginalFile(getFile());
+ dialog.create();
+
+ // dialog was canceled
+ if (dialog.open() == Window.CANCEL) {
+ if (progressMonitor != null) {
+ progressMonitor.setCanceled(true);
+ }
+
+ return;
+ }
+
+ // dialog OK'd
+ IPath filePath = dialog.getResult();
+
+ // make sure that file has the right extension
+ if (!JcrUiConstants.FileExtensions.CND.equals(filePath.getFileExtension())) {
+ filePath = filePath.addFileExtension(JcrUiConstants.FileExtensions.CND);
+ }
+
+ final IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IFile file = workspace.getRoot().getFile(filePath);
+
+ try {
+ // create set new editor input file
+ final InputStream emptyStream = new ByteArrayInputStream(new byte[0]);
+ file.create(emptyStream, true, progressMonitor);
+ setInput(new FileEditorInput(file));
+
+ // save CND in new file
+ internalSave(progressMonitor);
+ } catch (final Exception e) {
+ IStatus status = null;
+
+ if (!(e instanceof CoreException)) {
+ status = new Status(IStatus.ERROR, JcrUiConstants.PLUGIN_ID,
e.getLocalizedMessage());
+ } else {
+ status = ((CoreException)e).getStatus();
+ }
+
+ ErrorDialog.openError(getShell(), UiMessages.errorDialogTitle,
CndMessages.cndEditorSaveError, status);
+ }
}
/**
@@ -308,27 +333,18 @@
IMessageManager getMessageManager() {
return this.scrolledForm.getMessageManager();
}
-//
-// private IProgressMonitor getProgressMonitor() {
-// final IStatusLineManager statusLineMgr =
getEditorSite().getActionBars().getStatusLineManager();
-// return ((statusLineMgr == null) ? null : statusLineMgr.getProgressMonitor());
-// }
+ private IProgressMonitor getProgressMonitor() {
+ final IStatusLineManager statusLineMgr =
getEditorSite().getActionBars().getStatusLineManager();
+ return ((statusLineMgr == null) ? null : statusLineMgr.getProgressMonitor());
+ }
+
/**
* @return the editor's shell (never <code>null</code>)
*/
Shell getShell() {
return getEditorSite().getShell();
}
-//
-// /**
-// * Handler for page change listener.
-// */
-// void handlePageChanged() {
-// final FormPage page = (FormPage)getSelectedPage();
-// this.scrolledForm.setText(page.getTitle());
-// page.setFocus();
-// }
/**
* Registers an editor activation listener.
@@ -337,6 +353,16 @@
getContainer().addListener(SWT.Activate, this.refreshListener);
}
+ //
+ // /**
+ // * Handler for page change listener.
+ // */
+ // void handlePageChanged() {
+ // final FormPage page = (FormPage)getSelectedPage();
+ // this.scrolledForm.setText(page.getTitle());
+ // page.setFocus();
+ // }
+
/**
* {@inheritDoc}
*
@@ -360,16 +386,13 @@
final IEditorInput input = getEditorInput();
try {
- // TODO need a CND writer
- // ModelExtensionDefinitionWriter writer = new
ModelExtensionDefinitionWriter();
- // String medAsString = writer.writeAsText(this.cndBeingEdited);
- // IDocument document = this.documentProvider.getDocument(input);
- // document.set(medAsString);
- //
- // this.documentProvider.aboutToChange(input);
- // this.documentProvider.saveDocument(progressMonitor, input, document,
true);
- // this.modificationStamp =
this.documentProvider.getModificationStamp(input);
+ final IDocument document = this.documentProvider.getDocument(input);
+ document.set(getCnd().toCndNotation(NotationType.LONG)); // TODO hook this to
notation type preference
+ this.documentProvider.aboutToChange(input);
+ this.documentProvider.saveDocument(progressMonitor, input, document, true);
+ this.modificationStamp = this.documentProvider.getModificationStamp(input);
+
// create new original CND that that will then be copied over to the CND
being edited
createCnd();
} catch (final Exception e) {
@@ -451,7 +474,7 @@
createCnd();
- this.formsPage.handleCndReloaded();
+ // this.formsPage.handleCndReloaded();
} catch (final Exception e) {
// TODO log this
MessageFormDialog.openError(getShell(),
CndMessages.cndEditorRefreshErrorTitle,
@@ -572,6 +595,7 @@
@Override
public void restoreState( final IMemento memento ) {
this.memento = memento;
+ this.formsPage.restoreState(this.memento);
}
/**
@@ -582,7 +606,8 @@
@Override
public void saveState( final IMemento memento ) {
final int selectedPageNum = getActivePage();
- memento.putInteger(SELECTED_PAGE, selectedPageNum);
+ memento.putInteger(MementoKeys.SELECTED_PAGE, selectedPageNum);
+ this.formsPage.saveState(memento);
}
/**
@@ -637,4 +662,11 @@
getContainer().removeListener(SWT.Activate, this.refreshListener);
}
}
+
+ /**
+ * The memento keys for saving and restoring editor state.
+ */
+ private interface MementoKeys {
+ String SELECTED_PAGE = "SELECTED_PAGE"; //$NON-NLS-1$
+ }
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditorPage.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditorPage.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndEditorPage.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -16,6 +16,8 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableEditor;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.IMessageManager;
import org.eclipse.ui.forms.editor.FormPage;
@@ -24,11 +26,16 @@
import org.jboss.tools.modeshape.ui.forms.ErrorMessage;
/**
- *
+ * The CND editor's form page(s) base class.
*/
-public abstract class CndEditorPage extends FormPage {
+public abstract class CndEditorPage extends FormPage implements IPersistableEditor {
/**
+ * The memento used to restore editor state (can be <code>null</code>).
+ */
+ protected IMemento memento;
+
+ /**
* @param cndEditor the CND editor (cannot be <code>null</code>)
* @param id the unique page identifier (cannot be <code>null</code>)
* @param title the page part title (cannot be <code>null</code>)
@@ -117,6 +124,26 @@
/**
* {@inheritDoc}
*
+ * @see org.eclipse.ui.IPersistableEditor#restoreState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public final void restoreState( IMemento memento ) {
+ this.memento = memento;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveState( IMemento memento ) {
+ // nothing to do. subclassses can override.
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.eclipse.ui.forms.editor.FormPage#setFocus()
*/
@Override
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -49,6 +49,7 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
@@ -57,6 +58,7 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.IMessageManager;
@@ -73,7 +75,6 @@
import org.jboss.tools.modeshape.jcr.cnd.CompactNodeTypeDefinition;
import org.jboss.tools.modeshape.jcr.cnd.NamespaceMapping;
import org.jboss.tools.modeshape.jcr.cnd.NodeTypeDefinition;
-import org.jboss.tools.modeshape.jcr.cnd.NodeTypeDefinition.PropertyName;
import org.jboss.tools.modeshape.jcr.cnd.PropertyDefinition;
import org.jboss.tools.modeshape.jcr.cnd.QualifiedName;
import org.jboss.tools.modeshape.jcr.ui.JcrUiUtils;
@@ -91,6 +92,7 @@
class CndFormsEditorPage extends CndEditorPage implements PropertyChangeListener {
private IAction addChildNode;
+
private IAction addNamespace;
private IAction addNodeType;
private IAction addProperty;
@@ -100,7 +102,6 @@
private Button btnOrderable;
private Button btnQueryable;
private Section childNodeSection;
- private final ErrorMessage childNodesError;
private TableViewer childNodeViewer;
private IAction deleteChildNode;
private IAction deleteNamespace;
@@ -113,18 +114,18 @@
private IAction editProperty;
private IAction editSuperType;
private QualifiedNameEditor nameEditor;
+ private Section namespaceSection;
private final ErrorMessage namespacesError;
private TableViewer namespaceViewer;
- private final ErrorMessage nodeTypeNameError;
private String nodeTypeNameFilterPattern;
+ private Section nodeTypeSection;
private final ErrorMessage nodeTypesError;
private TableViewer nodeTypeViewer;
- private final ErrorMessage propertiesError;
private Section propertiesSection;
private TableViewer propertyViewer;
private NodeTypeDefinition selectedNodeType; // needed for property changes (can be
null)
- private final ErrorMessage superTypesError;
private TableViewer superTypesViewer;
+ private Text txtFilter;
/**
* @param cndEditor the CND editor this page belongs to (cannot be
<code>null</code>)
@@ -133,12 +134,8 @@
super(cndEditor, CND_FORMS_PAGE, CndMessages.cndEditorFormsPageTitle);
// construct form messages
- this.childNodesError = new ErrorMessage();
this.namespacesError = new ErrorMessage();
this.nodeTypesError = new ErrorMessage();
- this.nodeTypeNameError = new ErrorMessage();
- this.propertiesError = new ErrorMessage();
- this.superTypesError = new ErrorMessage();
}
/**
@@ -158,6 +155,9 @@
// fill GUI with CND
populateUi();
+
+ // clear any initial messages that were created before the control was set
+ getCndEditor().getMessageManager().removeAllMessages();
}
private void createChildNodeActions() {
@@ -213,9 +213,22 @@
private void createChildNodeSection( final IManagedForm managedForm,
final FormToolkit toolkit,
final Composite parent ) {
+ // restore expansion state
+ int sectionStyle = Styles.SECTION_STYLE;
+
+ if (this.memento == null) {
+ // don't expand
+ sectionStyle = sectionStyle & ~ExpandableComposite.EXPANDED;
+ } else {
+ final Boolean expanded =
this.memento.getBoolean(MementoKeys.CHILD_NODE_SECTION_EXPANDED);
+
+ if ((expanded != null) && !expanded.booleanValue()) {
+ sectionStyle = sectionStyle & ~ExpandableComposite.EXPANDED;
+ }
+ }
+
this.childNodeSection = FormUtils.createSection(managedForm, toolkit, parent,
CndMessages.cndEditorChildNodeSectionTitle,
-
CndMessages.cndEditorChildNodeSectionDescription, Styles.SECTION_STYLE
- &
~ExpandableComposite.EXPANDED, true);
+
CndMessages.cndEditorChildNodeSectionDescription, sectionStyle, true);
toolkit.paintBordersFor(this.childNodeSection);
// create actions
@@ -243,7 +256,6 @@
table.setMenu(menuManager.createContextMenu(table));
createChildNodeViewer(table);
- this.childNodesError.setControl(table);
}
private void createChildNodeViewer( final Table childNodeTable ) {
@@ -421,7 +433,7 @@
this.nameEditor = new QualifiedNameEditor(leftContainer,
SWT.NONE,
toolkit,
-
Messages.propertyDefinitionName,
+
Messages.nodeTypeDefinitionName,
getNamespacePrefixes(),
null);
((GridData)this.nameEditor.getLayoutData()).horizontalSpan = 2;
@@ -438,7 +450,6 @@
}
});
- this.nodeTypeNameError.setControl(this.nameEditor);
refreshNameControls(); // populate name editor controls
}
@@ -449,7 +460,6 @@
attributesContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
true, false));
((GridData)attributesContainer.getLayoutData()).horizontalSpan = 2;
toolkit.adapt(attributesContainer);
- //
attributesContainer.setBackground(toolkit.getColors().getColor(IFormColors.H_HOVER_LIGHT));
toolkit.paintBordersFor(attributesContainer);
this.btnAbstract = toolkit.createButton(attributesContainer,
CndMessages.abstractAttribute, SWT.CHECK);
@@ -536,7 +546,6 @@
table.setLinesVisible(false);
((GridData)table.getLayoutData()).heightHint = table.getItemHeight() * 2;
table.setToolTipText(CndMessages.supertypesToolTip);
- this.superTypesError.setControl(table);
createSuperTypesActions();
@@ -618,24 +627,38 @@
private void createNamespaceSection( final IManagedForm managedForm,
final FormToolkit toolkit,
final Composite parent ) {
+ // restore expansion state
+ int sectionStyle = Styles.SECTION_STYLE;
+
+ if (this.memento == null) {
+ // don't expand
+ sectionStyle = sectionStyle & ~ExpandableComposite.EXPANDED;
+ } else {
+ final Boolean expanded =
this.memento.getBoolean(MementoKeys.NAMESPACE_SECTION_EXPANDED);
+
+ if ((expanded != null) && !expanded.booleanValue()) {
+ sectionStyle = sectionStyle & ~ExpandableComposite.EXPANDED;
+ }
+ }
+
// create section
- final Section section = FormUtils.createSection(managedForm, toolkit, parent,
CndMessages.cndEditorNamespacesSectionTitle,
-
CndMessages.cndEditorNamespacesSectionDescription, Styles.SECTION_STYLE
- &
~ExpandableComposite.EXPANDED, true);
- toolkit.paintBordersFor(section);
+ this.namespaceSection = FormUtils.createSection(managedForm, toolkit, parent,
CndMessages.cndEditorNamespacesSectionTitle,
+
CndMessages.cndEditorNamespacesSectionDescription, sectionStyle, true);
+ toolkit.paintBordersFor(this.namespaceSection);
+ this.namespacesError.setControl(this.namespaceSection.getDescriptionControl());
// create actions
createNamespaceActions();
// create toolbar
- FormUtils.createSectionToolBar(section, toolkit, new IAction[] {
this.addNamespace, this.editNamespace,
+ FormUtils.createSectionToolBar(this.namespaceSection, toolkit, new IAction[] {
this.addNamespace, this.editNamespace,
this.deleteNamespace });
// create viewer
- final Composite container = toolkit.createComposite(section);
+ final Composite container = toolkit.createComposite(this.namespaceSection);
container.setLayout(new GridLayout());
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- section.setClient(container);
+ this.namespaceSection.setClient(container);
toolkit.paintBordersFor(container);
final Table table = FormUtils.createTable(toolkit, container);
@@ -649,7 +672,6 @@
table.setMenu(menuManager.createContextMenu(table));
createNamespaceViewer(table);
- this.namespacesError.setControl(table);
}
private void createNamespaceViewer( final Table namespaceTable ) {
@@ -810,23 +832,24 @@
final FormToolkit toolkit,
final Composite parent ) {
// create section
- final Section section = FormUtils.createSection(managedForm, toolkit, parent,
CndMessages.cndEditorNodeTypeSectionTitle,
-
CndMessages.cndEditorNodeTypeSectionDescription, Styles.SECTION_STYLE
- &
~ExpandableComposite.TWISTIE, false);
- toolkit.paintBordersFor(section);
+ this.nodeTypeSection = FormUtils.createSection(managedForm, toolkit, parent,
CndMessages.cndEditorNodeTypeSectionTitle,
+
CndMessages.cndEditorNodeTypeSectionDescription, Styles.SECTION_STYLE
+ &
~ExpandableComposite.TWISTIE, false);
+ toolkit.paintBordersFor(this.nodeTypeSection);
+ this.nodeTypesError.setControl(this.nodeTypeSection.getDescriptionControl());
// create actions
createNodeTypeActions();
// create toolbar
- FormUtils.createSectionToolBar(section, toolkit, new IAction[] {
this.addNodeType, this.deleteNodeType });
+ FormUtils.createSectionToolBar(this.nodeTypeSection, toolkit, new IAction[] {
this.addNodeType, this.deleteNodeType });
// splitter has node type table on left and node type detail, properties, and
child nodes on right
- final SashForm splitter = new SashForm(section, SWT.HORIZONTAL);
+ final SashForm splitter = new SashForm(this.nodeTypeSection, SWT.HORIZONTAL);
toolkit.adapt(splitter);
splitter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
splitter.setBackground(toolkit.getColors().getColor(IFormColors.SEPARATOR));
- section.setClient(splitter);
+ this.nodeTypeSection.setClient(splitter);
// left side is node type name filter and node type name table
final Composite leftContainer = toolkit.createComposite(splitter);
@@ -835,12 +858,11 @@
toolkit.paintBordersFor(leftContainer);
FILTER: {
- final Text txtFilter = toolkit.createText(leftContainer, Utils.EMPTY_STRING,
Styles.TEXT_STYLE | SWT.SEARCH
- | SWT.ICON_CANCEL);
- txtFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- txtFilter.setMessage(CndMessages.nodeTypeNamePatternMessage);
- txtFilter.setFont(JFaceResources.getDialogFont());
- txtFilter.addModifyListener(new ModifyListener() {
+ this.txtFilter = toolkit.createText(leftContainer, Utils.EMPTY_STRING,
Styles.TEXT_STYLE | SWT.SEARCH | SWT.ICON_CANCEL);
+ this.txtFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false));
+ this.txtFilter.setMessage(CndMessages.nodeTypeNamePatternMessage);
+ this.txtFilter.setFont(JFaceResources.getDialogFont());
+ this.txtFilter.addModifyListener(new ModifyListener() {
/**
* {@inheritDoc}
@@ -849,12 +871,12 @@
*/
@Override
public void modifyText( final ModifyEvent e ) {
- handleNodeTypeNameFilterModified(txtFilter.getText());
+ handleNodeTypeNameFilterModified(((Text)e.widget).getText());
}
});
}
- VIEWER: {
+ VIEWER: { // left-side
final Composite viewerContainer = toolkit.createComposite(leftContainer);
viewerContainer.setLayout(new GridLayout());
viewerContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -870,7 +892,6 @@
table.setMenu(menuManager.createContextMenu(table));
createNodeTypeViewer(table);
- this.nodeTypesError.setControl(table);
}
RIGHT_SIDE: {
@@ -879,17 +900,10 @@
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
toolkit.paintBordersFor(container);
- DETAILS: {
- createDetailsSection(managedForm, toolkit, container);
- }
-
- PROPERTIES: {
- createPropertySection(managedForm, toolkit, container);
- }
-
- CHILD_NODES: {
- createChildNodeSection(managedForm, toolkit, container);
- }
+ // create sections
+ createDetailsSection(managedForm, toolkit, container);
+ createPropertySection(managedForm, toolkit, container);
+ createChildNodeSection(managedForm, toolkit, container);
}
splitter.setWeights(new int[] { 20, 80 });
@@ -907,7 +921,13 @@
@Override
public String getText( final Object element ) {
final NodeTypeDefinition nodeTypeDefinition =
(NodeTypeDefinition)element;
- return nodeTypeDefinition.getName();
+ String name = nodeTypeDefinition.getName();
+
+ if (Utils.isEmpty(name)) {
+ name = Messages.missingName;
+ }
+
+ return name;
}
}
@@ -1069,10 +1089,22 @@
private void createPropertySection( final IManagedForm managedForm,
final FormToolkit toolkit,
final Composite parent ) {
- // create section
+ // restore expansion state
+ int sectionStyle = Styles.SECTION_STYLE;
+
+ if (this.memento == null) {
+ // don't expand
+ sectionStyle = sectionStyle & ~ExpandableComposite.EXPANDED;
+ } else {
+ final Boolean expanded =
this.memento.getBoolean(MementoKeys.PROPERTY_SECTION_EXPANDED);
+
+ if ((expanded != null) && !expanded.booleanValue()) {
+ sectionStyle = sectionStyle & ~ExpandableComposite.EXPANDED;
+ }
+ }
+
this.propertiesSection = FormUtils.createSection(managedForm, toolkit, parent,
CndMessages.cndEditorPropertySectionTitle,
-
CndMessages.cndEditorPropertySectionDescription, Styles.SECTION_STYLE
- &
~ExpandableComposite.EXPANDED, true);
+
CndMessages.cndEditorPropertySectionDescription, sectionStyle, true);
toolkit.paintBordersFor(this.propertiesSection);
// create actions
@@ -1100,7 +1132,6 @@
table.setMenu(menuManager.createContextMenu(table));
createPropertyViewer(table);
- this.propertiesError.setControl(table);
}
private void createPropertyViewer( final Table propertyTable ) {
@@ -1147,7 +1178,13 @@
}
assert (this.columnIndex == PropertyColumnIndexes.CONSTRAINTS) :
"Unexpected property column index"; //$NON-NLS-1$
- return propertyDefinition.getValueConstraintsCndNotation(notationType);
+ final String[] constraints = propertyDefinition.getValueConstraints();
+
+ if (Utils.isEmpty(constraints)) {
+ return Utils.EMPTY_STRING;
+ }
+
+ return UiUtils.join(Arrays.asList(constraints), null);
}
}
@@ -1683,11 +1720,8 @@
public void handleCndReloaded() {
// make sure GUI has been constructed before refreshing
if (this.propertyViewer != null) {
- refreshNameControls();
- refreshAttributeControls();
- refreshSuperTypes();
- refreshPropertyViewer();
- refreshChildNodeViewer();
+ refreshNamespaceControls();
+ refreshNodeTypeControls();
}
}
@@ -1947,8 +1981,6 @@
// update button enablements
final boolean enable = (getSelectedNamespace() != null);
- // this.addNamespace is always enabled
-
if (this.editNamespace.isEnabled() != enable) {
this.editNamespace.setEnabled(enable);
}
@@ -1966,7 +1998,7 @@
void handleNodeTypeNameFilterModified( final String namePattern ) {
this.nodeTypeNameFilterPattern = namePattern;
- this.nodeTypeViewer.refresh();
+ refreshNodeTypeControls();
}
void handleNodeTypeSelected() {
@@ -2043,6 +2075,7 @@
} else if (NodeTypeDefinition.PropertyName.NAME.toString().equals(propName))
{
validateName();
this.nodeTypeViewer.refresh(source);
+ UiUtils.pack(this.nodeTypeViewer);
} else if
(NodeTypeDefinition.PropertyName.PROPERTY_DEFINITIONS.toString().equals(propName)) {
validateProperties();
this.propertyViewer.refresh();
@@ -2054,12 +2087,15 @@
// tell editor about node type definition change
getCndEditor().refreshDirtyState();
} else if (source instanceof NamespaceMapping) {
+ validateNamespaces();
this.namespaceViewer.refresh(source);
+ UiUtils.pack(this.namespaceViewer);
} else if (source instanceof CompactNodeTypeDefinition) {
if
(CompactNodeTypeDefinition.PropertyName.NAMESPACE_MAPPINGS.toString().equals(propName)) {
- this.namespaceViewer.refresh();
+ validateNamespaces();
+ refreshNamespaceControls();
} else if
(CompactNodeTypeDefinition.PropertyName.NODE_TYPE_DEFINITIONS.toString().equals(propName))
{
- this.nodeTypeViewer.refresh();
+ refreshNodeTypeControls();
}
}
}
@@ -2107,11 +2143,33 @@
// size columns to the data
UiUtils.pack(this.namespaceViewer, this.nodeTypeViewer);
- if (this.nodeTypeViewer.getTable().getItemCount() != 0) {
- this.nodeTypeViewer.getTable().select(0);
- final Event e = new Event();
- e.widget = this.nodeTypeViewer.getTable();
- this.nodeTypeViewer.getTable().notifyListeners(SWT.Selection, e);
+ // restore selected node type and node type name pattern
+ if (this.memento == null) {
+ if (this.nodeTypeViewer.getTable().getItemCount() != 0) {
+ this.nodeTypeViewer.getTable().select(0);
+ final Event e = new Event();
+ e.widget = this.nodeTypeViewer.getTable();
+ this.nodeTypeViewer.getTable().notifyListeners(SWT.Selection, e);
+ }
+ } else {
+ final String nodeTypeName =
this.memento.getString(MementoKeys.SELECTED_NODE_TYPE);
+
+ if (!Utils.isEmpty(nodeTypeName)) {
+ for (final NodeTypeDefinition nodeTypeDefinition :
getCnd().getNodeTypeDefinitions()) {
+ if (nodeTypeName.equals(nodeTypeDefinition.getName())) {
+ this.nodeTypeViewer.setSelection(new
StructuredSelection(nodeTypeDefinition));
+ break;
+ }
+ }
+
+ }
+
+ // set last used node type filter pattern
+ final String filter = this.memento.getString(MementoKeys.NODE_TYPE_FILTER);
+
+ if (!Utils.isEmpty(filter)) {
+ this.txtFilter.setText(filter);
+ }
}
}
@@ -2186,6 +2244,29 @@
}
}
+ private void refreshNamespaceControls() {
+ this.namespaceViewer.refresh();
+ }
+
+ private void refreshNodeTypeControls() {
+ final NodeTypeDefinition selectedNodeType = getSelectedNodeType();
+ this.nodeTypeViewer.refresh(); // this will deselect node type
+
+ // reselect node type by name
+ if (selectedNodeType != null) {
+ final String name = selectedNodeType.getName();
+
+ // should always have a name but just make sure
+ if (!Utils.isEmpty(name)) {
+ for (final NodeTypeDefinition nodeType :
getCnd().getNodeTypeDefinitions()) {
+ if (name.equals(nodeType.getName())) {
+ this.nodeTypeViewer.setSelection(new
StructuredSelection(nodeType));
+ }
+ }
+ }
+ }
+ }
+
private void refreshPropertyViewer() {
if (this.propertyViewer != null) {
this.propertyViewer.setInput(this);
@@ -2205,6 +2286,32 @@
/**
* {@inheritDoc}
*
+ * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveState( final IMemento memento ) {
+ memento.putBoolean(MementoKeys.CHILD_NODE_SECTION_EXPANDED,
this.childNodeSection.isExpanded());
+ memento.putBoolean(MementoKeys.NAMESPACE_SECTION_EXPANDED,
this.namespaceSection.isExpanded());
+ memento.putBoolean(MementoKeys.PROPERTY_SECTION_EXPANDED,
this.propertiesSection.isExpanded());
+
+ // selected node type
+ final NodeTypeDefinition nodeTypeDefinition = getSelectedNodeType();
+
+ if (nodeTypeDefinition == null) {
+ memento.putString(MementoKeys.SELECTED_NODE_TYPE, Utils.EMPTY_STRING);
+ } else {
+ memento.putString(MementoKeys.SELECTED_NODE_TYPE,
nodeTypeDefinition.getName());
+ }
+
+ // node type filter
+ if (!Utils.isEmpty(this.nodeTypeNameFilterPattern)) {
+ memento.putString(MementoKeys.NODE_TYPE_FILTER,
this.nodeTypeNameFilterPattern);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
org.jboss.tools.modeshape.jcr.ui.cnd.CndEditorPage#setResourceReadOnly(boolean)
*/
@Override
@@ -2352,23 +2459,30 @@
private void updateMessage( final ValidationStatus status,
final ErrorMessage errorMessage ) {
final IMessageManager msgMgr = getCndEditor().getMessageManager();
+ msgMgr.setAutoUpdate(false);
+ final Control control = errorMessage.getControl();
+ msgMgr.removeMessages(control);
+
JcrUiUtils.setMessage(status, errorMessage);
- if (errorMessage.isOk()) {
- if (errorMessage.getControl() == null) {
- msgMgr.removeMessage(errorMessage.getKey());
+ if (!errorMessage.isOk()) {
+ if (status instanceof MultiValidationStatus) {
+ final Object data = errorMessage.getData();
+ final MultiValidationStatus multiStatus = (MultiValidationStatus)status;
+
+ for (final ValidationStatus singleStatus : multiStatus.getAll()) {
+ if (!singleStatus.isOk()) {
+ msgMgr.addMessage(singleStatus.getMessage(),
singleStatus.getMessage(), data,
+ JcrUiUtils.getMessageType(singleStatus),
control);
+ }
+ }
} else {
- msgMgr.removeMessage(errorMessage.getKey(), errorMessage.getControl());
- }
- } else {
- if (errorMessage.getControl() == null) {
msgMgr.addMessage(errorMessage.getKey(), errorMessage.getMessage(),
errorMessage.getData(),
- errorMessage.getMessageType());
- } else {
- msgMgr.addMessage(errorMessage.getKey(), errorMessage.getMessage(),
errorMessage.getData(),
errorMessage.getMessageType(),
errorMessage.getControl());
}
}
+
+ msgMgr.setAutoUpdate(true);
}
private void validateAttributes() {
@@ -2376,19 +2490,11 @@
}
private void validateChildNodes() {
- final NodeTypeDefinition nodeTypeDefinition = getSelectedNodeType();
-
- if (nodeTypeDefinition == null) {
- this.nodeTypesError.setOkMessage(null);
- } else {
- final MultiValidationStatus status =
CndValidator.validateChildNodeDefinitions(nodeTypeDefinition.getName(),
-
nodeTypeDefinition.getChildNodeDefinitions());
- updateMessage(status, this.nodeTypesError);
- }
+ validateNodeTypes();
}
private void validateName() {
- updateMessage(this.nameEditor.getStatus(), this.nodeTypeNameError);
+ validateNodeTypes();
}
private void validateNamespaces() {
@@ -2397,39 +2503,16 @@
}
private void validateNodeTypes() {
- final MultiValidationStatus status =
CndValidator.validateNodeTypeDefinitions(getCnd().getNodeTypeDefinitions());
+ final MultiValidationStatus status =
CndValidator.validateNodeTypeDefinitions(getCnd().getNodeTypeDefinitions(), true);
updateMessage(status, this.nodeTypesError);
}
private void validateProperties() {
- final NodeTypeDefinition nodeTypeDefinition = getSelectedNodeType();
-
- if (nodeTypeDefinition == null) {
- this.propertiesError.setOkMessage(null);
- } else {
- final MultiValidationStatus status =
CndValidator.validatePropertyDefinitions(nodeTypeDefinition.getName(),
-
nodeTypeDefinition.getPropertyDefinitions());
- updateMessage(status, this.propertiesError);
- }
+ validateNodeTypes();
}
private void validateSuperTypes() {
- final NodeTypeDefinition nodeTypeDefinition = getSelectedNodeType();
-
- if (nodeTypeDefinition == null) {
- this.superTypesError.setOkMessage(null);
- } else {
- String nodeTypeName = nodeTypeDefinition.getName();
-
- if (Utils.isEmpty(nodeTypeName)) {
- nodeTypeName = Messages.missingName;
- }
-
- final MultiValidationStatus status =
CndValidator.validateSuperTypes(nodeTypeName,
-
nodeTypeDefinition.getState(PropertyName.SUPERTYPES),
-
nodeTypeDefinition.getDeclaredSupertypeNames());
- updateMessage(status, this.superTypesError);
- }
+ validateNodeTypes();
}
interface ChildNodeColumnIndexes {
@@ -2439,6 +2522,17 @@
int REQUIRED_TYPES = 1;
}
+ /**
+ * The memento keys for saving and restoring editor state.
+ */
+ private interface MementoKeys {
+ String CHILD_NODE_SECTION_EXPANDED = "CHILD_NODE_SECTION_EXPANDED";
//$NON-NLS-1$
+ String NAMESPACE_SECTION_EXPANDED = "NAMESPACE_SECTION_EXPANDED";
//$NON-NLS-1$
+ String NODE_TYPE_FILTER = "NODE_TYPE_FILTER"; //$NON-NLS-1$
+ String PROPERTY_SECTION_EXPANDED = "PROPERTY_SECTION_EXPANDED";
//$NON-NLS-1$
+ String SELECTED_NODE_TYPE = "SELECTED_NODE_TYPE"; //$NON-NLS-1$
+ }
+
interface NamespaceColumnIndexes {
int PREFIX = 0;
int URI = 1;
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-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -925,7 +925,7 @@
if (dialog.open() == Window.OK) {
final String newDefaultValue = dialog.getValue();
- if (!this.propertyBeingEdited.addValueConstraint(newDefaultValue)) {
+ if (!this.propertyBeingEdited.addDefaultValue(newDefaultValue)) {
MessageFormDialog.openError(getShell(), UiMessages.errorDialogTitle,
JcrUiUtils.getCndEditorImage(),
NLS.bind(CndMessages.errorAddingDefaultValue,
newDefaultValue));
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/QualifiedNameEditor.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/QualifiedNameEditor.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/QualifiedNameEditor.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -175,7 +175,12 @@
}
void handleQualifierChanged( final String newQualifier ) {
- this.qualifier = newQualifier;
+ if (CndMessages.noNameQualifierChoice.equals(newQualifier)) {
+ this.qualifier = Utils.EMPTY_STRING;
+ } else {
+ this.qualifier = newQualifier;
+ }
+
validate();
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties 2012-03-27
20:03:21 UTC (rev 39856)
@@ -153,7 +153,7 @@
errorEditingRequiredType = There was an unexpected error updating required type
"{0}" to the CND.\nThe remove command result: {1}. The add command result: {2}.
errorEditingSupertype = There was an unexpected error updating supertype "{0}"
to the CND.\nThe remove command result: {1}. The add command result: {2}.
errorEditingValueConstraint = There was an unexpected error updating value constraint
"{0}" to the property definition.\nThe remove command result: {1}. The add
command result: {2}.
-errorOpeningCndEditor = There was a problem creating the CND editor.
+errorOpeningCndEditor = There were errors parsing the CND so the CND editor could not be
created. Fix errors and retry.
mandatoryAttribute = Mandatory
mandatoryAttributeToolTip = Indicates if the child node/property must exist
missingValue = <missing>
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/ErrorMessage.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/ErrorMessage.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/forms/ErrorMessage.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -18,6 +18,11 @@
public class ErrorMessage implements IMessage {
/**
+ * Used to hold additional information (can be <code>null</code>).
+ */
+ private Object data;
+
+ /**
* The error message (can be <code>null</code> or empty)
*/
private String message;
@@ -56,7 +61,7 @@
*/
@Override
public Object getData() {
- return null;
+ return this.data;
}
/**
@@ -135,6 +140,13 @@
}
/**
+ * @param data any additional information needed by the error message (can be
<code>null</code>)
+ */
+ public void setData( Object data ) {
+ this.data = data;
+ }
+
+ /**
* Also sets the message severity to an error.
*
* @param newMessage the new message (can be <code>null</code> or empty)
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-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -147,7 +147,7 @@
this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition);
this.nodeTypeDefinition.addChildNodeDefinition(child2);
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
true).isError());
}
@Test
@@ -162,22 +162,22 @@
this.nodeTypeDefinition.addPropertyDefinition(this.propertyDefinition);
this.nodeTypeDefinition.addPropertyDefinition(prop2);
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
true).isError());
}
@Test
public void nodeTypeDefinitionWithEmptyNameShouldAnError() {
this.nodeTypeDefinition.setName(null);
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
false).isError());
this.nodeTypeDefinition.setName(Utils.EMPTY_STRING);
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
false).isError());
}
@Test
public void nodeTypeDefinitionWithInvalidNameShouldBeAnError() {
this.nodeTypeDefinition.setName("invalid/name"); //$NON-NLS-1$
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
false).isError());
}
@Test
@@ -185,7 +185,7 @@
this.nodeTypeDefinition.setName("nodeTypeName"); //$NON-NLS-1$
this.nodeTypeDefinition.setPrimaryItemName("invalid/name");
//$NON-NLS-1$
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
false).isError());
}
@Test
@@ -193,13 +193,13 @@
this.nodeTypeDefinition.setName("nodeTypeName"); //$NON-NLS-1$
this.nodeTypeDefinition.addSuperType("invalid/name"); //$NON-NLS-1$
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isError());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
false).isError());
}
@Test
public void nodeTypeDefinitionWithoutPropertiesAndChildNodesShouldBeAWarning() {
this.nodeTypeDefinition.setName("name"); //$NON-NLS-1$
- assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition,
null).isWarning());
+ assertTrue(CndValidator.validateNodeTypeDefinition(this.nodeTypeDefinition, null,
false).isWarning());
}
@Test
@@ -241,26 +241,86 @@
}
@Test
- public void shouldNotAllDuplicateNamespacePrefixes() {
+ public void shouldAllowChildNodeDefinitionsWithResidualNames() {
+ this.childNodeDefinition.setName(ItemDefinition.RESIDUAL_NAME);
+ assertTrue(CndValidator.validateName(this.childNodeDefinition, null).isOk());
+ }
+
+ @Test
+ public void shouldAllowMultipleChildNodeDefinitionsWithResidualNames() {
+ this.nodeTypeDefinition.setName("nodeName"); //$NON-NLS-1$
+ this.childNodeDefinition.setName(ItemDefinition.RESIDUAL_NAME);
+ final ChildNodeDefinition childNode2 = new ChildNodeDefinition();
+ childNode2.setName(ItemDefinition.RESIDUAL_NAME);
+ this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition);
+ this.nodeTypeDefinition.addChildNodeDefinition(childNode2);
+
assertTrue(CndValidator.validateChildNodeDefinitions(this.nodeTypeDefinition.getName(),
+
this.nodeTypeDefinition.getChildNodeDefinitions()).isOk());
+ }
+
+ @Test
+ public void shouldAllowMultiplePropertyDefinitionsWithResidualNames() {
+ this.nodeTypeDefinition.setName("nodeName"); //$NON-NLS-1$
+ this.propertyDefinition.setName(ItemDefinition.RESIDUAL_NAME);
+ final PropertyDefinition propDefn2 = new PropertyDefinition();
+ propDefn2.setName(ItemDefinition.RESIDUAL_NAME);
+ this.nodeTypeDefinition.addPropertyDefinition(this.propertyDefinition);
+ this.nodeTypeDefinition.addPropertyDefinition(propDefn2);
+
assertTrue(CndValidator.validatePropertyDefinitions(this.nodeTypeDefinition.getName(),
+
this.nodeTypeDefinition.getPropertyDefinitions()).isOk());
+ }
+
+ @Test
+ public void shouldAllowPropertyDefinitionsWithResidualNames() {
+ this.propertyDefinition.setName(ItemDefinition.RESIDUAL_NAME);
+ assertTrue(CndValidator.validateName(this.propertyDefinition, null).isOk());
+ }
+
+ @Test
+ public void shouldNotAllowChildNodeDefinitionsWithSameName() {
+ this.nodeTypeDefinition.setName("nodeName"); //$NON-NLS-1$
+ this.childNodeDefinition.setName("name"); //$NON-NLS-1$
+ final ChildNodeDefinition childNode2 = new ChildNodeDefinition();
+ childNode2.setName(this.childNodeDefinition.getName());
+ this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition);
+ this.nodeTypeDefinition.addChildNodeDefinition(childNode2);
+
assertTrue(CndValidator.validateChildNodeDefinitions(this.nodeTypeDefinition.getName(),
+
this.nodeTypeDefinition.getChildNodeDefinitions()).isError());
+ }
+
+ @Test
+ public void shouldNotAllowDuplicateNamespacePrefixes() {
// create a namespace mapping with a prefix that already exists and a URI that
doesn't exist in the default namespaces
final NamespaceMapping namespaceMapping = new
NamespaceMapping(Constants.NAMESPACE_PREFIX1, "xyz"); //$NON-NLS-1$
assertTrue(CndValidator.validateNamespaceMapping(namespaceMapping,
Constants.Helper.getDefaultNamespaces()).isError());
}
@Test
- public void shouldNotAllDuplicateNamespaceUris() {
+ public void shouldNotAllowDuplicateNamespaceUris() {
// create a namespace mapping with a URI that already exists and a prefix that
doesn't exist in the default namespaces
final NamespaceMapping namespaceMapping = new NamespaceMapping("xyz",
Constants.NAMESPACE_URI1); //$NON-NLS-1$
assertTrue(CndValidator.validateNamespaceMapping(namespaceMapping,
Constants.Helper.getDefaultNamespaces()).isError());
}
@Test
- public void shouldNotAllDuplicateQualifiedNames() {
+ public void shouldNotAllowDuplicateQualifiedNames() {
assertTrue(CndValidator.validateQualifiedName(Constants.QUALIFIED_NAME1,
"propertyName",
Constants.Helper.getDefaultQualifiers(),
Constants.Helper.getDefaultQualifiedNames()).isError()); //$NON-NLS-1$
}
@Test
+ public void shouldNotAllowPropertyDefinitionsWithSameName() {
+ this.nodeTypeDefinition.setName("nodeName"); //$NON-NLS-1$
+ this.propertyDefinition.setName("name"); //$NON-NLS-1$
+ final PropertyDefinition propDefn2 = new PropertyDefinition();
+ propDefn2.setName(this.propertyDefinition.getName());
+ this.nodeTypeDefinition.addPropertyDefinition(this.propertyDefinition);
+ this.nodeTypeDefinition.addPropertyDefinition(propDefn2);
+
assertTrue(CndValidator.validatePropertyDefinitions(this.nodeTypeDefinition.getName(),
+
this.nodeTypeDefinition.getPropertyDefinitions()).isError());
+ }
+
+ @Test
public void shouldValidateAllQueryOperators() {
for (final QueryOperator operator : QueryOperator.values()) {
assertTrue(CndValidator.validateQueryOperator(operator.toString(),
"propName").isOk()); //$NON-NLS-1$
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -34,7 +34,7 @@
final String PREFIX = "prefix"; //$NON-NLS-1$
final String URI = "uri"; //$NON-NLS-1$
this.namespaceMapping = new NamespaceMapping(PREFIX, URI);
- assertEquals(NamespaceMapping.NOTATION_PREFIX + PREFIX +
NamespaceMapping.NOTATION_DELIMITER + URI
+ assertEquals(NamespaceMapping.NOTATION_PREFIX + PREFIX +
NamespaceMapping.NOTATION_DELIMITER + '\'' + URI + '\''
+ NamespaceMapping.NOTATION_SUFFIX,
this.namespaceMapping.toCndNotation(NotationType.COMPACT));
}
@@ -43,7 +43,7 @@
final String PREFIX = "prefix"; //$NON-NLS-1$
final String URI = "uri"; //$NON-NLS-1$
this.namespaceMapping = new NamespaceMapping(PREFIX, URI);
- assertEquals(NamespaceMapping.NOTATION_PREFIX + PREFIX +
NamespaceMapping.NOTATION_DELIMITER + URI
+ assertEquals(NamespaceMapping.NOTATION_PREFIX + PREFIX +
NamespaceMapping.NOTATION_DELIMITER + '\'' + URI + '\''
+ NamespaceMapping.NOTATION_SUFFIX,
this.namespaceMapping.toCndNotation(NotationType.COMPRESSED));
}
@@ -52,7 +52,7 @@
final String PREFIX = "prefix"; //$NON-NLS-1$
final String URI = "uri"; //$NON-NLS-1$
this.namespaceMapping = new NamespaceMapping(PREFIX, URI);
- assertEquals(NamespaceMapping.NOTATION_PREFIX + PREFIX +
NamespaceMapping.NOTATION_DELIMITER + URI
+ assertEquals(NamespaceMapping.NOTATION_PREFIX + PREFIX +
NamespaceMapping.NOTATION_DELIMITER + '\'' + URI + '\''
+ NamespaceMapping.NOTATION_SUFFIX,
this.namespaceMapping.toCndNotation(NotationType.LONG));
}
@@ -201,12 +201,12 @@
NamespaceMapping thatNamespaceMapping =
NamespaceMapping.copy(this.namespaceMapping);
assertEquals(this.namespaceMapping, thatNamespaceMapping);
assertEquals(this.namespaceMapping.hashCode(), thatNamespaceMapping.hashCode());
-
+
assertTrue(this.namespaceMapping.setPrefix(Constants.NAMESPACE_PREFIX1));
thatNamespaceMapping = NamespaceMapping.copy(this.namespaceMapping);
assertEquals(this.namespaceMapping, thatNamespaceMapping);
assertEquals(this.namespaceMapping.hashCode(), thatNamespaceMapping.hashCode());
-
+
assertTrue(this.namespaceMapping.setUri(Constants.NAMESPACE_URI1));
thatNamespaceMapping = NamespaceMapping.copy(this.namespaceMapping);
assertEquals(this.namespaceMapping, thatNamespaceMapping);
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -481,7 +481,7 @@
assertEquals(1, l.getCount());
assertEquals(PropertyName.PRIMARY_ITEM.toString(), l.getPropertyName());
assertEquals(PRIMARY_ITEM, l.getNewValue());
- assertNull(l.getOldValue());
+ assertTrue(Utils.isEmpty((String)l.getOldValue()));
}
@Test
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItemTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItemTest.java 2012-03-27
19:46:28 UTC (rev 39855)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/attributes/PrimaryItemTest.java 2012-03-27
20:03:21 UTC (rev 39856)
@@ -50,6 +50,9 @@
public void stateShouldBeIsNotWhenSettingEmptyPrimaryItem() {
assertTrue(this.attribute.setPrimaryItem("primaryItem"));
//$NON-NLS-1$
assertTrue(this.attribute.setPrimaryItem(Utils.EMPTY_STRING));
+ assertTrue(this.attribute.isNot());
+
+ assertTrue(this.attribute.setPrimaryItem("primaryItem"));
//$NON-NLS-1$
assertTrue(this.attribute.setPrimaryItem(null));
assertTrue(this.attribute.isNot());
}