if (getValue().equals(value)) {
// then ignore this
return;
}
JcrTextPropertyDescriptor pd = (JcrTextPropertyDescriptor) element;
JcrNode jcrNode = getNode();
Map.Entry me = (Entry) pd.getId();
switch(columnId) {
case NAME: {
final String oldKey = String.valueOf(getValue());
final String newKey = String.valueOf(value);
pd.setNewPropertyName(newKey);
Map<String, String> pseudoMap = new HashMap<String, String>();
final String propertyValue = jcrNode.getProperties().getValue(oldKey);
pseudoMap.put(newKey, propertyValue);
final Entry<String, String> mapEntry = pseudoMap.entrySet().iterator().next();
element = new TextPropertyDescriptor(mapEntry, propertyValue);
jcrNode.renameProperty(oldKey, newKey);
break;
}
case TYPE: {
int propertyType = PropertyTypeSupport.propertyTypeOfIndex((Integer)value);
jcrNode.changePropertyType(String.valueOf(me.getKey()), propertyType);
break;
}
case VALUE: {
try{
final JcrProperty property = getNode().getProperty(getPropertyName());
final int propertyType = property.getType();
String encodedValue;
if (property.isMultiple()) {
Object[] values = (Object[])value;
encodedValue = "";
for (int i = 0; i < values.length; i++) {
Object aValue = values[i];
String aValueAsString = PropertyTypeSupport.encodeValueAsString(aValue, propertyType);
if (i==0) {
encodedValue = aValueAsString;
} else {
encodedValue = encodedValue+","+aValueAsString;
}
}
encodedValue = "["+encodedValue+"]";
} else {
encodedValue = PropertyTypeSupport.encodeValueAsString(value, propertyType);
}
if (propertyType!=PropertyType.STRING && propertyType!=PropertyType.NAME) {
encodedValue = "{"+PropertyType.nameFromValue(propertyType)+"}"+encodedValue;
}
jcrNode.setPropertyValue(me.getKey(), encodedValue);
} catch(Exception e) {
// emergency fallback
jcrNode.setPropertyValue(me.getKey(), String.valueOf(value));
}
break;
}
case MULTIPLE: {
if (!(value instanceof Integer)) {
// value must be an integer
return;
}
final Integer newIsMultipleValue = (Integer) value;
final boolean newIsMultiple = newIsMultipleValue==1;
final JcrProperty property = getNode().getProperty(getPropertyName());
final boolean oldIsMultiple = property.isMultiple();
if (newIsMultiple==oldIsMultiple) {
// then nothing is to be done
return;
}
final String oldPropertyValue = getNode().getProperties().getValue(getPropertyName());
// split {type} prefix from value
int cPos = oldPropertyValue.indexOf("}");
final String prefix;
final String rawValue;
if (cPos==-1) {
prefix = "";
rawValue = oldPropertyValue;
} else {
prefix = oldPropertyValue.substring(0, cPos+1);
rawValue = oldPropertyValue.substring(cPos+1);
}
String newValue;
if (newIsMultiple) {
newValue = prefix + "[" + rawValue + "]";
} else {
newValue = rawValue.substring(1, rawValue.length()-1);
int commaPos = newValue.indexOf(",");
if (commaPos!=-1) {
newValue = newValue.substring(0, commaPos);
}
newValue = prefix + newValue;
}
jcrNode.setPropertyValue(getPropertyName(), newValue);
break;
}
}
view.refreshContent();