BrightSide Workbench Full Report + Source Code
AcceptancesGrid.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.zul.acceptance;
19 
20 import org.turro.acceptance.AcceptanceMail;
21 import org.turro.acceptance.AcceptanceUtil;
22 import org.turro.auth.Authentication;
23 import org.turro.contacts.Acceptance;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.zul.label.ContactInfo;
26 import org.turro.elephant.util.DateFormats;
27 import org.turro.entities.Entities;
28 import org.turro.i18n.I_;
29 import org.turro.plugin.contacts.IContact;
30 import org.turro.zkoss.grid.GroupExtended;
31 import org.turro.zkoss.grid.PagingGrid;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.event.EventListener;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zk.ui.ext.AfterCompose;
36 import org.zkoss.zul.*;
37 
42 public class AcceptancesGrid extends PagingGrid implements AfterCompose {
43 
44  private IContact contact = Authentication.getIContact();
45  private boolean showGroups = true;
46 
47  public void setShowGroups(boolean showGroups) {
48  this.showGroups = showGroups;
49  }
50 
51  @Override
52  public void afterCompose() {
53  loadRows();
54  }
55 
56  private void loadRows() {
57  if(getRows() == null) {
58  addColumns();
59  appendChild(new Rows());
60  }
61 
62  Rows rows = getRows();
63  rows.getChildren().clear();
64 
65  if(showGroups) {
66  rows.appendChild(new GroupExtended(I_.get("Pending to accept")));
67  }
68  for(final Acceptance acceptance : AcceptanceUtil.getPendingAcceptances((Contact) contact.getContact())) {
69  Row row = new Row();
70  row.setZclass("none");
71  for(String colStr : getVarColumnsList("contact,creation,entity,accept,comment")) {
72  if("contact".equals(colStr)) {
73  row.appendChild(new ContactInfo(acceptance.getPetitioner()));
74  } else if("creation".equals(colStr)) {
75  row.appendChild(new Label(DateFormats.format(acceptance.getDateRequest(), true)));
76  } else if("entity".equals(colStr)) {
77  row.appendChild(new Label(Entities.getController(acceptance.getPath()).getName()));
78  } else if("accept".equals(colStr)) {
79  Toolbarbutton b = new Toolbarbutton(I_.get("Accept"), "/_zul/images/ok.png");
80  b.addEventListener(Events.ON_CLICK, new EventListener() {
81  @Override
82  public void onEvent(Event event) throws Exception {
83  new AcceptanceMail(AcceptanceUtil.accept(acceptance)).sendMail();
84  loadRows();
85  }
86  });
87  row.appendChild(b);
88  } else if("comment".equals(colStr)) {
89  row.appendChild(new Label(acceptance.getAcceptanceComment()));
90  }
91  }
92  rows.appendChild(row);
93  }
94 
95  if(showGroups) {
96  rows.appendChild(new GroupExtended(I_.get("Pending requests")));
97  }
98  for(Acceptance acceptance : AcceptanceUtil.getPendingRequests((Contact) contact.getContact())) {
99  Row row = new Row();
100  row.setZclass("none");
101  for(String colStr : getVarColumnsList("contact,creation,entity,accept,comment")) {
102  if("contact".equals(colStr)) {
103  row.appendChild(new ContactInfo(acceptance.getContact()));
104  } else if("creation".equals(colStr)) {
105  row.appendChild(new Label(DateFormats.format(acceptance.getDateRequest(), true)));
106  } else if("entity".equals(colStr)) {
107  row.appendChild(new Label(Entities.getController(acceptance.getPath()).getName()));
108  } else if("accept".equals(colStr)) {
109  row.appendChild(new Label());
110  } else if("comment".equals(colStr)) {
111  row.appendChild(new Label(acceptance.getAcceptanceComment()));
112  }
113  }
114  rows.appendChild(row);
115  }
116 
118  }
119 
120  private void addColumns() {
121  Columns cols = new Columns();
122  cols.setSizable(true);
123  cols.setMenupopup("auto");
124  cols.setVisible(false);
125  appendChild(cols);
126 
127  for(String colStr : getVarColumnsList("contact,creation,entity,accept,comment")) {
128  if("contact".equals(colStr)) {
129  Column col = new Column(I_.get("Contact"));
130  cols.appendChild(col);
131  } else if("creation".equals(colStr)) {
132  Column col = new Column(I_.get("Creation"));
133  col.setWidth("120px");
134  cols.appendChild(col);
135  } else if("entity".equals(colStr)) {
136  Column col = new Column(I_.get("Entity"));
137  cols.appendChild(col);
138  } else if("accept".equals(colStr)) {
139  Column col = new Column();
140  col.setWidth("120px");
141  cols.appendChild(col);
142  } else if("comment".equals(colStr)) {
143  Column col = new Column(I_.get("Comment"));
144  col.setWidth("300px");
145  cols.appendChild(col);
146  }
147  }
148 
149  }
150 
151 }
Rows getRows(boolean create)
Collection< String > getVarColumnsList(String defaultCols)