Search in sources :

Example 1 with NodeType

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");
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) MessageUtil(org.openforis.collect.designer.util.MessageUtil) NodeType(org.openforis.collect.designer.metamodel.NodeType) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) FormObject(org.openforis.collect.designer.form.FormObject)

Aggregations

FormObject (org.openforis.collect.designer.form.FormObject)1 NodeType (org.openforis.collect.designer.metamodel.NodeType)1 MessageUtil (org.openforis.collect.designer.util.MessageUtil)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)1 SurveyObject (org.openforis.idm.metamodel.SurveyObject)1