BrightSide Workbench Full Report + Source Code
elephant-scheduler-www/src/main/java/org/turro/scheduler/zul/TaskListbox.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.HashSet;
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.context.IConstructor;
25 import org.turro.elephant.impl.context.ContextFactory;
26 import org.turro.reflection.Instances;
27 import org.turro.scheduler.motor.DefaultTask;
28 import org.turro.scheduler.motor.ScheduledTask;
29 import org.zkoss.zul.Listbox;
30 import org.zkoss.zul.Listitem;
31 
36 public class TaskListbox extends Listbox {
37 
38  public TaskListbox() {
39  setMold("select");
40  addItems();
41  }
42 
44  return getSelectedItem() != null ? (ScheduledTask) getSelectedItem().getValue() : null;
45  }
46 
47  private void addItems() {
48  HashSet<String> doneNames = new HashSet<>();
50  for(String s : (List<String>) ContextFactory.getImplementationNamesByType("IScheduledTask")) {
52  if(st != null && !Strings.isBlank(st.getName())) {
53  if(!doneNames.contains(st.getName())) {
54  doneNames.add(st.getName());
55  st.setImplementation(s);
56  Listitem item = new Listitem(st.getName());
57  item.setValue(st);
58  appendChild(item);
59  if(getSelectedItem() == null) {
60  setSelectedItem(item);
61  }
62  }
63  }
64  }
65  for(ScheduledTask s : Instances.cached().bySuper(DefaultTask.class, ScheduledTask.class)) {
66  if(s != null && !Strings.isBlank(s.getName())) {
67  if(!doneNames.contains(s.getName())) {
68  doneNames.add(s.getName());
69  s.setImplementation(s.getClass().getName());
70  Listitem item = new Listitem(s.getName());
71  item.setValue(s);
72  appendChild(item);
73  if(getSelectedItem() == null) {
74  setSelectedItem(item);
75  }
76  }
77  }
78  }
79  }
80 
81 }
static Object getImplementation(IElement iel, String name)