BrightSide Workbench Full Report + Source Code
TaskRow.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.scheduler.zul;
19 
20 import java.text.DateFormat;
21 import java.util.Date;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.util.Messages;
24 import org.turro.i18n.I_;
25 import org.turro.scheduler.motor.Motor;
26 import org.turro.scheduler.motor.ScheduledTask;
27 import org.turro.zkoss.dialog.Windows;
28 import org.turro.zkoss.label.LabelExtended;
29 import org.turro.zul.frame.Framework;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zul.Image;
34 import org.zkoss.zul.Label;
35 import org.zkoss.zul.Row;
36 
41 @Deprecated
42 public class TaskRow extends Row {
43 
44  private final DateFormat df = DateFormat.getDateInstance();
45 
46  @Override
47  public void setValue(Object value) {
48  super.setValue(value);
49 
50  final ScheduledTask scheduledTask = (ScheduledTask) getValue();
51 
52  Label label = new Label();
53  label.setValue(scheduledTask.getName());
54  if(Application.getApplication().isInRole("scheduled-task:edit")) {
55  label.setStyle("cursor:pointer");
56  label.addEventListener(Events.ON_CLICK, new EventListener() {
57  @Override
58  public void onEvent(Event event) throws Exception {
59  doEdit();
60  }
61  });
62  }
63  appendChild(label);
64 
65  LabelExtended lext = new LabelExtended();
66  lext.setValue(scheduledTask.getDescription());
67  lext.setMaxChars(70);
68  lext.setShowTooltip(true);
69  appendChild(lext);
70 
71  appendChild(new Label(Boolean.toString(scheduledTask.isActive())));
72 
73  appendChild(new Label(formatDate(scheduledTask.getStartDate())));
74 
75  appendChild(new Label(formatDate(scheduledTask.getEndDate())));
76 
77  if(Application.getApplication().isInRole("scheduled-task:delete")) {
78  Image img = new Image("/_zul/images/edit-delete.png");
79  img.setStyle("cursor:pointer");
80  img.addEventListener(Events.ON_CLICK, new EventListener() {
81  @Override
82  public void onEvent(Event event) throws Exception {
83  Messages.confirmDeletion().show(() -> {
84  Motor.getInstance().getTasks().remove(scheduledTask);
85  Framework.getCurrent().invalidateSelected();
86  });
87  }
88  });
89  appendChild(img);
90  }
91 
92  }
93 
94  private void doEdit() throws InterruptedException {
95  ScheduledTask scheduledTask = (ScheduledTask) getValue();
96  Windows.title(I_.get("Scheduled task"))
97  .addComponent(new TaskEdit(scheduledTask))
98  .sizeable()
99  .onClose((windows) -> reloadCells())
100  .show();
101  }
102 
103  private String formatDate(Date value) {
104  return (value == null ? "" : df.format(value));
105  }
106 
107  private void reloadCells() {
108  getChildren().clear();
109  setValue(getValue());
110  }
111 
112 }
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41
static Motor getInstance()
Definition: Motor.java:62
void setValue(Object value)
Definition: TaskRow.java:47
static Windows title(String title)
Definition: Windows.java:138
Windows onClose(Consumer< Windows > onClose)
Definition: Windows.java:81
LabelExtended setShowTooltip(boolean showTooltip)
LabelExtended setMaxChars(int maxChars)
static Framework getCurrent()
Definition: Framework.java:203