BrightSide Workbench Full Report + Source Code
dossier/DossierLabel.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.dossier.zul.dossier;
19 
20 import org.turro.string.Strings;
21 import org.turro.dossier.dossier.DossierWrapper;
22 import org.turro.dossier.entity.Dossier;
23 import org.turro.dossier.zul.menu.DossierMenu;
24 import org.turro.elephant.context.Application;
25 import org.turro.i18n.I_;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zk.ui.ext.AfterCompose;
30 import org.zkoss.zul.A;
31 
36 public class DossierLabel extends A implements AfterCompose {
37 
38  private Dossier entity;
39  private boolean fullDescription;
40 
41  public DossierLabel(Dossier entity, boolean fullDescription) {
42  setFullDescription(fullDescription);
43  setDossier(entity);
44  afterCompose();
45  }
46 
47  public DossierLabel() {
48  }
49 
50  public void setFullDescription(boolean fullDescription) {
51  this.fullDescription = fullDescription;
52  }
53 
54  public void setDossier(Dossier dossier) {
55  entity = dossier;
56  if(entity != null) {
57  if(fullDescription) {
58  setLabel(entity.getFullDescription());
59  } else {
60  setLabel(entity.getDescription());
61  }
62  if(Strings.isBlank(getLabel())) {
63  setLabel(I_.get("No description!"));
64  }
65  setImage("/_zul/images/dossier.png");
66  }
67  }
68 
69  private void addClickListener() {
70  addEventListener(Events.ON_CLICK, new EventListener() {
71  @Override
72  public void onEvent(Event event) throws Exception {
73  DossierMenu.showDossier(entity.getId());
74  }
75  });
76  }
77 
78  @Override
79  public void afterCompose() {
81  DossierWrapper dw = new DossierWrapper(entity);
82  if(app.isInRole("dossier:show") &&
83  (app.isInRole("dossier:all") || dw.isAssistant() || dw.isOwner())) {
84  addClickListener();
85  }
86  }
87 
88 }
void setFullDescription(boolean fullDescription)
DossierLabel(Dossier entity, boolean fullDescription)
static void showDossier(Dossier dossier)
static String get(String msg)
Definition: I_.java:41