BrightSide Workbench Full Report + Source Code
elephant-scheduler-www/src/main/java/org/turro/scheduler/zul/TaskGrid.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.util.Set;
21 import org.turro.elephant.context.Application;
22 import org.turro.i18n.I_;
23 import org.turro.scheduler.motor.Motor;
24 import org.turro.scheduler.motor.ScheduledTask;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.EventListener;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zul.Column;
29 import org.zkoss.zul.Columns;
30 import org.zkoss.zul.Grid;
31 import org.zkoss.zul.Rows;
32 import org.zkoss.zul.Toolbar;
33 import org.zkoss.zul.Toolbarbutton;
34 
39 @Deprecated
40 public class TaskGrid extends Grid {
41 
42  private Rows rows;
43  private Toolbar toolbar;
44 
45  public TaskGrid() {
46  addColumns();
47  addRows();
48  }
49 
50  public void setAddToolbar(boolean addToolbar) {
51  if(addToolbar) {
52  if(toolbar != null) getParent().removeChild(toolbar);
53  toolbar = new Toolbar();
54  getParent().insertBefore(toolbar, this);
55  addToolbarButtons();
56  }
57  }
58 
59  private void addColumns() {
60  Columns cols = new Columns();
61  cols.setSizable(true);
62  cols.setMenupopup("auto");
63  appendChild(cols);
64 
65  Column col = new Column(I_.get("Name"));
66  col.setWidth("300px");
67  cols.appendChild(col);
68  col = new Column(I_.get("Description"));
69  cols.appendChild(col);
70  col = new Column(I_.get("Active"));
71  col.setWidth("50px");
72  cols.appendChild(col);
73  col = new Column(I_.get("Start date"));
74  col.setWidth("150px");
75  cols.appendChild(col);
76  col = new Column(I_.get("End date"));
77  col.setWidth("150px");
78  cols.appendChild(col);
79  if(Application.getApplication().isInRole("scheduled-task:delete")) {
80  col = new Column();
81  col.setWidth("25px");
82  cols.appendChild(col);
83  }
84  }
85 
86  private void addRows() {
87 
88  if(rows != null) removeChild(rows);
89 
90  rows = new Rows();
91  appendChild(rows);
92 
93 // for(final ScheduledTask st : (Set<ScheduledTask>) Motor.getInstance().getTasks()) {
94 // TaskRow row = new TaskRow();
95 // row.setValue(st);
96 // rows.appendChild(row);
97 // }
98 
99  invalidate();
100  }
101 
102  private void addToolbarButtons() {
103  final TaskListbox tl = new TaskListbox();
104  toolbar.appendChild(tl);
105 
106  Toolbarbutton addButton = new Toolbarbutton(
107  I_.get("Add task"),
108  "/_zul/images/new.png"
109  );
110  addButton.addEventListener(Events.ON_CLICK, new EventListener() {
111  @Override
112  public void onEvent(Event event) throws Exception {
113 // Motor.getInstance().getTasks().add(tl.getTask());
114  addRows();
115  }
116  });
117  toolbar.appendChild(addButton);
118 
119  addButton.setDisabled(tl.getTask() == null);
120  }
121 
122 }
static String get(String msg)
Definition: I_.java:41