Search in sources :

Example 1 with Predicate

use of org.openforis.collect.designer.util.Predicate 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 Predicate

use of org.openforis.collect.designer.util.Predicate in project collect by openforis.

the class SchemaVM method openSelectParentNodePopupForReparent.

private void openSelectParentNodePopupForReparent(final NodeDefinition selectedItem) {
    UIOptions uiOptions = survey.getUIOptions();
    final Set<UITab> assignableTabs = new HashSet<UITab>(uiOptions.getAssignableTabs(editedNodeParentEntity, selectedItem));
    final EntityDefinition selectedItemParentDefn = selectedItem.getParentEntityDefinition();
    UITab inheritedTab = uiOptions.getAssignedTab(selectedItemParentDefn);
    assignableTabs.add(inheritedTab);
    Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

        public boolean evaluate(SurveyObject item) {
            if (item instanceof UITab) {
                return true;
            } else if (item instanceof NodeDefinition) {
                if (item instanceof EntityDefinition) {
                    EntityDefinition entityItemDef = (EntityDefinition) item;
                    if (entityItemDef.isVirtual()) {
                        return false;
                    } else if (selectedItem instanceof EntityDefinition && entityItemDef.isDescendantOf((EntityDefinition) selectedItem)) {
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    };
    Predicate<SurveyObject> disabledPredicate = new Predicate<SurveyObject>() {

        @Override
        public boolean evaluate(SurveyObject item) {
            if (item instanceof UITab) {
                return survey.isPublished() && !assignableTabs.contains(item);
            } else if (item instanceof NodeDefinition) {
                NodeDefinition itemNodeDef = (NodeDefinition) item;
                if (itemNodeDef.equals(selectedItemParentDefn)) {
                    return false;
                } else if (selectedItem instanceof EntityDefinition && itemNodeDef.isDescendantOf((EntityDefinition) selectedItem)) {
                    // is descendant of the selected item
                    return true;
                } else if (!survey.isPublished() && itemNodeDef instanceof EntityDefinition && !itemNodeDef.equals(selectedItem)) {
                    // published
                    return false;
                } else {
                    return true;
                }
            } else {
                // do not allow selecting non-node definitions
                return true;
            }
        }
    };
    String nodeName = editedNode instanceof NodeDefinition ? ((NodeDefinition) editedNode).getName() : "";
    UITab assignedTab = survey.getUIOptions().getAssignedTab((NodeDefinition) editedNode);
    String assignedTabLabel = assignedTab.getLabel(currentLanguageCode);
    String title = Labels.getLabel("survey.schema.move_node_popup_title", new String[] { getNodeTypeHeaderLabel(), nodeName, assignedTabLabel });
    // calculate parent item (tab or entity)
    SchemaTreeNode treeNode = treeModel.getTreeNode(selectedItem);
    TreeNode<SchemaNodeData> parentTreeNode = treeNode.getParent();
    SurveyObject parentItem = parentTreeNode.getData().getSurveyObject();
    final Window popup = SchemaTreePopUpVM.openPopup(title, selectedRootEntity, null, includedNodePredicate, false, true, disabledPredicate, null, parentItem, false);
    popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

        public void onEvent(NodeSelectedEvent event) throws Exception {
            SurveyObject selectedParent = event.getSelectedItem();
            changeEditedNodeParent(selectedParent, false);
            refreshNodeForm();
            closePopUp(popup);
        }
    });
}
Also used : Window(org.zkoss.zul.Window) SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Predicate(org.openforis.collect.designer.util.Predicate) UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData) HashSet(java.util.HashSet)

Example 3 with Predicate

use of org.openforis.collect.designer.util.Predicate in project collect by openforis.

the class SchemaAttributesImportVM method openParentEntitySelectionButton.

@Command
public void openParentEntitySelectionButton() {
    Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

        public boolean evaluate(SurveyObject item) {
            return item instanceof UITab || item instanceof EntityDefinition;
        }
    };
    Predicate<SurveyObject> selectableNodePredicate = new Predicate<SurveyObject>() {

        public boolean evaluate(SurveyObject item) {
            return item instanceof EntityDefinition;
        }
    };
    String title = Labels.getLabel("survey.schema.attributes_import.select_entity.popup.title");
    // calculate parent item (tab or entity)
    final Window popup = SchemaTreePopUpVM.openPopup(title, parentEntityDefinition.getRootEntity(), null, includedNodePredicate, true, true, null, selectableNodePredicate, parentEntityDefinition, false);
    popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

        public void onEvent(NodeSelectedEvent event) throws Exception {
            SurveyObject selectedParent = event.getSelectedItem();
            parentEntityDefinition = (EntityDefinition) selectedParent;
            notifyChange("parentEntityDefinitionPath");
            closePopUp(popup);
        }
    });
}
Also used : Window(org.zkoss.zul.Window) UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) ParseException(java.text.ParseException) Predicate(org.openforis.collect.designer.util.Predicate) Command(org.zkoss.bind.annotation.Command)

Example 4 with Predicate

use of org.openforis.collect.designer.util.Predicate in project collect by openforis.

the class SchemaVM method openSelectParentNodePopupForDuplicate.

private void openSelectParentNodePopupForDuplicate(final NodeDefinition node) {
    Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

        @Override
        public boolean evaluate(SurveyObject item) {
            return item instanceof UITab || item instanceof EntityDefinition;
        }
    };
    Predicate<SurveyObject> disabledPredicate = new Predicate<SurveyObject>() {

        @Override
        public boolean evaluate(SurveyObject item) {
            return !(item instanceof UITab || item instanceof EntityDefinition);
        }
    };
    String nodeName = node.getName();
    UITab assignedTab = survey.getUIOptions().getAssignedTab((NodeDefinition) node);
    String assignedTabLabel = assignedTab.getLabel(currentLanguageCode);
    String title = Labels.getLabel("survey.schema.duplicate_node_popup_title", new String[] { getNodeTypeHeaderLabel(), nodeName, assignedTabLabel });
    // calculate parent item (tab or entity)
    SchemaTreeNode treeNode = treeModel.getTreeNode(node);
    TreeNode<SchemaNodeData> parentTreeNode = treeNode.getParent();
    SurveyObject parentItem = parentTreeNode.getData().getSurveyObject();
    final Window popup = SchemaTreePopUpVM.openPopup(title, selectedRootEntity, null, includedNodePredicate, false, true, disabledPredicate, null, parentItem, false);
    popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

        public void onEvent(NodeSelectedEvent event) throws Exception {
            SurveyObject selectedParent = event.getSelectedItem();
            duplicateEditedNodeInto(node, selectedParent);
            closePopUp(popup);
        }
    });
}
Also used : Window(org.zkoss.zul.Window) SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) 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) SurveyObject(org.openforis.idm.metamodel.SurveyObject) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)

Example 5 with Predicate

use of org.openforis.collect.designer.util.Predicate 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)

Aggregations

Predicate (org.openforis.collect.designer.util.Predicate)5 NodeSelectedEvent (org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent)5 UITab (org.openforis.collect.metamodel.ui.UITab)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 SurveyObject (org.openforis.idm.metamodel.SurveyObject)5 Window (org.zkoss.zul.Window)5 Command (org.zkoss.bind.annotation.Command)3 SchemaNodeData (org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)2 SchemaTreeNode (org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode)2 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)2 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 AttributeDefinitionFormObject (org.openforis.collect.designer.form.AttributeDefinitionFormObject)1 CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)1 ReferenceableKeyAttributeHelper (org.openforis.collect.manager.validation.SurveyValidator.ReferenceableKeyAttributeHelper)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1