BrightSide Workbench Full Report + Source Code
ProposalGrid.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.ContactProposal;
22 import org.turro.contacts.proposal.GenericAttribute;
23 import org.zkoss.zk.ui.Component;
24 import org.zkoss.zul.Column;
25 import org.zkoss.zul.Columns;
26 import org.zkoss.zul.Grid;
27 import org.zkoss.zul.Rows;
28 
33 public class ProposalGrid extends Grid {
34 
35  private ContactProposal proposal;
36  private Rows rows;
37 
38  public ProposalGrid() {
39  Columns cols = new Columns();
40  cols.setSizable(true);
41  cols.setMenupopup("auto");
42  appendChild(cols);
43 
44  Column col;
45 
46  col = new Column("");
47  col.setWidth("40px");
48  cols.appendChild(col);
49 
50  col = new Column("");
51  cols.appendChild(col);
52  }
53 
55  return proposal.getDestination();
56  }
57 
58  public void setDestination(Contact destination) {
59  proposal.setDestination(destination);
60  updateRows();
61  }
62 
64  return proposal;
65  }
66 
67  public void setProposal(ContactProposal proposal) {
68  this.proposal = proposal;
69  updateRows();
70  }
71 
72  public void reload() {
73  if(proposal != null) {
74  proposal.reload();
75  }
76  updateRows();
77  }
78 
79  private void updateRows() {
80  if(rows == null) {
81  rows = new Rows();
82  appendChild(rows);
83  } else {
84  rows.getChildren().clear();
85  }
86  if(proposal == null) return;
87  for(GenericAttribute ga : proposal.getAttributes()) {
88  rows.appendChild(new ProposalRow(ga));
89  }
90  for(Component pr : rows.getChildren()) {
91  ((ProposalRow)pr).updateContent();
92  }
93  }
94 
95 }
void setProposal(ContactProposal proposal)