18 package org.turro.scheduler.zul.entities;
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.plugin.scheduler.ScheduledEdit;
26 import org.turro.scheduler.constraints.Month;
27 import org.turro.scheduler.constraints.WeekDay;
28 import org.turro.scheduler.entities.DefaultEntity;
29 import org.turro.scheduler.entities.ScheduledEntity;
30 import org.turro.scheduler.entities.ScheduledEntitySet;
31 import org.turro.zkoss.dialog.SelectionDialog;
32 import org.turro.zkoss.input.DateboxShort;
33 import org.zkoss.zk.ui.HtmlBasedComponent;
34 import org.zkoss.zk.ui.event.Event;
35 import org.zkoss.zk.ui.event.EventListener;
36 import org.zkoss.zk.ui.event.Events;
37 import org.zkoss.zul.Button;
38 import org.zkoss.zul.Caption;
39 import org.zkoss.zul.Checkbox;
40 import org.zkoss.zul.Datebox;
41 import org.zkoss.zul.Groupbox;
42 import org.zkoss.zul.Hbox;
43 import org.zkoss.zul.Label;
44 import org.zkoss.zul.Panel;
45 import org.zkoss.zul.Panelchildren;
46 import org.zkoss.zul.Textbox;
47 import org.zkoss.zul.Vbox;
58 private Panelchildren children;
59 private Textbox description, notify;
60 private Checkbox months[], weekDays[], daysOfMonth[], active;
61 private Datebox startDate, endDate;
64 this.scheduledEntity = scheduledEntity;
65 this.scheduledEdit = scheduledEdit;
66 children =
new Panelchildren();
67 children.setStyle(
"padding:10px");
68 appendChild(children);
72 private void addFields() {
76 children.getChildren().clear();
78 Vbox parentBox =
new Vbox();
79 parentBox.setSpacing(
"5px");
80 children.appendChild(parentBox);
82 Hbox hbox =
new Hbox();
83 hbox.setSpacing(
"5px");
84 parentBox.appendChild(hbox);
86 hbox.appendChild(
new Label(
I_.
get(
"Description")));
89 description.setCols(80);
90 hbox.appendChild(description);
103 if(scheduledEdit !=
null) {
104 HtmlBasedComponent hbc = (HtmlBasedComponent) scheduledEdit.
getDataEditor(scheduledEntity.
getData());
106 parentBox.appendChild(hbc);
111 hbox.setSpacing(
"5px");
112 parentBox.appendChild(hbox);
114 Groupbox gb =
new Groupbox();
116 hbox.appendChild(gb);
118 Caption caption =
new Caption(I_.get(
"Months"));
119 gb.appendChild(caption);
121 Vbox vbox =
new Vbox();
122 gb.appendChild(vbox);
124 months =
new Checkbox[12];
126 for(Month m : Month.values()) {
127 months[i] =
new Checkbox(Strings.capitalize(dfs.getMonths()[i]));
128 months[i].setChecked(((DefaultEntity) scheduledEntity).getConstraints().getMonths().contains(m));
129 vbox.appendChild(months[i]);
135 hbox.appendChild(gb);
137 caption =
new Caption(I_.get(
"Days of month"));
138 gb.appendChild(caption);
140 Hbox hb =
new Hbox();
143 daysOfMonth =
new Checkbox[31];
144 for(
int x = 0; x < 31; x++) {
147 hb.appendChild(vbox);
149 daysOfMonth[x] =
new Checkbox((x + 1) +
"");
150 daysOfMonth[x].setChecked(((DefaultEntity) scheduledEntity).getConstraints().getDaysOfMonth().contains(x + 1));
151 vbox.appendChild(daysOfMonth[x]);
156 hbox.appendChild(gb);
158 caption =
new Caption(I_.get(
"Days of week"));
159 gb.appendChild(caption);
162 gb.appendChild(vbox);
164 weekDays =
new Checkbox[7];
166 for(WeekDay wd : WeekDay.values()) {
167 weekDays[i] =
new Checkbox(Strings.capitalize(dfs.getWeekdays()[WeekDay.map(i)]));
168 weekDays[i].setChecked(((DefaultEntity) scheduledEntity).getConstraints().getWeekDays().contains(wd));
169 vbox.appendChild(weekDays[i]);
175 hbox.appendChild(gb);
178 gb.appendChild(vbox);
180 active =
new Checkbox(I_.get(
"Active"));
181 active.setChecked(scheduledEntity.isActive());
182 vbox.appendChild(active);
185 vbox.appendChild(hb);
187 Vbox vb =
new Vbox();
190 vb.appendChild(
new Label(I_.get(
"Start date")));
191 vb.appendChild(
new Label(I_.get(
"End date")));
196 startDate =
new DateboxShort(scheduledEntity.getStartDate());
197 vb.appendChild(startDate);
199 endDate =
new DateboxShort(scheduledEntity.getEndDate());
200 vb.appendChild(endDate);
203 hbox.setSpacing(
"5px");
204 parentBox.appendChild(hbox);
206 Button saveButton =
new Button(
208 "/_zul/images/save.png"
210 saveButton.addEventListener(Events.ON_CLICK,
new EventListener() {
213 public void onEvent(Event event)
throws Exception {
215 Events.postEvent(
new Event(Events.ON_CLOSE, Components.from(
TaskEdit.this).parent(SelectionDialog.class)));
219 hbox.appendChild(saveButton);
221 Button cancelButton =
new Button(
225 cancelButton.addEventListener(Events.ON_CLICK,
new EventListener() {
227 public void onEvent(Event event)
throws Exception {
228 Events.postEvent(
new Event(Events.ON_CLOSE, Components.from(
TaskEdit.this).parent(SelectionDialog.class)));
231 hbox.appendChild(cancelButton);
233 Button delButton =
new Button(
235 "/_zul/images/edit-delete.png"
237 delButton.addEventListener(Events.ON_CLICK,
new EventListener() {
240 public void onEvent(Event event)
throws Exception {
241 ScheduledEntitySet.removeEntity(scheduledEntity);
242 Events.postEvent(
new Event(Events.ON_CLOSE, Components.from(
TaskEdit.this).parent(SelectionDialog.class)));
246 hbox.appendChild(delButton);
249 private void doSave() {
250 scheduledEntity.setDescription(description.getText());
252 if(scheduledEdit !=
null) {
256 ((DefaultEntity) scheduledEntity).getConstraints().getMonths().clear();
258 for(Month m : Month.values()) {
259 if(months[i].isChecked()) {
260 ((DefaultEntity) scheduledEntity).getConstraints().getMonths().add(m);
265 ((DefaultEntity) scheduledEntity).getConstraints().getDaysOfMonth().clear();
266 for(
int x = 0; x < 31; x++) {
267 if(daysOfMonth[x].isChecked()) {
268 ((DefaultEntity) scheduledEntity).getConstraints().getDaysOfMonth().add(x + 1);
272 ((DefaultEntity) scheduledEntity).getConstraints().getWeekDays().clear();
274 for(WeekDay wd : WeekDay.values()) {
275 if(weekDays[i].isChecked()) {
276 ((DefaultEntity) scheduledEntity).getConstraints().getWeekDays().add(wd);
281 scheduledEntity.setStartDate(startDate.getValue());
282 scheduledEntity.setEndDate(endDate.getValue());
283 scheduledEntity.setActive(active.isChecked());
285 ScheduledEntitySet.addEntity(scheduledEntity);
static Locale getUsedLocale()
static String get(String msg)
TaskEdit(ScheduledEntity scheduledEntity, ScheduledEdit scheduledEdit)
Object getDataEditor(String data)
String getDataEditorValue()