Search in sources :

Example 6 with CodeAttributeDefinition

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

the class CodeAttribute method getCodeListItem.

/**
 * @deprecated Access code list items using manager class.
 *
 * @return
 */
@Deprecated
public CodeListItem getCodeListItem() {
    Code code = getValue();
    if (code != null) {
        String codeValue = code.getCode();
        if (StringUtils.isNotBlank(codeValue)) {
            ModelVersion currentVersion = getRecord().getVersion();
            CodeAttributeDefinition definition = getDefinition();
            String parentExpression = definition.getParentExpression();
            if (StringUtils.isBlank(parentExpression)) {
                return findCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
            } else {
                CodeAttribute codeParent = getCodeParent();
                if (codeParent != null) {
                    CodeListItem codeListItemParent = codeParent.getCodeListItem();
                    if (codeListItemParent != null) {
                        return findCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
                    }
                }
            }
        }
    }
    return null;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ModelVersion(org.openforis.idm.metamodel.ModelVersion) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 7 with CodeAttributeDefinition

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

the class CodeAttributeDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    String parent = getAttribute(PARENT, false);
    Boolean strict = getBooleanAttribute(STRICT, false);
    String listName = getAttribute(LIST, true);
    Boolean allowValuesSorting = getBooleanAttribute(ALLOW_VALUES_SORTING, false);
    CodeAttributeDefinition defn = (CodeAttributeDefinition) getDefinition();
    defn.setParentExpression(parent);
    defn.setAllowUnlisted(strict == null ? false : !strict);
    defn.setListName(listName);
    defn.setAllowValuesSorting(allowValuesSorting == null ? false : allowValuesSorting.booleanValue());
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 8 with CodeAttributeDefinition

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

the class CodeAttributeVM method openParentAttributeSelector.

@Command
public void openParentAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
    String title = Labels.getLabel("survey.schema.attribute.code.select_parent_for_node", new String[] { editedItem.getName() });
    final Collection<CodeAttributeDefinition> assignableParentAttributes = editedItem.getAssignableParentCodeAttributeDefinitions();
    if (assignableParentAttributes.isEmpty()) {
        MessageUtil.showWarning("survey.schema.attribute.code.no_assignable_parent_available");
    } else {
        CodeAttributeDefinition parentCodeAttributeDefinition = ((CodeAttributeDefinitionFormObject) formObject).getParentCodeAttributeDefinition();
        Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

            @Override
            public boolean evaluate(SurveyObject item) {
                return item instanceof UITab || item instanceof EntityDefinition || item instanceof CodeAttributeDefinition && assignableParentAttributes.contains(item);
            }
        };
        Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {

            @Override
            public boolean evaluate(SurveyObject item) {
                return !(item instanceof CodeAttributeDefinition);
            }
        };
        final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, parentCodeAttributeDefinition, true);
        parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

            public void onEvent(NodeSelectedEvent event) throws Exception {
                CodeAttributeDefinition parentAttrDefn = (CodeAttributeDefinition) event.getSelectedItem();
                CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) formObject;
                fo.setParentCodeAttributeDefinition(parentAttrDefn);
                String hierarchicalLevel = getHierarchicalLevelName(parentAttrDefn);
                fo.setHierarchicalLevel(hierarchicalLevel);
                notifyChange("formObject");
                dispatchApplyChangesCommand(binder);
                notifyChange("dependentCodePaths");
                closePopUp(parentSelectorPopUp);
            }
        });
    }
}
Also used : Window(org.zkoss.zul.Window) CodeAttributeDefinitionFormObject(org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) Predicate(org.openforis.collect.designer.util.Predicate) UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 9 with CodeAttributeDefinition

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

the class CodeAttributeVM method getDependentCodePaths.

public String getDependentCodePaths() {
    if (newItem) {
        return null;
    } else {
        StringBuilder sb = new StringBuilder();
        Collection<CodeAttributeDefinition> dependents = editedItem.getDependentCodeAttributeDefinitions();
        Iterator<CodeAttributeDefinition> it = dependents.iterator();
        while (it.hasNext()) {
            CodeAttributeDefinition dependent = it.next();
            sb.append(dependent.getPath());
            if (it.hasNext()) {
                sb.append(", ");
            }
        }
        return sb.toString();
    }
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Example 10 with CodeAttributeDefinition

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

the class CodeListsVM method getReferences.

protected List<NodeDefinition> getReferences(CodeList 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 CodeAttributeDefinition) {
            CodeList list = ((CodeAttributeDefinition) defn).getList();
            if (list.equals(item)) {
                references.add(defn);
            }
        }
        ;
    }
    return references;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) Stack(java.util.Stack)

Aggregations

CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)48 CodeList (org.openforis.idm.metamodel.CodeList)21 CodeListItem (org.openforis.idm.metamodel.CodeListItem)19 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)13 ArrayList (java.util.ArrayList)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)8 CodeListService (org.openforis.idm.metamodel.CodeListService)8 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)8 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)7 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)7 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)6 ModelVersion (org.openforis.idm.metamodel.ModelVersion)6 Code (org.openforis.idm.model.Code)6 Entity (org.openforis.idm.model.Entity)6 DataTable (org.openforis.collect.relational.model.DataTable)5 CodeAttribute (org.openforis.idm.model.CodeAttribute)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeTable (org.openforis.collect.relational.model.CodeTable)4 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)4