19 package org.turro.polls;
21 import java.util.Collections;
22 import java.util.Comparator;
23 import java.util.List;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.db.ElephantPU;
26 import org.turro.elephant.entities.db.Poll;
27 import org.turro.elephant.entities.db.PollVote;
28 import org.turro.i18n.I_;
29 import org.turro.util.CompareUtil;
30 import org.turro.zkoss.grid.DefaultRowRenderer;
31 import org.turro.zkoss.grid.PagingGrid;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.event.EventListener;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zul.Column;
36 import org.zkoss.zul.Columns;
37 import org.zkoss.zul.Group;
38 import org.zkoss.zul.GroupsModelArray;
39 import org.zkoss.zul.Label;
40 import org.zkoss.zul.Row;
41 import org.zkoss.zul.Toolbarbutton;
58 if(this.poll !=
null) {
61 addRows(Collections.EMPTY_LIST);
65 private void addColumns() {
66 Columns cols =
new Columns();
67 cols.setSizable(
true);
68 cols.setMenupopup(
"auto");
73 Column col =
new Column(
I_.
get(
"Contact"));
75 cols.appendChild(col);
76 col =
new Column(
I_.
get(
"Vote"));
78 cols.appendChild(col);
82 cols.appendChild(col);
86 private void addRows(List votes) {
88 setRowRenderer(
new DefaultRowRenderer<PollVote>() {
90 protected void renderRow(Row row, PollVote value) {
95 protected void renderGroup(Group group, PollVote value) {
96 group.setLabel(value.getPollData());
100 setModel(
new GroupsModelArray<PollVote, String, String, Object>(
101 (PollVote[]) votes.toArray(
new PollVote[0]),
102 new Comparator<PollVote>() {
104 public int compare(PollVote o1, PollVote o2) {
105 return CompareUtil.compare(o1.getPollData(), o2.getPollData());
110 protected String createGroupFoot(PollVote[] groupdata,
int index,
int col) {
111 int against = 0, abstention = 0, inFavor = 0;
112 for(PollVote pv : groupdata) {
113 if(pv.getVote() > 0) {
115 }
else if(pv.getVote() < 0) {
121 return String.format(
"%s: %d - %s: %d - %s: %d",
122 I_.get(
"Against"), against,
123 I_.get(
"Abstention"), abstention,
124 I_.get(
"In favor"), inFavor);
131 private void fillRow(Row row, PollVote value) {
132 row.appendChild(
new Label(value.getContact().getName()));
133 row.appendChild(
new Label(String.valueOf(value.getVote())));
134 if(Application.getApplication().isInRole(
"dossier:delete")) {
135 Toolbarbutton delVote =
new Toolbarbutton();
136 delVote.setImage(
"/_zul/images/edit-delete.png");
137 delVote.addEventListener(Events.ON_CLICK,
new EventListener() {
139 public void onEvent(Event event)
throws Exception {
140 new ElephantPU().deleteObject(value);
142 Events.postEvent(
new Event(Events.ON_CHANGE));
145 row.appendChild(delVote);
boolean isInRole(String role)
static Application getApplication()
List< PollVote > getVotes()
static String get(String msg)
void setRowCount(int rows)