Skip to content

Commit

Permalink
provide viewEditorRenderMode on view row-field level
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Nov 20, 2017
1 parent e132d28 commit 87bbe7d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/main/java/de/metas/ui/web/view/IViewRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentPath;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.ui.web.window.descriptor.ViewEditorRenderMode;

/*
* #%L
Expand Down Expand Up @@ -60,6 +61,11 @@ default Map<String, DocumentFieldWidgetType> getWidgetTypesByFieldName()
{
return ImmutableMap.of();
}

default Map<String, ViewEditorRenderMode> getViewEditorRenderModeByFieldName()
{
return ImmutableMap.of();
}

//
// Included documents (children)
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/de/metas/ui/web/view/json/JSONViewRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.adempiere.util.GuavaCollectors;
Expand All @@ -22,6 +23,7 @@
import de.metas.ui.web.window.datatypes.json.JSONDocumentField;
import de.metas.ui.web.window.datatypes.json.JSONLayoutWidgetType;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.ui.web.window.descriptor.ViewEditorRenderMode;
import lombok.Value;

/*
Expand Down Expand Up @@ -88,14 +90,11 @@ public static JSONViewRow ofRow(final IViewRow row, final IViewRowOverrides rowO
jsonFields.put(jsonIDField.getField(), jsonIDField);
}

final Map<String, DocumentFieldWidgetType> widgetTypesByFieldName = row.getWidgetTypesByFieldName();

// Append the other fields
row.getFieldNameAndJsonValues()
.entrySet()
.stream()
.map(e -> JSONDocumentField.ofNameAndValue(e.getKey(), e.getValue())
.setWidgetType(JSONLayoutWidgetType.fromNullable(widgetTypesByFieldName.get(e.getKey()))))
.map(createJSONDocumentField(row))
.forEach(jsonField -> jsonFields.put(jsonField.getField(), jsonField));

jsonRow.setFields(jsonFields);
Expand Down Expand Up @@ -142,6 +141,20 @@ public static JSONViewRow ofRow(final IViewRow row, final IViewRowOverrides rowO
return jsonRow;
}

private static final Function<Map.Entry<String, Object>, JSONDocumentField> createJSONDocumentField(final IViewRow row)
{
final Map<String, DocumentFieldWidgetType> widgetTypesByFieldName = row.getWidgetTypesByFieldName();
final Map<String, ViewEditorRenderMode> viewEditorRenderModeByFieldName = row.getViewEditorRenderModeByFieldName();

return fieldNameAndValue -> {
final String fieldName = fieldNameAndValue.getKey();
final Object value = fieldNameAndValue.getValue();
return JSONDocumentField.ofNameAndValue(fieldName, value)
.setWidgetType(JSONLayoutWidgetType.fromNullable(widgetTypesByFieldName.get(fieldName)))
.setViewEditorRenderMode(viewEditorRenderModeByFieldName.get(fieldName));
};
}

/**
* Record type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.common.base.MoreObjects;

import de.metas.ui.web.window.WindowConstants;
import de.metas.ui.web.window.descriptor.ViewEditorRenderMode;
import de.metas.ui.web.window.model.DocumentFieldChange;
import de.metas.ui.web.window.model.DocumentValidStatus;
import de.metas.ui.web.window.model.IDocumentChangesCollector.ReasonSupplier;
Expand Down Expand Up @@ -195,6 +196,10 @@ public static JSONDocumentField ofDocumentFieldChangedEvent(final DocumentFieldC
@JsonInclude(JsonInclude.Include.NON_NULL)
private DocumentValidStatus validStatus;

@JsonProperty("viewEditorRenderMode")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String viewEditorRenderMode;

/** Other properties */
private final Map<String, Object> otherProperties = new LinkedHashMap<>();

Expand Down Expand Up @@ -233,13 +238,13 @@ public String toString()
valueReason = reason;
return this;
}

public JSONDocumentField setWidgetType(final JSONLayoutWidgetType widgetType)
{
this.widgetType = widgetType;
return this;
}

public boolean isReadonly()
{
return readonly != null && readonly;
Expand All @@ -251,8 +256,8 @@ public JSONDocumentField setReadonly(final boolean readonly, final String reason
readonlyReason = reason;
return this;
}
public JSONDocumentField setReadonly(LogicExpressionResult readonly)

public JSONDocumentField setReadonly(final LogicExpressionResult readonly)
{
setReadonly(readonly.booleanValue(), readonly.getName());
return this;
Expand All @@ -272,7 +277,7 @@ private JSONDocumentField setMandatory(final boolean mandatory, final String rea
return this;
}

public JSONDocumentField setMandatory(LogicExpressionResult mandatory)
public JSONDocumentField setMandatory(final LogicExpressionResult mandatory)
{
setMandatory(mandatory.booleanValue(), mandatory.getName());
return this;
Expand All @@ -292,15 +297,15 @@ public JSONDocumentField setDisplayed(final boolean displayed, final String reas
return this;
}

public JSONDocumentField setDisplayed(LogicExpressionResult displayed)
public JSONDocumentField setDisplayed(final LogicExpressionResult displayed)
{
setDisplayed(displayed.booleanValue(), displayed.getName());
return this;
}

public JSONDocumentField setDisplayed(final boolean displayed)
{
String reason = null; // N/A
final String reason = null; // N/A
setDisplayed(displayed, reason);
return this;
}
Expand Down Expand Up @@ -404,4 +409,9 @@ public void putDebugProperties(final Map<String, Object> debugProperties)
}
}

public JSONDocumentField setViewEditorRenderMode(final ViewEditorRenderMode viewEditorRenderMode)
{
this.viewEditorRenderMode = viewEditorRenderMode != null ? viewEditorRenderMode.toJson() : null;
return this;
}
}

0 comments on commit 87bbe7d

Please sign in to comment.