Search in sources :

Example 11 with CodeList

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

the class CodeAttributeVM method confirmCodeListChange.

private void confirmCodeListChange(final Binder binder, final CodeList list) {
    CodeList oldList = ((CodeAttributeDefinitionFormObject) getFormObject()).getList();
    ConfirmParams confirmParams = new ConfirmParams(new MessageUtil.ConfirmHandler() {

        @Override
        public void onOk() {
            performListChange(binder, list);
        }
    }, "survey.schema.attribute.code.confirm_change_list.message");
    confirmParams.setOkLabelKey("global.change");
    confirmParams.setCancelLabelKey("global.leave_original_value");
    confirmParams.setMessageArgs(new String[] { oldList.getName(), list.getName() });
    MessageUtil.showConfirm(confirmParams);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ConfirmParams(org.openforis.collect.designer.util.MessageUtil.ConfirmParams) CodeAttributeDefinitionFormObject(org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject) MessageUtil(org.openforis.collect.designer.util.MessageUtil)

Example 12 with CodeList

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

Example 13 with CodeList

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

the class CodeListsVM method closeCodeListItemPopUp.

@GlobalCommand
public void closeCodeListItemPopUp(@BindingParam("undoChanges") boolean undoChanges, @BindingParam("imageModified") boolean imageModified, @BindingParam("imageFileWrapper") FileWrapper imageFileWrapper) {
    if (codeListItemPopUp == null) {
        // handling code list from node editor form?
        return;
    }
    closePopUp(codeListItemPopUp);
    codeListItemPopUp = null;
    if (undoChanges) {
        dispatchCurrentFormValidatedCommand(true);
    } else {
        if (newChildItem) {
            addChildItemToCodeList();
        } else {
            dispatchSurveySaveCommand();
            if (editedChildItem instanceof PersistedCodeListItem) {
                codeListManager.save((PersistedCodeListItem) editedChildItem);
            }
            BindUtils.postNotifyChange(null, null, editedChildItem, "*");
        }
        if (imageModified) {
            PersistedCodeListItem persistedItem;
            if (editedChildItem instanceof PersistedCodeListItem) {
                persistedItem = (PersistedCodeListItem) editedChildItem;
            } else {
                CodeList codeList = editedChildItem.getCodeList();
                codeListManager.persistCodeListItems(codeList);
                reloadSelectedItems();
                initItemsPerLevel();
                persistedItem = codeListManager.loadItem(codeList, editedChildItem.getId());
            }
            if (imageFileWrapper == null) {
                codeListManager.deleteImageContent(persistedItem);
            } else {
                codeListManager.saveImageContent(persistedItem, imageFileWrapper);
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 14 with CodeList

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

the class CodeListsVM method createItemInstance.

@Override
protected CodeList createItemInstance() {
    CodeList instance = survey.createCodeList();
    instance.setCodeScope(CodeScope.LOCAL);
    return instance;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList)

Example 15 with CodeList

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

the class CodeListController method exportCodeList.

protected String exportCodeList(HttpServletResponse response, int surveyId, int codeListId) throws IOException {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    CodeList list = survey.getCodeListById(codeListId);
    String fileName = list.getName() + CSV_EXTENSION;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    response.setContentType(CSV_CONTENT_TYPE);
    ServletOutputStream out = response.getOutputStream();
    CodeListExportProcess process = new CodeListExportProcess(codeListManager);
    process.exportToCSV(out, survey, codeListId);
    return "ok";
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ServletOutputStream(javax.servlet.ServletOutputStream) CodeListExportProcess(org.openforis.collect.manager.dataexport.codelist.CodeListExportProcess) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

CodeList (org.openforis.idm.metamodel.CodeList)88 CodeListItem (org.openforis.idm.metamodel.CodeListItem)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)20 ArrayList (java.util.ArrayList)16 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)14 Test (org.junit.Test)10 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)10 HashMap (java.util.HashMap)7 NameValueEntry (org.openforis.collect.model.NameValueEntry)7 CodeListService (org.openforis.idm.metamodel.CodeListService)7 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)6 List (java.util.List)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Code (org.openforis.idm.model.Code)5 Record (org.openforis.idm.model.Record)5 CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)4 CodeListImportProcess (org.openforis.collect.manager.codelistimport.CodeListImportProcess)4