use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FormRenderer method renderHeaderRow.
private int renderHeaderRow(Appendable writer, Map<String, Object> context) throws IOException {
int maxNumOfColumns = 0;
// We will render one title/column for all the fields with the same name
// in this model: we can have more fields with the same name when use-when
// conditions are used or when a form is extended or when the fields are
// automatically retrieved by a service or entity definition.
List<ModelFormField> tempFieldList = new LinkedList<>();
tempFieldList.addAll(modelForm.getFieldList());
for (int j = 0; j < tempFieldList.size(); j++) {
ModelFormField modelFormField = tempFieldList.get(j);
for (int i = j + 1; i < tempFieldList.size(); i++) {
ModelFormField curField = tempFieldList.get(i);
if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
tempFieldList.remove(i--);
}
}
}
// ===========================
// Preprocessing
// ===========================
// We get a sorted (by position, ascending) set of lists;
// each list contains all the fields with that position.
Collection<List<ModelFormField>> fieldListsByPosition = this.getFieldListsByPosition(tempFieldList);
// this list will contain maps, each one containing the list of fields for a position
List<Map<String, List<ModelFormField>>> fieldRowsByPosition = new LinkedList<>();
for (List<ModelFormField> mainFieldList : fieldListsByPosition) {
int numOfColumns = 0;
List<ModelFormField> innerDisplayHyperlinkFieldsBegin = new LinkedList<>();
List<ModelFormField> innerFormFields = new LinkedList<>();
List<ModelFormField> innerDisplayHyperlinkFieldsEnd = new LinkedList<>();
// render title for each field, except hidden & ignored, etc
// start by rendering all display and hyperlink fields, until we
// get to a field that should go into the form cell, then render
// the form cell with all non-display and non-hyperlink fields, then
// do a start after the first form input field and
// render all display and hyperlink fields after the form
// prepare the two lists of display and hyperlink fields
// the fields in the first list will be rendered as columns before the
// combined column for the input fields; the fields in the second list
// will be rendered as columns after it
boolean inputFieldFound = false;
for (ModelFormField modelFormField : mainFieldList) {
FieldInfo fieldInfo = modelFormField.getFieldInfo();
// if the field's title is explicitly set to "" (title="") then
// the header is not created for it; this is useful for position list
// where one line can be rendered with more than one row, and we
// only want to display the title header for the main row
String modelFormFieldTitle = modelFormField.getTitle(context);
if ("".equals(modelFormFieldTitle)) {
continue;
}
// don't do any header for hidden or ignored fields
if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
continue;
}
if (modelFormField.shouldIgnore(context)) {
continue;
}
if (FieldInfo.isInputFieldType(fieldInfo.getFieldType())) {
inputFieldFound = true;
continue;
}
// separate into two lists the display/hyperlink fields found before and after the first input fields
if (!inputFieldFound) {
innerDisplayHyperlinkFieldsBegin.add(modelFormField);
} else {
innerDisplayHyperlinkFieldsEnd.add(modelFormField);
}
numOfColumns++;
}
// prepare the combined title for the column that will contain the form/input fields
for (ModelFormField modelFormField : mainFieldList) {
FieldInfo fieldInfo = modelFormField.getFieldInfo();
// don't do any header for hidden or ignored fields
if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
continue;
}
// skip all of the display/hyperlink fields
if (!FieldInfo.isInputFieldType(fieldInfo.getFieldType())) {
continue;
}
innerFormFields.add(modelFormField);
}
if (innerFormFields.size() > 0) {
numOfColumns++;
}
if (maxNumOfColumns < numOfColumns) {
maxNumOfColumns = numOfColumns;
}
Map<String, List<ModelFormField>> fieldRow = UtilMisc.toMap("displayBefore", innerDisplayHyperlinkFieldsBegin, "inputFields", innerFormFields, "displayAfter", innerDisplayHyperlinkFieldsEnd, "mainFieldList", mainFieldList);
fieldRowsByPosition.add(fieldRow);
}
// ===========================
// Rendering
// ===========================
formStringRenderer.renderFormatHeaderOpen(writer, context, modelForm);
for (Map<String, List<ModelFormField>> listsMap : fieldRowsByPosition) {
List<ModelFormField> innerDisplayHyperlinkFieldsBegin = listsMap.get("displayBefore");
List<ModelFormField> innerFormFields = listsMap.get("inputFields");
List<ModelFormField> innerDisplayHyperlinkFieldsEnd = listsMap.get("displayAfter");
List<ModelFormField> mainFieldList = listsMap.get("mainFieldList");
int numOfCells = innerDisplayHyperlinkFieldsBegin.size() + innerDisplayHyperlinkFieldsEnd.size() + (innerFormFields.size() > 0 ? 1 : 0);
int numOfColumnsToSpan = maxNumOfColumns - numOfCells + 1;
if (numOfColumnsToSpan < 1) {
numOfColumnsToSpan = 1;
}
if (numOfCells > 0) {
formStringRenderer.renderFormatHeaderRowOpen(writer, context, modelForm);
if (modelForm.getGroupColumns()) {
Iterator<ModelFormField> innerDisplayHyperlinkFieldsBeginIt = innerDisplayHyperlinkFieldsBegin.iterator();
while (innerDisplayHyperlinkFieldsBeginIt.hasNext()) {
ModelFormField modelFormField = innerDisplayHyperlinkFieldsBeginIt.next();
// span columns only if this is the last column in the row (not just in this first list)
if (innerDisplayHyperlinkFieldsBeginIt.hasNext() || numOfCells > innerDisplayHyperlinkFieldsBegin.size()) {
formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, modelForm, modelFormField, 1);
} else {
formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, modelForm, modelFormField, numOfColumnsToSpan);
}
formStringRenderer.renderFieldTitle(writer, context, modelFormField);
formStringRenderer.renderFormatHeaderRowCellClose(writer, context, modelForm, modelFormField);
}
if (innerFormFields.size() > 0) {
// TODO: manage colspan
formStringRenderer.renderFormatHeaderRowFormCellOpen(writer, context, modelForm);
Iterator<ModelFormField> innerFormFieldsIt = innerFormFields.iterator();
while (innerFormFieldsIt.hasNext()) {
ModelFormField modelFormField = innerFormFieldsIt.next();
if (modelForm.getSeparateColumns() || modelFormField.getSeparateColumn()) {
formStringRenderer.renderFormatItemRowCellOpen(writer, context, modelForm, modelFormField, 1);
}
// render title (unless this is a submit or a reset field)
formStringRenderer.renderFieldTitle(writer, context, modelFormField);
if (modelForm.getSeparateColumns() || modelFormField.getSeparateColumn()) {
formStringRenderer.renderFormatItemRowCellClose(writer, context, modelForm, modelFormField);
}
if (innerFormFieldsIt.hasNext()) {
// TODO: determine somehow if this is the last one... how?
if (!modelForm.getSeparateColumns() && !modelFormField.getSeparateColumn()) {
formStringRenderer.renderFormatHeaderRowFormCellTitleSeparator(writer, context, modelForm, modelFormField, false);
}
}
}
formStringRenderer.renderFormatHeaderRowFormCellClose(writer, context, modelForm);
}
Iterator<ModelFormField> innerDisplayHyperlinkFieldsEndIt = innerDisplayHyperlinkFieldsEnd.iterator();
while (innerDisplayHyperlinkFieldsEndIt.hasNext()) {
ModelFormField modelFormField = innerDisplayHyperlinkFieldsEndIt.next();
// span columns only if this is the last column in the row (not just in this first list)
if (innerDisplayHyperlinkFieldsEndIt.hasNext() || numOfCells > innerDisplayHyperlinkFieldsEnd.size()) {
formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, modelForm, modelFormField, 1);
} else {
formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, modelForm, modelFormField, numOfColumnsToSpan);
}
formStringRenderer.renderFieldTitle(writer, context, modelFormField);
formStringRenderer.renderFormatHeaderRowCellClose(writer, context, modelForm, modelFormField);
}
} else {
Iterator<ModelFormField> mainFieldListIter = mainFieldList.iterator();
while (mainFieldListIter.hasNext()) {
ModelFormField modelFormField = mainFieldListIter.next();
// don't do any header for hidden or ignored fields
FieldInfo fieldInfo = modelFormField.getFieldInfo();
if (fieldInfo.getFieldType() == FieldInfo.HIDDEN || fieldInfo.getFieldType() == FieldInfo.IGNORED) {
continue;
}
// span columns only if this is the last column in the row (not just in this first list)
if (mainFieldListIter.hasNext() || numOfCells > mainFieldList.size()) {
formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, modelForm, modelFormField, 1);
} else {
formStringRenderer.renderFormatHeaderRowCellOpen(writer, context, modelForm, modelFormField, numOfColumnsToSpan);
}
formStringRenderer.renderFieldTitle(writer, context, modelFormField);
formStringRenderer.renderFormatHeaderRowCellClose(writer, context, modelForm, modelFormField);
}
}
formStringRenderer.renderFormatHeaderRowClose(writer, context, modelForm);
}
}
formStringRenderer.renderFormatHeaderClose(writer, context, modelForm);
return maxNumOfColumns;
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FoFormRenderer method renderDropDownField.
public void renderDropDownField(Appendable writer, Map<String, Object> context, DropDownField dropDownField) throws IOException {
ModelFormField modelFormField = dropDownField.getModelFormField();
String currentValue = modelFormField.getEntry(context);
List<ModelFormField.OptionValue> allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context));
// if the current value should go first, display it
if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) {
String explicitDescription = dropDownField.getCurrentDescription(context);
if (UtilValidate.isNotEmpty(explicitDescription)) {
this.makeBlockString(writer, modelFormField.getWidgetStyle(), explicitDescription);
} else {
this.makeBlockString(writer, modelFormField.getWidgetStyle(), FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues));
}
} else {
boolean optionSelected = false;
for (ModelFormField.OptionValue optionValue : allOptionValues) {
String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context);
if ((UtilValidate.isNotEmpty(currentValue) && currentValue.equals(optionValue.getKey()) && "selected".equals(dropDownField.getCurrent())) || (UtilValidate.isEmpty(currentValue) && noCurrentSelectedKey != null && noCurrentSelectedKey.equals(optionValue.getKey()))) {
this.makeBlockString(writer, modelFormField.getWidgetStyle(), optionValue.getDescription());
optionSelected = true;
break;
}
}
if (!optionSelected) {
this.makeBlockString(writer, null, "");
}
}
appendWhitespace(writer);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FoFormRenderer method renderDisplayField.
public void renderDisplayField(Appendable writer, Map<String, Object> context, DisplayField displayField) throws IOException {
ModelFormField modelFormField = displayField.getModelFormField();
this.makeBlockString(writer, modelFormField.getWidgetStyle(), displayField.getDescription(context));
appendWhitespace(writer);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FoFormRenderer method renderDateTimeField.
public void renderDateTimeField(Appendable writer, Map<String, Object> context, DateTimeField dateTimeField) throws IOException {
ModelFormField modelFormField = dateTimeField.getModelFormField();
this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateTimeField.getDefaultValue(context)));
appendWhitespace(writer);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FoFormRenderer method renderRangeFindField.
public void renderRangeFindField(Appendable writer, Map<String, Object> context, RangeFindField rangeFindField) throws IOException {
ModelFormField modelFormField = rangeFindField.getModelFormField();
this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, rangeFindField.getDefaultValue(context)));
appendWhitespace(writer);
}
Aggregations