BrightSide Workbench Full Report + Source Code
DossierVersionLabel.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.zul.dossier;
20 
21 import java.util.Set;
22 import org.turro.dossier.entity.Dossier;
23 import org.turro.dossier.entity.DossierVersion;
24 import org.turro.dossier.entity.DossierVersionStatus;
25 import org.turro.elephant.zkoss.EntityGrid;
26 import org.turro.zkoss.label.LabelTypes;
27 import org.zkoss.zk.ui.Component;
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.zul.Hlayout;
32 import org.zkoss.zul.Label;
33 
38 public class DossierVersionLabel extends Hlayout {
39 
40  private Dossier dossier;
41 
42  public void setDossier(Dossier dossier) {
43  this.dossier = dossier;
44  initLabels();
45  }
46 
47  private void initLabels() {
48  Set<DossierVersion> dvs = dossier.getActiveVersions();
49  if(!dvs.isEmpty()) {
50  for(DossierVersion dv : dvs) {
51  if(dv.isActive()) {
52  appendChild(createLabel(dv));
53  }
54  }
55  }
56  }
57 
58  private Component createLabel(final DossierVersion dv) {
59  Label l = LabelTypes.getPreLabel(dv.getVersionString());
60  final DossierVersionStatus dvs = dv.getStatus();
61  if(dvs.equals(DossierVersionStatus.VERSION_READY)) {
62  l.setStyle("color:#1EBC30");
63  } else if(dvs.equals(DossierVersionStatus.VERSION_STOPPED)) {
64  l.setStyle("color:#DB2828;cursor:pointer");
65  l.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
66  @Override
67  public void onEvent(Event event) throws Exception {
68  EntityGrid.showEntities(dv.getByStatus(dvs));
69  }
70  });
71  } else if(dvs.equals(DossierVersionStatus.VERSION_NOTRECOMMENDED)) {
72  l.setStyle("color:#2185D0;cursor:pointer");
73  l.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
74  @Override
75  public void onEvent(Event event) throws Exception {
76  EntityGrid.showEntities(dv.getByStatus(dvs));
77  }
78  });
79  }
80  return l;
81  }
82 
83 }
Set< DossierVersion > getActiveVersions()
Definition: Dossier.java:269