Skip to content

Commit

Permalink
Custom view in the KV grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Nov 1, 2015
1 parent 905b2cd commit 5ab1921
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions rapidoid-gui/src/main/java/org/rapidoid/gui/KVGrid.java
Expand Up @@ -27,6 +27,7 @@
import org.rapidoid.annotation.Since;
import org.rapidoid.gui.base.AbstractWidget;
import org.rapidoid.html.tag.TableTag;
import org.rapidoid.lambda.Lmbd;
import org.rapidoid.lambda.Mapper;

@Authors("Nikolche Mihajlovski")
Expand All @@ -35,8 +36,9 @@ public class KVGrid extends AbstractWidget {

private final String[] headers = { "Key", "Value" };

@SuppressWarnings("rawtypes")
private final Mapper[] view = { null, null };
private Mapper<Object, Object> keyView = null;

private Mapper<Object, Object> valueView = null;

private Map<?, ?> map;

Expand All @@ -45,7 +47,17 @@ protected Object render() {
TableTag tbl = table_(tr(th(headers[0]), th(headers[1])));

for (Entry<?, ?> e : map.entrySet()) {
tbl = tbl.append(tr(td(e.getKey()), td(e.getValue())));
Object key = e.getKey();
if (keyView != null) {
key = Lmbd.eval(keyView, key);
}

Object val = e.getValue();
if (valueView != null) {
val = Lmbd.eval(valueView, val);
}

tbl = tbl.append(tr(td(key), td(val)));
}

return tbl;
Expand All @@ -70,4 +82,22 @@ public KVGrid headers(String keyHeader, String valueHeader) {
return this;
}

public Mapper<Object, Object> keyView() {
return keyView;
}

public Mapper<Object, Object> valueView() {
return valueView;
}

public KVGrid keyView(Mapper<Object, Object> keyView) {
this.keyView = keyView;
return this;
}

public KVGrid valueView(Mapper<Object, Object> valueView) {
this.valueView = valueView;
return this;
}

}

0 comments on commit 5ab1921

Please sign in to comment.