use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class NodeDefinitionFormObject method saveTo.
@Override
public void saveTo(T dest, String languageCode) {
super.saveTo(dest, languageCode);
if (!name.equals(dest.getName())) {
dest.rename(name);
}
dest.setLabel(Type.HEADING, languageCode, headingLabel);
dest.setLabel(Type.INSTANCE, languageCode, instanceLabel);
dest.setLabel(Type.NUMBER, languageCode, numberLabel);
dest.setLabel(Type.ABBREVIATED, languageCode, abbreviatedLabel);
dest.setLabel(Type.REPORTING, languageCode, reportingLabel);
dest.setPrompt(Prompt.Type.HANDHELD, languageCode, handheldPromptLabel);
dest.setPrompt(Prompt.Type.INTERVIEW, languageCode, interviewPromptLabel);
dest.setPrompt(Prompt.Type.PAPER, languageCode, paperPromptLabel);
dest.setPrompt(Prompt.Type.PC, languageCode, pcPromptLabel);
dest.setDescription(languageCode, description);
dest.setMinCountExpression(null);
dest.setMaxCountExpression(null);
dest.setRequiredExpression(null);
CollectSurvey survey = (CollectSurvey) dest.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
annotations.setAutoGenerateMinItems(dest, isMultiple() && StringUtils.isNotBlank(getMinCountExpression()) && autoGenerateMinItems);
if (dest instanceof EntityDefinition && parentDefinition == null) {
// root entity is always true
dest.setMultiple(true);
} else if (!(dest instanceof AttributeDefinition && calculated)) {
dest.setMultiple(multiple);
if (multiple) {
dest.setMinCountExpression(StringUtils.trimToNull(minCountExpression));
dest.setMaxCountExpression(StringUtils.trimToNull(maxCountExpression));
} else {
RequirenessType requirenessTypeEnum = RequirenessType.valueOf(requirenessType);
switch(requirenessTypeEnum) {
case ALWAYS_REQUIRED:
dest.setAlwaysRequired();
break;
case REQUIRED_WHEN:
dest.setRequiredExpression(StringUtils.trimToNull(requiredWhenExpression));
break;
default:
break;
}
}
}
UIOptions uiOptions = survey.getUIOptions();
RelevanceType relevanceTypeEnum = RelevanceType.valueOf(relevanceType);
switch(relevanceTypeEnum) {
case RELEVANT_WHEN:
dest.setRelevantExpression(StringUtils.trimToNull(relevantExpression));
uiOptions.setHideWhenNotRelevant(dest, hideWhenNotRelevant);
break;
default:
dest.setRelevantExpression(null);
uiOptions.setHideWhenNotRelevant(dest, false);
}
if (dest instanceof AttributeDefinition) {
AttributeDefinition attrDef = (AttributeDefinition) dest;
annotations.setFromCollectEarthCSV(attrDef, fromCollectEarthCSV);
annotations.setIncludedInCollectEarthHeader(attrDef, includedInCollectEarthHeader);
annotations.setShowReadOnlyFieldInCollectEarth(attrDef, showReadOnlyFieldInCollectEarth);
annotations.setHideKeyInCollectEarthRecordList(attrDef, hideKeyInCollectEarthRecordList);
annotations.setShowInSummary(attrDef, showInSummary);
annotations.setQualifier(attrDef, qualifier);
}
// layout
uiOptions.setColumn(dest, column);
uiOptions.setColumnSpan(dest, columnSpan);
uiOptions.setWidth(dest, width);
uiOptions.setLabelWidth(dest, labelWidth);
uiOptions.setLabelOrientation(dest, Orientation.valueOf(labelOrientation));
if (dest instanceof Calculable) {
((Calculable) dest).setCalculated(calculated);
// include in data export
annotations.setIncludeInDataExport(dest, includeInDataExport);
// show in ui
uiOptions.setHidden(dest, !showInUI);
}
annotations.setBackgroundColor(dest, backgroundColor);
annotations.setBackgroundAlpha(dest, fromTransparencyToAlpha(backgroundTransparency));
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class AttributeDefinitionFormObject method saveTo.
@Override
public void saveTo(T dest, String languageCode) {
super.saveTo(dest, languageCode);
dest.setKey(key);
// save attribute defaults
dest.removeAllAttributeDefaults();
if (attributeDefaults != null) {
for (AttributeDefault attrDefault : attributeDefaults) {
dest.addAttributeDefault(attrDefault);
}
}
dest.setReferencedAttribute(referencedAttributePath == null ? null : (AttributeDefinition) dest.getSchema().getDefinitionByPath(referencedAttributePath));
CollectSurvey survey = (CollectSurvey) dest.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
annotations.setPhaseToApplyDefaultValue(dest, Step.valueOf(phaseToApplyDefaultValue));
annotations.setEditable(dest, editable);
annotations.setMeasurementAttribute(dest, measurement);
annotations.setShowInMapBalloon(dest, showInMapBalloon);
// save checks
dest.removeAllChecks();
if (checks != null) {
for (Check<?> check : checks) {
dest.addCheck(check);
}
}
UIOptions uiOptions = getUIOptions(dest);
uiOptions.setVisibleFields(dest, visibleFields);
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class UITreeModelCreator method createChildNodes.
private List<AbstractNode<SchemaNodeData>> createChildNodes(EntityDefinition entityDefn) {
List<AbstractNode<SchemaNodeData>> childNodes = new ArrayList<AbstractNode<SchemaNodeData>>();
CollectSurvey survey = (CollectSurvey) entityDefn.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
UITab assignedTab = uiOptions.getAssignedTab(entityDefn);
// include node definitions
List<NodeDefinition> childDefns = entityDefn.getChildDefinitions();
Collection<? extends AbstractNode<SchemaNodeData>> schemaTreeNodes = createNodes(assignedTab, childDefns);
childNodes.addAll(schemaTreeNodes);
// include tabs
if (entityDefn.isMultiple() && uiOptions.getLayout(entityDefn) == Layout.FORM) {
List<UITab> tabs = uiOptions.getTabsAssignableToChildren(entityDefn, false);
Collection<? extends AbstractNode<SchemaNodeData>> tabNodes = createNodes(tabs);
childNodes.addAll(tabNodes);
}
return childNodes;
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class UITreeModelCreator method createChildNodes.
private List<SchemaTreeNode> createChildNodes(UITab tab) {
List<SchemaTreeNode> result = new ArrayList<SchemaTreeNode>();
// add schema node definition tree nodes
UIOptions uiOptions = tab.getUIOptions();
List<NodeDefinition> childDefns = uiOptions.getNodesPerTab(tab, false);
List<SchemaTreeNode> childSchemaNodes = createNodes(tab, childDefns);
result.addAll(childSchemaNodes);
// add children unassigned tab tree nodes
// List<UITab> unassignedTabs = new ArrayList<UITab>();
// UITabSet rootTabSet = tab.getRootTabSet();
// EntityDefinition rootEntity = uiOptions.getRootEntityDefinition(rootTabSet);
//
// for (UITab childTab : tab.getTabs()) {
// boolean unassigned = uiOptions.isUnassigned(childTab, rootEntity);
// if ( unassigned ) {
// unassignedTabs.add(childTab);
// }
// }
// List<SchemaTreeNode> unassignedTabNodes = fromTabsList(unassignedTabs, version, includeAttributes, labelLanguage);
// result.addAll(unassignedTabNodes);
List<UITab> nestedTabs = new ArrayList<UITab>();
for (UITab childTab : tab.getTabs()) {
List<NodeDefinition> nodes = uiOptions.getNodesPerTab(childTab, false);
boolean toBeAdded = true;
for (NodeDefinition nestedTabChildNode : nodes) {
for (NodeDefinition childDefn : childDefns) {
if (childDefn == nestedTabChildNode || (childDefn instanceof EntityDefinition && nestedTabChildNode.isDescendantOf((EntityDefinition) childDefn))) {
toBeAdded = false;
break;
}
}
}
if (toBeAdded) {
nestedTabs.add(childTab);
}
}
Collection<SchemaTreeNode> tabNodes = createNodes(nestedTabs);
result.addAll(tabNodes);
return result;
}
use of org.openforis.collect.metamodel.ui.UIOptions in project collect by openforis.
the class EntityDefinitionFormObject method loadFrom.
@Override
public void loadFrom(T source, String languageCode) {
super.loadFrom(source, languageCode);
virtual = source.isVirtual();
generatorExpression = source.getGeneratorExpression();
enumerate = source.isEnumerate();
UIOptions uiOptions = getUIOptions(source);
Layout layout = uiOptions.getLayout(source);
layoutType = layout.name();
countInRecordSummary = uiOptions.getCountInSumamryListValue(source);
showRowNumbers = uiOptions.getShowRowNumbersValue(source);
direction = uiOptions.getDirection(source).getValue();
}
Aggregations