BrightSide Workbench Full Report + Source Code
RelatedStoresGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.financials.model;
19 
20 import java.util.Set;
21 import org.turro.financials.entity.RelatedStoreDefinition;
22 import org.turro.financials.menu.FinancialsMenu;
23 import org.turro.zkoss.grid.PagingGrid;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zul.Hlayout;
28 import org.zkoss.zul.Image;
29 import org.zkoss.zul.Label;
30 import org.zkoss.zul.Row;
31 import org.zkoss.zul.Rows;
32 
37 public class RelatedStoresGrid extends PagingGrid {
38 
39  private Set<RelatedStoreDefinition> relatedStoreDefinitions;
40 
41  public RelatedStoresGrid(Set<RelatedStoreDefinition> relatedStoreDefinitions) {
42  this.relatedStoreDefinitions = relatedStoreDefinitions;
43  setSizedByContent(true);
44  setDefaultBehavior(false);
45  addRows();
46  }
47 
48  private void addRows() {
49  Rows rows = new Rows();
50  appendChild(rows);
51 
52  for(final RelatedStoreDefinition rsd : relatedStoreDefinitions) {
53  Row row = new Row();
54  rows.appendChild(row);
55 
56  Hlayout hbox = new Hlayout();
57  hbox.setSpacing("20px");
58  Label l = new Label(rsd.getRelatedStore().getName());
59  l.setStyle("cursor:pointer");
60  l.addEventListener(Events.ON_CLICK, new EventListener() {
61  @Override
62  public void onEvent(Event event) throws Exception {
63  FinancialsMenu.showContractDefinition(rsd.getRelatedStore().getId());
64  }
65  });
66  hbox.appendChild(l);
67  if(rsd.getRelatedStore().isStock()) {
68  hbox.appendChild(new Image("/_zul/images/store.png"));
69  }
70  if(rsd.getRelatedStore().isCash()) {
71  hbox.appendChild(new Image("/_zul/images/cash.png"));
72  }
73  if(rsd.isAllowed()) {
74  hbox.appendChild(new Image("/_zul/images/ok.png"));
75  } else {
76  hbox.appendChild(new Image("/_zul/images/cancel.png"));
77  }
78  row.appendChild(hbox);
79  }
80 
81  setRowCount(relatedStoreDefinitions.size());
82  }
83 
84 }
RelatedStoresGrid(Set< RelatedStoreDefinition > relatedStoreDefinitions)
void setDefaultBehavior(boolean defaultBehavior)