Search in sources :

Example 31 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations 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)

Example 32 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.

the class CollectEarthBalloonGenerator method getHiddenNodeDefinitions.

private List<AttributeDefinition> getHiddenNodeDefinitions() {
    final List<AttributeDefinition> nodesFromCSV = new ArrayList<AttributeDefinition>();
    final CollectAnnotations annotations = survey.getAnnotations();
    Schema schema = survey.getSchema();
    schema.traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition definition) {
            if (definition instanceof AttributeDefinition) {
                AttributeDefinition attrDef = (AttributeDefinition) definition;
                if (annotations.isFromCollectEarthCSV(attrDef) && !annotations.isShowReadOnlyFieldInCollectEarth(attrDef) || attrDef.isKey() && definition.getParentEntityDefinition().isRoot()) {
                    nodesFromCSV.add(attrDef);
                }
            }
        }
    });
    return nodesFromCSV;
}
Also used : Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) 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) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Aggregations

CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)32 CollectSurvey (org.openforis.collect.model.CollectSurvey)21 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)11 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)7 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)7 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)5 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)5 ArrayList (java.util.ArrayList)4 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)4 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)4 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)4 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)4 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)3 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)3 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)3 TextInput (org.openforis.collect.metamodel.CollectAnnotations.TextInput)2 UIConfiguration (org.openforis.collect.metamodel.ui.UIConfiguration)2