BrightSide Workbench Full Report + Source Code
ContractDisagreementsGrid.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.contract;
19 
20 import org.turro.string.Strings;
21 import org.turro.contacts.Address;
22 import org.turro.contacts.Contact;
23 import org.turro.contacts.zul.menu.ContactMenu;
24 import org.turro.elephant.security.IUser;
25 import org.turro.financials.model.contract.ContractDisagreements;
26 import org.turro.i18n.I_;
27 import org.turro.util.PhraseBuilder;
28 import org.turro.zkoss.grid.CollectionGrid;
29 import org.turro.zkoss.grid.EditableCell;
30 import org.zkoss.zk.ui.HtmlBasedComponent;
31 import org.zkoss.zk.ui.event.Event;
32 import org.zkoss.zk.ui.event.EventListener;
33 import org.zkoss.zk.ui.event.Events;
34 import org.zkoss.zul.A;
35 import org.zkoss.zul.Row;
36 
41 public class ContractDisagreementsGrid extends CollectionGrid<Contact> {
42 
44  super(new ContractDisagreements());
45  }
46 
47  @Override
48  protected void initiateRow(Row row, Contact value) {
49  row.setValue(value);
50  }
51 
52  @Override
53  protected boolean deleteRow(Row row) {
54  return false;
55  }
56 
57  @Override
58  protected boolean isValid(Contact v) {
59  return true;
60  }
61 
62  @Override
63  protected HtmlBasedComponent createRenderer(EditableCell editableCell) {
64  if(editableCell.getCellIndex() == 0) {
65  final Contact contact = (Contact) editableCell.getRow().getValue();
66  A b = new A(getDisagreementString(contact));
67  b.setImage("/_zul/images/contact.png");
68  b.addEventListener(Events.ON_CLICK, new EventListener() {
69  @Override
70  public void onEvent(Event event) throws Exception {
71  ContactMenu.showContact(contact.getId());
72  }
73  });
74  return b;
75  }
76  return super.createRenderer(editableCell);
77  }
78 
79  @Override
80  public void afterCompose() {
81  setReadOnly(true);
82  addColumns();
83  super.afterCompose();
84  }
85 
86  private void addColumns() {
87  addColumn(I_.get("Contact"), String.class,
88  "fullName", null, 0, false, false);
89  }
90 
91  private String getDisagreementString(Contact contact) {
92  PhraseBuilder pb = new PhraseBuilder();
93  if(contact != null) {
94  pb.addWord(contact.getName());
95  if(Strings.isBlank(contact.getGlobalIdentifier())) {
96  pb.addWord(I_.get("Global identifier"), "[]");
97  } else {
98  pb.addWord(contact.getGlobalIdentifier());
99  }
100  Address address = contact.getAddressMap().get(IUser.ADDRESS_FISCAL);
101  if(address == null) {
102  pb.addWord(I_.get("Address"), "[]");
103  } else {
104  pb.addWord(address.getAddressString());
105  if(Strings.isBlank(address.getZipCode())) {
106  pb.addWord(I_.get("Zip code"), "[]");
107  }
108  }
109  }
110  return pb.toString();
111  }
112 
113 }
static void showContact(Contact contact)
HtmlBasedComponent createRenderer(EditableCell editableCell)
static String get(String msg)
Definition: I_.java:41
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
void setReadOnly(boolean readOnly)