Search in sources :

Example 21 with SurveyObject

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

the class AttributeVM method openReferencedAttributeSelector.

@Command
public void openReferencedAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
    ReferenceableKeyAttributeHelper referenceableKeyAttributeHelper = new ReferenceableKeyAttributeHelper(editedItem);
    final Set<EntityDefinition> referenceableEntityDefinitions = referenceableKeyAttributeHelper.determineReferenceableEntities();
    final Set<AttributeDefinition> selectableAttributes = referenceableKeyAttributeHelper.determineReferenceableAttributes();
    if (selectableAttributes.isEmpty()) {
        MessageUtil.showWarning("survey.schema.attribute.no_referenceable_attributes_available");
    } else {
        Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

            public boolean evaluate(SurveyObject item) {
                EntityDefinition parentEntity;
                if (item instanceof UITab) {
                    parentEntity = survey.getUIOptions().getParentEntityForAssignedNodes((UITab) item);
                } else {
                    parentEntity = ((NodeDefinition) item).getParentEntityDefinition();
                }
                for (EntityDefinition entityDef : referenceableEntityDefinitions) {
                    if (parentEntity == entityDef || parentEntity.isAncestorOf(entityDef)) {
                        return true;
                    }
                }
                return false;
            }
        };
        Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {

            public boolean evaluate(SurveyObject item) {
                return !selectableAttributes.contains(item);
            }
        };
        String title = Labels.getLabel("survey.schema.attribute.select_attribute_referenced_by", new String[] { editedItem.getName() });
        final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, editedItem.getReferencedAttribute(), true);
        parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

            public void onEvent(NodeSelectedEvent event) throws Exception {
                AttributeDefinition referencedAttribute = (AttributeDefinition) event.getSelectedItem();
                AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
                fo.setReferencedAttributePath(referencedAttribute == null ? null : referencedAttribute.getPath());
                notifyChange("formObject");
                dispatchApplyChangesCommand(binder);
                closePopUp(parentSelectorPopUp);
            }
        });
    }
}
Also used : Window(org.zkoss.zul.Window) AttributeDefinitionFormObject(org.openforis.collect.designer.form.AttributeDefinitionFormObject) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Predicate(org.openforis.collect.designer.util.Predicate) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) SurveyObject(org.openforis.idm.metamodel.SurveyObject) ReferenceableKeyAttributeHelper(org.openforis.collect.manager.validation.SurveyValidator.ReferenceableKeyAttributeHelper) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 22 with SurveyObject

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

the class SurveyErrorsPopUpVM method openPopUp.

public static Window openPopUp(String title, String message, List<? extends SurveyObject> nodesWithErrors, final ConfirmHandler confirmHandler, boolean hideCancelButton) {
    List<SurveyObjectError> errors = createErrors(nodesWithErrors);
    Map<String, Object> args = new HashMap<String, Object>();
    args.put("title", title);
    args.put("message", message);
    args.put("errors", errors);
    args.put("hideCancelButton", hideCancelButton);
    Window result = PopUpUtil.openPopUp(Resources.Component.CONFIRM_SURVEY_ERRORS_POPUP.getLocation(), true, args);
    initEventListeners(result, confirmHandler);
    return result;
}
Also used : Window(org.zkoss.zul.Window) HashMap(java.util.HashMap) SurveyObject(org.openforis.idm.metamodel.SurveyObject)

Example 23 with SurveyObject

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

the class SurveyErrorsPopUpVM method createErrors.

protected static List<SurveyObjectError> createErrors(List<? extends SurveyObject> items) {
    List<SurveyObjectError> errors = new ArrayList<SurveyErrorsPopUpVM.SurveyObjectError>();
    for (SurveyObject item : items) {
        String path = null;
        String message = null;
        if (item instanceof NodeDefinition) {
            path = ((NodeDefinition) item).getPath();
        } else if (item instanceof CodeList) {
            path = ((CodeList) item).getName();
        } else if (item instanceof CodeListItem) {
            CodeListItem codeListItem = (CodeListItem) item;
            path = getPath(codeListItem);
        }
        SurveyObjectError error = new SurveyObjectError(path, message);
        errors.add(error);
    }
    return errors;
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) SurveyObject(org.openforis.idm.metamodel.SurveyObject) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

SurveyObject (org.openforis.idm.metamodel.SurveyObject)23 UITab (org.openforis.collect.metamodel.ui.UITab)10 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)9 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)7 SchemaNodeData (org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)6 Window (org.zkoss.zul.Window)6 SchemaTreeNode (org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode)5 Predicate (org.openforis.collect.designer.util.Predicate)5 NodeSelectedEvent (org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent)5 Command (org.zkoss.bind.annotation.Command)5 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)4 HashSet (java.util.HashSet)3 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)3 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)3 ArrayList (java.util.ArrayList)2 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)2 TreeNode (org.zkoss.zul.TreeNode)2 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 AbstractNode (org.openforis.collect.designer.component.BasicTreeModel.AbstractNode)1