Search in sources :

Example 1 with CodeAttributeDefinitionFormObject

use of org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject 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 2 with CodeAttributeDefinitionFormObject

use of org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject 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 3 with CodeAttributeDefinitionFormObject

use of org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject in project collect by openforis.

the class CodeAttributeVM method codeListsPopUpClosed.

@GlobalCommand
public void codeListsPopUpClosed(@ContextParam(ContextType.BINDER) Binder binder, @BindingParam(CodeListsVM.EDITING_ATTRIBUTE_PARAM) Boolean editingAttribute, @BindingParam(CodeListsVM.SELECTED_CODE_LIST_PARAM) CodeList selectedCodeList) {
    if (editingAttribute && selectedCodeList != null) {
        CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) getFormObject();
        CodeList oldList = fo.getList();
        if (oldList != null && !oldList.equals(selectedCodeList)) {
            if (oldList != survey.getSamplingDesignCodeList()) {
                confirmCodeListChange(binder, selectedCodeList);
            }
        } else {
            onListChanged(binder, selectedCodeList);
            validateForm(binder);
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinitionFormObject(org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 4 with CodeAttributeDefinitionFormObject

use of org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject in project collect by openforis.

the class CodeAttributeVM method onListChanged.

@Command
public void onListChanged(@ContextParam(ContextType.BINDER) Binder binder, @BindingParam("list") CodeList list) {
    CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) getFormObject();
    CodeList oldList = fo.getList();
    boolean listChanged = oldList != null && !oldList.equals(list);
    if (oldList == null) {
        performListChange(binder, list);
    } else if (listChanged) {
        if (editedItem.hasDependentCodeAttributeDefinitions()) {
            confirmParentCodeListChange(binder, list);
        } else {
            performListChange(binder, list);
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinitionFormObject(org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 5 with CodeAttributeDefinitionFormObject

use of org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject in project collect by openforis.

the class CodeAttributeVM method performListChange.

private void performListChange(Binder binder, CodeList list) {
    CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) getFormObject();
    CodeList oldList = fo.getList();
    fo.setParentCodeAttributeDefinition(null);
    fo.setList(list);
    setFormFieldValue(binder, "list", list);
    setFormFieldValue(binder, "list.hierarchical", list != null && list.isHierarchical());
    setFormFieldValue(binder, "parentCodeAttributeDefinitionPath", null);
    setFormFieldValue(binder, "hierarchicalLevel", null);
    dispatchApplyChangesCommand(binder);
    notifyChange("dependentCodePaths");
    dispatchCodeListAssignedCommand(list, oldList);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinitionFormObject(org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)

Aggregations

CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)5 CodeList (org.openforis.idm.metamodel.CodeList)4 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)3 Command (org.zkoss.bind.annotation.Command)2 MessageUtil (org.openforis.collect.designer.util.MessageUtil)1 ConfirmParams (org.openforis.collect.designer.util.MessageUtil.ConfirmParams)1 Predicate (org.openforis.collect.designer.util.Predicate)1 NodeSelectedEvent (org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent)1 UITab (org.openforis.collect.metamodel.ui.UITab)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 SurveyObject (org.openforis.idm.metamodel.SurveyObject)1 Window (org.zkoss.zul.Window)1