Search in sources :

Example 1 with NodeDefinitionVerifier

use of org.openforis.idm.metamodel.NodeDefinitionVerifier in project collect by openforis.

the class CodeListManager method isInUse.

public boolean isInUse(final CodeList list) {
    Survey survey = list.getSurvey();
    Schema schema = survey.getSchema();
    NodeDefinition attrDefnUsingCodeList = schema.findNodeDefinition(new NodeDefinitionVerifier() {

        @Override
        public boolean verify(NodeDefinition definition) {
            return definition instanceof CodeAttributeDefinition && ((CodeAttributeDefinition) definition).getList() == list;
        }
    });
    return attrDefnUsingCodeList != null;
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVerifier(org.openforis.idm.metamodel.NodeDefinitionVerifier)

Example 2 with NodeDefinitionVerifier

use of org.openforis.idm.metamodel.NodeDefinitionVerifier in project collect by openforis.

the class UIOptions method getParentEntityForAssignedNodes.

public EntityDefinition getParentEntityForAssignedNodes(final UITab tab) {
    UITabSet root = tab.getRootTabSet();
    EntityDefinition rootEntity = getRootEntityDefinition(root);
    if (tab.getDepth() == 1) {
        return rootEntity;
    }
    EntityDefinition tabEntityDefn = rootEntity.getSchema().findNodeDefinition(new NodeDefinitionVerifier() {

        public boolean verify(NodeDefinition nodeDefn) {
            if (nodeDefn instanceof EntityDefinition) {
                EntityDefinition entityDefn = (EntityDefinition) nodeDefn;
                UITab assignedTab = getAssignedTab(entityDefn, false);
                return assignedTab == tab;
            } else {
                return false;
            }
        }
    });
    if (tabEntityDefn != null) {
        return tabEntityDefn;
    } else {
        UITabSet parentTab = tab.getParent();
        if (parentTab != null && parentTab instanceof UITab) {
            return getParentEntityForAssignedNodes((UITab) parentTab);
        } else {
            throw new IllegalStateException("Parent entity for assigned nodes not found for tab: " + tab.getName());
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVerifier(org.openforis.idm.metamodel.NodeDefinitionVerifier)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 NodeDefinitionVerifier (org.openforis.idm.metamodel.NodeDefinitionVerifier)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 Survey (org.openforis.idm.metamodel.Survey)1