Search in sources :

Example 66 with UIOptions

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

the class CollectEarthBalloonGenerator method createEnumeratedEntityComponent.

private CEComponent createEnumeratedEntityComponent(EntityDefinition def) {
    String label = def.getLabel(Type.INSTANCE, language);
    if (label == null && !isDefaultLanguage()) {
        label = def.getLabel(Type.INSTANCE);
    }
    if (label == null) {
        label = def.getName();
    }
    UIOptions uiOptions = survey.getUIOptions();
    String tableTooltip = def.getDescription(language);
    CEEnumeratedEntityTable ceTable = new CEEnumeratedEntityTable(def.getName(), label, tableTooltip);
    for (NodeDefinition child : def.getChildDefinitions()) {
        if (!uiOptions.isHidden(child)) {
            String heading = child.getLabel(Type.INSTANCE, language);
            if (heading == null && !isDefaultLanguage()) {
                heading = child.getLabel(Type.INSTANCE);
            }
            if (heading == null) {
                heading = child.getName();
            }
            ceTable.addHeading(heading);
        }
    }
    CodeAttributeDefinition enumeratingCodeAttribute = def.getEnumeratingKeyCodeAttribute();
    CodeListService codeListService = def.getSurvey().getContext().getCodeListService();
    List<CodeListItem> codeItems = codeListService.loadRootItems(enumeratingCodeAttribute.getList());
    int codeItemIdx = 0;
    for (CodeListItem item : codeItems) {
        String key = item.getCode();
        String itemLabel = CEComponentHTMLFormatter.getItemLabel(item, language);
        String tooltip = CEComponentHTMLFormatter.getDescription(item, language);
        CETableRow row = new CETableRow(key, itemLabel, tooltip);
        for (NodeDefinition child : def.getChildDefinitions()) {
            if (!uiOptions.isHidden(child)) {
                row.addChild(createComponent(child, codeItemIdx + 1));
            }
        }
        ceTable.addRow(row);
        codeItemIdx++;
    }
    return ceTable;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 67 with UIOptions

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

Example 68 with UIOptions

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

the class SurveyCreator method createTemporarySimpleSurvey.

private CollectSurvey createTemporarySimpleSurvey(String name, List<SimpleCodeList> simpleCodeLists) {
    CollectSurvey survey = surveyManager.createTemporarySurvey(name, languageCode);
    for (int codeListIdx = 0; codeListIdx < simpleCodeLists.size(); codeListIdx++) {
        SimpleCodeList simpleCodeList = simpleCodeLists.get(codeListIdx);
        CodeList codeList = survey.createCodeList();
        codeList.setName("values_" + (codeListIdx + 1));
        codeList.setLabel(CodeListLabel.Type.ITEM, survey.getDefaultLanguage(), simpleCodeList.getName());
        List<ListItem> items = simpleCodeList.getItems();
        for (int itemIdx = 0; itemIdx < items.size(); itemIdx++) {
            ListItem paramItem = items.get(itemIdx);
            CodeListItem item = codeList.createItem(1);
            // specified code or item index
            item.setCode(ObjectUtils.defaultIfNull(paramItem.getCode(), String.valueOf(itemIdx + 1)));
            item.setLabel(languageCode, paramItem.getLabel());
            item.setColor(paramItem.getColor());
            codeList.addItem(item);
        }
        survey.addCodeList(codeList);
    }
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.createEntityDefinition();
    rootEntityDef.setName(singleAttributeSurveyRootEntityName);
    schema.addRootEntityDefinition(rootEntityDef);
    CodeAttributeDefinition idAttrDef = schema.createCodeAttributeDefinition();
    idAttrDef.setName(singleAttributeSurveyKeyAttributeName);
    idAttrDef.setKey(true);
    idAttrDef.setList(survey.getSamplingDesignCodeList());
    rootEntityDef.addChildDefinition(idAttrDef);
    TextAttributeDefinition operatorAttrDef = schema.createTextAttributeDefinition();
    operatorAttrDef.setName(singleAttributeSurveyOperatorAttributeName);
    operatorAttrDef.setKey(true);
    operatorAttrDef.setLabel(Type.INSTANCE, languageCode, singleAttributeSurveyOperatorAttributeLabel);
    survey.getAnnotations().setMeasurementAttribute(operatorAttrDef, true);
    rootEntityDef.addChildDefinition(operatorAttrDef);
    EntityDefinition secondLevelEntityDef = schema.createEntityDefinition();
    secondLevelEntityDef.setName(singleAttributeSurveySecondLevelEntityName);
    secondLevelEntityDef.setMultiple(true);
    rootEntityDef.addChildDefinition(secondLevelEntityDef);
    CodeAttributeDefinition secondLevelIdAttrDef = schema.createCodeAttributeDefinition();
    secondLevelIdAttrDef.setName(singleAttributeSurveySecondLevelIdAttributeName);
    secondLevelIdAttrDef.setKey(true);
    secondLevelIdAttrDef.setList(survey.getSamplingDesignCodeList());
    secondLevelIdAttrDef.setParentCodeAttributeDefinition(idAttrDef);
    secondLevelEntityDef.addChildDefinition(secondLevelIdAttrDef);
    for (int i = 0; i < simpleCodeLists.size(); i++) {
        String codeListName = "values_" + (i + 1);
        CodeList codeList = survey.getCodeList(codeListName);
        CodeAttributeDefinition valueAttrDef = schema.createCodeAttributeDefinition();
        valueAttrDef.setName(codeListName);
        valueAttrDef.setList(codeList);
        secondLevelEntityDef.addChildDefinition(valueAttrDef);
    }
    // create root tab set
    UIOptions uiOptions = survey.getUIOptions();
    UITabSet rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntityDef);
    UITab mainTab = uiOptions.getMainTab(rootTabSet);
    mainTab.setLabel(languageCode, singleAttributeSurveyTabLabel);
    UIConfiguration uiConfiguration = new UIOptionsMigrator().migrateToUIConfiguration(uiOptions);
    survey.setUIConfiguration(uiConfiguration);
    SurveyObjectsGenerator surveyObjectsGenerator = new SurveyObjectsGenerator();
    surveyObjectsGenerator.addPredefinedObjects(survey);
    if (survey.getSamplingDesignCodeList() == null) {
        survey.addSamplingDesignCodeList();
    }
    return survey;
}
Also used : Schema(org.openforis.idm.metamodel.Schema) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) SurveyObjectsGenerator(org.openforis.collect.manager.SurveyObjectsGenerator) UIOptionsMigrator(org.openforis.collect.metamodel.ui.UIOptionsMigrator) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) SimpleCodeList(org.openforis.collect.metamodel.SimpleSurveyCreationParameters.SimpleCodeList) SimpleCodeList(org.openforis.collect.metamodel.SimpleSurveyCreationParameters.SimpleCodeList) CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) ListItem(org.openforis.collect.metamodel.SimpleSurveyCreationParameters.ListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 69 with UIOptions

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

the class AttributeDefinitionProxy method getVisibleFieldIndexes.

@ExternalizedProperty
public List<Integer> getVisibleFieldIndexes() {
    List<Integer> result = new ArrayList<Integer>();
    UIOptions uiOptions = getUIOptions();
    String[] fieldNames = uiOptions.getVisibleFields(attributeDefinition);
    for (String fieldName : fieldNames) {
        int fieldIdx = attributeDefinition.getFieldNames().indexOf(fieldName);
        if (fieldIdx < 0) {
            throw new IllegalStateException(String.format("Field %s not found in attribute definition %s", fieldName, attributeDefinition.getName()));
        }
        result.add(fieldIdx);
    }
    return result;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Aggregations

UIOptions (org.openforis.collect.metamodel.ui.UIOptions)69 CollectSurvey (org.openforis.collect.model.CollectSurvey)38 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)22 UITab (org.openforis.collect.metamodel.ui.UITab)19 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)18 Layout (org.openforis.collect.metamodel.ui.UIOptions.Layout)10 ArrayList (java.util.ArrayList)9 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)9 UITabSet (org.openforis.collect.metamodel.ui.UITabSet)9 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)5 Schema (org.openforis.idm.metamodel.Schema)5 Command (org.zkoss.bind.annotation.Command)5 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)5 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)4 SchemaNodeData (org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)4 SchemaTreeNode (org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode)4 SurveyObjectsGenerator (org.openforis.collect.manager.SurveyObjectsGenerator)3 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)3 SurveyObject (org.openforis.idm.metamodel.SurveyObject)3