18 package org.turro.zul.log;
20 import java.util.Date;
21 import java.util.List;
22 import org.amic.util.date.DateFormats;
23 import org.amic.util.string.Strings;
24 import org.turro.contacts.LogEntry;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.entities.Entities;
29 import org.turro.entities.IElephantEntity;
30 import org.turro.i18n.I_;
31 import org.turro.jpa.Dao;
32 import org.turro.jpa.list.RendererOnDemand;
33 import org.turro.jpa.serializer.SerializerMessage;
34 import org.turro.zkoss.label.TipCell;
35 import org.turro.zkoss.layout.ListheaderAdapter;
36 import org.zkoss.zk.ui.event.Event;
37 import org.zkoss.zk.ui.event.EventListener;
38 import org.zkoss.zk.ui.event.Events;
39 import org.zkoss.zk.ui.ext.AfterCompose;
40 import org.zkoss.zul.*;
47 public class LogListbox extends Listbox implements AfterCompose {
49 private String logPath, logName, logComment;
50 private Date fromDate;
57 this.fromDate = fromDate;
65 this.logComment = logComment;
73 this.logName = logName;
81 this.logPath = logPath;
85 setModel(
new ListModelList(getLogEntries()));
94 private void addHeaders() {
95 appendChild(
new Listhead());
97 I_.
get(
"Type"),
"80px"));
99 I_.
get(
"Date"),
"120px"));
100 if(Strings.isBlank(logName)) {
102 I_.
get(
"User"),
"/_zul/images/contact.png",
"2"));
104 if(Strings.isBlank(logPath)) {
105 getListhead().appendChild(
new ListheaderAdapter(
106 I_.get(
"Entity"),
"/_zul/images/entity.png",
"3"));
108 getListhead().appendChild(
new ListheaderAdapter(
109 I_.get(
"Comment"),
"1"));
110 getListhead().appendChild(
new ListheaderAdapter(
111 I_.get(
"Data"),
"3"));
112 getListhead().setSizable(
true);
115 private void addItems() {
116 final Dao dao =
new ContactsPU();
118 setItemRenderer(
new RendererOnDemand<LogEntry, String>() {
120 protected Dao getDao() {
124 protected void renderItem(Listitem item,
final LogEntry entry) {
125 item.appendChild(
new Listcell(I_.byKey(entry.getLogType().toString())));
126 item.appendChild(
new Listcell(DateFormats.format(entry.getDateLog(),
"SHORT",
"SHORT", Application.getUsedLocale())));
127 if(Strings.isBlank(logName)) {
128 item.appendChild(
new Listcell(entry.getName()));
130 if(Strings.isBlank(logPath)) {
131 IElephantEntity ee = Entities.getController(entry.getPath());
132 String name = ee.getName();
133 if(Strings.isBlank(name)) name = ee.getLabel();
134 item.appendChild(
new TipCell(name, 100));
136 item.appendChild(
new TipCell(entry.getComment(), 40));
137 final Object data = entry.getObject();
138 if(!(data instanceof String)) {
139 item.appendChild(
new Listcell());
141 if(isReadableAndShort((String) data)) {
142 item.appendChild(
new Listcell((String) data));
144 Listcell info =
new Listcell(
null,
"/_zul/images/info.png");
145 info.addEventListener(Events.ON_CLICK,
new EventListener() {
147 public void onEvent(Event event)
throws Exception {
148 new SerializerMessage((String) data).show(getPage());
151 item.appendChild(info);
157 setModel(
new ListModelList(getLogEntries()));
160 private List<LogEntry> getLogEntries() {
161 WhereClause wc =
new WhereClause();
162 wc.addClause(
"select log.id from LogEntry as log");
163 wc.addClause(
"where 1=1");
164 if(!Strings.isBlank(logPath)) {
165 wc.addClause(
"and log.path = :path");
166 wc.addNamedValue(
"path", logPath);
168 if(!Strings.isBlank(logName)) {
169 wc.addClause(
"and log.name = :name");
170 wc.addNamedValue(
"name", logName);
172 if(fromDate !=
null) {
173 wc.addClause(
"and log.dateLog >= :date");
174 wc.addNamedValue(
"date", fromDate);
176 if(!Strings.isBlank(logComment)) {
177 wc.addClause(
"and log.comment = :comment");
178 wc.addNamedValue(
"comment", logComment);
180 wc.addClause(
"order by log.dateLog DESC");
181 return new ContactsPU().getResultList(wc);
184 private boolean isReadableAndShort(String data) {
185 return (!data.startsWith(
"<") && data.length() <= 50);
static String get(String msg)
void setFromDate(Date fromDate)
void setLogName(String logName)
void setLogComment(String logComment)
void setLogPath(String logPath)