Search in sources :

Example 56 with NodeDefinition

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

the class SchemaVM method openSelectParentNodePopupForReparent.

private void openSelectParentNodePopupForReparent(final NodeDefinition selectedItem) {
    UIOptions uiOptions = survey.getUIOptions();
    final Set<UITab> assignableTabs = new HashSet<UITab>(uiOptions.getAssignableTabs(editedNodeParentEntity, selectedItem));
    final EntityDefinition selectedItemParentDefn = selectedItem.getParentEntityDefinition();
    UITab inheritedTab = uiOptions.getAssignedTab(selectedItemParentDefn);
    assignableTabs.add(inheritedTab);
    Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

        public boolean evaluate(SurveyObject item) {
            if (item instanceof UITab) {
                return true;
            } else if (item instanceof NodeDefinition) {
                if (item instanceof EntityDefinition) {
                    EntityDefinition entityItemDef = (EntityDefinition) item;
                    if (entityItemDef.isVirtual()) {
                        return false;
                    } else if (selectedItem instanceof EntityDefinition && entityItemDef.isDescendantOf((EntityDefinition) selectedItem)) {
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    };
    Predicate<SurveyObject> disabledPredicate = new Predicate<SurveyObject>() {

        @Override
        public boolean evaluate(SurveyObject item) {
            if (item instanceof UITab) {
                return survey.isPublished() && !assignableTabs.contains(item);
            } else if (item instanceof NodeDefinition) {
                NodeDefinition itemNodeDef = (NodeDefinition) item;
                if (itemNodeDef.equals(selectedItemParentDefn)) {
                    return false;
                } else if (selectedItem instanceof EntityDefinition && itemNodeDef.isDescendantOf((EntityDefinition) selectedItem)) {
                    // is descendant of the selected item
                    return true;
                } else if (!survey.isPublished() && itemNodeDef instanceof EntityDefinition && !itemNodeDef.equals(selectedItem)) {
                    // published
                    return false;
                } else {
                    return true;
                }
            } else {
                // do not allow selecting non-node definitions
                return true;
            }
        }
    };
    String nodeName = editedNode instanceof NodeDefinition ? ((NodeDefinition) editedNode).getName() : "";
    UITab assignedTab = survey.getUIOptions().getAssignedTab((NodeDefinition) editedNode);
    String assignedTabLabel = assignedTab.getLabel(currentLanguageCode);
    String title = Labels.getLabel("survey.schema.move_node_popup_title", new String[] { getNodeTypeHeaderLabel(), nodeName, assignedTabLabel });
    // calculate parent item (tab or entity)
    SchemaTreeNode treeNode = treeModel.getTreeNode(selectedItem);
    TreeNode<SchemaNodeData> parentTreeNode = treeNode.getParent();
    SurveyObject parentItem = parentTreeNode.getData().getSurveyObject();
    final Window popup = SchemaTreePopUpVM.openPopup(title, selectedRootEntity, null, includedNodePredicate, false, true, disabledPredicate, null, parentItem, false);
    popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

        public void onEvent(NodeSelectedEvent event) throws Exception {
            SurveyObject selectedParent = event.getSelectedItem();
            changeEditedNodeParent(selectedParent, false);
            refreshNodeForm();
            closePopUp(popup);
        }
    });
}
Also used : Window(org.zkoss.zul.Window) SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Predicate(org.openforis.collect.designer.util.Predicate) UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData) HashSet(java.util.HashSet)

Example 57 with NodeDefinition

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

the class CollectEarthBalloonGenerator method createComponent.

private CEComponent createComponent(NodeDefinition def, int entityPosition) {
    String label = def.getLabel(Type.INSTANCE, language);
    if (label == null && !isDefaultLanguage()) {
        label = def.getLabel(Type.INSTANCE);
    }
    if (label == null) {
        label = def.getName();
    }
    boolean multiple = def.isMultiple();
    UIOptions uiOptions = survey.getUIOptions();
    boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
    CEComponent comp;
    if (def instanceof EntityDefinition) {
        if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
            comp = createEnumeratedEntityComponent((EntityDefinition) def);
        } else {
            String tooltip = def.getDescription(language);
            CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
            for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
                if (!uiOptions.isHidden(child)) {
                    fieldSet.addChild(createComponent(child));
                }
            }
            comp = fieldSet;
        }
    } else {
        AttributeDefinition attrDef = (AttributeDefinition) def;
        String htmlParameterName;
        boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
        if (insideEnumeratedEntity) {
            htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
        } else {
            htmlParameterName = getHtmlParameterName(def);
        }
        String tooltip = attrDef.getDescription(language);
        CEFieldType type = getFieldType(def);
        boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
        if (insideEnumeratedEntity && key) {
            comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
        } else if (def instanceof CodeAttributeDefinition) {
            CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
            CodeList list = codeAttrDef.getList();
            Integer listLevelIndex = codeAttrDef.getListLevelIndex();
            Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
            CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
            String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
            comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
        } else {
            comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
        }
        CollectAnnotations annotations = survey.getAnnotations();
        if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
            ((CEField) comp).setReadOnly(true);
        }
    }
    comp.hideWhenNotRelevant = hideWhenNotRelevant;
    componentByName.put(comp.getName(), comp);
    return comp;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeList(org.openforis.idm.metamodel.CodeList) CEFieldType(org.openforis.collect.io.metadata.collectearth.balloon.CEField.CEFieldType) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) HashMap(java.util.HashMap) Map(java.util.Map)

Example 58 with NodeDefinition

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

the class UnitsVM method getReferences.

protected List<NodeDefinition> getReferences(Unit item) {
    List<NodeDefinition> references = new ArrayList<NodeDefinition>();
    Schema schema = survey.getSchema();
    List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
    Stack<NodeDefinition> stack = new Stack<NodeDefinition>();
    stack.addAll(rootEntities);
    while (!stack.isEmpty()) {
        NodeDefinition defn = stack.pop();
        if (defn instanceof EntityDefinition) {
            stack.addAll(((EntityDefinition) defn).getChildDefinitions());
        } else if (defn instanceof NumericAttributeDefinition) {
            List<Unit> units = ((NumericAttributeDefinition) defn).getUnits();
            if (units.contains(item)) {
                references.add(defn);
            }
        }
    }
    return references;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) Stack(java.util.Stack)

Example 59 with NodeDefinition

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

the class EditableListOfNodesVM method getChildDefinitionsInTab.

public List<NodeDefinition> getChildDefinitionsInTab(EntityDefinition entityDefn) {
    UIOptions uiOpts = getUIOptions();
    List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitions();
    List<NodeDefinition> result = new ArrayList<NodeDefinition>();
    ModelVersion formVersion = getLayoutFormVersion();
    for (NodeDefinition nodeDefn : childDefinitions) {
        if (formVersion == null || formVersion.isApplicable(nodeDefn)) {
            UITab nodeTab = uiOpts.getAssignedTab(nodeDefn);
            if (nodeTab == tab) {
                result.add(nodeDefn);
            }
        }
    }
    return result;
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Example 60 with NodeDefinition

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

the class EditableListOfNodesVM method getChildDefinitions.

public List<NodeDefinition> getChildDefinitions(EntityDefinition entityDefn) {
    List<NodeDefinition> result = new ArrayList<NodeDefinition>();
    List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitions();
    ModelVersion formVersion = getLayoutFormVersion();
    for (NodeDefinition nodeDefn : childDefinitions) {
        if (formVersion == null || formVersion.isApplicable(nodeDefn)) {
            result.add(nodeDefn);
        }
    }
    return childDefinitions;
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

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