Search in sources :

Example 1 with UITable

use of org.openforis.collect.metamodel.ui.UITable in project collect by openforis.

the class SurveyMigrator method migrate.

public void migrate(final CollectSurvey survey) {
    fixCodeListHierarchyLevelNames(survey);
    if (survey.getCollectVersion().compareTo(ENUMERATE_VERSION) < 0) {
        survey.getSchema().traverse(new NodeDefinitionVisitor() {

            public void visit(NodeDefinition defn) {
                if (defn instanceof EntityDefinition && defn.isMultiple()) {
                    EntityDefinition entityDefn = (EntityDefinition) defn;
                    UIConfiguration uiConfig = survey.getUIConfiguration();
                    if (uiConfig != null) {
                        UIModelObject uiModelObject = uiConfig.getModelObjectByNodeDefinitionId(entityDefn.getId());
                        CollectAnnotations annotations = survey.getAnnotations();
                        if (survey.getTarget() == SurveyTarget.COLLECT_EARTH || uiModelObject == null || uiModelObject instanceof UITable) {
                            if (defn.getMinCountExpression() != null) {
                                annotations.setAutoGenerateMinItems(entityDefn, true);
                            }
                            if (entityDefn.isEnumerable()) {
                                entityDefn.setEnumerate(true);
                            }
                        }
                    }
                }
            }
        });
    }
    survey.setCollectVersion(VERSION);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UIModelObject(org.openforis.collect.metamodel.ui.UIModelObject) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) UITable(org.openforis.collect.metamodel.ui.UITable) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 2 with UITable

use of org.openforis.collect.metamodel.ui.UITable in project collect by openforis.

the class CollectEarthBalloonGenerator method createTabComponent.

private CETab createTabComponent(EntityDefinition rootEntityDef, UIForm form, boolean main) {
    final CollectAnnotations annotations = survey.getAnnotations();
    String label = form.getLabel(language);
    if (label == null && !isDefaultLanguage()) {
        String defaultLanguage = survey.getDefaultLanguage();
        label = form.getLabel(defaultLanguage);
    }
    CETab tab = new CETab(rootEntityDef.getName(), label);
    // consider the first tab as the main one
    tab.setMain(main);
    for (UIFormComponent formComponent : form.getChildren()) {
        if (formComponent instanceof NodeDefinitionUIComponent) {
            NodeDefinition nodeDef = ((NodeDefinitionUIComponent) formComponent).getNodeDefinition();
            if (formComponent instanceof UIField) {
                AttributeDefinition attrDef = ((UIField) formComponent).getAttributeDefinition();
                String nodeName = nodeDef.getName();
                boolean includeInHTML = !(HIDDEN_ATTRIBUTE_NAMES.contains(nodeName) || (annotations.isFromCollectEarthCSV(attrDef) && !annotations.isShowReadOnlyFieldInCollectEarth(attrDef)) || ((UIField) formComponent).isHidden() || ((UIField) formComponent).getAttributeDefinition().isKey());
                boolean includeAsAncillaryData = annotations.isIncludedInCollectEarthHeader((AttributeDefinition) nodeDef);
                if (includeInHTML) {
                    CEComponent component = createComponent(nodeDef);
                    tab.addChild(component);
                } else if (includeAsAncillaryData) {
                    CEAncillaryFields ancillaryDataHeader = tab.getAncillaryDataHeader();
                    if (ancillaryDataHeader == null) {
                        ancillaryDataHeader = new CEAncillaryFields("ancillary_data", "Ancillary data");
                        tab.setAncillaryDataHeader(ancillaryDataHeader);
                    }
                    CEComponent component = createComponent(nodeDef);
                    ancillaryDataHeader.addChild(component);
                }
            } else if (formComponent instanceof UITable || formComponent instanceof UIFormSection) {
                CEComponent component = createComponent(nodeDef);
                tab.addChild(component);
            } else {
                // $NON-NLS-1$
                throw new IllegalArgumentException("Form component not supported: " + formComponent.getClass().getName());
            }
        }
    }
    return tab;
}
Also used : NodeDefinitionUIComponent(org.openforis.collect.metamodel.ui.NodeDefinitionUIComponent) UIFormSection(org.openforis.collect.metamodel.ui.UIFormSection) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) UIField(org.openforis.collect.metamodel.ui.UIField) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) UITable(org.openforis.collect.metamodel.ui.UITable) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) UIFormComponent(org.openforis.collect.metamodel.ui.UIFormComponent)

Aggregations

CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)2 UITable (org.openforis.collect.metamodel.ui.UITable)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 NodeDefinitionUIComponent (org.openforis.collect.metamodel.ui.NodeDefinitionUIComponent)1 UIConfiguration (org.openforis.collect.metamodel.ui.UIConfiguration)1 UIField (org.openforis.collect.metamodel.ui.UIField)1 UIFormComponent (org.openforis.collect.metamodel.ui.UIFormComponent)1 UIFormSection (org.openforis.collect.metamodel.ui.UIFormSection)1 UIModelObject (org.openforis.collect.metamodel.ui.UIModelObject)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)1 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)1 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)1 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)1