BrightSide Workbench Full Report + Source Code
SubscriptionsGrid.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.publication.zul.ctrl;
19 
20 import java.util.List;
21 import org.turro.auth.Authentication;
22 import org.turro.log.SystemLogType;
23 import org.turro.log.SystemLogger;
24 import org.turro.plugin.contacts.IContact;
25 import org.turro.publication.db.PublicationPU;
26 import org.turro.publication.entity.PublicationCategory;
27 import org.turro.publication.util.PublicationUtil;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.Checkbox;
33 import org.zkoss.zul.Grid;
34 import org.zkoss.zul.Hbox;
35 import org.zkoss.zul.Label;
36 import org.zkoss.zul.Row;
37 import org.zkoss.zul.Rows;
38 import org.zkoss.zul.Vbox;
39 
44 @Deprecated
45 public class SubscriptionsGrid extends Grid implements AfterCompose {
46 
47  protected IContact contact;
48 
49  public SubscriptionsGrid() {
50  this.contact = Authentication.getIContact();
51  }
52 
54  this.contact = contact;
55  }
56 
57  public IContact getContact() {
58  return contact;
59  }
60 
61  public void setContact(IContact contact) {
62  this.contact = contact;
63  }
64 
65  @Override
66  public void afterCompose() {
67  if(contact != null) {
68  addRows();
69  }
70  }
71 
72  private void addRows() {
73  setZclass("none");
74 
75  Rows rows = new Rows();
76  appendChild(rows);
77 
78  List<PublicationCategory> list = new PublicationPU().getResultList(
79  "select pubcat from PublicationCategory as pubcat where publishable = TRUE");
80 
81  for(final PublicationCategory pc : list) {
82  Row row = new Row();
83  row.setZclass("none");
84  rows.appendChild(row);
85 
86  Hbox hbox = new Hbox();
87  hbox.setSpacing("20px");
88  row.appendChild(hbox);
89 
90  final Checkbox cb = new Checkbox();
91  hbox.appendChild(cb);
92  cb.setChecked(PublicationUtil.getChecked(contact, pc));
93  cb.addEventListener(Events.ON_CHECK, new EventListener() {
94  @Override
95  public void onEvent(Event event) throws Exception {
97  (cb.isChecked() ? "subscribed" : "unsubscribed"), contact.getName());
98  PublicationUtil.setChecked(contact, pc, cb.isChecked());
99  }
100  });
101 
102  Vbox vbox = new Vbox();
103  setSclass("pubSide");
104  hbox.appendChild(vbox);
105 
106  Label label = new Label(pc.getName());
107  label.setSclass("pubName");
108  vbox.appendChild(label);
109  label = new Label(pc.getDescription());
110  label.setPre(true);
111  label.setSclass("pubDesc");
112  vbox.appendChild(label);
113  }
114  }
115 
116 }
static ISystemLogger getInstance()
static boolean getChecked(IContact contact, PublicationCategory v)
static void setChecked(IContact contact, PublicationCategory v, boolean checked)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)