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;
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations