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);
}
});
}
}
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);
}
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);
}
}
}
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);
}
}
}
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);
}
Aggregations