Search in sources :

Example 6 with CodeListItem

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

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

the class CodeListsVM method closeCodeListImportPopUp.

@GlobalCommand
public void closeCodeListImportPopUp() {
    closePopUp(codeListImportPopUp);
    codeListImportPopUp = null;
    if (editedItem != null) {
        boolean hasMultipleLevels = editedItem.getHierarchy().size() > 1;
        Type type = hasMultipleLevels ? Type.HIERARCHICAL : Type.FLAT;
        CodeListFormObject fo = (CodeListFormObject) formObject;
        fo.setType(type.name());
        selectedItemsPerLevel = new ArrayList<CodeListItem>();
        initItemsPerLevel();
        notifyChange("formObject", "listLevels", "selectedItemsPerLevel");
    }
}
Also used : Type(org.openforis.collect.designer.form.CodeListFormObject.Type) ContextType(org.zkoss.bind.annotation.ContextType) CodeListFormObject(org.openforis.collect.designer.form.CodeListFormObject) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 8 with CodeListItem

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

the class CodeListsVM method moveChildItem.

@Command
public void moveChildItem(@ContextParam(ContextType.TRIGGER_EVENT) DropEvent event) {
    Listitem dragged = (Listitem) event.getDragged();
    Listitem dropped = (Listitem) event.getTarget();
    CodeListItem draggedItem = dragged.getValue();
    CodeListItem droppedItem = dropped.getValue();
    int indexTo = getItemIndex(droppedItem);
    moveChildItem(draggedItem, indexTo);
}
Also used : Listitem(org.zkoss.zul.Listitem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 9 with CodeListItem

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

the class CodeListItemFormValidator method validateCodeUniqueness.

protected boolean validateCodeUniqueness(ValidationContext ctx) {
    SurveyObjectBaseVM<CodeListItem> viewModel = getVM(ctx);
    CodeListItem editedItem = viewModel.getEditedItem();
    String code = (String) getValue(ctx, CODE_FIELD);
    CodeListItem existingItem = getExistingCodeListItem(ctx, code);
    if (existingItem != null && existingItem.getId() != editedItem.getId()) {
        String message = Labels.getLabel(CODE_ALREADY_DEFINED_MESSAGE_KEY);
        addInvalidMessage(ctx, CODE_FIELD, message);
        return false;
    } else {
        return true;
    }
}
Also used : CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 10 with CodeListItem

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

the class CodeListController method toViews.

private List<CodeListItemView> toViews(List<CodeListItem> items) {
    List<CodeListItemView> views = new ArrayList<CodeListItemView>(items.size());
    for (CodeListItem item : items) {
        CodeListItemView view = new CodeListItemView();
        view.setCode(item.getCode());
        view.setLabel(item.getLabel());
        views.add(view);
    }
    return views;
}
Also used : ArrayList(java.util.ArrayList) CodeListItemView(org.openforis.collect.metamodel.view.CodeListItemView) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

CodeListItem (org.openforis.idm.metamodel.CodeListItem)69 CodeList (org.openforis.idm.metamodel.CodeList)26 ArrayList (java.util.ArrayList)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)19 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)18 CodeListService (org.openforis.idm.metamodel.CodeListService)13 List (java.util.List)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 ModelVersion (org.openforis.idm.metamodel.ModelVersion)7 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)5 Entity (org.openforis.idm.model.Entity)5 Record (org.openforis.idm.model.Record)5 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeAttribute (org.openforis.idm.model.CodeAttribute)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3