Search in sources :

Example 1 with SchemaTreeNode

use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode 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 2 with SchemaTreeNode

use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode 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)

Example 3 with SchemaTreeNode

use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode in project collect by openforis.

the class UITreeModelCreator method createRootNode.

private SchemaTreeNode createRootNode(EntityDefinition rootEntity) {
    SchemaNodeData data = new SchemaNodeData(rootEntity, rootEntity.getName(), false, false);
    SchemaTreeNode treeNode = (SchemaTreeNode) createNode(data, false);
    return treeNode;
}
Also used : SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)

Example 4 with SchemaTreeNode

use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode in project collect by openforis.

the class UITreeModelCreator method createFirstLevelNodes.

@Override
protected List<AbstractNode<SchemaNodeData>> createFirstLevelNodes(EntityDefinition rootEntity) {
    List<AbstractNode<SchemaNodeData>> firstLevelTreeNodes = new ArrayList<AbstractNode<SchemaNodeData>>();
    if (includeRootEntity) {
        SchemaTreeNode node = createRootNode(rootEntity);
        if (node != null) {
            firstLevelTreeNodes.add(node);
        }
    } else {
        CollectSurvey survey = (CollectSurvey) rootEntity.getSurvey();
        UIOptions uiOptions = survey.getUIOptions();
        UITabSet tabSet = uiOptions.getAssignedRootTabSet(rootEntity);
        for (UITab tab : tabSet.getTabs()) {
            SchemaTreeNode node = createNode(tab);
            if (node != null) {
                firstLevelTreeNodes.add(node);
            }
        }
    }
    return firstLevelTreeNodes;
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) AbstractNode(org.openforis.collect.designer.component.BasicTreeModel.AbstractNode) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)

Example 5 with SchemaTreeNode

use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode in project collect by openforis.

the class UITreeModelCreator method createNodes.

protected List<SchemaTreeNode> createNodes(UITab parentTab, List<? extends NodeDefinition> nodes) {
    List<SchemaTreeNode> result = null;
    if (nodes != null) {
        result = new ArrayList<SchemaTreeNode>();
        for (NodeDefinition nodeDefn : nodes) {
            if (includeNodePredicate == null || includeNodePredicate.evaluate(nodeDefn)) {
                CollectSurvey survey = (CollectSurvey) nodeDefn.getSurvey();
                UIOptions uiOptions = survey.getUIOptions();
                UITab assignedTab = uiOptions.getAssignedTab(nodeDefn);
                if (assignedTab == parentTab && (version == null || version.isApplicable(nodeDefn))) {
                    SchemaNodeData data = new SchemaNodeData(nodeDefn, nodeDefn.getName(), false, false);
                    SchemaTreeNode treeNode = (SchemaTreeNode) createNode(data, false);
                    if (treeNode != null) {
                        result.add(treeNode);
                    }
                }
            }
        }
    }
    return result;
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)

Aggregations

SchemaTreeNode (org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode)12 SchemaNodeData (org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)9 UITab (org.openforis.collect.metamodel.ui.UITab)6 SurveyObject (org.openforis.idm.metamodel.SurveyObject)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 AbstractNode (org.openforis.collect.designer.component.BasicTreeModel.AbstractNode)3 ArrayList (java.util.ArrayList)2 Predicate (org.openforis.collect.designer.util.Predicate)2 NodeSelectedEvent (org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent)2 UITabSet (org.openforis.collect.metamodel.ui.UITabSet)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 Treeitem (org.zkoss.zul.Treeitem)2 Window (org.zkoss.zul.Window)2 HashSet (java.util.HashSet)1 Schema (org.openforis.idm.metamodel.Schema)1 Menupopup (org.zkoss.zul.Menupopup)1