BrightSide Workbench Full Report + Source Code
ProposalRow.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.contacts.zul.proposal;
19 
20 import org.turro.contacts.Contact;
21 import org.turro.contacts.proposal.GenericAttribute;
22 import org.zkoss.zk.ui.event.Event;
23 import org.zkoss.zk.ui.event.EventListener;
24 import org.zkoss.zk.ui.event.Events;
25 import org.zkoss.zul.Checkbox;
26 import org.zkoss.zul.Detail;
27 import org.zkoss.zul.Hbox;
28 import org.zkoss.zul.Include;
29 import org.zkoss.zul.Label;
30 import org.zkoss.zul.Row;
31 
36 public class ProposalRow extends Row {
37 
38  private GenericAttribute attribute;
39 
40  public ProposalRow(GenericAttribute attribute) {
41  this.attribute = attribute;
42  }
43 
44  public void setGridDestination(Contact contact) {
45  ProposalGrid pg = (ProposalGrid) ProposalRow.this.getGrid();
46  pg.setDestination(contact);
47  Events.postEvent(new Event(Events.ON_SELECT, pg));
48  }
49 
50  public void updateContent() {
51  addDetail();
52 
53  Hbox hbox = new Hbox();
54  hbox.setAlign("center");
55  appendChild(hbox);
56 
57  final Checkbox active = new Checkbox();
58  active.setChecked(attribute.isActive());
59  active.addEventListener(Events.ON_CHECK, new EventListener() {
60  @Override
61  public void onEvent(Event event) throws Exception {
62  attribute.setActive(active.isChecked());
63  }
64  });
65  hbox.appendChild(active);
66  Label l = new Label(attribute.getAttributeName());
67  l.setSclass("attrName");
68  hbox.appendChild(l);
69  l = new Label(attribute.getAsString());
70  l.setSclass("attrValue");
71  hbox.appendChild(l);
72  }
73 
74  private void addDetail() {
75  Detail detail = new Detail();
76  appendChild(detail);
77 
78  Include include = new Include("/WEB-INF/_zul/contact/proposalRow.zul");
79  include.setDynamicProperty("attribute", attribute);
80  include.setDynamicProperty("row", this);
81  detail.appendChild(include);
82 
83  detail.setOpen(attribute.getRelated().size() > 1);
84  }
85 
86 }
ProposalRow(GenericAttribute attribute)