18 package org.turro.scheduler.zul;
20 import java.text.DateFormatSymbols;
21 import org.turro.string.Strings;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.util.Components;
24 import org.turro.i18n.I_;
25 import org.turro.scheduler.constraints.Month;
26 import org.turro.scheduler.constraints.WeekDay;
27 import org.turro.scheduler.motor.DefaultTask;
28 import org.turro.scheduler.motor.Motor;
29 import org.turro.scheduler.motor.ScheduledSet;
30 import org.turro.scheduler.motor.ScheduledTask;
31 import org.turro.zkoss.dialog.SelectionDialog;
32 import org.turro.zkoss.input.DateboxShort;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zul.Button;
37 import org.zkoss.zul.Caption;
38 import org.zkoss.zul.Checkbox;
39 import org.zkoss.zul.Datebox;
40 import org.zkoss.zul.Groupbox;
41 import org.zkoss.zul.Hbox;
42 import org.zkoss.zul.Label;
43 import org.zkoss.zul.Panel;
44 import org.zkoss.zul.Panelchildren;
45 import org.zkoss.zul.Textbox;
46 import org.zkoss.zul.Vbox;
57 private Panelchildren children;
58 private Textbox description, data;
59 private Checkbox months[], weekDays[], daysOfMonth[],
60 hours[], minutes[], active;
61 private Datebox startDate, endDate;
64 this.scheduledTask = scheduledTask;
65 children =
new Panelchildren();
66 children.setStyle(
"padding:10px");
67 appendChild(children);
71 private void addFields() {
75 children.getChildren().clear();
77 Vbox parentBox =
new Vbox();
78 parentBox.setSpacing(
"5px");
79 children.appendChild(parentBox);
81 Hbox hbox =
new Hbox();
82 hbox.setSpacing(
"5px");
83 parentBox.appendChild(hbox);
85 hbox.appendChild(
new Label(
I_.
get(
"Description")));
88 description.setCols(80);
89 hbox.appendChild(description);
93 hbox.setSpacing(
"5px");
94 parentBox.appendChild(hbox);
96 hbox.appendChild(
new Label(scheduledTask.
getDataLabel()));
98 data =
new Textbox(scheduledTask.
getData());
100 hbox.appendChild(data);
104 hbox.setSpacing(
"5px");
105 parentBox.appendChild(hbox);
107 Groupbox gb =
new Groupbox();
109 hbox.appendChild(gb);
111 Caption caption =
new Caption(I_.get(
"Months"));
112 gb.appendChild(caption);
114 Vbox vbox =
new Vbox();
115 gb.appendChild(vbox);
117 months =
new Checkbox[12];
119 for(Month m : Month.values()) {
120 months[i] =
new Checkbox(Strings.capitalize(dfs.getMonths()[i]));
121 months[i].setChecked(((DefaultTask) scheduledTask).getConstraints().getMonths().contains(m));
122 vbox.appendChild(months[i]);
128 hbox.appendChild(gb);
130 caption =
new Caption(I_.get(
"Days of month"));
131 gb.appendChild(caption);
133 Hbox hb =
new Hbox();
136 daysOfMonth =
new Checkbox[31];
137 for(
int x = 0; x < 31; x++) {
140 hb.appendChild(vbox);
142 daysOfMonth[x] =
new Checkbox((x + 1) +
"");
143 daysOfMonth[x].setChecked(((DefaultTask) scheduledTask).getConstraints().getDaysOfMonth().contains(x + 1));
144 vbox.appendChild(daysOfMonth[x]);
149 hbox.appendChild(gb);
151 caption =
new Caption(I_.get(
"Days of week"));
152 gb.appendChild(caption);
155 gb.appendChild(vbox);
157 weekDays =
new Checkbox[7];
159 for(WeekDay wd : WeekDay.values()) {
160 weekDays[i] =
new Checkbox(Strings.capitalize(dfs.getWeekdays()[WeekDay.map(i)]));
161 weekDays[i].setChecked(((DefaultTask) scheduledTask).getConstraints().getWeekDays().contains(wd));
162 vbox.appendChild(weekDays[i]);
168 hbox.appendChild(gb);
170 caption =
new Caption(I_.get(
"Hours"));
171 gb.appendChild(caption);
176 hours =
new Checkbox[24];
177 for(
int x = 0; x < 24; x++) {
180 hb.appendChild(vbox);
182 hours[x] =
new Checkbox(x +
"");
183 hours[x].setChecked(((DefaultTask) scheduledTask).getConstraints().getHours().contains(x));
184 vbox.appendChild(hours[x]);
189 hbox.appendChild(gb);
191 caption =
new Caption(I_.get(
"Minutes"));
192 gb.appendChild(caption);
195 gb.appendChild(vbox);
197 minutes =
new Checkbox[12];
198 for(
int x = 0; x < 12; x++) {
199 minutes[x] =
new Checkbox((x * 5) +
"");
200 minutes[x].setChecked(((DefaultTask) scheduledTask).getConstraints().getMinutes().contains((x * 5)));
201 vbox.appendChild(minutes[x]);
206 hbox.appendChild(gb);
209 gb.appendChild(vbox);
211 active =
new Checkbox(I_.get(
"Active"));
212 active.setChecked(scheduledTask.isActive());
213 vbox.appendChild(active);
216 vbox.appendChild(hb);
218 Vbox vb =
new Vbox();
221 vb.appendChild(
new Label(I_.get(
"Start date")));
222 vb.appendChild(
new Label(I_.get(
"End date")));
227 startDate =
new DateboxShort(scheduledTask.getStartDate());
228 vb.appendChild(startDate);
230 endDate =
new DateboxShort(scheduledTask.getEndDate());
231 vb.appendChild(endDate);
234 hbox.setSpacing(
"5px");
235 parentBox.appendChild(hbox);
237 Button saveButton =
new Button(
239 "/_zul/images/save.png"
241 saveButton.addEventListener(Events.ON_CLICK,
new EventListener() {
243 public void onEvent(Event event)
throws Exception {
245 Events.postEvent(
new Event(Events.ON_CLOSE, Components.from(
TaskEdit.this).parent(SelectionDialog.class)));
249 hbox.appendChild(saveButton);
251 Button saveRunButton =
new Button(
252 I_.get(
"Save and run"),
253 "/_zul/images/service.png"
255 saveRunButton.addEventListener(Events.ON_CLICK,
new EventListener() {
257 public void onEvent(Event event)
throws Exception {
259 Events.postEvent(
new Event(Events.ON_CLOSE, Components.from(
TaskEdit.this).parent(SelectionDialog.class)));
260 if(scheduledTask.isDone()) {
261 scheduledTask.doRun(Motor.getInstance());
266 hbox.appendChild(saveRunButton);
268 Button cancelButton =
new Button(
272 cancelButton.addEventListener(Events.ON_CLICK,
new EventListener() {
274 public void onEvent(Event event)
throws Exception {
275 Events.postEvent(
new Event(Events.ON_CLOSE, Components.from(
TaskEdit.this).parent(SelectionDialog.class)));
278 hbox.appendChild(cancelButton);
281 private void doSave() {
282 scheduledTask.setDescription(description.getText());
283 if(scheduledTask.getDataLabel() !=
null) {
284 scheduledTask.setData(data.getText());
287 ((DefaultTask) scheduledTask).getConstraints().getMonths().clear();
289 for(Month m : Month.values()) {
290 if(months[i].isChecked()) {
291 ((DefaultTask) scheduledTask).getConstraints().getMonths().add(m);
296 ((DefaultTask) scheduledTask).getConstraints().getDaysOfMonth().clear();
297 for(
int x = 0; x < 31; x++) {
298 if(daysOfMonth[x].isChecked()) {
299 ((DefaultTask) scheduledTask).getConstraints().getDaysOfMonth().add(x + 1);
303 ((DefaultTask) scheduledTask).getConstraints().getWeekDays().clear();
305 for(WeekDay wd : WeekDay.values()) {
306 if(weekDays[i].isChecked()) {
307 ((DefaultTask) scheduledTask).getConstraints().getWeekDays().add(wd);
312 ((DefaultTask) scheduledTask).getConstraints().getHours().clear();
313 for(
int x = 0; x < 24; x++) {
314 if(hours[x].isChecked()) {
315 ((DefaultTask) scheduledTask).getConstraints().getHours().add(x);
319 ((DefaultTask) scheduledTask).getConstraints().getMinutes().clear();
320 for(
int x = 0; x < 12; x++) {
321 if(minutes[x].isChecked()) {
322 ((DefaultTask) scheduledTask).getConstraints().getMinutes().add(x * 5);
326 scheduledTask.setStartDate(startDate.getValue());
327 scheduledTask.setEndDate(endDate.getValue());
328 scheduledTask.setActive(active.isChecked());
330 ScheduledSet.saveSet(Application.getApplication().getConstructor(), Motor.getInstance().getTasks());
static Locale getUsedLocale()
static String get(String msg)
TaskEdit(ScheduledTask scheduledTask)