Search in sources :

Example 6 with SurveyObject

use of org.openforis.idm.metamodel.SurveyObject 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 7 with SurveyObject

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

the class SchemaVM method checkCanAddChildTab.

private boolean checkCanAddChildTab() {
    if (TreeViewType.DATA.name().equalsIgnoreCase(selectedTreeViewType)) {
        MessageUtil.showWarning("survey.schema.unsupported_operation_in_data_view");
        return false;
    } else {
        SurveyObject selectedSurveyObject = selectedTreeNode.getSurveyObject();
        if (selectedSurveyObject instanceof UITab) {
            UITab parentTab = getSelectedNodeParentTab();
            UIOptions uiOptions = survey.getUIOptions();
            if (parentTab != null && uiOptions.isAssociatedWithMultipleEntityForm(parentTab)) {
                MessageUtil.showWarning("survey.schema.cannot_add_nested_tab.form_entity_assosicated");
                return false;
            }
        }
        return true;
    }
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) SurveyObject(org.openforis.idm.metamodel.SurveyObject) UIOptions(org.openforis.collect.metamodel.ui.UIOptions)

Example 8 with SurveyObject

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

the class SchemaTreeModel method setOpenSchemaNodes.

public void setOpenSchemaNodes(Collection<SurveyObject> nodes) {
    Set<SchemaTreeNode> opened = new HashSet<SchemaTreeNode>();
    for (SurveyObject node : nodes) {
        SchemaTreeNode treeNode = getTreeNode(node);
        if (treeNode != null) {
            opened.add(treeNode);
        }
    }
    setOpenObjects(opened);
}
Also used : SurveyObject(org.openforis.idm.metamodel.SurveyObject) HashSet(java.util.HashSet)

Example 9 with SurveyObject

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

the class SchemaTreeModel method getNearestParentEntityDefinition.

public EntityDefinition getNearestParentEntityDefinition(SurveyObject surveyObject) {
    SchemaTreeNode treeNode = getTreeNode(surveyObject);
    SchemaTreeNode parentNode = (SchemaTreeNode) treeNode.getParent();
    while (parentNode != null && parentNode.getData() != null) {
        SurveyObject currentSurveyObject = parentNode.getData().getSurveyObject();
        if (currentSurveyObject instanceof EntityDefinition) {
            return (EntityDefinition) currentSurveyObject;
        }
        parentNode = (SchemaTreeNode) parentNode.getParent();
    }
    // if not found, return root entity
    return rootEntity;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject)

Example 10 with SurveyObject

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

the class SurveyObjectTreeModelCreator method createNode.

public AbstractNode<SchemaNodeData> createNode(SchemaNodeData data, boolean defineEmptyChildrenForLeaves) {
    SchemaTreeNode node = null;
    SurveyObject surveyObject = data.getSurveyObject();
    if (includeNodePredicate == null || includeNodePredicate.evaluate(surveyObject)) {
        List<AbstractNode<SchemaNodeData>> childNodes = createChildNodes(surveyObject);
        // create result
        if (childNodes == null) {
            node = new SchemaTreeNode(data);
        } else if (childNodes.isEmpty()) {
            if (includeEmptyNodes) {
                if (defineEmptyChildrenForLeaves) {
                    node = new SchemaTreeNode(data, Collections.<AbstractNode<SchemaNodeData>>emptyList());
                } else {
                    node = new SchemaTreeNode(data);
                }
            } else {
                node = null;
            }
        } else {
            node = new SchemaTreeNode(data, (List<AbstractNode<SchemaNodeData>>) childNodes);
        }
    }
    if (node != null && disabledNodePredicate != null) {
        if (disabledNodePredicate.evaluate(surveyObject)) {
            node.setDisabled(true);
        }
    }
    return node;
}
Also used : SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) SurveyObject(org.openforis.idm.metamodel.SurveyObject) AbstractNode(org.openforis.collect.designer.component.BasicTreeModel.AbstractNode) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)

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