use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class CalculatedAttributeDefinitionFormObject method saveTo.
@Override
public void saveTo(T dest, String languageCode) {
super.saveTo(dest, languageCode);
dest.setType(Type.valueOf(type));
dest.setFormulas(formulas);
CollectSurvey survey = (CollectSurvey) dest.getSurvey();
// include in data export
CollectAnnotations annotations = survey.getAnnotations();
annotations.setIncludeInDataExport(dest, includeInDataExport);
// show in ui
UIOptions uiOptions = survey.getUIOptions();
uiOptions.setShowInUI(dest, showInUI);
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class CalculatedAttributeDefinitionFormObject method loadFrom.
@Override
public void loadFrom(T source, String languageCode) {
super.loadFrom(source, languageCode);
Type typeEnum = source.getType();
type = typeEnum.name();
formulas = new ArrayList<CalculatedAttributeDefinition.Formula>(source.getFormulas());
CollectSurvey survey = (CollectSurvey) source.getSurvey();
// show in UI
UIOptions uiOptions = survey.getUIOptions();
showInUI = uiOptions.isShownInUI(source);
CollectAnnotations annotations = survey.getAnnotations();
includeInDataExport = annotations.isIncludedInDataExport(source);
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class SurveyValidator method validateEntity.
protected List<SurveyValidationResult> validateEntity(EntityDefinition entityDef) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidator.SurveyValidationResult>();
List<NodeDefinition> childDefinitions = entityDef.getChildDefinitions();
if (childDefinitions.size() == 0) {
// empty entity
results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.empty_entity"));
}
if (entityDef.isMultiple()) {
UIOptions uiOptions = ((CollectSurvey) entityDef.getSurvey()).getUIOptions();
EntityDefinition parentEntity = entityDef.getParentEntityDefinition();
if (parentEntity != null && parentEntity.isMultiple()) {
Layout layout = uiOptions.getLayout(entityDef);
Layout parentLayout = uiOptions.getLayout(parentEntity);
if (TABLE == layout && TABLE == parentLayout) {
results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.nested_tables"));
}
}
}
if (entityDef.isVirtual()) {
String generatorExpression = entityDef.getGeneratorExpression();
String sourceEntityPath = Path.getAbsolutePath(generatorExpression);
EntityDefinition sourceEntityDef = (EntityDefinition) entityDef.getParentDefinition().getDefinitionByPath(sourceEntityPath);
for (NodeDefinition sourceChildDef : sourceEntityDef.getChildDefinitions()) {
boolean skipNode = sourceChildDef instanceof AttributeDefinition && ((AttributeDefinition) sourceChildDef).getReferencedAttribute() != null;
if (!skipNode) {
if (entityDef.containsChildDefinition(sourceChildDef.getName())) {
NodeDefinition foundChildDef = entityDef.getChildDefinition(sourceChildDef.getName());
if (foundChildDef.getClass() != sourceChildDef.getClass()) {
results.add(new SurveyValidationResult(Flag.ERROR, entityDef.getPath(), "survey.validation.entity.error.invalid_virtual_node_type", foundChildDef.getName()));
}
} else {
results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.missing_virtual_node", sourceChildDef.getName()));
}
}
}
for (NodeDefinition virtualChildDef : entityDef.getChildDefinitions()) {
if (!sourceEntityDef.containsChildDefinition(virtualChildDef.getName())) {
results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.source_node_not_found_for_virtual_node", virtualChildDef.getName(), sourceEntityDef.getName()));
}
}
}
return results;
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class CollectTaxonVernacularLanguageValidator method evaluate.
/**
* Returns:
* - OK if vernacular name, language code and language variety are all blank or all specified or
* vernacular name is specified and language code and language variety are not visible in the UI
* - ERROR if vernacular name is specified but language code not
* - WARNING if vernacular name is specified and reason blank for language code is specified too
*/
@Override
public ValidationResultFlag evaluate(TaxonAttribute attribute) {
TaxonAttributeDefinition defn = attribute.getDefinition();
CollectSurvey survey = (CollectSurvey) defn.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
boolean vernacularNameBlank = StringUtils.isBlank(attribute.getVernacularName());
boolean langCodeBlank = StringUtils.isBlank(attribute.getLanguageCode());
boolean langCodeVisible = uiOptions.isVisibleField(defn, TaxonAttributeDefinition.LANGUAGE_CODE_FIELD_NAME);
boolean langVarietyBlank = StringUtils.isBlank(attribute.getLanguageVariety());
if ((vernacularNameBlank && langCodeBlank && langVarietyBlank) || (!vernacularNameBlank && !(langCodeVisible && langCodeBlank))) {
return ValidationResultFlag.OK;
} else {
CollectRecord record = (CollectRecord) attribute.getRecord();
Step step = record.getStep();
if (step == Step.ENTRY && langCodeBlank && FieldSymbol.isReasonBlankSpecified(attribute.getLanguageCodeField())) {
return ValidationResultFlag.WARNING;
} else {
return ValidationResultFlag.ERROR;
}
}
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class CollectEarthBalloonGenerator method generateRootComponent.
private CETabSet generateRootComponent() {
EntityDefinition rootEntityDef = getRootEntity();
UIOptions uiOptions = survey.getUIOptions();
UIConfiguration uiConfiguration = survey.getUIConfiguration();
if (uiConfiguration == null) {
// $NON-NLS-1$
throw new IllegalStateException("Error unmarshalling the survey - no UI configruration!");
}
if (uiConfiguration.getFormSets().isEmpty()) {
// no ui configuration defined
// $NON-NLS-1$ //$NON-NLS-2$
CETabSet tabSet = new CETabSet("", "");
// $NON-NLS-1$
CETab tab = new CETab(rootEntityDef.getName(), "");
for (NodeDefinition childDef : rootEntityDef.getChildDefinitions()) {
if (!uiOptions.isHidden(childDef)) {
tab.addChild(createComponent(childDef));
}
}
tabSet.addTab(tab);
return tabSet;
} else {
// $NON-NLS-1$ //$NON-NLS-2$
CETabSet tabSet = new CETabSet("", "");
UIFormSet formSet = uiConfiguration.getMainFormSet();
for (UIForm form : formSet.getForms()) {
boolean main = tabSet.getTabs().isEmpty();
CETab tab = createTabComponent(rootEntityDef, form, main);
tabSet.addTab(tab);
}
return tabSet;
}
}
Aggregations