BrightSide Workbench Full Report + Source Code
VoteItGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zul.voteit;
20 
21 import org.turro.command.CommandUtil;
22 import org.turro.contacts.VoteIt;
23 import org.turro.elephant.context.Application;
24 import org.turro.i18n.I_;
25 import org.turro.voteit.VoteItUtil;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.turro.zkoss.label.LabelExtended;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Column;
30 import org.zkoss.zul.Columns;
31 import org.zkoss.zul.Label;
32 import org.zkoss.zul.Row;
33 import org.zkoss.zul.Rows;
34 
39 public class VoteItGrid extends PagingGrid implements AfterCompose {
40 
41  private Application app = Application.getApplication();
42  private String entityPath;
43 
44  public VoteItGrid() {
45  addColumns();
46  }
47 
48  public void setEntityPath(String entityPath) {
49  this.entityPath = entityPath;
50  }
51 
52  @Override
53  public void afterCompose() {
54  addRows();
55  }
56 
57  private void addColumns() {
58  Columns cols = new Columns();
59  cols.setSizable(true);
60  cols.setMenupopup("auto");
61  appendChild(cols);
62 
63  Column col = new Column(I_.get("Date"), null, "120px");
64  cols.appendChild(col);
65 
66  col = new Column(I_.get("Author"));
67  cols.appendChild(col);
68 
69  col = new Column(I_.get("Votes"), null, "80px");
70  col.setAlign("right");
71  cols.appendChild(col);
72  }
73 
74  private void addRows() {
75  Rows rows = getRows(true);
76  rows.getChildren().clear();
77 
78  for(final VoteIt vi : VoteItUtil.allVotes(entityPath)) {
79  final Row row = new Row();
80  row.setValign("top");
81  rows.appendChild(row);
82 
83  LabelExtended lext = new LabelExtended();
84  lext.setDate(vi.getDateCreation());
85  lext.setSclass("ldate");
86  row.appendChild(lext);
87 
88  row.appendChild(CommandUtil.getLinkOrSpace(vi.getCreator()));
89 
90  row.appendChild(new Label(vi.getVote() + ""));
91  }
92  }
93 
94 }
static String get(String msg)
Definition: I_.java:41
Rows getRows(boolean create)
void setEntityPath(String entityPath)
Definition: VoteItGrid.java:48