public String addElement() throws ObjectLockedException, ObjectExistsException {
CustomTreeNode tnb = (CustomTreeNode) this.metadataTreeModel.getNode();
ViewElement selectedViewElement = (ViewElement) tnb.getContent();
String elementName = selectedViewElement.getSelectedNamedChildElementName();
for (Iterator childTypesIt = selectedViewElement.getNamedChildElementTypes().iterator(); childTypesIt.hasNext(); ) {
ElementType currentElementType = (ElementType) childTypesIt.next();
if (currentElementType.getName().equals(elementName)) {
if (currentElementType.getType().equals(NodesTypes.PREFIX + MetadataDao.VALUE_ELEMENT_HOLDER)) {
Element element = DefaultElementImpl.createEmptyValueHolder(selectedViewElement.getMetadataParent(), selectedViewElement);
element.setName(elementName);
List elements = selectedViewElement.getElements();
if (elements == null) {
elements = new ArrayList();
}
//Insert after last same name
int pos = 0;
boolean found = false;
for (Iterator elementsIt = elements.iterator(); elementsIt.hasNext(); pos++) {
Element currentElement = (Element) elementsIt.next();
if (currentElement.getName().compareToIgnoreCase(element.getName()) == 0) {
found = true;
} else if (found) {
break;
}
}
selectedViewElement.getElements().add(pos, element);
} else {
Element element = new DefaultElementImpl(selectedViewElement.getMetadataParent(), selectedViewElement);
element.setName(elementName);
selectedViewElement.getElements().add(element);
}
break;
}
}
MetadataDao.createInstance().update(selectedViewElement.getMetadataParent());
this.metadataTreeModel = getMetadataTreeNode();
return "";
}