Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/entry/beans/DigiListBean.java @ 1:2e911857a759
(none)
author | jurzua |
---|---|
date | Wed, 29 Oct 2014 14:00:28 +0000 |
parents | |
children | 4aa8c425685d |
comparison
equal
deleted
inserted
replaced
0:74df02964906 | 1:2e911857a759 |
---|---|
1 package de.mpiwg.itgroup.ismi.entry.beans; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Collections; | |
5 import java.util.List; | |
6 | |
7 import javax.faces.event.ActionEvent; | |
8 import javax.faces.event.AjaxBehaviorEvent; | |
9 import javax.faces.event.ValueChangeEvent; | |
10 import javax.faces.model.SelectItem; | |
11 | |
12 import org.apache.commons.lang.StringUtils; | |
13 import org.apache.log4j.Logger; | |
14 import org.mpi.openmind.cache.WrapperService; | |
15 import org.mpi.openmind.repository.bo.Entity; | |
16 | |
17 import de.mpiwg.itgroup.ismi.utils.templates.DigitalizationTemplate; | |
18 | |
19 public class DigiListBean extends AbstractBean{ | |
20 private static final long serialVersionUID = 8982550339613012125L; | |
21 private static Logger logger = Logger.getLogger(DigiListBean.class); | |
22 | |
23 | |
24 private static List<SelectItem> codexFilter; | |
25 | |
26 private static int ALL = 0; | |
27 private static int WITH_CODEX = 1; | |
28 private static int WITHOUT_CODEX = 2; | |
29 private int selectedFilter = ALL; | |
30 | |
31 static{ | |
32 codexFilter = new ArrayList<SelectItem>(); | |
33 codexFilter.add(new SelectItem(ALL, "All")); | |
34 codexFilter.add(new SelectItem(WITH_CODEX, "With codex")); | |
35 codexFilter.add(new SelectItem(WITHOUT_CODEX, "Without codex")); | |
36 } | |
37 | |
38 private List<DigitalizationTemplate> allList; | |
39 private List<DigitalizationTemplate> list; | |
40 private List<String> suggestionList; | |
41 private String filterTerm; | |
42 | |
43 public DigiListBean(WrapperService om){ | |
44 reset(om); | |
45 } | |
46 | |
47 | |
48 /* | |
49 public void listenerDigiFilter(ValueChangeEvent event){ | |
50 //System.out.println("listenerDigiFilter"); | |
51 //System.out.println(event.getNewValue()); | |
52 this.filterTerm = event.getNewValue() + ""; | |
53 filter(); | |
54 }*/ | |
55 | |
56 public void eventFilter(AjaxBehaviorEvent event){ | |
57 //System.out.println("AjaxBehaviorEvent: " + this.filterTerm); | |
58 if(StringUtils.isNotEmpty(filterTerm)){ | |
59 filter(); | |
60 }else{ | |
61 reset(getAppBean().getWrapper()); | |
62 } | |
63 } | |
64 | |
65 private void filter(){ | |
66 //System.out.println(this.allList.size()); | |
67 this.list = new ArrayList<DigitalizationTemplate>(); | |
68 this.suggestionList = new ArrayList<String>(); | |
69 | |
70 for(DigitalizationTemplate digi : this.allList){ | |
71 if(StringUtils.containsIgnoreCase(digi.getEntity().getOwnValue(), filterTerm)){ | |
72 addDigi(digi); | |
73 } | |
74 } | |
75 //System.out.println(this.list.size()); | |
76 Collections.sort(list); | |
77 } | |
78 | |
79 private void reset(WrapperService om){ | |
80 //System.out.println("Reset"); | |
81 list = new ArrayList<DigitalizationTemplate>(); | |
82 allList = new ArrayList<DigitalizationTemplate>(); | |
83 suggestionList = new ArrayList<String>(); | |
84 filterTerm = null; | |
85 | |
86 long start = System.currentTimeMillis(); | |
87 List<Entity> entList = om.getEntitiesByDef("DIGITALIZATION"); | |
88 for(Entity digi : entList){ | |
89 DigitalizationTemplate d = new DigitalizationTemplate(digi, om); | |
90 d.init(); | |
91 if(selectedFilter == ALL){ | |
92 //list.add(d); | |
93 this.addDigi(d); | |
94 }else if(selectedFilter == WITH_CODEX && d.isHasCodex()){ | |
95 //list.add(d); | |
96 this.addDigi(d); | |
97 }else if(selectedFilter == WITHOUT_CODEX && !d.isHasCodex()){ | |
98 //list.add(d); | |
99 this.addDigi(d); | |
100 } | |
101 } | |
102 Collections.sort(list); | |
103 this.allList = new ArrayList<DigitalizationTemplate>(list); | |
104 | |
105 long diff = System.currentTimeMillis() - start; | |
106 logger.info("DigitalizationList Generation - Time[ms] = " + diff); | |
107 } | |
108 | |
109 private void addDigi(DigitalizationTemplate d){ | |
110 this.list.add(d); | |
111 if(!suggestionList.contains(d.getEntity().getOwnValue())){ | |
112 this.suggestionList.add(d.getEntity().getOwnValue()); | |
113 } | |
114 } | |
115 | |
116 public int getListSize(){ | |
117 return this.list.size(); | |
118 } | |
119 | |
120 public void listenerRefresh(ActionEvent event){ | |
121 System.out.println("listenerRefresh"); | |
122 reset(getAppBean().getWrapper()); | |
123 } | |
124 | |
125 public String actionEditDigi(){ | |
126 DigitalizationTemplate digi = (DigitalizationTemplate)getRequestBean("digi"); | |
127 if(digi != null){ | |
128 getSessionBean().editEntity(digi.getEntity()); | |
129 return "entry_edit_entity"; | |
130 } | |
131 return null; | |
132 } | |
133 | |
134 public String actionEditWitness(){ | |
135 Entity entity = (Entity)getRequestBean("witness"); | |
136 if(entity != null){ | |
137 getSessionBean().editEntity(entity); | |
138 return "entry_edit_entity"; | |
139 } | |
140 return null; | |
141 } | |
142 | |
143 public List<DigitalizationTemplate> getList() { | |
144 return list; | |
145 } | |
146 | |
147 public int getSelectedFilter() { | |
148 return selectedFilter; | |
149 } | |
150 | |
151 public void setSelectedFilter(int selectedFilter) { | |
152 this.selectedFilter = selectedFilter; | |
153 } | |
154 | |
155 public List<SelectItem> getCodexFilter(){ | |
156 return codexFilter; | |
157 } | |
158 | |
159 | |
160 public String getFilterTerm() { | |
161 return filterTerm; | |
162 } | |
163 | |
164 | |
165 public void setFilterTerm(String filterTerm) { | |
166 this.filterTerm = filterTerm; | |
167 } | |
168 | |
169 public List<String> getSuggesstionList(){ | |
170 return this.suggestionList; | |
171 } | |
172 } |