Search in sources :

Example 6 with Layout

use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.

the class SchemaVM method isTableEntity.

public boolean isTableEntity(SchemaNodeData data) {
    if (isEntity(data)) {
        UIOptions uiOptions = survey.getUIOptions();
        EntityDefinition entityDefn = (EntityDefinition) data.getSurveyObject();
        Layout layout = uiOptions.getLayout(entityDefn);
        return layout == Layout.TABLE;
    } else {
        return false;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Layout(org.openforis.collect.metamodel.ui.UIOptions.Layout) UIOptions(org.openforis.collect.metamodel.ui.UIOptions)

Example 7 with Layout

use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.

the class SchemaVM method getEntityIcon.

protected static String getEntityIcon(EntityDefinition entityDefn) {
    CollectSurvey survey = (CollectSurvey) entityDefn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    Layout layout = uiOptions.getLayout(entityDefn);
    String icon;
    if (entityDefn.isMultiple()) {
        switch(layout) {
            case TABLE:
                icon = "table-small.png";
                break;
            case FORM:
            default:
                icon = "form-small.png";
        }
    } else {
        icon = "grouping-small.png";
    }
    return NODE_TYPES_IMAGES_PATH + icon;
}
Also used : Layout(org.openforis.collect.metamodel.ui.UIOptions.Layout) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 8 with Layout

use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.

the class EntityDefinitionFormValidator method validateLayout.

protected void validateLayout(ValidationContext ctx) {
    EntityDefinition editedNode = (EntityDefinition) getEditedNode(ctx);
    if (editedNode.isVirtual()) {
        // skip check
        return;
    }
    String field = LAYOUT_FIELD;
    String layoutValue = getValue(ctx, field);
    Layout layout = Layout.valueOf(layoutValue);
    EntityDefinition parentEntity = getParentEntity(ctx);
    CollectSurvey survey = (CollectSurvey) editedNode.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    Boolean multiple = getValue(ctx, MULTIPLE_FIELD);
    UITab tab = uiOptions.getAssignedTab(editedNode);
    // UITab tab = getAssociatedTab(ctx, uiOptions, parentEntity);
    if (tab != null) {
        boolean valid = uiOptions.isLayoutSupported(parentEntity, editedNode.getId(), tab, multiple, layout);
        if (!valid) {
            String message = Labels.getLabel(LabelKeys.LAYOUT_NOT_SUPPORTED_MESSAGE_KEY);
            addInvalidMessage(ctx, field, message);
        }
    } else {
    // defining root entity, not yet added to schema...
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) Layout(org.openforis.collect.metamodel.ui.UIOptions.Layout) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 9 with Layout

use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.

the class SurveyValidator method validateEntity.

protected List<SurveyValidationResult> validateEntity(EntityDefinition entityDef) {
    List<SurveyValidationResult> results = new ArrayList<SurveyValidator.SurveyValidationResult>();
    List<NodeDefinition> childDefinitions = entityDef.getChildDefinitions();
    if (childDefinitions.size() == 0) {
        // empty entity
        results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.empty_entity"));
    }
    if (entityDef.isMultiple()) {
        UIOptions uiOptions = ((CollectSurvey) entityDef.getSurvey()).getUIOptions();
        EntityDefinition parentEntity = entityDef.getParentEntityDefinition();
        if (parentEntity != null && parentEntity.isMultiple()) {
            Layout layout = uiOptions.getLayout(entityDef);
            Layout parentLayout = uiOptions.getLayout(parentEntity);
            if (TABLE == layout && TABLE == parentLayout) {
                results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.nested_tables"));
            }
        }
    }
    if (entityDef.isVirtual()) {
        String generatorExpression = entityDef.getGeneratorExpression();
        String sourceEntityPath = Path.getAbsolutePath(generatorExpression);
        EntityDefinition sourceEntityDef = (EntityDefinition) entityDef.getParentDefinition().getDefinitionByPath(sourceEntityPath);
        for (NodeDefinition sourceChildDef : sourceEntityDef.getChildDefinitions()) {
            boolean skipNode = sourceChildDef instanceof AttributeDefinition && ((AttributeDefinition) sourceChildDef).getReferencedAttribute() != null;
            if (!skipNode) {
                if (entityDef.containsChildDefinition(sourceChildDef.getName())) {
                    NodeDefinition foundChildDef = entityDef.getChildDefinition(sourceChildDef.getName());
                    if (foundChildDef.getClass() != sourceChildDef.getClass()) {
                        results.add(new SurveyValidationResult(Flag.ERROR, entityDef.getPath(), "survey.validation.entity.error.invalid_virtual_node_type", foundChildDef.getName()));
                    }
                } else {
                    results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.missing_virtual_node", sourceChildDef.getName()));
                }
            }
        }
        for (NodeDefinition virtualChildDef : entityDef.getChildDefinitions()) {
            if (!sourceEntityDef.containsChildDefinition(virtualChildDef.getName())) {
                results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.source_node_not_found_for_virtual_node", virtualChildDef.getName(), sourceEntityDef.getName()));
            }
        }
    }
    return results;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Layout(org.openforis.collect.metamodel.ui.UIOptions.Layout) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 10 with Layout

use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.

the class EditableListOfNodesVM method getTemplateName.

public String getTemplateName(NodeDefinition nodeDefn) {
    if (nodeDefn instanceof EntityDefinition) {
        if (nodeDefn.isMultiple()) {
            UIOptions uiOpts = getUIOptions();
            Layout layout = uiOpts.getLayout((EntityDefinition) nodeDefn);
            switch(layout) {
                case FORM:
                    return "multiple_entity_form";
                default:
                    return "multiple_entity_table";
            }
        } else {
            return "entity";
        }
    } else {
        return "attribute";
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Layout(org.openforis.collect.metamodel.ui.UIOptions.Layout) UIOptions(org.openforis.collect.metamodel.ui.UIOptions)

Aggregations

UIOptions (org.openforis.collect.metamodel.ui.UIOptions)10 Layout (org.openforis.collect.metamodel.ui.UIOptions.Layout)10 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 ArrayList (java.util.ArrayList)1 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)1 Direction (org.openforis.collect.metamodel.ui.UIOptions.Direction)1 UITab (org.openforis.collect.metamodel.ui.UITab)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1 TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)1 Command (org.zkoss.bind.annotation.Command)1 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)1 NotifyChange (org.zkoss.bind.annotation.NotifyChange)1