BrightSide Workbench Full Report + Source Code
CalendarInfoComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.info;
20 
21 import java.util.Date;
22 import org.amic.util.date.CheckDate;
23 import org.turro.calendar.CalendarMode;
24 import org.turro.elephant.util.DateFormats;
25 import org.turro.util.Chars;
26 import org.zkoss.zk.ui.Component;
27 import org.zkoss.zk.ui.event.ForwardEvent;
28 import org.zkoss.zk.ui.util.Clients;
29 import org.zkoss.zk.ui.util.GenericForwardComposer;
30 import org.zkoss.zul.Datebox;
31 import org.zkoss.zul.Label;
32 
37 public class CalendarInfoComposer extends GenericForwardComposer<Component> {
38 
39  private CalendarInfo calendar;
40  private Label currentDate;
41  private Datebox currentBox;
42 
43  public void onClick$butDay() {
44  calendar.setMode(CalendarMode.DAY_MODE);
45  calendar.refreshModel();
46  setCurrentDate();
47  }
48 
49  public void onClick$butWeek() {
50  calendar.setMode(CalendarMode.WEEK_MODE);
51  calendar.refreshModel();
52  setCurrentDate();
53  }
54 
55  public void onClick$butMonth() {
57  calendar.refreshModel();
58  setCurrentDate();
59  }
60 
61  public void onClick$butPrior() {
62  calendar.previousPage();
63  setCurrentDate();
64  }
65 
66  public void onClick$butNext() {
67  calendar.nextPage();
68  setCurrentDate();
69  }
70 
71  public void onClick$butToday() {
72  calendar.setCurrentDate(java.util.Calendar.getInstance().getTime());
73  calendar.refreshModel();
74  setCurrentDate();
75  }
76 
77  public void onDayClick$calendar(ForwardEvent event) {
78  calendar.setCurrentDate((Date) event.getOrigin().getData());
79  if(calendar.getMode() == CalendarMode.MONTH_MODE) {
80  calendar.setMode(CalendarMode.WEEK_MODE);
81  } else if(calendar.getMode() == CalendarMode.WEEK_MODE) {
82  calendar.setMode(CalendarMode.DAY_MODE);
83  }
84  calendar.refreshModel();
85  setCurrentDate();
86  }
87 
88  public void onChange$currentBox() {
89  calendar.setCurrentDate(currentBox.getValue());
90  calendar.refreshModel();
91  setCurrentDate();
92  }
93 
94  private void setCurrentDate() {
95  Date curr = calendar.getCurrentDate();
96  if(calendar.getMode() == CalendarMode.DAY_MODE) {
97  currentDate.setValue(DateFormats.format(curr, true));
98  currentBox.setValue(curr);
99  } else if(calendar.getMode() == CalendarMode.WEEK_MODE) {
100  currentDate.setValue(
101  DateFormats.format(calendar.getBeginDate(), true) +
102  Chars.forward().spaced().toString() +
103  DateFormats.format(calendar.getEndDate(), true));
104  currentBox.setValue(calendar.getBeginDate());
105  } else if(calendar.getMode() == CalendarMode.MONTH_MODE) {
106  currentDate.setValue(DateFormats.monthName(curr) +
107  Chars.forward().spaced().toString() +
108  new CheckDate(curr).getYear());
109  currentBox.setValue(calendar.getBeginDate());
110  }
111  setTooltips();
112  }
113 
114  @Override
115  public void doAfterCompose(Component comp) throws Exception {
116  super.doAfterCompose(comp);
117  setCurrentDate();
118  }
119 
120  private void setTooltips() {
121  Clients.evalJavaScript("setTimeout(addTooltips, 1000);");
122  }
123 
124 }
void onDayClick $calendar(ForwardEvent event)
void setMode(CalendarMode mode)
static final String format(Date d, boolean dateOnly)