Search in sources :

Example 91 with EntityDefinition

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

the class SchemaVM method determineRelatedEntity.

private EntityDefinition determineRelatedEntity(SurveyObject obj) {
    if (obj instanceof UITab) {
        UITab tab = (UITab) obj;
        EntityDefinition newParentEntityDef = tab.getUIOptions().getParentEntityForAssignedNodes(tab);
        return newParentEntityDef;
    } else {
        return (EntityDefinition) obj;
    }
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition)

Example 92 with EntityDefinition

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

the class SchemaVM method changeEditedNodeParent.

private void changeEditedNodeParent(SurveyObject newParent, boolean forceReassignment) {
    EntityDefinition newParentEntityDef = determineRelatedEntity(newParent);
    NodeDefinition editedNodeDef = (NodeDefinition) editedNode;
    if (forceReassignment || editedNodeDef.getParentDefinition() != newParentEntityDef) {
        changeEditedNodeParentEntity(newParentEntityDef);
    }
    if (newParent instanceof UITab) {
        associateNodeToTab(editedNodeDef, (UITab) newParent);
    }
    dispatchSurveyChangedCommand();
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 93 with EntityDefinition

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

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

the class SchemaVM method createRootEntityDefinition.

protected EntityDefinition createRootEntityDefinition() {
    EntityDefinition rootEntity = createEntityDefinition();
    rootEntity.setName(SurveyController.DEFAULT_ROOT_ENTITY_NAME);
    survey.getSchema().addRootEntityDefinition(rootEntity);
    UIOptions uiOptions = survey.getUIOptions();
    rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntity);
    UITab mainTab = uiOptions.getMainTab(rootTabSet);
    mainTab.setLabel(currentLanguageCode, SurveyController.DEFAULT_MAIN_TAB_LABEL);
    notifyChange("rootEntities");
    return rootEntity;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) UIOptions(org.openforis.collect.metamodel.ui.UIOptions)

Example 95 with EntityDefinition

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

the class SurveyBaseVM method getRootEntities.

public List<EntityDefinition> getRootEntities() {
    CollectSurvey survey = getSurvey();
    if (survey == null) {
        // TODO session expired...?
        return Collections.emptyList();
    } else {
        Schema schema = survey.getSchema();
        List<EntityDefinition> result = schema.getRootEntityDefinitions();
        return result;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9