Search in sources :

Example 76 with NodeDefinition

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

the class UIOptions method getNodesPerTab.

public List<NodeDefinition> getNodesPerTab(UITab tab, boolean includeDescendants) {
    List<NodeDefinition> result = new ArrayList<NodeDefinition>();
    UITabSet tabSet = tab.getRootTabSet();
    Queue<NodeDefinition> queue = new LinkedList<NodeDefinition>();
    EntityDefinition rootEntity = getRootEntityDefinition(tabSet);
    queue.addAll(rootEntity.getChildDefinitions());
    while (!queue.isEmpty()) {
        NodeDefinition defn = queue.remove();
        UITab nodeTab = getAssignedTab(defn);
        boolean nodeInTab = false;
        if (nodeTab != null && nodeTab.equals(tab)) {
            result.add(defn);
            nodeInTab = true;
        }
        if (defn instanceof EntityDefinition && (includeDescendants || !nodeInTab)) {
            queue.addAll(((EntityDefinition) defn).getChildDefinitions());
        }
    }
    return result;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 77 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition 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)

Example 78 with NodeDefinition

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

the class UIOptions method removeTabAssociation.

public void removeTabAssociation(UITab tab) {
    Deque<UITab> stack = new LinkedList<UITab>();
    stack.push(tab);
    while (!stack.isEmpty()) {
        UITab currentTab = stack.pop();
        List<NodeDefinition> nodesPerTab = getNodesPerTab(currentTab, true);
        for (NodeDefinition nodeDefn : nodesPerTab) {
            performTabAssociationRemoval(nodeDefn);
        }
        List<UITab> childTabs = currentTab.getTabs();
        stack.addAll(childTabs);
    }
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) LinkedList(java.util.LinkedList)

Example 79 with NodeDefinition

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

the class UIOptionsMigrator method findAssignedEntityDefinition.

// protected void createFormFromFormEntity(UITab parentTab, Form parent, EntityDefinition entityDefn) {
// Form form = parent.createForm();
// copyLabels(entityDefn, form);
// form.setEntityId(entityDefn.getId());
// form.setMultiple(true);
// createMainFormSection(form, parentTab.getUIOptions(), entityDefn.getChildDefinitions());
// createInnerForms(parentTab, form);
// parent.addForm(form);
// }
protected EntityDefinition findAssignedEntityDefinition(UITab tab) {
    UIOptions oldUIOptions = tab.getUIOptions();
    List<NodeDefinition> nodesPerTab = oldUIOptions.getNodesPerTab(tab, false);
    if (nodesPerTab.size() == 1) {
        NodeDefinition firstNode = nodesPerTab.get(0);
        if (firstNode instanceof EntityDefinition) {
            return (EntityDefinition) firstNode;
        }
    }
    return null;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 80 with NodeDefinition

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

the class UIOptionsMigrator method createTableHeadingComponent.

protected UITableHeadingComponent createTableHeadingComponent(UITableHeadingContainer parent, NodeDefinition nodeDefn) throws UIOptionsMigrationException {
    UITableHeadingComponent component;
    if (nodeDefn instanceof EntityDefinition) {
        EntityDefinition entityDefn = (EntityDefinition) nodeDefn;
        if (entityDefn.isMultiple()) {
            throw new UIOptionsMigrationException("Nested multiple entity inside table layout entity is not supported: " + nodeDefn.getPath());
        }
        component = parent.createColumnGroup();
        UIColumnGroup columnGroup = (UIColumnGroup) component;
        columnGroup.setEntityDefinition(entityDefn);
        List<NodeDefinition> innerChildDefns = entityDefn.getChildDefinitions();
        for (NodeDefinition innerChildDefn : innerChildDefns) {
            UITableHeadingComponent innerComponent = createTableHeadingComponent(columnGroup, innerChildDefn);
            columnGroup.addHeadingComponent(innerComponent);
        }
    } else {
        component = parent.createColumn();
        ((UIColumn) component).setAttributeDefinition((AttributeDefinition) nodeDefn);
    }
    return component;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8