BrightSide Workbench Full Report + Source Code
LabelControl.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.command;
20 
21 import org.turro.string.Strings;
22 import org.turro.auth.Authentication;
23 import org.turro.entities.Entities;
24 import org.turro.entities.IElephantEntity;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.EventListener;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.A;
30 import org.zkoss.zul.Popup;
31 
36 public class LabelControl extends A implements AfterCompose {
37 
38  protected Object entity;
39  private boolean linkEntity = true;
40  private Popup _popup;
41  private int maxChars = 200;
42  private final ClickListener onclick = new ClickListener();
43 
44  class ClickListener implements EventListener<Event> {
45  @Override
46  public void onEvent(Event event) throws Exception {
47  if(_popup != null) {
48  _popup.open(LabelControl.this);
49  } else {
51  }
52  }
53  }
54 
55  public LabelControl() {
56  }
57 
58  public LabelControl(Object entity) {
59  this.entity = entity;
60  }
61 
62  public LabelControl(Object entity, boolean linkEntity) {
63  this.entity = entity;
64  this.linkEntity = linkEntity;
65  }
66 
67  public Object getEntity() {
68  return entity;
69  }
70 
71  public void setEntity(Object entity) {
72  this.entity = entity;
73  }
74 
75  public boolean isLinkEntity() {
76  return linkEntity;
77  }
78 
79  public void setLinkEntity(boolean linkEntity) {
80  this.linkEntity = linkEntity;
81  }
82 
83  public int getMaxChars() {
84  return maxChars;
85  }
86 
87  public void setMaxChars(int maxChars) {
88  this.maxChars = maxChars;
89  }
90 
91  public void generate() {
92  createComponents();
93  }
94 
95  private void createComponents() {
96  removeEventListener(Events.ON_CLICK, onclick);
98  if(ee != null) {
99  String label = ee.getName();
100  setLabel(Strings.truncateAndWarn(label, maxChars));
101  setTooltiptext(label);
102  setImage(ee.getImage());
103  if(linkEntity && (Boolean) ee.canEdit(Authentication.getIContact())) {
104  addEventListener(Events.ON_CLICK, onclick);
105  }
106  }
107  }
108 
109  @Override
110  public void afterCompose() {
111  generate();
112  }
113 
114  @Override
115  public void setContext(Popup popup) {
116  super.setContext(popup);
117  _popup = popup;
118  }
119 
120 }
void setMaxChars(int maxChars)
LabelControl(Object entity, boolean linkEntity)
void setEntity(Object entity)
void setLinkEntity(boolean linkEntity)
static IElephantEntity getController(String path)
Definition: Entities.java:78
boolean canEdit(IContact contact)