BrightSide Workbench Full Report + Source Code
DossierSelfSummary.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.dossier.command;
20 
21 import java.util.Collection;
22 import org.turro.annotation.ElephantPlugin;
23 import org.turro.dossier.db.DossierPU;
24 import org.turro.dossier.entity.Dossier;
25 import org.turro.dossier.search.DossierResults;
26 import org.turro.dossier.zul.menu.DossierMenu;
27 import org.turro.elephant.context.Application;
28 import org.turro.elephant.util.Images;
29 import org.turro.i18n.I_;
30 import org.turro.jpa.Dao;
31 import org.turro.plugin.command.SelfSummaryPlugin;
32 import org.turro.zkoss.label.LabelTypes;
33 import org.turro.zkoss.layout.GroupboxArrow;
34 import org.zkoss.zk.ui.event.Event;
35 import org.zkoss.zk.ui.event.EventListener;
36 import org.zkoss.zk.ui.event.Events;
37 import org.zkoss.zul.Button;
38 import org.zkoss.zul.Hlayout;
39 import org.zkoss.zul.Image;
40 import org.zkoss.zul.Include;
41 import org.zkoss.zul.Space;
42 
47 @ElephantPlugin
48 public class DossierSelfSummary extends SelfSummaryPlugin {
49 
50  private Collection<Dossier> dossiers;
51 
52  @Override
53  protected void executePlugin() {
55  if(app.isInRole("dossier:list")) {
56  openDossiers();
57  if(!dossiers.isEmpty()) {
58  GroupboxArrow gba = new GroupboxArrow() {
59  @Override
60  protected void doFillContent() {
61  Include report = new Include("/WEB-INF/_zul/dossier/dossierSummary.zul");
62  appendChild(report);
63  }
64  };
65  Hlayout hbox = new Hlayout();
66  gba.setCaption(hbox);
67  hbox.setSclass("z-valign-middle");
68  hbox.setValign("middle");
69  hbox.appendChild(new Image(Images.getImage("dossier")));
70  hbox.appendChild(LabelTypes.getSoftLabel(I_.get("Dossiers") + ":"));
71  hbox.appendChild(LabelTypes.getPreLabel(dossiers.size() + " " + I_.get("Opened")));
72  hbox.appendChild(new Space());
73  Button visit = new Button(I_.get("My dossiers"));
74  visit.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
75  @Override
76  public void onEvent(Event event) throws Exception {
77  DossierMenu.showMyDossiers();
78  }
79  });
80  hbox.appendChild(visit);
81  if(app.isInRole("dossier:participants")) {
82  if(pending() > 0) {
83  Button pending = new Button(I_.get("Pending to accept"));
84  pending.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
85  @Override
86  public void onEvent(Event event) throws Exception {
87  DossierMenu.showPending();
88  }
89  });
90  hbox.appendChild(pending);
91  }
92  }
93  gba.setOpen(false);
94  addResult("dossier", gba);
95  }
96  }
97  }
98 
99  private void openDossiers() {
100  DossierResults ir = new DossierResults();
101  dossiers = ir.getDossierList();
102  }
103 
104  private long pending() {
105  Dao dao = new DossierPU();
106  Long count = (Long) dao.getSingleResultOrNull(
107  "select count(a) from ParticipantRequest as a");
108  count += (Long) dao.getSingleResultOrNull(
109  "select count(a) from CategoryRequest as a");
110  return count;
111  }
112 
113 }
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