Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dev-misc/scripts/fix-rendering-customisers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

command grep -l -E --include='*.java' 'implements\s+IRenderingCustomiser<Map<String,\s*Object>>' -R . \
| xargs sed -E -i \
-e '10a import ua.com.fielden.platform.web.centre.api.resultset.CssRenderingCustomiser;' \
-e 's/implements\s+IRenderingCustomiser<Map<String,\s*Object>>/extends CssRenderingCustomiser/g' \
-e 's/Optional<Map<String,\s*Object>>\s+getCustomRenderingFor/Map<String, Object> getCustomRenderingFor/g'
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ private List<Integer> createPrimaryActionIndices(final List<?> entities) {
}

/**
* Calculates rendering hints for {@code entities}.
* Calculates rendering hints for {@code entities}. The returned list must be either empty or strictly of the same length as the input list.
*
* @param entities
* @return
Expand All @@ -771,7 +771,7 @@ private List<Object> createRenderingHints(final List<?> entities) {
final IRenderingCustomiser<?> renderer = renderingCustomiser.get();
final List<Object> renderingHints = new ArrayList<>();
for (final Object entity : entities) {
renderingHints.add(renderer.getCustomRenderingFor((AbstractEntity<?>)entity).get());
renderingHints.add(renderer.getCustomRenderingFor((AbstractEntity<?>)entity));
}
return renderingHints;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import ua.com.fielden.platform.entity.AbstractEntity;
import ua.com.fielden.platform.sample.domain.TgPersistentStatus;
import ua.com.fielden.platform.web.centre.api.resultset.IRenderingCustomiser;
import ua.com.fielden.platform.web.centre.api.resultset.CssRenderingCustomiser;

public class TestRenderingCustomiser implements IRenderingCustomiser<Map<String, Object>> {
public class TestRenderingCustomiser extends CssRenderingCustomiser {
private final Map<String, String> statusColouringScheme = new HashMap<String, String>() {
{
put("dR", "yellow");
Expand All @@ -33,7 +32,7 @@ public class TestRenderingCustomiser implements IRenderingCustomiser<Map<String,
};

@Override
public Optional<Map<String, Object>> getCustomRenderingFor(final AbstractEntity<?> entity) {
public Map<String, Object> getCustomRenderingFor(final AbstractEntity<?> entity) {
final Map<String, Object> res = new HashMap<>();
for (final String propName : properties) {
final Map<String, Map<String, String>> propStyle = new HashMap<>();
Expand All @@ -54,23 +53,23 @@ public Optional<Map<String, Object>> getCustomRenderingFor(final AbstractEntity<

final TgPersistentStatus currentStatus = entity.get("status");
for (final Map.Entry<String, String> entry : statusColouringScheme.entrySet()) {

final Map<String, Map<String, String>> propStyle = new HashMap<>();
res.put(entry.getKey(), propStyle);

final Map<String, String> backgroundStyles = new HashMap<>();
final Map<String, String> valueStyles = new HashMap<>();
propStyle.put("backgroundStyles", backgroundStyles);
propStyle.put("valueStyles", valueStyles);

// TODO uncomment to hide the "X" value in calculated properties, which is really needed only for data export
//valueStyles.put("visibility", "hidden");
if (currentStatus != null && entry.getKey().equalsIgnoreCase(currentStatus.getKey())) {
backgroundStyles.put("background-color", entry.getValue());
}


}
return Optional.of(res);
};

return res;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ua.com.fielden.platform.web.centre.api.resultset;

import java.util.Collections;
import java.util.Map;

/**
* An abstract base class for implementation of CSS rendering customisers, used by the Entity Centre DSL.
*
* @see IRenderingCustomiser
* @author TG Team
*/
public abstract class CssRenderingCustomiser implements IRenderingCustomiser<Map<String, Object>> {

protected static final String BACKGROUND_STYLES = "backgroundStyles";
protected static final String VALUE_STYLES = "valueStyles";

private static final Map<String, Object> EMPTY_HINTS = Collections.emptyMap();

@Override
public final Map<String, Object> empty() {
return EMPTY_HINTS;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ua.com.fielden.platform.web.centre.api.resultset;

import java.util.Optional;

import ua.com.fielden.platform.entity.AbstractEntity;

/**
Expand All @@ -13,23 +11,29 @@
* <p>
* This contract should be view as a function that returns rendering hints for a single passed as an argument entity.
* <p>
* This type is not parameterized by <code>T extends AbstractEntity<?></code> specifically to reflect the fact that the entities, which are handled by entity centres are derived from a concrete entity type, but are not polymorphic with it.
* This type is not parameterized by <code>T extends AbstractEntity<?></code> specifically to reflect the fact that the entities, which are handled by entity centres are derived from a concrete entity type, but are not polymorphic with it.
*
* @author TG Team
*
* @param <R>
* @param <R> the type of the structure of rendering hints
*/
public interface IRenderingCustomiser<R> {

/**
* Accepts an entity instance and computes rendering hints for its representation, and representation of its properties.
* <p>
* There could be a situation where an entity instance does not require customisation of its rendering.
* In such cases an empty {@link Optional} instance should be returned, which is the default implementation of this contract.
* In such cases the result of {@link #empty()} should be returned, which is the default implementation of this contract.
*
* @param entity
*/
default Optional<R> getCustomRenderingFor(final AbstractEntity<?> entity) {
return Optional.empty();
default R getCustomRenderingFor(final AbstractEntity<?> entity) {
return empty();
}

/**
* Returns an empty structure of rendering hints.
*/
R empty();

}