BrightSide Workbench Full Report + Source Code
CampaignGrid.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.crm.zul.sale;
20 
21 import java.util.Collection;
22 import org.turro.command.CommandUtil;
23 import org.turro.crm.entity.Campaign;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.grid.PagingGrid;
26 import org.turro.zkoss.label.LabelExtended;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.Column;
29 import org.zkoss.zul.Columns;
30 import org.zkoss.zul.Row;
31 import org.zkoss.zul.Rows;
32 
37 public class CampaignGrid extends PagingGrid implements AfterCompose {
38 
39  private CampaignFilter filter = new CampaignFilter();
40  private CampaignFilterGrid filterGrid;
41 
43  return filter;
44  }
45 
46  public void setFilterGrid(CampaignFilterGrid filterGrid) {
47  this.filterGrid = filterGrid;
48  }
49 
50  public void reload() {
51  if(getRows() != null) {
52  getRows().detach();
53  }
54  addRows();
55  }
56 
57  @Override
58  public void afterCompose() {
59  addColumns();
60  }
61 
62  private void addRows() {
63  if(!filterGrid.hasValues()) return;
64 
65  Collection<Campaign> list = filter.getCampaigns(filterGrid.getValues());
66 
67  Rows rows = new Rows();
68  appendChild(rows);
69 
70  for(final Campaign cd : list) {
71  Row row = new Row();
72  rows.appendChild(row);
73  row.appendChild(new LabelExtended().setDate(cd.getCampaignDate()));
74  row.appendChild(CommandUtil.getLinkOrSpace(cd));
75  }
76 
77  setRowCount(list.size());
78  }
79 
80  private void addColumns() {
81  Columns cols = new Columns();
82  appendChild(cols);
83 
84  Column col = new Column(I_.get("Date"), null, "90px");
85  cols.appendChild(col);
86 
87  col = new Column(I_.get("Description"));
88  cols.appendChild(col);
89  }
90 
91 }
static HtmlBasedComponent getLinkOrSpace(Object entity)
Collection< Campaign > getCampaigns(List< IFilterValue > values)
void setFilterGrid(CampaignFilterGrid filterGrid)
List< IFilterValue > getValues()
Rows getRows(boolean create)