BrightSide Workbench Full Report + Source Code
ContractInfo.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.zul.label.ContactInfo;
22 import org.turro.elephant.util.Images;
23 import org.turro.financials.entity.Contract;
24 import org.turro.financials.entity.ContractParticipant;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.label.LabelExtended;
27 import org.turro.zkoss.label.LabelTypes;
28 import org.turro.zul.frame.Framework;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zk.ui.ext.AfterCompose;
33 import org.zkoss.zul.A;
34 import org.zkoss.zul.Hlayout;
35 import org.zkoss.zul.Image;
36 import org.zkoss.zul.Popup;
37 import org.zkoss.zul.Vlayout;
38 
43 public class ContractInfo extends A implements AfterCompose {
44 
45  private Contract contract;
46  private boolean onlyIcon;
47 
48  public ContractInfo(Contract contract) {
49  this.contract = contract;
50  updateLabel();
51  }
52 
53  public ContractInfo() {
54  }
55 
56  public Contract getContract() {
57  return contract;
58  }
59 
60  public void setContract(Contract contract) {
61  this.contract = contract;
62  updateLabel();
63  }
64 
65  public boolean isOnlyIcon() {
66  return onlyIcon;
67  }
68 
69  public void setOnlyIcon(boolean onlyIcon) {
70  this.onlyIcon = onlyIcon;
71  updateLabel();
72  }
73 
74  @Override
75  public void afterCompose() {
76  updateLabel();
77  addClickListener();
78  }
79 
80  private void addClickListener() {
81  addEventListener(Events.ON_CLICK, new EventListener() {
82  @Override
83  public void onEvent(Event event) throws Exception {
84  fillContactPopup();
85  }
86  });
87  }
88 
89  private void fillContactPopup() {
90  if(contract == null) {
91  return;
92  }
93 
94  Popup popup = Framework.getCurrent().getGlobalPopup();
95 
96  Vlayout vbox = new Vlayout();
97  vbox.setStyle("font-size:11px");
98  popup.appendChild(vbox);
99 
100  vbox.appendChild(LabelTypes.getCaptionLabel(contract.getContractDefinition().getName()));
101 
102  if(!Strings.isBlank(contract.getGlobalId())) {
103  vbox.appendChild(LabelTypes.getSoftLabel(I_.get("Global identifier") + ": " + contract.getGlobalId()));
104  }
105  if(contract.getDepartment() != null) {
106  vbox.appendChild(LabelTypes.getSoftLabel(I_.get("Department") + ": " + contract.getDepartment().getFullName()));
107  }
108  if(contract.getService() != null) {
109  vbox.appendChild(LabelTypes.getSoftLabel(I_.get("Service") + ": " + contract.getService().getFullName()));
110  }
111  if(!Strings.isBlank(contract.getContractor())) {
112  ContactInfo ci = new ContactInfo(contract.getContractor());
113  ci.setSclass("softLabel");
114  vbox.appendChild(ci);
115  }
116  if(contract.getFee() > 0) {
117  Hlayout hbox = new Hlayout();
118  hbox.appendChild(new LabelExtended().setDouble(contract.getFee()));
119  hbox.appendChild(new LabelExtended().setEnum(contract.getPeriodicity()));
120  vbox.appendChild(hbox);
121  }
122  if(!Strings.isBlank(contract.getNotes())) {
123  vbox.appendChild(LabelTypes.getPreLabel(contract.getNotes()));
124  }
125  for(ContractParticipant cp : contract.getParticipants()) {
126  Hlayout hbox = new Hlayout();
127  ContactInfo ci = new ContactInfo(cp.getIdContact());
128  ci.setSclass("softLabel");
129  hbox.appendChild(ci);
130  hbox.appendChild(new LabelExtended().setEnum(cp.getInterventionType()));
131  if(cp.isSendDocuments()) {
132  hbox.appendChild(new Image(Images.getImage("mail_send")));
133  }
134  vbox.appendChild(hbox);
135  }
136  if(!vbox.getChildren().isEmpty()) popup.open(this);
137  }
138 
139  private void updateLabel() {
140  if(contract != null) {
141  if(!onlyIcon) {
142  setLabel(contract.getFullDescription());
143  setImage(Images.getImage("contract"));
144  } else {
145  setLabel(null);
146  setImage(Images.getImage("info"));
147  }
148  } else {
149  setLabel(null);
150  setImage(Images.getImage("info"));
151  }
152  }
153 }
Set< ContractParticipant > getParticipants()
Definition: Contract.java:260
ContractDefinition getContractDefinition()
Definition: Contract.java:125