BrightSide Workbench Full Report + Source Code
PublicationSelfSummary.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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 
19 package org.turro.publication.command;
20 
21 import org.turro.annotation.ElephantPlugin;
22 import org.turro.commentit.CommentItUtil;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.util.Images;
25 import org.turro.i18n.I_;
26 import org.turro.plugin.command.SelfSummaryPlugin;
27 import org.turro.publication.db.PublicationPU;
28 import org.turro.publication.zul.menu.PublicationMenu;
29 import org.turro.publication.zul.www.PublicationChart;
30 import org.turro.zkoss.label.LabelTypes;
31 import org.turro.zkoss.layout.GroupboxArrow;
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.zul.Button;
36 import org.zkoss.zul.Hlayout;
37 import org.zkoss.zul.Image;
38 import org.zkoss.zul.Space;
39 
44 @ElephantPlugin
46 
47  @Override
48  protected void executePlugin() {
50  if(app.isInRole("publication:accept")) {
51  int pubs = pendingPublications(),
52  coms = (int) CommentItUtil.countPending();
53  if(pubs > 0 || coms > 0) {
54  GroupboxArrow gba = new GroupboxArrow() {
55  @Override
56  protected void doFillContent() {
57  appendChild(new PublicationChart());
58  }
59  };
60  Hlayout hbox = new Hlayout();
61  gba.setCaption(hbox);
62  hbox.setSclass("z-valign-middle");
63  hbox.setValign("middle");
64  hbox.appendChild(new Image(Images.getImage("publication")));
65  hbox.appendChild(LabelTypes.getSoftLabel(I_.get("Publication") + ":"));
66  hbox.appendChild(LabelTypes.getPreLabel(pubs + " " + I_.get("Pending")));
67  hbox.appendChild(new Space());
68  hbox.appendChild(LabelTypes.getSoftLabel(I_.get("Comment") + ":"));
69  hbox.appendChild(LabelTypes.getPreLabel(coms + " " + I_.get("Pending")));
70  hbox.appendChild(new Space());
71  Button visit = new Button(I_.get("Pending to accept"));
72  visit.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
73  @Override
74  public void onEvent(Event event) throws Exception {
75  PublicationMenu.showPending();
76  }
77  });
78  hbox.appendChild(visit);
79  gba.setOpen(false);
80  addResult("publication", gba);
81  }
82  }
83  }
84 
85  private int pendingPublications() {
86  Number n = (Number) new PublicationPU().getSingleResult(
87  "select count(p) from Publication as p where accepted = FALSE");
88  return n == null ? 0 : n.intValue();
89  }
90 
91 }
Object addResult(String key, Object value)
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
static Label getPreLabel(String value)
Definition: LabelTypes.java:52
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28