Search in sources :

Example 16 with UITabSet

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

the class NewSurveyParametersPopUpVM method createEmptySurvey.

protected CollectSurvey createEmptySurvey(String name, String langCode) {
    // create empty survey
    CollectSurvey survey = surveyManager.createTemporarySurvey(name, langCode);
    // add default root entity
    Schema schema = survey.getSchema();
    EntityDefinition rootEntity = schema.createEntityDefinition();
    rootEntity.setMultiple(true);
    rootEntity.setName(SurveyController.DEFAULT_ROOT_ENTITY_NAME);
    schema.addRootEntityDefinition(rootEntity);
    // create root tab set
    UIOptions uiOptions = survey.getUIOptions();
    UITabSet rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntity);
    UITab mainTab = uiOptions.getMainTab(rootTabSet);
    mainTab.setLabel(langCode, SurveyController.DEFAULT_MAIN_TAB_LABEL);
    SurveyObjectsGenerator surveyObjectsGenerator = new SurveyObjectsGenerator();
    surveyObjectsGenerator.addPredefinedObjects(survey);
    return survey;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) 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) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 17 with UITabSet

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

the class EntityDefinitionFormValidator method getAssociatedTab.

protected UITab getAssociatedTab(ValidationContext ctx, UIOptions uiOptions, EntityDefinition parentEntity) {
    String tabName = getValue(ctx, TAB_NAME_FIELD);
    if (parentEntity == null) {
        NodeDefinition editedNode = getEditedNode(ctx);
        UITabSet rootTabSet = uiOptions.getAssignedRootTabSet((EntityDefinition) editedNode);
        if (rootTabSet != null) {
            return uiOptions.getMainTab(rootTabSet);
        } else {
            return null;
        }
    } else {
        if (StringUtils.isNotBlank(tabName)) {
            List<UITab> assignableTabs = uiOptions.getTabsAssignableToChildren(parentEntity);
            for (UITab tab : assignableTabs) {
                if (tab.getName().equals(tabName)) {
                    return tab;
                }
            }
        }
        // inherited tab
        return uiOptions.getAssignedTab(parentEntity);
    }
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 18 with UITabSet

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

the class SurveyController method createEmptySurvey.

private CollectSurvey createEmptySurvey(String name, String langCode) {
    // create empty survey
    CollectSurvey survey = surveyManager.createTemporarySurvey(name, langCode);
    // add default root entity
    Schema schema = survey.getSchema();
    EntityDefinition rootEntity = schema.createEntityDefinition();
    rootEntity.setMultiple(true);
    rootEntity.setName(DEFAULT_ROOT_ENTITY_NAME);
    schema.addRootEntityDefinition(rootEntity);
    // create root tab set
    UIOptions uiOptions = survey.getUIOptions();
    UITabSet rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntity);
    UITab mainTab = uiOptions.getMainTab(rootTabSet);
    mainTab.setLabel(langCode, DEFAULT_MAIN_TAB_LABEL);
    SurveyObjectsGenerator surveyObjectsGenerator = new SurveyObjectsGenerator();
    surveyObjectsGenerator.addPredefinedObjects(survey);
    return survey;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) 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) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 19 with UITabSet

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

the class UITabsTreeModel method getNodePath.

@Override
protected int[] getNodePath(UITabSet item) {
    List<Integer> result = new ArrayList<Integer>();
    UITabSet parent = item.getParent();
    UITabSet currentItem = item;
    while (parent != null) {
        List<UITab> siblings = parent.getTabs();
        int index = siblings.indexOf(currentItem);
        result.add(0, index);
        currentItem = parent;
        parent = currentItem.getParent();
    }
    return toArray(result);
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) ArrayList(java.util.ArrayList)

Example 20 with UITabSet

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

Aggregations

UITabSet (org.openforis.collect.metamodel.ui.UITabSet)20 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 UITab (org.openforis.collect.metamodel.ui.UITab)8 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 Schema (org.openforis.idm.metamodel.Schema)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 ArrayList (java.util.ArrayList)3 SurveyObjectsGenerator (org.openforis.collect.manager.SurveyObjectsGenerator)3 IOException (java.io.IOException)2 SchemaTreeNode (org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode)2 XmlParseException (org.openforis.idm.metamodel.xml.XmlParseException)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 Command (org.zkoss.bind.annotation.Command)2 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)2 NotifyChange (org.zkoss.bind.annotation.NotifyChange)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Stack (java.util.Stack)1 Test (org.junit.Test)1