Author: elvisisking
Date: 2012-04-21 10:39:01 -0400 (Sat, 21 Apr 2012)
New Revision: 40399
Added:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CommentedCndElement.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/viewers/
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/viewers/CheckBoxLabelProvider.java
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/ChildNodeDialog.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/CndMessages.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/NamespaceMappingDialog.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/cndMessages.properties
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ChildNodeDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ItemDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/PropertyDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndImporter.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizer.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/CompactNodeTypeDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/preference/JcrPreferenceStore.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/META-INF/MANIFEST.MF
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndImporterTest.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizerTest.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/PropertyDefinitionTest.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/aircraft.cnd
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/cnd-reader-test-input.cnd
Log:
JBIDE-11586 ModeShape Tools JCR CND Editor Deletes Comments And Vendor Extensions.
Modified CndImporter and CndTokenizer so that comments are now parsed. CND Editor now
supports one comment for each namespace mapping, node type definition, property
definition, and child node definition.
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ChildNodeDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ChildNodeDefinition.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ChildNodeDefinition.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -15,12 +15,16 @@
import javax.jcr.nodetype.NodeDefinitionTemplate;
import javax.jcr.nodetype.NodeType;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.modeshape.jcr.attributes.AttributeState.Value;
import org.jboss.tools.modeshape.jcr.attributes.DefaultType;
import org.jboss.tools.modeshape.jcr.attributes.NodeAttributes;
import org.jboss.tools.modeshape.jcr.attributes.OnParentVersion;
import org.jboss.tools.modeshape.jcr.attributes.RequiredTypes;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceConstants;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceStore;
@@ -46,6 +50,9 @@
// name
copy.setName(childNodeBeingCopied.getName());
+ // comment
+ copy.comment = childNodeBeingCopied.comment;
+
// attributes
copy.attributes.getAutocreated().set(childNodeBeingCopied.attributes.getAutocreated().get());
copy.attributes.getMandatory().set(childNodeBeingCopied.attributes.getMandatory().get());
@@ -73,6 +80,11 @@
private final NodeAttributes attributes;
/**
+ * An optional comment (can be <code>null</code> or empty).
+ */
+ private String comment;
+
+ /**
* The node default type (never <code>null</code>).
*/
private final DefaultType defaultType;
@@ -260,7 +272,11 @@
return false;
}
- return this.requiredTypes.equals(that.requiredTypes);
+ if (!this.requiredTypes.equals(that.requiredTypes)) {
+ return false;
+ }
+
+ return Utils.equals(this.comment, that.comment);
}
/**
@@ -280,6 +296,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#getComment()
+ */
+ @Override
+ public String getComment() {
+ return this.comment;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
* @throws UnsupportedOperationException if method is called
*/
@@ -464,7 +490,7 @@
@Override
public int hashCode() {
return Utils.hashCode(this.attributes, this.name, this.defaultType,
this.requiredTypes,
- getDeclaringNodeTypeDefinitionName());
+ getDeclaringNodeTypeDefinitionName(), this.comment);
}
/**
@@ -525,7 +551,12 @@
try {
((PropertyChangeListener)listener).propertyChange(event);
} catch (final Exception e) {
- // TODO log this
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
+
this.listeners.remove(listener);
}
}
@@ -572,6 +603,28 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#setComment(java.lang.String)
+ */
+ @Override
+ public boolean setComment( String newComment ) {
+ if (!Utils.isEmpty(newComment)) {
+ newComment = newComment.trim();
+ }
+
+ final Object oldValue = this.comment;
+ final boolean changed = !Utils.equivalent(this.comment, newComment);
+
+ if (changed) {
+ this.comment = newComment;
+ notifyChangeListeners(PropertyName.COMMENT, oldValue, newComment);
+ }
+
+ return changed;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
javax.jcr.nodetype.NodeDefinitionTemplate#setDefaultPrimaryTypeName(java.lang.String)
*/
@Override
@@ -691,9 +744,34 @@
*/
@Override
public String toCndNotation( final NotationType notationType ) {
- JcrPreferenceStore prefStore = JcrPreferenceStore.get();
+ final JcrPreferenceStore prefStore = JcrPreferenceStore.get();
+ final StringBuilder builder = new StringBuilder();
+ String indent = Utils.EMPTY_STRING;
- final StringBuilder builder = new StringBuilder(NOTATION_PREFIX);
+ if (NotationType.LONG == notationType) {
+ indent =
prefStore.get(JcrPreferenceConstants.CndPreference.ELEMENTS_START_DELIMITER);
+ }
+
+ { // comment
+ if (!Utils.isEmpty(this.comment)) {
+ String commentNotation = Utils.EMPTY_STRING;
+
+ if (NotationType.LONG == notationType) {
+ commentNotation += '\n';
+ }
+
+ commentNotation +=
CommentedCndElement.Helper.addCommentCharacters(this.comment, indent) + '\n';
+
+ // add comment above node type
+ builder.append(commentNotation);
+
+ if (NotationType.LONG == notationType) {
+ builder.append(indent);
+ }
+ }
+ }
+
+ builder.append(NOTATION_PREFIX);
builder.append((NotationType.LONG == notationType) ? Utils.SPACE_STRING :
Utils.EMPTY_STRING);
final String DELIM =
prefStore.get(JcrPreferenceConstants.CndPreference.CHILD_NODE_PROPERTY_DELIMITER);
@@ -716,6 +794,11 @@
AUTOCREATED,
/**
+ * The comment.
+ */
+ COMMENT,
+
+ /**
* The default type.
*/
DEFAULT_TYPE,
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ItemDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ItemDefinition.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/ItemDefinition.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -7,12 +7,12 @@
*/
package org.jboss.tools.modeshape.jcr;
-import org.jboss.tools.modeshape.jcr.cnd.CndElement;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
/**
* An interface for property definitions and child node definitions.
*/
-public interface ItemDefinition extends CndElement, Comparable<ItemDefinition> {
+public interface ItemDefinition extends CommentedCndElement,
Comparable<ItemDefinition> {
/**
* Defines a residual set of child items.
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NamespaceMapping.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -12,13 +12,14 @@
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
-import org.jboss.tools.modeshape.jcr.cnd.CndElement;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
/**
* The <code>NamespaceMapping</code> class represents a namespace. Each
namespace mapping includes a prefix and a URI.
*/
-public class NamespaceMapping implements CndElement, Comparable {
+public class NamespaceMapping implements CommentedCndElement, Comparable {
/**
* The delimeter used to separate the prefix from the URI.
@@ -40,10 +41,17 @@
* @return a new namespace mapping exactly equal to the one that was copied (never
<code>null</code>)
*/
public static NamespaceMapping copy( final NamespaceMapping namespaceMappingToCopy )
{
- return new NamespaceMapping(namespaceMappingToCopy.getPrefix(),
namespaceMappingToCopy.getUri());
+ final NamespaceMapping copy = new
NamespaceMapping(namespaceMappingToCopy.getPrefix(), namespaceMappingToCopy.getUri());
+ copy.comment = namespaceMappingToCopy.comment;
+ return copy;
}
/**
+ * An optional comment (can be <code>null</code> or empty).
+ */
+ private String comment;
+
+ /**
* The registered property change listeners (never <code>null</code>).
*/
private final CopyOnWriteArrayList<PropertyChangeListener> listeners;
@@ -127,13 +135,26 @@
public boolean equals( final Object obj ) {
if ((obj != null) && getClass().equals(obj.getClass())) {
final NamespaceMapping that = (NamespaceMapping)obj;
- return (this.prefix.equals(that.prefix) &&
this.uri.equals(that.uri));
+
+ if (this.prefix.equals(that.prefix) && this.uri.equals(that.uri)) {
+ return Utils.equals(this.comment, that.comment);
+ }
}
return false;
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#getComment()
+ */
+ @Override
+ public String getComment() {
+ return this.comment;
+ }
+
+ /**
* @return the prefix (can be <code>null</code> or empty)
*/
public String getPrefix() {
@@ -154,7 +175,7 @@
*/
@Override
public int hashCode() {
- return Utils.hashCode(this.prefix, this.uri);
+ return Utils.hashCode(this.prefix, this.uri, this.comment);
}
/**
@@ -173,7 +194,12 @@
try {
((PropertyChangeListener)listener).propertyChange(event);
} catch (final Exception e) {
- Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
+
this.listeners.remove(listener);
}
}
@@ -189,6 +215,28 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#setComment(java.lang.String)
+ */
+ @Override
+ public boolean setComment( String newComment ) {
+ if (!Utils.isEmpty(newComment)) {
+ newComment = newComment.trim();
+ }
+
+ final Object oldValue = this.comment;
+ final boolean changed = !Utils.equivalent(this.comment, newComment);
+
+ if (changed) {
+ this.comment = newComment;
+ notifyChangeListeners(PropertyName.COMMENT, oldValue, newComment);
+ }
+
+ return changed;
+ }
+
+ /**
* @param newPrefix the new prefix value (can be <code>null</code> or
empty)
* @return true if the prefix was changed
*/
@@ -226,15 +274,31 @@
@Override
public String toCndNotation( final NotationType notationType ) {
final StringBuilder builder = new StringBuilder();
+
+ // comment
+ if (!Utils.isEmpty(this.comment)) {
+ String commentNotation = Utils.EMPTY_STRING;
+
+ if (NotationType.LONG == notationType) {
+ commentNotation += '\n';
+ }
+
+ commentNotation +=
CommentedCndElement.Helper.addCommentCharacters(this.comment, null) + '\n';
+
+ // add comment above namespace
+ builder.append(commentNotation);
+ }
+
+ // namespace mapping
builder.append(NOTATION_PREFIX);
builder.append(this.prefix.toCndNotation(notationType));
-
+
if (NotationType.LONG == notationType) {
builder.append(Utils.SPACE_STRING);
}
builder.append(NOTATION_DELIMITER);
-
+
if (NotationType.LONG == notationType) {
builder.append(Utils.SPACE_STRING);
}
@@ -268,6 +332,11 @@
public enum PropertyName {
/**
+ * The comment.
+ */
+ COMMENT,
+
+ /**
* The namespace prefix.
*/
PREFIX,
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -25,13 +25,14 @@
import org.jboss.tools.modeshape.jcr.attributes.NodeTypeAttributes;
import org.jboss.tools.modeshape.jcr.attributes.SuperTypes;
import org.jboss.tools.modeshape.jcr.cnd.CndElement;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceConstants;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceStore;
/**
* Represents a CND node type definition.
*/
-public class NodeTypeDefinition implements CndElement, Comparable, ItemOwnerProvider,
NodeTypeTemplate {
+public class NodeTypeDefinition implements CommentedCndElement, Comparable,
ItemOwnerProvider, NodeTypeTemplate {
/**
* Then node type name prefix used in the CND notation.
@@ -55,6 +56,9 @@
// name
copy.setName(nodeTypeToCopy.getName());
+ // comment
+ copy.comment = nodeTypeToCopy.comment;
+
// attributes
copy.attributes.setAbstract(nodeTypeToCopy.attributes.getAbstract().get());
copy.attributes.setMixin(nodeTypeToCopy.attributes.getMixin().get());
@@ -94,6 +98,11 @@
private List<CndElement> cndElements;
/**
+ * An optional comment (can be <code>null</code> or empty).
+ */
+ private String comment;
+
+ /**
* The collection of property change listeners (never
<code>null</code>).
*/
private final CopyOnWriteArrayList<PropertyChangeListener> listeners;
@@ -313,7 +322,7 @@
}
}
- return true;
+ return Utils.equals(this.comment, that.comment);
}
/**
@@ -338,6 +347,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#getComment()
+ */
+ @Override
+ public String getComment() {
+ return this.comment;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.nodetype.NodeTypeDefinition#getDeclaredChildNodeDefinitions()
*/
@Override
@@ -573,7 +592,7 @@
*/
@Override
public int hashCode() {
- final int result1 = Utils.hashCode(this.name, this.attributes, this.superTypes);
+ final int result1 = Utils.hashCode(this.name, this.attributes, this.superTypes,
this.comment);
final int result2 = Utils.hashCode(getElements().toArray());
return Utils.hashCode(result1, result2);
}
@@ -739,6 +758,28 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#setComment(java.lang.String)
+ */
+ @Override
+ public boolean setComment( String newComment ) {
+ if (!Utils.isEmpty(newComment)) {
+ newComment = newComment.trim();
+ }
+
+ final Object oldValue = this.comment;
+ final boolean changed = !Utils.equivalent(this.comment, newComment);
+
+ if (changed) {
+ this.comment = newComment;
+ notifyChangeListeners(PropertyName.COMMENT, oldValue, newComment);
+ }
+
+ return changed;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
javax.jcr.nodetype.NodeTypeTemplate#setDeclaredSuperTypeNames(java.lang.String[])
*/
@Override
@@ -830,6 +871,21 @@
final JcrPreferenceStore prefStore = JcrPreferenceStore.get();
final StringBuilder builder = new StringBuilder();
+ { // comment
+ if (!Utils.isEmpty(this.comment)) {
+ String commentNotation = Utils.EMPTY_STRING;
+
+ if (NotationType.LONG == notationType) {
+ commentNotation += '\n';
+ }
+
+ commentNotation +=
CommentedCndElement.Helper.addCommentCharacters(this.comment, null) + '\n';
+
+ // add comment above node type
+ builder.append(commentNotation);
+ }
+ }
+
{ // name
builder.append(NAME_NOTATION_PREFIX).append(this.name.toCndNotation(notationType)).append(NAME_NOTATION_SUFFIX);
@@ -897,6 +953,11 @@
CHILD_NODES,
/**
+ * The comment.
+ */
+ COMMENT,
+
+ /**
* The mixin attribute.
*/
MIXIN,
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/PropertyDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/PropertyDefinition.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/PropertyDefinition.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -16,6 +16,9 @@
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinitionTemplate;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.modeshape.jcr.attributes.AttributeState;
import org.jboss.tools.modeshape.jcr.attributes.AttributeState.Value;
@@ -26,6 +29,7 @@
import org.jboss.tools.modeshape.jcr.attributes.QueryOperators;
import org.jboss.tools.modeshape.jcr.attributes.QueryOperators.QueryOperator;
import org.jboss.tools.modeshape.jcr.attributes.ValueConstraints;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceConstants;
import org.jboss.tools.modeshape.jcr.preference.JcrPreferenceStore;
@@ -56,6 +60,9 @@
// name
copy.setName(propertyBeingCopied.getName());
+ // comment
+ copy.comment = propertyBeingCopied.comment;
+
// attributes
copy.attributes.getAutocreated().set(propertyBeingCopied.attributes.getAutocreated().get());
copy.attributes.getMandatory().set(propertyBeingCopied.attributes.getMandatory().get());
@@ -93,6 +100,11 @@
private final PropertyAttributes attributes;
/**
+ * An optional comment (can be <code>null</code> or empty).
+ */
+ private String comment;
+
+ /**
* The property default values (never <code>null</code>).
*/
private final DefaultValues defaultValues;
@@ -339,7 +351,11 @@
return false;
}
- return this.valueConstraints.equals(that.valueConstraints);
+ if (!this.valueConstraints.equals(that.valueConstraints)) {
+ return false;
+ }
+
+ return Utils.equals(this.comment, that.comment);
}
/**
@@ -369,6 +385,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#getComment()
+ */
+ @Override
+ public String getComment() {
+ return this.comment;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
* @throws UnsupportedOperationException if method is called
*/
@@ -540,7 +566,7 @@
@Override
public int hashCode() {
return Utils.hashCode(this.attributes, this.name, this.defaultValues, this.type,
this.valueConstraints,
- getDeclaringNodeTypeDefinitionName());
+ getDeclaringNodeTypeDefinitionName(), this.comment);
}
/**
@@ -635,7 +661,12 @@
try {
((PropertyChangeListener)listener).propertyChange(event);
} catch (final Exception e) {
- // TODO log this
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
+
this.listeners.remove(listener);
}
}
@@ -724,7 +755,11 @@
changed = true;
}
} catch (final Exception e) {
- // TODO log the invalid query operator
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
}
}
}
@@ -737,6 +772,28 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement#setComment(java.lang.String)
+ */
+ @Override
+ public boolean setComment( String newComment ) {
+ if (!Utils.isEmpty(newComment)) {
+ newComment = newComment.trim();
+ }
+
+ final Object oldValue = this.comment;
+ final boolean changed = !Utils.equivalent(this.comment, newComment);
+
+ if (changed) {
+ this.comment = newComment;
+ notifyChangeListeners(PropertyName.COMMENT, oldValue, newComment);
+ }
+
+ return changed;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
javax.jcr.nodetype.PropertyDefinitionTemplate#setDefaultValues(javax.jcr.Value[])
*/
@Override
@@ -751,7 +808,11 @@
changed = true;
}
} catch (final Exception e) {
- // TODO log this
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
}
}
}
@@ -917,8 +978,33 @@
@Override
public String toCndNotation( final NotationType notationType ) {
final JcrPreferenceStore prefStore = JcrPreferenceStore.get();
+ final StringBuilder builder = new StringBuilder();
+ String indent = Utils.EMPTY_STRING;
- final StringBuilder builder = new StringBuilder(NOTATION_PREFIX);
+ if (NotationType.LONG == notationType) {
+ indent =
prefStore.get(JcrPreferenceConstants.CndPreference.ELEMENTS_START_DELIMITER);
+ }
+
+ { // comment
+ if (!Utils.isEmpty(this.comment)) {
+ String commentNotation = Utils.EMPTY_STRING;
+
+ if (NotationType.LONG == notationType) {
+ commentNotation += '\n';
+ }
+
+ commentNotation +=
CommentedCndElement.Helper.addCommentCharacters(this.comment, indent) + '\n';
+
+ // add comment above node type
+ builder.append(commentNotation);
+
+ if (NotationType.LONG == notationType) {
+ builder.append(indent);
+ }
+ }
+ }
+
+ builder.append(NOTATION_PREFIX);
builder.append((NotationType.LONG == notationType) ? Utils.SPACE_STRING :
Utils.EMPTY_STRING);
final String DELIM =
prefStore.get(JcrPreferenceConstants.CndPreference.PROPERTY_DEFINITION_ATTRIBUTES_DELIMITER);
@@ -943,6 +1029,11 @@
AUTOCREATED,
/**
+ * The comment.
+ */
+ COMMENT,
+
+ /**
* A collection of default values.
*/
DEFAULT_VALUES,
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndImporter.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndImporter.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndImporter.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Stack;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.modeshape.jcr.ChildNodeDefinition;
@@ -60,21 +61,11 @@
@NotThreadSafe
public final class CndImporter {
- private final boolean jcr170;
+ private final boolean jcr170 = true;
- /**
- * Constructs an importer that is not JCR 170 compatible.
- */
- public CndImporter() {
- this.jcr170 = true;
- }
+ private final Stack<CndElement> cndElements = new Stack<CndElement>();
- /**
- * @param compatibleWithPreJcr2 indicates if the importer should be compatible with
pre JCR 2 CND notation
- */
- public CndImporter( final boolean compatibleWithPreJcr2 ) {
- this.jcr170 = compatibleWithPreJcr2;
- }
+ private String currentComment;
/**
* Import the CND content from the supplied stream, placing the content into the
importer's destination.
@@ -137,7 +128,10 @@
Utils.verifyIsNotNull(content, "content is null"); //$NON-NLS-1$
final CompactNodeTypeDefinition cnd = new CompactNodeTypeDefinition();
- final Tokenizer tokenizer = new CndTokenizer(false, false);
+
+ // start processing CND
+ push(cnd);
+ final Tokenizer tokenizer = new CndTokenizer();
final TokenStream tokens = new TokenStream(content, tokenizer, false);
tokens.start();
@@ -152,6 +146,8 @@
} else if (tokens.matches(NodeTypeDefinition.NAME_NOTATION_PREFIX,
NodeTypeDefinition.NAME_NOTATION_SUFFIX)) {
// empty node type name (no problem recorded here but editor validation
will have an error)
parseNodeTypeDefinition(tokens, cnd);
+ } else if (tokens.matches(CndTokenizer.COMMENT)) {
+ parseComment(tokens);
} else {
final Position position = tokens.previousPosition();
final Object[] args = new Object[] { tokens.consume(),
position.getLine(), position.getColumn() };
@@ -159,6 +155,9 @@
}
}
+ // finished processing CND
+ final CndElement cndElement = pop();
+ assert (cnd == cndElement) : "CND Element not the expected CND: " +
cndElement.toCndNotation(NotationType.LONG); //$NON-NLS-1$
return cnd;
}
@@ -177,6 +176,9 @@
tokens.consume(ChildNodeDefinition.NOTATION_PREFIX);
final ChildNodeDefinition childNodeDefn = new ChildNodeDefinition(nodeTypeDefn);
+ // start processing child node
+ push(childNodeDefn);
+
// name
final String name = parseName(tokens);
@@ -184,19 +186,41 @@
childNodeDefn.setName(name);
}
+ parseComment(tokens); // comment before required types
+
// required types
parseRequiredPrimaryTypes(tokens, childNodeDefn);
+ parseComment(tokens); // comment before default type
+
// default types
parseDefaultType(tokens, childNodeDefn.getDefaultType());
+ parseComment(tokens); // comment before attributes
+
// attributes
parseNodeAttributes(tokens, nodeTypeDefn, childNodeDefn);
// add child node definition
nodeTypeDefn.addChildNodeDefinition(childNodeDefn);
+
+ // finished processing child node
+ final CndElement cndElement = pop();
+ assert (childNodeDefn == cndElement) : "Element not expected child node:
" + cndElement.toCndNotation(NotationType.LONG); //$NON-NLS-1$
}
+ private void parseComment( final TokenStream tokens ) {
+ if (tokens.matches(CndTokenizer.COMMENT)) {
+ final String newComment =
CommentedCndElement.Helper.removeCommentCharacters(tokens.consume());
+
+ if (Utils.isEmpty(this.currentComment)) {
+ this.currentComment = newComment;
+ } else {
+ this.currentComment += '\n' + newComment;
+ }
+ }
+ }
+
/**
* Parse the child node definition's default type, if they appear next on the
token stream.
*
@@ -209,6 +233,9 @@
assert (tokens != null) : "tokens is null"; //$NON-NLS-1$
assert (defaultType != null) : "defaultType is null"; //$NON-NLS-1$
+ // start processing default type
+ push(defaultType);
+
if (tokens.canConsume(DefaultType.NOTATION)) {
if (tokens.canConsume(AttributeState.VARIANT_CHAR)) {
defaultType.set(Value.VARIANT);
@@ -220,6 +247,10 @@
}
}
}
+
+ // finished processing default type
+ final CndElement cndElement = pop();
+ assert (defaultType == cndElement) : "Element not expected default type:
" + cndElement.toCndNotation(NotationType.LONG); //$NON-NLS-1$
}
/**
@@ -297,14 +328,25 @@
assert (tokens != null) : "tokens is null"; //$NON-NLS-1$
assert (cnd != null) : "cnd is null"; //$NON-NLS-1$
+ final NamespaceMapping namespaceMapping = new NamespaceMapping();
+
+ // start processing namespace mapping
+ push(namespaceMapping);
+
tokens.consume(NamespaceMapping.NOTATION_PREFIX);
final String prefix = removeQuotes(tokens.consume());
+ namespaceMapping.setPrefix(prefix);
tokens.consume(NamespaceMapping.NOTATION_DELIMITER);
final String uri = removeQuotes(tokens.consume());
+ namespaceMapping.setUri(uri);
tokens.consume(NamespaceMapping.NOTATION_SUFFIX);
- cnd.addNamespaceMapping(new NamespaceMapping(prefix, uri));
+ cnd.addNamespaceMapping(namespaceMapping);
+
+ // finished processing namespace mapping
+ final CndElement cndElement = pop();
+ assert (namespaceMapping == cndElement) : "Element not expected namespace
mapping: " + cndElement.toCndNotation(NotationType.LONG); //$NON-NLS-1$
}
/**
@@ -472,6 +514,9 @@
final NodeTypeDefinition nodeType = new NodeTypeDefinition();
+ // start processing node type
+ push(nodeType);
+
// name
final String name = parseNodeTypeName(tokens);
@@ -487,13 +532,22 @@
nodeType.addSuperType(superType);
}
}
+
+ parseComment(tokens); // comment before attributes
+
// Read the node type options (and vendor extensions) ...
parseNodeTypeAttributes(tokens, nodeType);
+ parseComment(tokens); // comment before item definitions
+
// Parse property and child node definitions ...
parsePropertyOrChildNodeDefinitions(tokens, nodeType);
cnd.addNodeTypeDefinition(nodeType);
+
+ // finished processing node type
+ final CndElement cndElement = pop();
+ assert (nodeType == cndElement) : "Element not expected node type: " +
cndElement.toCndNotation(NotationType.LONG); //$NON-NLS-1$
}
/**
@@ -621,6 +675,9 @@
tokens.consume(PropertyDefinition.NOTATION_PREFIX);
final PropertyDefinition propDefn = new PropertyDefinition(nodeTypeDefn);
+ // start processing property
+ push(propDefn);
+
// name
final String name = parseName(tokens);
@@ -628,19 +685,31 @@
propDefn.setName(name);
}
+ parseComment(tokens); // comment before type
+
// required type
parsePropertyType(tokens, propDefn);
+ parseComment(tokens); // comment before default values
+
// Parse the default values ...
parseDefaultValues(tokens, propDefn);
+ parseComment(tokens); // comment before attributes
+
// Parse the property attributes (and vendor extensions) ...
parsePropertyAttributes(tokens, nodeTypeDefn, propDefn);
+ parseComment(tokens); // comment before value constraints
+
// Parse the property constraints ...
parseValueConstraints(tokens, propDefn);
nodeTypeDefn.addPropertyDefinition(propDefn);
+
+ // finished processing property
+ final CndElement cndElement = pop();
+ assert (propDefn == cndElement) : "Element not expected property: " +
cndElement.toCndNotation(NotationType.LONG); //$NON-NLS-1$
}
/**
@@ -661,6 +730,8 @@
parsePropertyDefinition(tokens, nodeTypeDefn);
} else if (tokens.matches(ChildNodeDefinition.NOTATION_PREFIX)) {
parseChildNodeDefinition(tokens, nodeTypeDefn);
+ } else if (tokens.matches(CndTokenizer.COMMENT)) {
+ parseComment(tokens);
} else {
// The next token does not signal either one of these, so stop ...
break;
@@ -827,6 +898,43 @@
}
}
+ private CndElement pop() {
+ return this.cndElements.pop();
+ }
+
+ private void push( final CndElement cndElement ) {
+ // set comment if one exists
+ if (!Utils.isEmpty(this.currentComment)) {
+ CommentedCndElement commentedElement = null;
+
+ if (cndElement instanceof CommentedCndElement) {
+ commentedElement = (CommentedCndElement)cndElement;
+ } else if (!this.cndElements.isEmpty()) {
+ // this should probably look back in the stack until it finds a
CommentedCndElement
+ CndElement top = this.cndElements.peek();
+
+ if (top instanceof CommentedCndElement) {
+ commentedElement = (CommentedCndElement)top;
+ }
+ }
+
+ if (commentedElement != null) {
+ String cndElementComment = commentedElement.getComment();
+
+ if (cndElementComment == null) {
+ cndElementComment = Utils.EMPTY_STRING;
+ } else if (!cndElementComment.endsWith("\n")) { //$NON-NLS-1$
+ cndElementComment += '\n';
+ }
+
+ commentedElement.setComment(cndElementComment + this.currentComment);
+ this.currentComment = null;
+ }
+ }
+
+ this.cndElements.push(cndElement);
+ }
+
private final String removeQuotes( final String text ) {
// Remove leading and trailing quotes, if there are any ...
return text.replaceFirst("^['\"]+",
"").replaceAll("['\"]+$", ""); //$NON-NLS-1$
//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizer.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizer.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizer.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -35,42 +35,31 @@
/**
* The token type for tokens that consist of an individual '.' character.
*/
- public static final int DECIMAL = 3;
+ public static final int DECIMAL = 4;
/**
* The token type for tokens that consist of all the characters within single-quotes.
Single quote characters are included if
* they are preceded (escaped) by a '\' character.
*/
- public static final int SINGLE_QUOTED_STRING = 4;
+ public static final int SINGLE_QUOTED_STRING = 8;
/**
* The token type for tokens that consist of all the characters within double-quotes.
Double quote characters are included if
* they are preceded (escaped) by a '\' character.
*/
- public static final int DOUBLE_QUOTED_STRING = 5;
+ public static final int DOUBLE_QUOTED_STRING = 16;
/**
* The token type for tokens that consist of all the characters between
"/*" and "*/" or between "//" and the next line
* terminator (e.g., '\n', '\r' or "\r\n").
*/
- public static final int COMMENT = 6;
+ public static final int COMMENT = 32;
/**
* The token type for the token containing a vendor extension block.
*/
- public static final int VENDOR_EXTENSION = 7;
+ public static final int VENDOR_EXTENSION = 64;
- private final boolean useComments = false;
+ private final boolean useComments = true;
private final boolean useVendorExtensions = false;
/**
- * <strong>Currently comments and vendor extensions are not supported by the
framework.</strong>
- * @param useComments a flag indicating if comments should be used
- * @param useVendorExtensions a flag indicating if vendor extensions should be used
- */
- public CndTokenizer( boolean useComments,
- boolean useVendorExtensions ) {
-// this.useComments = useComments;
-// this.useVendorExtensions = useVendorExtensions;
- }
-
- /**
* {@inheritDoc}
*
* @see org.modeshape.common.text.TokenStream.Tokenizer#tokenize(CharacterStream,
Tokens)
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-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -17,6 +17,7 @@
import java.util.StringTokenizer;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.modeshape.jcr.Activator;
@@ -741,7 +742,11 @@
}
}
} catch (final Exception e) {
- Activator.get().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
null, e));
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
}
return status;
Added:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CommentedCndElement.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CommentedCndElement.java
(rev 0)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CommentedCndElement.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import org.jboss.tools.modeshape.jcr.Utils;
+
+/**
+ * An element found in a CND file that may have an attached comment.
+ */
+public interface CommentedCndElement extends CndElement {
+
+ /**
+ * The characters that end a block comment. Value is {@value} .
+ */
+ String BLOCK_COMMENT_END_CHARS = "*/"; //$NON-NLS-1$
+
+ /**
+ * The characters that begin all lines besides the first and last line of a block
comment. Value is {@value} .
+ */
+ String BLOCK_COMMENT_INNER_CHARS = " * "; //$NON-NLS-1$
+
+ /**
+ * The characters that start a block comment. Value is {@value} .
+ */
+ String BLOCK_COMMENT_START_CHARS = "/*"; //$NON-NLS-1$
+
+ /**
+ * The characters that start a line comment. Value is {@value} .
+ */
+ String LINE_COMMENT_CHARS = "//"; //$NON-NLS-1$
+
+ /**
+ * @return the comment associated with this CND element (can be
<code>null</code> or empty)
+ */
+ String getComment();
+
+ /**
+ * @param text the comment text (can be <code>null</code> or empty)
+ * @return <code>true</code> if the comment was changed
+ */
+ boolean setComment( String text );
+
+ /**
+ * Utilities related to a commented CND elements.
+ */
+ public class Helper {
+
+ private static String BLOCK_COMMENT_INNER_CHARS2 = "* "; //$NON-NLS-1$
+
+ /**
+ * @param text the text that the comment characters will be added to (cannot be
<code>null</code>)
+ * @param indent an optional indent string (can be <code>null</code>
or empty)
+ * @return the commented text (never <code>null</code>)
+ */
+ public static String addCommentCharacters( final String text,
+ String indent ) {
+ Utils.verifyIsNotNull(text, "text"); //$NON-NLS-1$
+
+ if (indent == null) {
+ indent = Utils.EMPTY_STRING;
+ }
+
+ final StringBuilder builder = new StringBuilder(indent +
BLOCK_COMMENT_START_CHARS);
+
+ if (!text.startsWith("\n")) { //$NON-NLS-1$
+ builder.append('\n');
+ }
+
+ builder.append(indent + BLOCK_COMMENT_INNER_CHARS);
+ builder.append(text.replace("\n", '\n' + indent +
BLOCK_COMMENT_INNER_CHARS)); //$NON-NLS-1$
+
+ if (!text.endsWith("\n")) { //$NON-NLS-1$
+ builder.append('\n');
+ }
+
+ builder.append(indent + Utils.SPACE_STRING).append(BLOCK_COMMENT_END_CHARS);
+ return builder.toString();
+ }
+
+ /**
+ * @param comment the comment whose comment characters are being removed (cannot
be <code>null</code>)
+ * @return the comment stripped of all comment characters (never
<code>null</code>) or the original text if the comment is
+ * not properly formatted
+ */
+ public static String removeCommentCharacters( final String comment ) {
+ Utils.verifyIsNotNull(comment, "comment"); //$NON-NLS-1$
+
+ if (Utils.isEmpty(comment)) {
+ return comment;
+ }
+
+ String result = comment.trim();
+
+ if (result.startsWith(BLOCK_COMMENT_START_CHARS)) {
+ // invalid since no end comment block
+ if (result.length() == BLOCK_COMMENT_START_CHARS.length()) {
+ return comment;
+ }
+
+ // remove start comment chars
+ result = comment.substring(BLOCK_COMMENT_START_CHARS.length());
+ result = result.trim();
+
+ if (result.endsWith(BLOCK_COMMENT_END_CHARS)) {
+ result = result.substring(0, (result.length() -
BLOCK_COMMENT_END_CHARS.length()));
+ result = result.trim();
+
+ // empty comment
+ if (result.isEmpty()) {
+ return result;
+ }
+
+ // remove beginning inner comment chars
+ if (result.startsWith(BLOCK_COMMENT_INNER_CHARS)) {
+ result = result.substring(BLOCK_COMMENT_INNER_CHARS.length());
+ result.trim();
+ } else if (result.startsWith(BLOCK_COMMENT_INNER_CHARS2)) {
+ result = result.substring(BLOCK_COMMENT_INNER_CHARS2.length());
+ result.trim();
+ }
+
+ // remove other inner comment chars
+ result = result.replace('\n' + BLOCK_COMMENT_INNER_CHARS,
"\n"); //$NON-NLS-1$
+
+ return result.trim();
+ }
+ } else if (comment.startsWith(LINE_COMMENT_CHARS)) {
+ if (comment.length() == LINE_COMMENT_CHARS.length()) {
+ return Utils.EMPTY_STRING;
+ }
+
+ return comment.substring(LINE_COMMENT_CHARS.length()).trim();
+ }
+
+ return comment;
+ }
+ }
+}
Property changes on:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CommentedCndElement.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CompactNodeTypeDefinition.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -16,6 +16,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.jboss.tools.modeshape.jcr.Activator;
import org.jboss.tools.modeshape.jcr.ChildNodeDefinition;
@@ -296,7 +297,11 @@
try {
matches.addAll(WorkspaceRegistry.get().getMatchingNodeTypeDefinitions(namespacePrefix));
} catch (final Exception e) {
- Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
}
}
@@ -426,7 +431,12 @@
try {
((PropertyChangeListener)listener).propertyChange(event);
} catch (final Exception e) {
- Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
+
this.listeners.remove(listener);
}
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/preference/JcrPreferenceStore.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/preference/JcrPreferenceStore.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/preference/JcrPreferenceStore.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -189,7 +189,11 @@
try {
this.prefs.flush();
} catch (final BackingStoreException e) {
- Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ if (Platform.isRunning()) {
+ Activator.get().getLog().log(new Status(IStatus.ERROR,
Activator.PLUGIN_ID, null, e));
+ } else {
+ System.err.print(e.getMessage());
+ }
}
} else {
// test mode
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/ChildNodeDialog.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/ChildNodeDialog.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/ChildNodeDialog.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -33,6 +33,8 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
@@ -47,6 +49,7 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
@@ -61,10 +64,12 @@
import org.jboss.tools.modeshape.jcr.ValidationStatus;
import org.jboss.tools.modeshape.jcr.attributes.OnParentVersion;
import org.jboss.tools.modeshape.jcr.cnd.CndValidator;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.ui.Activator;
import org.jboss.tools.modeshape.jcr.ui.JcrUiConstants;
import org.jboss.tools.modeshape.jcr.ui.JcrUiUtils;
import org.jboss.tools.modeshape.ui.UiMessages;
+import org.jboss.tools.modeshape.ui.UiUtils;
import org.jboss.tools.modeshape.ui.actions.DelegateAction;
import org.jboss.tools.modeshape.ui.forms.ErrorMessage;
import org.jboss.tools.modeshape.ui.forms.FormUtils;
@@ -98,9 +103,9 @@
private final ErrorMessage nameError;
private ChildNodeDefinition originalChildNode;
-
+
private QualifiedNameProposalProvider requiredTypeProposalProvider;
-
+
private final ErrorMessage requiredTypesError;
private TableViewer requiredTypesViewer;
@@ -458,8 +463,10 @@
final Table table = FormUtils.createTable(toolkit, rightContainer);
table.setHeaderVisible(false);
table.setLinesVisible(false);
- ((GridData)table.getLayoutData()).horizontalSpan = 2;
- ((GridData)table.getLayoutData()).heightHint = table.getItemHeight() * 2;
+ GridData gd = (GridData)table.getLayoutData();
+ gd.horizontalSpan = 2;
+ gd.heightHint = table.getItemHeight() * 4;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(table, 40);
this.requiredTypesError.setControl(table);
// table context menu
@@ -475,6 +482,44 @@
this.requiredTypesViewer.setInput(this);
}
+ { // bottom - comments
+ final Composite commentsContainer = toolkit.createComposite(body);
+ commentsContainer.setLayout(new GridLayout(2, false));
+ commentsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
+ ((GridData)commentsContainer.getLayoutData()).horizontalSpan = 2;
+ toolkit.paintBordersFor(commentsContainer);
+
+ final Label lblComment = toolkit.createLabel(commentsContainer,
CndMessages.commentLabel, SWT.NONE);
+ lblComment.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+
+ Text txtComment = toolkit.createText(commentsContainer, null,
Styles.TEXT_STYLE | SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ txtComment.setToolTipText(CndMessages.commentedToolTip);
+
+ final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.verticalIndent += ((GridLayout)body.getLayout()).verticalSpacing;
+ gd.heightHint = txtComment.getLineHeight() * 3;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(txtComment, 80);
+ txtComment.setLayoutData(gd);
+
+ if (isEditMode() &&
!Utils.isEmpty(this.childNodeBeingEdited.getComment())) {
+
txtComment.setText(CommentedCndElement.Helper.removeCommentCharacters(this.childNodeBeingEdited.getComment()));
+ }
+
+ txtComment.addModifyListener(new ModifyListener() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ @Override
+ public void modifyText( final ModifyEvent e ) {
+ handleCommentChanged(((Text)e.widget).getText());
+ }
+ });
+ }
+
// must be done after constructor
this.childNodeBeingEdited.addListener(new PropertyChangeListener() {
@@ -666,6 +711,10 @@
this.childNodeBeingEdited.setAutoCreated(newAutocreated);
}
+ void handleCommentChanged( final String newComment ) {
+ this.childNodeBeingEdited.setComment(newComment);
+ }
+
void handleDefaultTypeChanged( final String newDefaultType ) {
this.childNodeBeingEdited.setDefaultPrimaryTypeName(newDefaultType);
}
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-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndFormsEditorPage.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -25,6 +25,8 @@
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -82,6 +84,7 @@
import org.jboss.tools.modeshape.jcr.ValidationStatus;
import org.jboss.tools.modeshape.jcr.cnd.CndElement.NotationType;
import org.jboss.tools.modeshape.jcr.cnd.CndValidator;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.cnd.CompactNodeTypeDefinition;
import org.jboss.tools.modeshape.jcr.ui.Activator;
import org.jboss.tools.modeshape.jcr.ui.JcrUiConstants;
@@ -92,6 +95,7 @@
import org.jboss.tools.modeshape.ui.forms.FormUtils;
import org.jboss.tools.modeshape.ui.forms.FormUtils.Styles;
import org.jboss.tools.modeshape.ui.forms.MessageFormDialog;
+import org.jboss.tools.modeshape.ui.viewers.CheckBoxLabelProvider;
/**
* The GUI part of the CND editor.
@@ -134,6 +138,7 @@
private IAction showInheritedChildNodes;
private IAction showInheritedProperties;
private TableViewer superTypesViewer;
+ private Text txtComment;
private Text txtFilter;
/**
@@ -390,9 +395,21 @@
assert (this.columnIndex == ChildNodeColumnIndexes.ATTRIBUTES) :
"Unexpected child node column index"; //$NON-NLS-1$
return childNodeDefinition.getAttributesCndNotation(notationType);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText( Object element ) {
+ final ChildNodeDefinition childNodeDefinition =
(ChildNodeDefinition)element;
+ return childNodeDefinition.toCndNotation(NotationType.LONG);
+ }
}
this.childNodeViewer = new TableViewer(childNodeTable);
+ ColumnViewerToolTipSupport.enableFor(this.childNodeViewer);
this.childNodeViewer.setContentProvider(new IStructuredContentProvider() {
/**
@@ -478,36 +495,42 @@
}
});
- { // create name column
+ { // name column
final TableViewerColumn nameColumn = new
TableViewerColumn(this.childNodeViewer, SWT.LEFT);
UiUtils.configureColumn(nameColumn, new
ChildNodeLabelProvider(ChildNodeColumnIndexes.NAME),
CndMessages.nameHeaderText,
CndMessages.childNodeNameToolTip, false, true);
}
- { // create type column
+ { // type column
final TableViewerColumn typeColumn = new
TableViewerColumn(this.childNodeViewer, SWT.LEFT);
UiUtils.configureColumn(typeColumn, new
ChildNodeLabelProvider(ChildNodeColumnIndexes.REQUIRED_TYPES),
CndMessages.requiredTypesHeaderText,
CndMessages.childNodeRequiredTypesToolTip, false, true);
}
- { // create default values column
+ { // default values column
final TableViewerColumn defaultValuesColumn = new
TableViewerColumn(this.childNodeViewer, SWT.LEFT);
UiUtils.configureColumn(defaultValuesColumn, new
ChildNodeLabelProvider(ChildNodeColumnIndexes.DEFAULT_TYPE),
CndMessages.defaultTypeHeaderText,
CndMessages.childNodeDefaultTypeToolTip, false, true);
}
- { // create attributes column
+ { // attributes column
final TableViewerColumn attributesColumn = new
TableViewerColumn(this.childNodeViewer, SWT.LEFT);
UiUtils.configureColumn(attributesColumn, new
ChildNodeLabelProvider(ChildNodeColumnIndexes.ATTRIBUTES),
CndMessages.attributesHeaderText,
CndMessages.childNodeAttributesToolTip, false, true);
}
- { // create declaring node type column
+ { // declaring node type column
final TableViewerColumn nodeTypeColumn = new
TableViewerColumn(this.childNodeViewer, SWT.LEFT);
UiUtils.configureColumn(nodeTypeColumn, new
ChildNodeLabelProvider(ChildNodeColumnIndexes.DECLARING_NODE_TYPE),
CndMessages.declaringNodeTypeHeaderText,
CndMessages.declaringNodeTypeToolTip, false, true);
}
+ { // create comment column
+ final TableViewerColumn commentColumn = new
TableViewerColumn(this.childNodeViewer, SWT.RIGHT);
+ UiUtils.configureColumn(commentColumn, new
CommentLabelProvider(this.childNodeViewer), CndMessages.commentedHeaderText,
+ CndMessages.commentedToolTip, false, false);
+ }
+
// this will sort by child node name
this.childNodeViewer.setSorter(new ViewerSorter() {
@@ -686,42 +709,83 @@
rightContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
toolkit.paintBordersFor(rightContainer);
- final Label label = toolkit.createLabel(rightContainer,
CndMessages.supertypesLabel);
- label.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false));
+ { // supertypes
+ final Label label = toolkit.createLabel(rightContainer,
CndMessages.supertypesLabel);
+ label.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false));
- createSuperTypesActions();
+ createSuperTypesActions();
- // add toolbar buttons (add, edit, delete)
- final ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT |
SWT.HORIZONTAL);
- final ToolBar toolBar = toolBarManager.createControl(rightContainer);
- toolBar.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
- toolkit.adapt(toolBar);
+ // add toolbar buttons (add, edit, delete)
+ final ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT |
SWT.HORIZONTAL);
+ final ToolBar toolBar = toolBarManager.createControl(rightContainer);
+ toolBar.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
+ toolkit.adapt(toolBar);
- final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
- toolBar.setCursor(handCursor);
- toolBarManager.add(this.addSuperType);
- toolBarManager.add(this.editSuperType);
- toolBarManager.add(this.deleteSuperType);
- toolBarManager.update(true);
+ final Cursor handCursor = new Cursor(Display.getCurrent(),
SWT.CURSOR_HAND);
+ toolBar.setCursor(handCursor);
+ toolBarManager.add(this.addSuperType);
+ toolBarManager.add(this.editSuperType);
+ toolBarManager.add(this.deleteSuperType);
+ toolBarManager.update(true);
- final Table table = FormUtils.createTable(toolkit, rightContainer);
- table.setHeaderVisible(false);
- table.setLinesVisible(false);
- ((GridData)table.getLayoutData()).horizontalSpan = 2;
- ((GridData)table.getLayoutData()).heightHint = table.getItemHeight() * 4;
- table.setToolTipText(CndMessages.supertypesToolTip);
+ final Table table = FormUtils.createTable(toolkit, rightContainer);
+ table.setHeaderVisible(false);
+ table.setLinesVisible(false);
+ GridData gd = (GridData)table.getLayoutData();
+ gd.horizontalSpan = 2;
+ gd.heightHint = table.getItemHeight() * 4;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(table, 40);
+ table.setToolTipText(CndMessages.supertypesToolTip);
- // table context menu
- final MenuManager menuManager = new MenuManager();
- menuManager.add(new DelegateAction(CndMessages.addSuperTypeMenuText,
this.addSuperType));
- menuManager.add(new DelegateAction(CndMessages.editSuperTypeMenuText,
this.editSuperType));
- menuManager.add(new DelegateAction(CndMessages.deleteSuperTypeMenuText,
this.deleteSuperType));
- table.setMenu(menuManager.createContextMenu(table));
+ // table context menu
+ final MenuManager menuManager = new MenuManager();
+ menuManager.add(new DelegateAction(CndMessages.addSuperTypeMenuText,
this.addSuperType));
+ menuManager.add(new DelegateAction(CndMessages.editSuperTypeMenuText,
this.editSuperType));
+ menuManager.add(new DelegateAction(CndMessages.deleteSuperTypeMenuText,
this.deleteSuperType));
+ table.setMenu(menuManager.createContextMenu(table));
- createSuperTypesViewer(table);
+ createSuperTypesViewer(table);
+ // fill with data from CND
+ refreshSuperTypes();
+ }
+ }
+
+ { // bottom of details section (comments)
+ final Composite commentsContainer =
toolkit.createComposite(detailsContainer);
+ commentsContainer.setLayout(new GridLayout());
+ commentsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
+ ((GridData)commentsContainer.getLayoutData()).horizontalSpan = 2;
+ toolkit.paintBordersFor(commentsContainer);
+
+ final Label lblComment = toolkit.createLabel(commentsContainer,
CndMessages.commentLabel, SWT.NONE);
+ lblComment.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+
+ this.txtComment = toolkit.createText(commentsContainer, null,
Styles.TEXT_STYLE | SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ this.txtComment.setToolTipText(CndMessages.commentedToolTip);
+
+ final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.verticalIndent +=
((GridLayout)detailsContainer.getLayout()).verticalSpacing;
+ gd.heightHint = this.txtComment.getLineHeight() * 3;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(this.txtComment, 80);
+ this.txtComment.setLayoutData(gd);
+
+ this.txtComment.addModifyListener(new ModifyListener() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ @Override
+ public void modifyText( final ModifyEvent e ) {
+ handleCommentChanged(((Text)e.widget).getText());
+ }
+ });
+
// fill with data from CND
- refreshSuperTypes();
+ refreshComments();
}
}
@@ -847,11 +911,27 @@
return namespaceMapping.getPrefix();
}
- return namespaceMapping.getUri();
+ if (this.columnIndex == NamespaceColumnIndexes.URI) {
+ return namespaceMapping.getUri();
+ }
+
+ return Utils.EMPTY_STRING;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText( Object element ) {
+ final NamespaceMapping namespaceMapping = (NamespaceMapping)element;
+ return namespaceMapping.toCndNotation(NotationType.LONG);
+ }
}
this.namespaceViewer = new TableViewer(namespaceTable);
+ ColumnViewerToolTipSupport.enableFor(this.namespaceViewer);
this.namespaceViewer.setContentProvider(new IStructuredContentProvider() {
/**
@@ -932,6 +1012,12 @@
CndMessages.namespaceUriHeaderText,
CndMessages.namespaceUriToolTip, false, true);
}
+ { // create comment column
+ final TableViewerColumn commentColumn = new
TableViewerColumn(this.namespaceViewer, SWT.RIGHT);
+ UiUtils.configureColumn(commentColumn, new
CommentLabelProvider(this.namespaceViewer), CndMessages.commentedHeaderText,
+ CndMessages.commentedToolTip, false, false);
+ }
+
// this will sort by prefix
this.namespaceViewer.setSorter(new ViewerSorter() {
@@ -1037,6 +1123,7 @@
final Table table = FormUtils.createTable(toolkit, viewerContainer);
table.setLinesVisible(false);
+ ((GridData)table.getLayoutData()).widthHint =
UiUtils.convertWidthInCharsToPixels(table, 30);
// table context menu
final MenuManager menuManager = new MenuManager();
@@ -1082,9 +1169,21 @@
return name;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText( Object element ) {
+ final NodeTypeDefinition nodeTypeDefinition =
(NodeTypeDefinition)element;
+ return nodeTypeDefinition.toCndNotation(NotationType.LONG);
+ }
}
this.nodeTypeViewer = new TableViewer(nodeTypeTable);
+ ColumnViewerToolTipSupport.enableFor(this.nodeTypeViewer);
this.nodeTypeViewer.setContentProvider(new IStructuredContentProvider() {
/**
@@ -1424,9 +1523,21 @@
return UiUtils.join(Arrays.asList(constraints), null);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
+ */
+ @Override
+ public String getToolTipText( Object element ) {
+ final PropertyDefinition propertyDefinition =
(PropertyDefinition)element;
+ return propertyDefinition.toCndNotation(NotationType.LONG);
+ }
}
this.propertyViewer = new TableViewer(propertyTable);
+ ColumnViewerToolTipSupport.enableFor(this.propertyViewer);
this.propertyViewer.setContentProvider(new IStructuredContentProvider() {
/**
@@ -1549,6 +1660,12 @@
CndMessages.declaringNodeTypeHeaderText,
CndMessages.declaringNodeTypeToolTip, false, true);
}
+ { // create comment column
+ final TableViewerColumn commentColumn = new
TableViewerColumn(this.propertyViewer, SWT.RIGHT);
+ UiUtils.configureColumn(commentColumn, new
CommentLabelProvider(this.propertyViewer), CndMessages.commentedHeaderText,
+ CndMessages.commentedToolTip, false, false);
+ }
+
// this will sort by property name
this.propertyViewer.setSorter(new ViewerSorter() {
@@ -2063,6 +2180,14 @@
}
}
+ void handleCommentChanged( final String newComment ) {
+ final NodeTypeDefinition nodeType = getSelectedNodeType();
+
+ if (nodeType != null) {
+ nodeType.setComment(newComment);
+ }
+ }
+
void handleDeleteChildNode() {
assert (getSelectedNodeType() != null) : "Delete child node button is
enabled and there is no node type selected"; //$NON-NLS-1$
assert (getSelectedChildNode() != null) : "Delete child node button is
enabled and there is no child node selected"; //$NON-NLS-1$
@@ -2214,8 +2339,6 @@
void handleEditNamespace() {
assert (getSelectedNamespace() != null) : "Edit namespace handler has been
called when there is no namespace selected"; //$NON-NLS-1$
final NamespaceMapping selectedNamespace = getSelectedNamespace();
-
- // TODO if prefix is changed should qualified names with old prefix be
automatically updated?
final NamespaceMappingDialog dialog = new NamespaceMappingDialog(getShell(),
getCnd().getNamespaceMappings(),
selectedNamespace);
@@ -2393,6 +2516,7 @@
refreshNameControls();
refreshAttributeControls();
refreshSuperTypes();
+ refreshComments();
refreshPropertyViewer();
refreshChildNodeViewer();
}
@@ -2540,9 +2664,6 @@
private void populateUi() {
this.namespaceViewer.setInput(this);
-
this.namespaceViewer.getTable().setToolTipText(NLS.bind(CndMessages.namespacesTableToolTip,
getCnd().getNamespaceMappings()
-
.size()));
-
this.nodeTypeViewer.setInput(this);
// size columns to the data
@@ -2711,6 +2832,22 @@
}
}
+ private void refreshComments() {
+ final NodeTypeDefinition nodeTypeDefinition = getSelectedNodeType();
+
+ if (nodeTypeDefinition == null) {
+ if (!Utils.isEmpty(this.txtComment.getText())) {
+ this.txtComment.setText(Utils.EMPTY_STRING);
+ }
+ } else {
+ String comment = nodeTypeDefinition.getComment();
+
+ if (!Utils.equivalent(comment, this.txtComment.getText())) {
+ this.txtComment.setText((comment == null) ? Utils.EMPTY_STRING :
comment);
+ }
+ }
+ }
+
private void refreshNameControls() {
final NodeTypeDefinition nodeTypeDefinition = getSelectedNodeType();
@@ -2726,8 +2863,6 @@
private void refreshNamespaceControls() {
this.namespaceViewer.refresh();
-
this.namespaceViewer.getTable().setToolTipText(NLS.bind(CndMessages.namespacesTableToolTip,
getCnd().getNamespaceMappings()
-
.size()));
}
private void refreshNodeTypeControls() {
@@ -3012,12 +3147,34 @@
interface ChildNodeColumnIndexes {
int ATTRIBUTES = 3;
+ int COMMENTS = 5;
int DECLARING_NODE_TYPE = 4;
int DEFAULT_TYPE = 2;
int NAME = 0;
int REQUIRED_TYPES = 1;
}
+ class CommentLabelProvider extends CheckBoxLabelProvider {
+
+ /**
+ * @param viewer the viewer (cannot be <code>null</code>)
+ */
+ public CommentLabelProvider( final ColumnViewer viewer ) {
+ super(viewer);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.tools.modeshape.ui.viewers.CheckBoxLabelProvider#isChecked(java.lang.Object)
+ */
+ @Override
+ protected boolean isChecked( final Object element ) {
+ final CommentedCndElement cndElement = (CommentedCndElement)element;
+ return !Utils.isEmpty(cndElement.getComment());
+ }
+ }
+
/**
* The memento keys for saving and restoring editor state.
*/
@@ -3030,14 +3187,16 @@
}
interface NamespaceColumnIndexes {
+ int COMMENT = 2;
int PREFIX = 0;
int URI = 1;
}
interface PropertyColumnIndexes {
int ATTRIBUTES = 3;
- int CONSTRAINTS = 4;
- int DECLARING_NODE_TYPE = 5;
+ int COMMENT = 6;
+ int CONSTRAINTS = 5;
+ int DECLARING_NODE_TYPE = 4;
int DEFAULT_VALUES = 2;
int NAME = 0;
int TYPE = 1;
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/CndMessages.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -338,6 +338,21 @@
* The title of the CND prefrence page.
*/
public static String cndPrefPageTitle;
+
+ /**
+ * The column header text indicating if a CND element has a comment.
+ */
+ public static String commentedHeaderText;
+
+ /**
+ * The tool tip message indicating the CND element has a comment.
+ */
+ public static String commentedToolTip;
+
+ /**
+ * A label for a control that shows a CND comment.
+ */
+ public static String commentLabel;
/**
* The column header text of the declaring node type of an item definition.
@@ -896,11 +911,6 @@
public static String namespacePrefixToolTip;
/**
- * The tool tip for a namespace mappings table.
- */
- public static String namespacesTableToolTip;
-
- /**
* The column header text for a namespace URI.
*/
public static String namespaceUriHeaderText;
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/NamespaceMappingDialog.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/NamespaceMappingDialog.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/NamespaceMappingDialog.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -11,6 +11,8 @@
import java.util.Collection;
import java.util.List;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.swt.SWT;
@@ -33,6 +35,7 @@
import org.jboss.tools.modeshape.jcr.Utils;
import org.jboss.tools.modeshape.jcr.WorkspaceRegistry;
import org.jboss.tools.modeshape.jcr.cnd.CndValidator;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.ui.Activator;
import org.jboss.tools.modeshape.jcr.ui.JcrUiConstants;
import org.jboss.tools.modeshape.ui.forms.FormUtils.Styles;
@@ -44,6 +47,8 @@
private Button btnOk;
+ private String comment;
+
/**
* An optional list of existing namespace mappings. When this is non-empty, it is
checked to make sure the prefix and URI being
* edited is not a duplicate.
@@ -95,6 +100,7 @@
this.namespaceBeingEdited = namespaceBeingEdited;
this.prefix = this.namespaceBeingEdited.getPrefix();
this.uri = this.namespaceBeingEdited.getUri();
+ this.comment = this.namespaceBeingEdited.getComment();
// remove the namespace mapping being edited so validating doesn't show it as
a duplicate
this.existingNamespaces.remove(this.namespaceBeingEdited);
@@ -209,6 +215,36 @@
}
});
}
+
+ { // comment
+ final Label lblComment = toolkit.createLabel(body, CndMessages.commentLabel,
SWT.NONE);
+ lblComment.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+
+ Text txtComment = toolkit.createText(body, null, Styles.TEXT_STYLE |
SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ txtComment.setToolTipText(CndMessages.commentedToolTip);
+
+ final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.verticalIndent += ((GridLayout)body.getLayout()).verticalSpacing;
+ gd.heightHint = txtComment.getLineHeight() * 3;
+ txtComment.setLayoutData(gd);
+
+ if (isEditMode() &&
!Utils.isEmpty(this.namespaceBeingEdited.getComment())) {
+
txtComment.setText(CommentedCndElement.Helper.removeCommentCharacters(this.namespaceBeingEdited.getComment()));
+ }
+
+ txtComment.addModifyListener(new ModifyListener() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ @Override
+ public void modifyText( final ModifyEvent e ) {
+ handleCommentChanged(((Text)e.widget).getText());
+ }
+ });
+ }
}
/**
@@ -217,9 +253,16 @@
* @return a namespace mapping representing the dialog changes (never
<code>null</code>)
*/
public NamespaceMapping getNamespaceMapping() {
- return new NamespaceMapping(this.prefix, this.uri);
+ NamespaceMapping namespaceMapping = new NamespaceMapping(this.prefix, this.uri);
+ namespaceMapping.setComment(this.comment);
+ return namespaceMapping;
}
+ void handleCommentChanged( final String newComment ) {
+ this.comment = newComment;
+ updateState();
+ }
+
void handlePrefixChanged( final String newPrefix ) {
this.prefix = newPrefix;
@@ -234,6 +277,7 @@
}
}
} catch (final Exception e) {
+ Activator.getSharedInstance().getLog().log(new Status(IStatus.ERROR,
JcrUiConstants.PLUGIN_ID, null, e));
}
updateState();
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-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/PropertyDialog.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -33,6 +33,8 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
@@ -47,6 +49,7 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
@@ -63,10 +66,12 @@
import org.jboss.tools.modeshape.jcr.attributes.PropertyType;
import org.jboss.tools.modeshape.jcr.attributes.QueryOperators.QueryOperator;
import org.jboss.tools.modeshape.jcr.cnd.CndValidator;
+import org.jboss.tools.modeshape.jcr.cnd.CommentedCndElement;
import org.jboss.tools.modeshape.jcr.ui.Activator;
import org.jboss.tools.modeshape.jcr.ui.JcrUiConstants;
import org.jboss.tools.modeshape.jcr.ui.JcrUiUtils;
import org.jboss.tools.modeshape.ui.UiMessages;
+import org.jboss.tools.modeshape.ui.UiUtils;
import org.jboss.tools.modeshape.ui.actions.DelegateAction;
import org.jboss.tools.modeshape.ui.forms.ErrorMessage;
import org.jboss.tools.modeshape.ui.forms.FormUtils;
@@ -779,9 +784,9 @@
}
}
- { // bottom (default values, value constraints)
+ { // bottom (default values, value constraints, comments)
final Composite bottomContainer = toolkit.createComposite(body);
- bottomContainer.setLayout(new GridLayout(2, true));
+ bottomContainer.setLayout(new GridLayout(2, false));
bottomContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
toolkit.paintBordersFor(bottomContainer);
@@ -812,8 +817,10 @@
final Table table = FormUtils.createTable(toolkit,
defaultValuesContainer);
table.setHeaderVisible(false);
table.setLinesVisible(false);
- ((GridData)table.getLayoutData()).heightHint = table.getItemHeight() *
4;
- ((GridData)table.getLayoutData()).horizontalSpan = 2;
+ GridData gd = (GridData)table.getLayoutData();
+ gd.heightHint = table.getItemHeight() * 4;
+ gd.horizontalSpan = 2;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(table, 40);
table.setToolTipText(CndMessages.defaultValuesToolTip);
this.defaultValuesError.setControl(table);
@@ -857,8 +864,10 @@
final Table table = FormUtils.createTable(toolkit,
valueConstraintsContainer);
table.setHeaderVisible(false);
table.setLinesVisible(false);
- ((GridData)table.getLayoutData()).heightHint = table.getItemHeight() *
4;
- ((GridData)table.getLayoutData()).horizontalSpan = 2;
+ GridData gd = (GridData)table.getLayoutData();
+ gd.heightHint = table.getItemHeight() * 4;
+ gd.horizontalSpan = 2;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(table, 40);
table.setToolTipText(CndMessages.valueConstraintsToolTip);
this.valueConstraintsError.setControl(table);
@@ -874,6 +883,44 @@
// fill with data
this.valueConstraintsViewer.setInput(this);
}
+
+ { // comments
+ final Composite commentsContainer =
toolkit.createComposite(bottomContainer);
+ commentsContainer.setLayout(new GridLayout(2, false));
+ commentsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
+ ((GridData)commentsContainer.getLayoutData()).horizontalSpan = 2;
+ toolkit.paintBordersFor(commentsContainer);
+
+ final Label lblComment = toolkit.createLabel(commentsContainer,
CndMessages.commentLabel, SWT.NONE);
+ lblComment.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+
+ Text txtComment = toolkit.createText(commentsContainer, null,
Styles.TEXT_STYLE | SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ txtComment.setToolTipText(CndMessages.commentedToolTip);
+
+ final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.verticalIndent += ((GridLayout)body.getLayout()).verticalSpacing;
+ gd.heightHint = txtComment.getLineHeight() * 3;
+ gd.widthHint = UiUtils.convertWidthInCharsToPixels(txtComment, 80);
+ txtComment.setLayoutData(gd);
+
+ if (isEditMode() &&
!Utils.isEmpty(this.propertyBeingEdited.getComment())) {
+
txtComment.setText(CommentedCndElement.Helper.removeCommentCharacters(this.propertyBeingEdited.getComment()));
+ }
+
+ txtComment.addModifyListener(new ModifyListener() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ @Override
+ public void modifyText( final ModifyEvent e ) {
+ handleCommentChanged(((Text)e.widget).getText());
+ }
+ });
+ }
}
// must be done after constructor
@@ -1168,6 +1215,10 @@
this.propertyBeingEdited.setAutoCreated(newAutocreated);
}
+ void handleCommentChanged( final String newComment ) {
+ this.propertyBeingEdited.setComment(newComment);
+ }
+
void handleDefaultValueSelected() {
// update button enablements
final boolean enable = (getSelectedDefaultValue() != null);
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-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/cnd/cndMessages.properties 2012-04-21
14:39:01 UTC (rev 40399)
@@ -72,6 +72,9 @@
cndPrefPageDescription = Settings that determine how CND files are formatted.
cndPrefPageMessage = CND Notation
cndPrefPageTitle = CND Notation
+commentedHeaderText = Comments
+commentedToolTip = Indicates if there is an associated comment for the CND element
+commentLabel = Comments:
declaringNodeTypeHeaderText = Declaring Node Type
declaringNodeTypeToolTip = The node type definition that defines the property or child
node
defaultTypeHeaderText = Default Type
@@ -185,7 +188,6 @@
namespacePrefixHeaderText = Prefix
namespacePrefixLabel = Prefix:
namespacePrefixToolTip = The prefix of the namespace mapping. Must be unique within a
CND.
-namespacesTableToolTip = The mappings of prefixes to the namespace URIs used in a JCR
repository. The current number of mappings in this CND is {0}.
namespaceUriHeaderText = URI
namespaceUriToolTip = The URI of the namespace mapping. Must be unique with a CND.
newNamespaceDialogTitle = New Namespace
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr.ui/src/org/jboss/tools/modeshape/jcr/ui/preferences/CndPreferencePage.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -63,17 +63,20 @@
final String content = "<abc =
'http://namespace.com/abc/1.0'>\n" //$NON-NLS-1$
+ "<xyz = 'http://namespace.com/xyz/1.0'>\n"
//$NON-NLS-1$
+ + "/* This is a comment for node type definition abc:NodeType.
*/\n" //$NON-NLS-1$
+ "[abc:NodeType] > abc:ParentType1, abc:ParentType2 abstract
orderable mixin noquery primaryitem abc:propertyABC\n" //$NON-NLS-1$
+ "- abc:propertyABC (STRING) = 'default1',
'default2' mandatory autocreated protected multiple VERSION\n" //$NON-NLS-1$
+ " queryops '=, <>, <, <=, >, >=,
LIKE' nofulltext noqueryorder < 'constraint1', 'constraint2'"
//$NON-NLS-1$
+ "+ abc:node (abc:reqType1, abc:reqType2) = abc:defaultType
mandatory autocreated protected sns version\n" //$NON-NLS-1$
+ "[xyz:NodeTypeX]\n" //$NON-NLS-1$
- + "- xyz:propertyX" //$NON-NLS-1$
+ + "/* This is a comment for property definition xyz:propertyX.
*/\n" //$NON-NLS-1$
+ + "- xyz:propertyX\n" //$NON-NLS-1$
+ "[xyz:NodeTypeY]\n" //$NON-NLS-1$
- + "- xyz:propertyY (LONG)" //$NON-NLS-1$
- + "+ xyz:childNodeY"; //$NON-NLS-1$
+ + "- xyz:propertyY (LONG)\n" //$NON-NLS-1$
+ + "/* This is a comment for child node definition
xyz:childNodeX. */\n" //$NON-NLS-1$
+ + "+ xyz:childNodeY\n"; //$NON-NLS-1$
- CndImporter importer = new CndImporter(true);
+ CndImporter importer = new CndImporter();
Collection<Throwable> problems = new ArrayList<Throwable>();
_previewCnd = importer.importFrom(content, problems, "string");
//$NON-NLS-1$
@@ -142,7 +145,8 @@
this.txtPreview = new Text(previewPanel, SWT.READ_ONLY | SWT.MULTI |
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
this.txtPreview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.txtPreview.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
- ((GridData)this.txtPreview.getLayoutData()).widthHint =
convertWidthInCharsToPixels(120);
+ ((GridData)this.txtPreview.getLayoutData()).widthHint =
convertWidthInCharsToPixels(100);
+ ((GridData)this.txtPreview.getLayoutData()).heightHint =
convertHeightInCharsToPixels(20);
refreshPreview();
}
Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/META-INF/MANIFEST.MF 2012-04-21
12:34:27 UTC (rev 40398)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/META-INF/MANIFEST.MF 2012-04-21
14:39:01 UTC (rev 40399)
@@ -14,5 +14,6 @@
Export-Package: org.jboss.tools.modeshape.ui,
org.jboss.tools.modeshape.ui.actions,
org.jboss.tools.modeshape.ui.forms,
- org.jboss.tools.modeshape.ui.graphics
+ org.jboss.tools.modeshape.ui.graphics,
+ org.jboss.tools.modeshape.ui.viewers
Bundle-Activator: org.jboss.tools.modeshape.ui.Activator
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/UiUtils.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -10,10 +10,14 @@
import java.util.Collection;
import java.util.Iterator;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.TableColumn;
/**
@@ -67,6 +71,21 @@
}
/**
+ * @param control the control whose font will be used during calculation (cannot be
<code>null</code>)
+ * @param numChars the number of characters whose pixel width is being requested
+ * @return the number of pixels corresponding to the width of the given number of
characters
+ */
+ public static int convertWidthInCharsToPixels( Control control,
+ int numChars ) {
+ verifyIsNotNull(control, "control"); //$NON-NLS-1$
+ GC gc = new GC(control);
+ gc.setFont(control.getFont());
+ FontMetrics fontMetrics = gc.getFontMetrics();
+ gc.dispose();
+ return Dialog.convertWidthInCharsToPixels(fontMetrics, numChars);
+ }
+
+ /**
* @param stringBeingChecked the string being checked (can be
<code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
*/
Added:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/viewers/CheckBoxLabelProvider.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/viewers/CheckBoxLabelProvider.java
(rev 0)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/viewers/CheckBoxLabelProvider.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -0,0 +1,93 @@
+/*
+ * 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.ui.viewers;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.modeshape.ui.UiUtils;
+
+/**
+ * Draws a native-looking checkbox.
+ */
+public abstract class CheckBoxLabelProvider extends ColumnLabelProvider {
+
+ private static final String CHECKED_KEY = "CHECKED"; //$NON-NLS-1$
+
+ private static final String UNCHECK_KEY = "UNCHECKED"; //$NON-NLS-1$
+
+ /**
+ * @param viewer the viewer installing this label provider (cannot be
<code>null</code>)
+ */
+ public CheckBoxLabelProvider( final ColumnViewer viewer ) {
+ UiUtils.verifyIsNotNull(viewer, "viewer"); //$NON-NLS-1$
+
+ if (JFaceResources.getImageRegistry().getDescriptor(CHECKED_KEY) == null) {
+ JFaceResources.getImageRegistry().put(UNCHECK_KEY,
createImage(viewer.getControl().getShell(), false));
+ JFaceResources.getImageRegistry().put(CHECKED_KEY,
createImage(viewer.getControl().getShell(), true));
+ }
+ }
+
+ private Image createImage( final Shell shell,
+ final boolean type ) {
+ final Shell s = new Shell(shell, SWT.NO_TRIM);
+ final Button b = new Button(s, SWT.CHECK);
+ b.setSelection(type);
+
+ final Point bsize = b.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ b.setSize(bsize);
+ b.setLocation(0, 0);
+ s.setSize(bsize);
+ s.open();
+
+ final GC gc = new GC(b);
+ final Image image = new Image(shell.getDisplay(), bsize.x, bsize.y);
+ gc.copyArea(image, 0, 0);
+ gc.dispose();
+
+ s.close();
+
+ return image;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Image getImage( final Object element ) {
+ if (isChecked(element)) {
+ return
JFaceResources.getImageRegistry().getDescriptor(CHECKED_KEY).createImage();
+ }
+
+ return
JFaceResources.getImageRegistry().getDescriptor(UNCHECK_KEY).createImage();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText( Object element ) {
+ return UiUtils.EMPTY_STRING;
+ }
+
+ /**
+ * @param element the element being displayed in the viewer (cannot be
<code>null</code>)
+ * @return <code>true</code> if a checked checkbox image should be
returned
+ */
+ protected abstract boolean isChecked( Object element );
+}
Property changes on:
trunk/modeshape/plugins/org.jboss.tools.modeshape.ui/src/org/jboss/tools/modeshape/ui/viewers/CheckBoxLabelProvider.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/ChildNodeDefinitionTest.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -37,7 +37,7 @@
public void beforeEach() {
this.owner = new NodeTypeDefinition();
this.owner.setName(OWNER_NAME.get());
- this.childNodeDefinition = new ChildNodeDefinition(owner);
+ this.childNodeDefinition = new ChildNodeDefinition(this.owner);
}
@Test
@@ -51,6 +51,11 @@
assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
assertEquals(this.childNodeDefinition.hashCode(),
thatChildNodeDefinition.hashCode());
+ this.childNodeDefinition.setComment("comment goes here");
//$NON-NLS-1$
+ thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition,
this.owner);
+ assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
+ assertEquals(this.childNodeDefinition.hashCode(),
thatChildNodeDefinition.hashCode());
+
this.childNodeDefinition.setDefaultPrimaryTypeName(Constants.DEFAULT_TYPE);
thatChildNodeDefinition = ChildNodeDefinition.copy(this.childNodeDefinition,
this.owner);
assertEquals(this.childNodeDefinition, thatChildNodeDefinition);
@@ -96,6 +101,10 @@
that.setName(this.childNodeDefinition.getName());
assertEquals(this.childNodeDefinition, that);
+ this.childNodeDefinition.setComment("comment goes here");
//$NON-NLS-1$
+ that.setComment(this.childNodeDefinition.getComment());
+ assertEquals(this.childNodeDefinition, that);
+
this.childNodeDefinition.setDefaultPrimaryTypeName(Constants.DEFAULT_TYPE);
that.setDefaultPrimaryTypeName(this.childNodeDefinition.getDefaultPrimaryTypeName());
assertEquals(this.childNodeDefinition, that);
@@ -148,6 +157,13 @@
}
@Test
+ public void shouldAllowNullEmptyComment() {
+ this.childNodeDefinition.setComment(null);
+ this.childNodeDefinition.setComment(Utils.EMPTY_STRING);
+
+ }
+
+ @Test
public void shouldChangeAutocreatedPropertyState() {
assertTrue(this.childNodeDefinition.changeState(PropertyName.AUTOCREATED,
Value.IS));
assertEquals(this.childNodeDefinition.getState(PropertyName.AUTOCREATED),
Value.IS);
@@ -255,6 +271,12 @@
}
@Test
+ public void shouldNotChangeCommentToSameValue() {
+ this.childNodeDefinition.setComment("newComment"); //$NON-NLS-1$
+
assertFalse(this.childNodeDefinition.setComment(this.childNodeDefinition.getComment()));
+ }
+
+ @Test
public void shouldNotClearSuperTypesWhenEmpty() {
assertFalse(this.childNodeDefinition.clearRequiredTypes());
}
@@ -353,6 +375,21 @@
}
@Test
+ public void shouldReceiveEventWhenCommentIsChanged() {
+ final Listener l = new Listener();
+ assertTrue(this.childNodeDefinition.addListener(l));
+
+ final String NEW_COMMENT = "comment"; //$NON-NLS-1$
+ this.childNodeDefinition.setComment(NEW_COMMENT);
+
+ assertEquals(NEW_COMMENT, this.childNodeDefinition.getComment());
+ assertEquals(1, l.getCount());
+ assertEquals(PropertyName.COMMENT.toString(), l.getPropertyName());
+ assertEquals(NEW_COMMENT, l.getNewValue());
+ assertNull(l.getOldValue());
+ }
+
+ @Test
public void shouldReceiveEventWhenOnParentVersionIsChanged() {
final Listener l = new Listener();
assertTrue(this.childNodeDefinition.addListener(l));
@@ -386,6 +423,13 @@
}
@Test
+ public void shouldSetComment() {
+ final String NEW_COMMENT = "newComment"; //$NON-NLS-1$
+ assertTrue(this.childNodeDefinition.setComment(NEW_COMMENT));
+ assertEquals(NEW_COMMENT, this.childNodeDefinition.getComment());
+ }
+
+ @Test
public void shouldSetMandatory() {
this.childNodeDefinition.setMandatory(true);
assertTrue(this.childNodeDefinition.isMandatory());
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndImporterTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndImporterTest.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndImporterTest.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -187,7 +187,7 @@
this.problems = new ArrayList<Throwable>();
// Set up the importer ...
- this.importer = new CndImporter(true);
+ this.importer = new CndImporter();
}
private NodeDefinition childDefn( final NodeTypeDefinition nodeType,
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizerTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizerTest.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndTokenizerTest.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -30,7 +30,7 @@
@Before
public void beforeEach() {
- this.tokenizer = new CndTokenizer(false, false);
+ this.tokenizer = new CndTokenizer();
final LinkedList<int[]> tokenValues = new LinkedList<int[]>();
this.tokenFactory = new Tokens() {
@Override
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-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NamespaceMappingTest.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -54,6 +54,11 @@
assertEquals(this.namespaceMapping, thatNamespaceMapping);
assertEquals(this.namespaceMapping.hashCode(), thatNamespaceMapping.hashCode());
+ assertTrue(this.namespaceMapping.setComment("comment goes here"));
//$NON-NLS-1$
+ 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);
@@ -76,6 +81,11 @@
}
@Test
+ public void shouldHaveEmptyCommentAfterConstruction() {
+ assertTrue(Utils.isEmpty(this.namespaceMapping.getComment()));
+ }
+
+ @Test
public void shouldHaveEmptyPrefixAfterConstruction() {
assertTrue(Utils.isEmpty(this.namespaceMapping.getPrefix()));
}
@@ -98,6 +108,13 @@
}
@Test
+ public void shouldNotSetCommentToSameValue() {
+ final String COMMENT = "comment"; //$NON-NLS-1$
+ assertTrue(this.namespaceMapping.setComment(COMMENT));
+ assertFalse(this.namespaceMapping.setComment(COMMENT));
+ }
+
+ @Test
public void shouldNotSetPrefixToSameValue() {
final String PREFIX = "prefix"; //$NON-NLS-1$
assertTrue(this.namespaceMapping.setPrefix(PREFIX));
@@ -112,6 +129,20 @@
}
@Test
+ public void shouldReceivePropertyChangeEventWhenCommentIsChanged() {
+ final Listener l = new Listener();
+ this.namespaceMapping.addListener(l);
+
+ final String OLD_VALUE = this.namespaceMapping.getComment();
+ final String NEW_VALUE = "comment"; //$NON-NLS-1$
+ assertTrue(this.namespaceMapping.setComment(NEW_VALUE));
+ assertEquals(1, l.getCount());
+ assertEquals(NamespaceMapping.PropertyName.COMMENT.toString(),
l.getPropertyName());
+ assertEquals(OLD_VALUE, l.getOldValue());
+ assertEquals(NEW_VALUE, l.getNewValue());
+ }
+
+ @Test
public void shouldReceivePropertyChangeEventWhenPrefixIsChanged() {
final Listener l = new Listener();
this.namespaceMapping.addListener(l);
@@ -140,6 +171,13 @@
}
@Test
+ public void shouldSetComment() {
+ final String COMMENT = "comment"; //$NON-NLS-1$
+ assertTrue(this.namespaceMapping.setComment(COMMENT));
+ assertEquals(COMMENT, this.namespaceMapping.getComment());
+ }
+
+ @Test
public void shouldSetPrefix() {
final String PREFIX = "prefix"; //$NON-NLS-1$
assertTrue(this.namespaceMapping.setPrefix(PREFIX));
@@ -168,19 +206,12 @@
}
@Test
- public void
twoNamespaceMappingsWithDifferentPrefixesAndSameUriShouldHaveDifferentHashCodes() {
- final NamespaceMapping namespace1 = new NamespaceMapping("prefix",
"uri"); //$NON-NLS-1$ //$NON-NLS-2$
- final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix() +
"different", namespace1.getUri()); //$NON-NLS-1$
-
- assertFalse(namespace1.hashCode() == namespace2.hashCode());
- }
-
- @Test
public void twoNamespaceMappingsWithDifferentPrefixesAndSameUriShouldNotBeEqual() {
final NamespaceMapping namespace1 = new NamespaceMapping("prefix",
"uri"); //$NON-NLS-1$ //$NON-NLS-2$
final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix() +
"different", namespace1.getUri()); //$NON-NLS-1$
assertFalse(namespace1.equals(namespace2));
+ assertFalse(namespace1.hashCode() == namespace2.hashCode());
}
@Test
@@ -189,13 +220,17 @@
final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix(),
namespace1.getUri() + "different"); //$NON-NLS-1$
assertFalse(namespace1.equals(namespace2));
+ assertFalse(namespace1.hashCode() == namespace2.hashCode());
}
@Test
- public void
twoNamespaceMappingsWithSamePrefixAndDifferentUrisShouldNotHaveSameHashCode() {
+ public void
twoNamespaceMappingsWithSamePrefixAndSameUriButDifferentCommentShouldNotBeEqual() {
final NamespaceMapping namespace1 = new NamespaceMapping("prefix",
"uri"); //$NON-NLS-1$ //$NON-NLS-2$
- final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix(),
namespace1.getUri() + "different"); //$NON-NLS-1$
+ namespace1.setComment("comment"); //$NON-NLS-1$
+ final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix(),
namespace1.getUri());
+ namespace2.setComment(namespace1.getComment() + "changed");
//$NON-NLS-1$
+ assertFalse(namespace1.equals(namespace2));
assertFalse(namespace1.hashCode() == namespace2.hashCode());
}
@@ -205,13 +240,6 @@
final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix(),
namespace1.getUri());
assertTrue(namespace1.equals(namespace2));
- }
-
- @Test
- public void twoNamespaceMappingsWithSamePrefixAndSameUriShouldHaveSameHashCode() {
- final NamespaceMapping namespace1 = new NamespaceMapping("prefix",
"uri"); //$NON-NLS-1$ //$NON-NLS-2$
- final NamespaceMapping namespace2 = new NamespaceMapping(namespace1.getPrefix(),
namespace1.getUri());
-
assertEquals(namespace1.hashCode(), namespace2.hashCode());
}
}
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-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -49,6 +49,11 @@
assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
assertEquals(this.nodeTypeDefinition.hashCode(),
thatNodeTypeDefinition.hashCode());
+ this.nodeTypeDefinition.setComment("comment goes here"); //$NON-NLS-1$
+ thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
+ assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
+ assertEquals(this.nodeTypeDefinition.hashCode(),
thatNodeTypeDefinition.hashCode());
+
this.nodeTypeDefinition.setAbstract(!this.nodeTypeDefinition.isAbstract());
thatNodeTypeDefinition = NodeTypeDefinition.copy(this.nodeTypeDefinition);
assertEquals(this.nodeTypeDefinition, thatNodeTypeDefinition);
@@ -112,6 +117,13 @@
}
@Test
+ public void shouldAllowNullEmptyComment() {
+ this.nodeTypeDefinition.setComment(null);
+ this.nodeTypeDefinition.setComment(Utils.EMPTY_STRING);
+
+ }
+
+ @Test
public void shouldChangeAbstractPropertyState() {
assertTrue(this.nodeTypeDefinition.changeState(PropertyName.ABSTRACT,
Value.IS));
assertEquals(this.nodeTypeDefinition.getState(PropertyName.ABSTRACT), Value.IS);
@@ -201,6 +213,12 @@
}
@Test
+ public void shouldNotChangeCommentToSameValue() {
+ this.nodeTypeDefinition.setComment("newComment"); //$NON-NLS-1$
+
assertFalse(this.nodeTypeDefinition.setComment(this.nodeTypeDefinition.getComment()));
+ }
+
+ @Test
public void shouldNotHaveChildNodeDefinitionsAfterConstruction() {
assertEquals(0, this.nodeTypeDefinition.getChildNodeDefinitions().size());
}
@@ -358,6 +376,21 @@
}
@Test
+ public void shouldReceiveEventWhenCommentIsChanged() {
+ final Listener l = new Listener();
+ assertTrue(this.nodeTypeDefinition.addListener(l));
+
+ final String NEW_COMMENT = "comment"; //$NON-NLS-1$
+ this.nodeTypeDefinition.setComment(NEW_COMMENT);
+
+ assertEquals(NEW_COMMENT, this.nodeTypeDefinition.getComment());
+ assertEquals(1, l.getCount());
+ assertEquals(PropertyName.COMMENT.toString(), l.getPropertyName());
+ assertEquals(NEW_COMMENT, l.getNewValue());
+ assertNull(l.getOldValue());
+ }
+
+ @Test
public void shouldRemoveChildNodeDefinition() {
assertTrue(this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition));
assertTrue(this.nodeTypeDefinition.removeChildNodeDefinition(this.childNodeDefinition));
@@ -393,6 +426,13 @@
}
@Test
+ public void shouldSetComment() {
+ final String NEW_COMMENT = "newComment"; //$NON-NLS-1$
+ assertTrue(this.nodeTypeDefinition.setComment(NEW_COMMENT));
+ assertEquals(NEW_COMMENT, this.nodeTypeDefinition.getComment());
+ }
+
+ @Test
public void shouldSetMixinProperty() {
this.nodeTypeDefinition.setMixin(true);
assertTrue(this.nodeTypeDefinition.isMixin());
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/PropertyDefinitionTest.java 2012-04-21
14:39:01 UTC (rev 40399)
@@ -52,6 +52,11 @@
assertEquals(this.propDefn, thatPropDefn);
assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
+ this.propDefn.setComment("comment goes here"); //$NON-NLS-1$
+ thatPropDefn = PropertyDefinition.copy(this.propDefn, this.owner);
+ assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
+
this.propDefn.setAvailableQueryOperators(Constants.Helper.getDefaultQueryOperators());
thatPropDefn = PropertyDefinition.copy(this.propDefn, this.owner);
assertEquals(this.propDefn, thatPropDefn);
@@ -117,62 +122,75 @@
public void differentInstancesWithSameValuesShouldBeEqual() {
final PropertyDefinition thatPropDefn = new PropertyDefinition(this.owner);
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setAvailableQueryOperators(Constants.Helper.getDefaultQueryOperators());
thatPropDefn.setAvailableQueryOperators(this.propDefn.getAvailableQueryOperators());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setAutoCreated(!this.propDefn.isAutoCreated());
thatPropDefn.setAutoCreated(this.propDefn.isAutoCreated());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
+ this.propDefn.setComment("comment"); //$NON-NLS-1$
+ thatPropDefn.setComment(this.propDefn.getComment());
+ assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
+
this.propDefn.setDefaultValues(Constants.Helper.getDefaultStringValues());
thatPropDefn.setDefaultValues(this.propDefn.getDefaultValues());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setFullTextSearchable(!this.propDefn.isFullTextSearchable());
thatPropDefn.setFullTextSearchable(this.propDefn.isFullTextSearchable());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setMandatory(!this.propDefn.isMandatory());
thatPropDefn.setMandatory(this.propDefn.isMandatory());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setMultiple(!this.propDefn.isMultiple());
thatPropDefn.setMultiple(this.propDefn.isMultiple());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setName(Constants.QUALIFIED_NAME1.get());
thatPropDefn.setName(this.propDefn.getName());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setOnParentVersion(OnParentVersion.COMPUTE.asJcrValue());
thatPropDefn.setOnParentVersion(this.propDefn.getOnParentVersion());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setProtected(!this.propDefn.isProtected());
thatPropDefn.setProtected(this.propDefn.isProtected());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setQueryOrderable(!this.propDefn.isQueryOrderable());
thatPropDefn.setQueryOrderable(this.propDefn.isQueryOrderable());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setRequiredType(PropertyType.BINARY.asJcrValue());
thatPropDefn.setRequiredType(this.propDefn.getRequiredType());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
this.propDefn.setValueConstraints(Constants.DEFAULT_VALUE_CONSTRAINTS);
thatPropDefn.setValueConstraints(this.propDefn.getValueConstraints());
assertEquals(this.propDefn, thatPropDefn);
+ assertEquals(this.propDefn.hashCode(), thatPropDefn.hashCode());
}
@Test
- public void differentInstancesWithSameValuesShouldHaveSameHashCode() {
- assertEquals(this.propDefn.hashCode(), new
PropertyDefinition(this.owner).hashCode());
- }
-
- @Test
public void onParentVersionDefaultValueShouldBeCopy() {
assertEquals(OnParentVersion.COPY, OnParentVersion.DEFAULT_VALUE);
}
@@ -202,30 +220,24 @@
}
@Test
- public void shouldSupportAllQueryOperatorsInitially() {
- // setup
- String[] queryOps = this.propDefn.getAvailableQueryOperators();
- QueryOperator[] allOperators = QueryOperator.values();
-
- assertEquals(allOperators.length, queryOps.length);
-
- for (String queryOp : queryOps) {
- QueryOperator.find(queryOp); // throws exception if not found
- }
- }
-
- @Test
public void shouldAddValueConstraint() {
- final String CONSTRAINT = "constraint"; //$NON-NLS-1$
+ final String CONSTRAINT = Constants.VALUE_CONSTRAINT1;
assertTrue(this.propDefn.addValueConstraint(CONSTRAINT));
assertEquals(1, this.propDefn.getValueConstraints().length);
assertEquals(CONSTRAINT, this.propDefn.getValueConstraints()[0]);
}
@Test
+ public void shouldAllowNullEmptyComment() {
+ this.propDefn.setComment(null);
+ this.propDefn.setComment(Utils.EMPTY_STRING);
+
+ }
+
+ @Test
public void shouldAllowNullEmptyName() {
this.propDefn.setName(null);
- this.propDefn.setName(""); //$NON-NLS-1$
+ this.propDefn.setName(Utils.EMPTY_STRING);
}
@@ -408,6 +420,12 @@
}
@Test
+ public void shouldNotChangeCommentToSameValue() {
+ this.propDefn.setComment("newComment"); //$NON-NLS-1$
+ assertFalse(this.propDefn.setComment(this.propDefn.getComment()));
+ }
+
+ @Test
public void shouldNotClearDefaultValuesWhenEmpty() {
assertFalse(this.propDefn.clearDefaultValues());
}
@@ -588,6 +606,21 @@
}
@Test
+ public void shouldReceiveEventWhenCommentIsChanged() {
+ final Listener l = new Listener();
+ assertTrue(this.propDefn.addListener(l));
+
+ final String NEW_COMMENT = "comment"; //$NON-NLS-1$
+ this.propDefn.setComment(NEW_COMMENT);
+
+ assertEquals(NEW_COMMENT, this.propDefn.getComment());
+ assertEquals(1, l.getCount());
+ assertEquals(PropertyName.COMMENT.toString(), l.getPropertyName());
+ assertEquals(NEW_COMMENT, l.getNewValue());
+ assertNull(l.getOldValue());
+ }
+
+ @Test
public void shouldReceiveEventWhenNameIsChanged() {
final Listener l = new Listener();
assertTrue(this.propDefn.addListener(l));
@@ -693,6 +726,13 @@
}
@Test
+ public void shouldSetComment() {
+ final String NEW_COMMENT = "newComment"; //$NON-NLS-1$
+ assertTrue(this.propDefn.setComment(NEW_COMMENT));
+ assertEquals(NEW_COMMENT, this.propDefn.getComment());
+ }
+
+ @Test
public void shouldSetDefaultValues() {
assertTrue(this.propDefn.addDefaultValue("defaultValueBeingOverridden"));
//$NON-NLS-1$
@@ -884,4 +924,17 @@
this.propDefn.setValueConstraints(null);
assertEquals(0, this.propDefn.getValueConstraints().length);
}
+
+ @Test
+ public void shouldSupportAllQueryOperatorsInitially() {
+ // setup
+ final String[] queryOps = this.propDefn.getAvailableQueryOperators();
+ final QueryOperator[] allOperators = QueryOperator.values();
+
+ assertEquals(allOperators.length, queryOps.length);
+
+ for (final String queryOp : queryOps) {
+ QueryOperator.find(queryOp); // throws exception if not found
+ }
+ }
}
Modified: trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/aircraft.cnd
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/aircraft.cnd 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/aircraft.cnd 2012-04-21
14:39:01 UTC (rev 40399)
@@ -59,6 +59,6 @@
< '\d{1,3}(,?\d{3})*\s*(lb|kg|gal|L)' // followed by
'lb', 'kg', 'gal', or 'L'
- air:crew (long) < '[0,)' // any
non-negative value
- air:numberBuilt (string) // any integer (with optional
',' every 1000s place)
- < '\d{1,3}(,?\d{3})*\s*[+]?' , // optionally
followed by '+'
- '([<>]\s*)?\d{1,3}(,?\d{3})*' // or prefixed
by '<' or '>'
+ < '\d{1,3}(,?\d{3})*\s*[+]?' ,
+ '([<>]\s*)?\d{1,3}(,?\d{3})*' // optionally
followed by '+' or prefixed by '<' or '>'
- air:url (string)
\ No newline at end of file
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/cnd-reader-test-input.cnd
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/cnd-reader-test-input.cnd 2012-04-21
12:34:27 UTC (rev 40398)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/testdata/cnd-reader-test-input.cnd 2012-04-21
14:39:01 UTC (rev 40399)
@@ -16,23 +16,25 @@
*/
<ex = "http://example.org/jackrabbit/example">
<
jcr='http://www.jcp.org/jcr/1.0'>
-<mix='http://www.jcp.org/jcr/mix/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'> // added since no auto-registering
<
nt='http://www.jcp.org/jcr/nt/1.0'>
// test remapping
<REP='internal'>
-// omit this namespace to test auto-registering
-// <
mix='http://www.jcp.org/jcr/mix/1.0'>
-
//------------------------------------------------------------------------------
// E X A M P L E T Y P E S
//------------------------------------------------------------------------------
[ex:NodeType] > ex:ParentNodeType1, ex:ParentNodeType2
+// node type comment
orderable mixin
- - ex:property (long) = '1', '2' primary mandatory autocreated protected
multiple version < '[1,10]'
- + ex:node (ex:RequiredNodeType1, ex:RequiredNodeType2) = ex:RequiredNodeType1 mandatory
autocreated protected multiple version
+ - ex:property
+ // property comment
+ (long) = '1', '2' primary mandatory autocreated protected multiple
version < '[1,10]'
+ + ex:node
+ // child node comment
+ (ex:RequiredNodeType1, ex:RequiredNodeType2) = ex:RequiredNodeType1 mandatory
autocreated protected multiple version
[ex:AnotherNodeType] > ex:NodeType
- * (string) = 'a residual property' multiple