BrightSide Workbench Full Report + Source Code
ScheduleListbox.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.calendar;
20 
21 import java.text.DateFormat;
22 import java.util.Collection;
23 import java.util.Date;
24 import org.amic.util.date.CheckDate;
25 import org.turro.string.Strings;
26 import org.turro.auth.Authentication;
27 import org.turro.calendar.event.CalendarEventSet;
28 import org.turro.elephant.context.Application;
29 import org.turro.i18n.I_;
30 import org.turro.plugin.calendar.ICalendarEvent;
31 import org.turro.plugin.command.CalendarPlugin;
32 import org.turro.zkoss.input.CollectionListbox;
33 import org.zkoss.zul.Listhead;
34 import org.zkoss.zul.Listheader;
35 import org.zkoss.zul.Listitem;
36 
41 public class ScheduleListbox extends CollectionListbox<ICalendarEvent> {
42 
43  private Date now;
44  private Listitem firstTodo;
45 
46  public void refresh() {
47  firstTodo = null;
48  now = new Date();
49  Collection events = CalendarPlugin.getCalendarFor(
51  new CheckDate(now).addMonths(-3).getDate(),
52  new CheckDate(now).addMonths(1).getDate());
53  if(events != null) {
54  updateCollection(new CalendarEventSet(events, true));
55  if(firstTodo != null) {
56  setSelectedItem(firstTodo);
57  }
58  }
59  }
60 
61  @Override
62  protected String convertToString(ICalendarEvent v) {
63  return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Application.getUsedLocale())
64  .format(v.getBeginDate()) + ITEM_SEPARATOR +
65  v.getTitle() + SUBITEM_SEPARATOR +
66  Strings.truncateAndWarn(v.getContent(), 50).replaceAll("\\n", SUBITEM_SEPARATOR);
67  }
68 
69  @Override
70  protected void beforeAppend(Listitem li) {
71  ICalendarEvent ce = li.getValue();
72  li.setStyle("vertical-align:top;color:" + ce.getHeaderColor() + ";");
73  if(now.after(ce.getBeginDate())) {
74  li.setSclass("invalid");
75  li.setStyle(li.getStyle() + "background-color:#ddd;");
76  } else if(firstTodo == null) {
77  firstTodo = li;
78  }
79  }
80 
81  @Override
82  public void afterCompose() {
83  addHeaders();
84  super.afterCompose();
85  if(firstTodo != null) {
86  setSelectedItem(firstTodo);
87  }
88  }
89 
90  private void addHeaders() {
91  if(getListhead() != null) return;
92  Listhead lh = new Listhead();
93  lh.setSizable(true);
94  lh.appendChild(new Listheader(I_.get("Date"), null, "100px"));
95  lh.appendChild(new Listheader(I_.get("Description")));
96  appendChild(lh);
97  }
98 
99 }
String convertToString(ICalendarEvent v)
static String get(String msg)
Definition: I_.java:41
static Collection< Object > getCalendarFor(IContact contact, Date from, Date to)