use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.
the class SchemaVM method isTableEntity.
public boolean isTableEntity(SchemaNodeData data) {
if (isEntity(data)) {
UIOptions uiOptions = survey.getUIOptions();
EntityDefinition entityDefn = (EntityDefinition) data.getSurveyObject();
Layout layout = uiOptions.getLayout(entityDefn);
return layout == Layout.TABLE;
} else {
return false;
}
}
use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.
the class SchemaVM method getEntityIcon.
protected static String getEntityIcon(EntityDefinition entityDefn) {
CollectSurvey survey = (CollectSurvey) entityDefn.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
Layout layout = uiOptions.getLayout(entityDefn);
String icon;
if (entityDefn.isMultiple()) {
switch(layout) {
case TABLE:
icon = "table-small.png";
break;
case FORM:
default:
icon = "form-small.png";
}
} else {
icon = "grouping-small.png";
}
return NODE_TYPES_IMAGES_PATH + icon;
}
use of org.openforis.collect.metamodel.ui.UIOptions.Layout in project collect by openforis.
the class EntityDefinitionFormValidator method validateLayout.
protected void validateLayout(ValidationContext ctx) {
EntityDefinition editedNode = (EntityDefinition) getEditedNode(ctx);
if (editedNode.isVirtual()) {
// skip check
return;
}
String field = LAYOUT_FIELD;
String layoutValue = getValue(ctx, field);
Layout layout = Layout.valueOf(layoutValue);
EntityDefinition parentEntity = getParentEntity(ctx);
CollectSurvey survey = (CollectSurvey) editedNode.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
Boolean multiple = getValue(ctx, MULTIPLE_FIELD);
UITab tab = uiOptions.getAssignedTab(editedNode);
// UITab tab = getAssociatedTab(ctx, uiOptions, parentEntity);
if (tab != null) {
boolean valid = uiOptions.isLayoutSupported(parentEntity, editedNode.getId(), tab, multiple, layout);
if (!valid) {
String message = Labels.getLabel(LabelKeys.LAYOUT_NOT_SUPPORTED_MESSAGE_KEY);
addInvalidMessage(ctx, field, message);
}
} else {
// defining root entity, not yet added to schema...
}
}
use of org.openforis.collect.metamodel.ui.UIOptions.Layout 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.Layout 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";
}
}
Aggregations