use of org.openforis.collect.designer.metamodel.NodeType in project collect by openforis.
the class SchemaVM method removeNodeDefinition.
protected void removeNodeDefinition(final NodeDefinition nodeDefn) {
String confirmMessageKey;
Object[] extraMessageArgs = null;
if (nodeDefn instanceof EntityDefinition && !((EntityDefinition) nodeDefn).getChildDefinitions().isEmpty()) {
confirmMessageKey = CONFIRM_REMOVE_NON_EMPTY_ENTITY_MESSAGE_KEY;
} else if (nodeDefn.hasDependencies()) {
confirmMessageKey = CONFIRM_REMOVE_NODE_WITH_DEPENDENCIES_MESSAGE_KEY;
} else if (nodeDefn instanceof AttributeDefinition && !((AttributeDefinition) nodeDefn).getReferencingAttributes().isEmpty()) {
confirmMessageKey = CONFIRM_REMOVE_REFERENCED_ATTRIBUTE_MESSAGE_KEY;
List<String> referencedAttrNames = org.openforis.commons.collection.CollectionUtils.project(((AttributeDefinition) nodeDefn).getReferencingAttributes(), "name");
extraMessageArgs = new String[] { StringUtils.join(referencedAttrNames, ", ") };
} else {
confirmMessageKey = CONFIRM_REMOVE_NODE_MESSAGE_KEY;
}
NodeType type = NodeType.valueOf(nodeDefn);
String typeLabel = type.getLabel().toLowerCase(Locale.ENGLISH);
boolean isRootEntity = nodeDefn.getParentDefinition() == null;
if (isRootEntity) {
typeLabel = Labels.getLabel("survey.schema.root_entity");
}
Object[] messageArgs = new String[] { typeLabel, nodeDefn.getName() };
if (extraMessageArgs != null) {
messageArgs = ArrayUtils.addAll(messageArgs, extraMessageArgs);
}
Object[] titleArgs = new String[] { typeLabel };
MessageUtil.showConfirm(new MessageUtil.ConfirmHandler() {
@Override
public void onOk() {
performRemoveNode(nodeDefn);
}
}, confirmMessageKey, messageArgs, CONFIRM_REMOVE_NODE_TITLE_KEY, titleArgs, "global.remove_item", "global.cancel");
}
Aggregations