BrightSide Workbench Full Report + Source Code
CommandUtil.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.entities.Entities;
22 import org.turro.entities.IElephantEntity;
23 import org.zkoss.zk.ui.HtmlBasedComponent;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zul.Hlayout;
26 import org.zkoss.zul.Image;
27 import org.zkoss.zul.Label;
28 import org.zkoss.zul.Space;
29 
34 public class CommandUtil {
35 
36  public static HtmlBasedComponent getEntityControl(Object entity) {
37  return getEntityControl(entity, true, true);
38  }
39 
40  public static HtmlBasedComponent getEntityControl(Object entity, boolean showDescription, boolean linkEntity) {
41  EntityControl e = new EntityControl(entity, showDescription, linkEntity);
42  e.afterCompose();
43  return e;
44  }
45 
46  public static ControlAdapter getNameAdapter(Object entity) {
48  return new ControlAdapter(new Label(iee.getName()));
49  }
50 
51  public static ControlAdapter getAdapterOrSpace(Object entity) {
53  return new ControlAdapter(getLinkOrSpace(entity));
54  }
55 
56  public static ControlAdapter getAdapter(Object entity) {
57  return new ControlAdapter(getLink(entity));
58  }
59 
60  public static HtmlBasedComponent getLinkOrSpace(Object entity) {
61  HtmlBasedComponent comp = getLink(entity);
62  return comp == null ? new Space() : comp;
63  }
64 
65  public static HtmlBasedComponent getLink(Object entity) {
67  HtmlBasedComponent hbc = (HtmlBasedComponent) iee.getLabelCtrl();
68  if(hbc instanceof AfterCompose) {
69  ((AfterCompose) hbc).afterCompose();
70  }
71  return hbc;
72  }
73 
74  public static ControlAdapter getLabelAdapter(Object entity) {
75  return new ControlAdapter(getLabel(entity));
76  }
77 
78  public static HtmlBasedComponent getLabel(Object entity) {
80  if(iee != null) {
81  Hlayout hbox = new Hlayout();
82  String img = (String) iee.getImage(),
83  name = (String) iee.getName();
84  if(img != null) {
85  hbox.appendChild(new Image(img));
86  }
87  if(name != null) {
88  hbox.appendChild(new Label(name));
89  }
90  return hbox;
91  }
92  return null;
93  }
94 
95 }
static ControlAdapter getAdapterOrSpace(Object entity)
static HtmlBasedComponent getLink(Object entity)
static HtmlBasedComponent getLinkOrSpace(Object entity)
static HtmlBasedComponent getLabel(Object entity)
static ControlAdapter getAdapter(Object entity)
static HtmlBasedComponent getEntityControl(Object entity, boolean showDescription, boolean linkEntity)
static ControlAdapter getNameAdapter(Object entity)
static ControlAdapter getLabelAdapter(Object entity)
static HtmlBasedComponent getEntityControl(Object entity)
static IElephantEntity getController(String path)
Definition: Entities.java:78