BrightSide Workbench Full Report + Source Code
EntityControl.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.turro.zkoss.label.LabelTypes;
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.*;
31 
36 public class EntityControl extends Vlayout implements AfterCompose {
37 
38  private Object entity;
39  private boolean showDescription = false, linkEntity = true;
40 
41  public EntityControl() {
42  }
43 
44  public EntityControl(Object entity) {
45  this.entity = entity;
46  }
47 
48  public EntityControl(Object entity, boolean showDescription, boolean linkEntity) {
49  this.entity = entity;
50  this.showDescription = showDescription;
51  this.linkEntity = linkEntity;
52  }
53 
54  public Object getEntity() {
55  return entity;
56  }
57 
58  public void setEntity(Object entity) {
59  this.entity = entity;
60  }
61 
62  public boolean isLinkEntity() {
63  return linkEntity;
64  }
65 
66  public void setLinkEntity(boolean linkEntity) {
67  this.linkEntity = linkEntity;
68  }
69 
70  public boolean isShowDescription() {
71  return showDescription;
72  }
73 
74  public void setShowDescription(boolean showDescription) {
75  this.showDescription = showDescription;
76  }
77 
78  public void generate() {
79  createComponents();
80  }
81 
82  private void createComponents() {
83  getChildren().clear();
84  final IElephantEntity ee = Entities.getController(entity);
85  if(ee != null) {
86  if(linkEntity && ee.canEdit(Authentication.getIContact())) {
87  A link = new A(ee.getName(), ee.getImage());
88  link.addEventListener(Events.ON_CLICK, new EventListener() {
89  @Override
90  public void onEvent(Event event) throws Exception {
91  ee.showEntity();
92  }
93  });
94  appendChild(link);
95  } else {
96  Hlayout hbox = new Hlayout();
97  if(!Strings.isBlank(ee.getImage())) {
98  hbox.appendChild(new Image(ee.getImage()));
99  }
100  if(!Strings.isBlank(ee.getName())) {
101  hbox.appendChild(new Label(ee.getName()));
102  }
103  appendChild(hbox);
104  }
105  if(showDescription && !Strings.isBlank(ee.getDescription())) {
106  appendChild(LabelTypes.getSoftLabel(ee.getDescription()));
107  }
108  }
109  }
110 
111  @Override
112  public void afterCompose() {
113  generate();
114  }
115 
116 }
void setLinkEntity(boolean linkEntity)
void setShowDescription(boolean showDescription)
EntityControl(Object entity, boolean showDescription, boolean linkEntity)
static IElephantEntity getController(String path)
Definition: Entities.java:78
boolean canEdit(IContact contact)