BrightSide Workbench Full Report + Source Code
bserp-www/src/main/java/org/turro/erp/task/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.erp.task;
19 
20 import java.util.Collection;
21 import org.turro.string.Strings;
22 import org.turro.contacts.zul.label.ContactInfo;
23 import org.turro.elephant.context.Application;
24 import org.turro.erp.entity.Task;
25 import org.turro.erp.menu.ErpMenu;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.turro.zkoss.label.LabelAdapter;
28 import org.turro.zkoss.label.LabelTypes;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zk.ui.ext.AfterCompose;
33 import org.zkoss.zul.*;
34 
39 public class TaskGrid extends PagingGrid implements AfterCompose {
40 
41  private TaskFilter filter = new TaskFilter();
42  private TaskFilterGrid filterGrid;
43 
44  public TaskFilter getFilter() {
45  return filter;
46  }
47 
48  public void setFilterGrid(TaskFilterGrid filterGrid) {
49  this.filterGrid = filterGrid;
50  }
51 
52  public void reload() {
53  if(getRows() != null) {
54  getRows().detach();
55  }
56  addRows();
57  }
58 
59  @Override
60  public void afterCompose() {
61  addColumns();
62  }
63 
64  private void addRows() {
65  if(!filterGrid.hasValues()) return;
66 
67  Collection<Task> list = filter.getTasks(filterGrid.getValues());
68 
69  Rows rows = getRows(true);
70  appendChild(rows);
71 
72  for(final Task t : list) {
73  Row r = new Row();
74  if(t.isEmpty()) {
75  r.setSclass("invalid");
76  }
77  getRows(true).appendChild(r);
78  Vlayout vbox = new Vlayout();
79  vbox.setSpacing("10px");
80  r.appendChild(vbox);
81  Hlayout hbox = new Hlayout();
82  hbox.setSpacing("10px");
83  vbox.appendChild(hbox);
84  A name = new A(t.getId() + " - " + t.getName(), "/_zul/images/task.png");
85  name.addEventListener(Events.ON_CLICK, new EventListener() {
86  @Override
87  public void onEvent(Event event) throws Exception {
88  //ErpMenu.showTask(t.getId());
89  ErpMenu.showTaskDetail(t, true);
90  }
91  });
92  hbox.appendChild(name);
93  if(t.isMilestone()) {
94  hbox.appendChild(new Image("/_zul/images/milestone.png"));
95  }
96  hbox.appendChild(LabelTypes.getSoftLabel(Application.getString(t.getStatus().toString())));
97  if(t.getAptitudeDegree() != null) {
98  hbox.appendChild(new Image("/_zul/images/aptitude.png"));
99  hbox.appendChild(LabelTypes.getSoftLabel(t.getAptitudeDegree().getFullName()));
100  }
101  if(t.getSupervised() != null) {
102  ContactInfo ci = new ContactInfo(t.getSupervised().getHumanResource().getContract().getContractor());
103  ci.setSclass("softLabel");
104  hbox.appendChild(ci);
105  }
106  if(!Strings.isBlank(t.getDescription())) {
107  vbox.appendChild(new LabelAdapter(LabelTypes.getSoftLabel(t.getDescription())).setMultiline(true));
108  }
109  }
110  }
111 
112  private void addColumns() {
113  getColumns(true).appendChild(new Column());
114  getColumns().setVisible(false);
115  }
116 
117 }
Collection< Task > getTasks(List< IFilterValue > values)
Definition: TaskFilter.java:45
List< IFilterValue > getValues()
Columns getColumns(boolean create)
Rows getRows(boolean create)