sounds like you’re looking for a
GeneratedPropertyContainer , which you can wrap around your SQLContainer. For the arrow icon, you can use some
Renderer , maybe an ImageRenderer or a HTMLRenderer.
I did it like this (code below). It seems to work OK (generating columns and sorting values)…but I’m not fully sure.
In your opinion - is it OK or it should be done in other way? Generally: I want to sort newVAL property values based on TIME property values sorting.
.addGeneratedProperty("newVAL", new PropertyValueGenerator<String>() {
private final String propID = "TIME";
private final String propID_prev = "PREV_TIME";
@Override
public String getValue(Item item, Object itemId, Object propertyId) {
Number val = null;
if (item.getItemProperty(propID).getValue() != null)
val = (Number) item.getItemProperty(propID).getValue();
Number val_p = null;
if (item.getItemProperty(propID_prev).getValue() != null)
val_p = (Number) item.getItemProperty(propID_prev).getValue();
if (val != null && val_p != null) {
if (val.doubleValue() > val_p.doubleValue())
return "<font color=\"green\">" + FontAwesome.ARROW_CIRCLE_UP.getHtml() + "</font>" + " " + item.getItemProperty(propID).getValue();
else if (val.doubleValue() < val_p.doubleValue())
return "<font color=\"red\">" + FontAwesome.ARROW_CIRCLE_DOWN.getHtml() + "</font>" + " " + item.getItemProperty(propID).getValue();
else
return FontAwesome.ARROWS_H.getHtml() + " " + item.getItemProperty(propID).getValue();
} else
return item.getItemProperty(propID).getValue().toString();
}
@Override
public Class<String> getType() {
return String.class;
}
@Override
public SortOrder[] getSortProperties(final SortOrder order) {
return new SortOrder[] { new SortOrder(propID, order.getDirection()) };
}
});