Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/EntityList.java @ 216:93d33f138c9e default tip
update medeniyet image server URL.
author | casties |
---|---|
date | Wed, 26 Jan 2022 16:39:32 +0100 |
parents | 28a0c2726466 |
children |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.util.guiComponents; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Collections; | |
5 import java.util.HashMap; | |
6 import java.util.List; | |
7 import java.util.Map; | |
8 | |
9 import javax.faces.event.ActionEvent; | |
10 import javax.faces.event.ValueChangeEvent; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 import org.mpi.openmind.cache.WrapperService; | |
14 import org.mpi.openmind.repository.bo.Attribute; | |
15 import org.mpi.openmind.repository.bo.Entity; | |
16 import org.mpi.openmind.repository.bo.Node; | |
17 | |
18 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; | |
19 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; | |
20 | |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
21 public class EntityList extends AbstractISMIBean { |
1 | 22 |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
23 protected static final long serialVersionUID = -3339006604248018647L; |
1 | 24 |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
25 protected static Logger logger = Logger.getLogger(EntityList.class); |
1 | 26 |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
27 protected List<Entity> entities = new ArrayList<Entity>(); |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
28 protected Map<Long, Boolean> selections = new HashMap<Long, Boolean>(); |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
29 protected String title; |
1 | 30 |
31 //some relations have an attribute date | |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
32 protected boolean useCalendar; |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
33 protected Map<Long, Calendar> calendarMap; |
1 | 34 |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
35 protected ListenerObject lo; |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
36 |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
37 protected String input; |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
38 protected Long id; |
1 | 39 |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
40 protected WrapperService otg; |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
41 protected String user; |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
42 |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
43 public EntityList() { |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
44 // empty default constructor |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
45 } |
1 | 46 |
47 public EntityList(String oc, String attName, String title){ | |
48 this.lo = new ListenerObject(oc, attName); | |
49 this.title = title; | |
50 } | |
51 | |
52 public EntityList(String oc, String attName, boolean useCalendar){ | |
53 this.lo = new ListenerObject(oc, attName); | |
54 this.useCalendar = useCalendar; | |
55 this.calendarMap = new HashMap<Long, Calendar>(); | |
56 } | |
57 | |
58 public EntityList(String oc, String attName, WrapperService otg, String user){ | |
59 this.lo = new ListenerObject(oc, attName); | |
60 this.otg = otg; | |
61 this.user = user; | |
62 } | |
63 | |
64 public EntityList(String oc, String attName, WrapperService otg, String user, boolean useCalendar){ | |
65 this.lo = new ListenerObject(oc, attName); | |
66 this.otg = otg; | |
67 this.user = user; | |
68 this.useCalendar = useCalendar; | |
69 this.calendarMap = new HashMap<Long, Calendar>(); | |
70 } | |
71 | |
72 | |
73 public void listenerAddRole(ActionEvent event){ | |
74 if(otg != null && isUnique(id)){ | |
75 Entity role = otg.getEntityById(id); | |
76 if(role != null){ | |
77 this.add(role); | |
78 } | |
79 } | |
80 } | |
81 | |
82 public void listenerCreate(ActionEvent event){ | |
83 try { | |
84 if(otg != null && isUnique(input)){ | |
85 Entity e = new Entity(Node.TYPE_ABOX, lo.getClassObj(), false); | |
86 e.setOwnValue(input); | |
87 e.addAttribute(new Attribute(this.lo.getAttName(), "text", input)); | |
124
28a0c2726466
changed saveEntity() to use new EditIntent. Set up EditIntent for TEXT, PERSON, REFERENCE.
casties
parents:
112
diff
changeset
|
88 otg.saveEntity(e, this.user, null); |
1 | 89 this.add(e); |
90 } | |
91 } catch (Exception e) { | |
92 logger.error(e.getMessage(), e); | |
93 e.printStackTrace(); | |
94 this.printInternalError(e); | |
95 } | |
96 } | |
97 | |
98 public void listenerCreateNoUnique(ActionEvent event){ | |
99 try { | |
100 if(otg != null ){ | |
101 Entity e = new Entity(Node.TYPE_ABOX, lo.getClassObj(), false); | |
102 e.setOwnValue(input); | |
103 e.addAttribute(new Attribute(this.lo.getAttName(), "text", input)); | |
124
28a0c2726466
changed saveEntity() to use new EditIntent. Set up EditIntent for TEXT, PERSON, REFERENCE.
casties
parents:
112
diff
changeset
|
104 otg.saveEntity(e, this.user, null); |
1 | 105 this.add(e); |
106 } | |
107 } catch (Exception e) { | |
108 logger.error(e.getMessage(), e); | |
109 e.printStackTrace(); | |
110 this.printInternalError(e); | |
111 } | |
112 } | |
113 | |
114 private boolean isUnique(Long id){ | |
115 for(Entity e : entities){ | |
116 if(e.getId().compareTo(id) == 0){ | |
117 addErrorMsg("This entity was already selected."); | |
118 return false; | |
119 } | |
120 } | |
121 return true; | |
122 } | |
123 | |
124 private boolean isUnique(String input){ | |
125 for(Entity e : entities){ | |
126 if(e.getOwnValue().equals(input)){ | |
127 addErrorMsg("An entity " + lo.getClassObj() + " with name " + input + " exists already."); | |
128 return false; | |
129 } | |
130 } | |
131 return true; | |
132 } | |
133 | |
134 public void listenerChanged(ValueChangeEvent event) { | |
135 this.lo = changeListener(event, lo, this.lo.getClassObj(), this.lo.getAttName()); | |
136 if(lo.entity != null && lo.entity.isPersistent()){ | |
137 lo.statusImage.setStatus(StatusImage.STATUS_OK); | |
138 }else{ | |
139 lo.statusImage.setStatus(StatusImage.STATUS_UNSET); | |
140 } | |
141 } | |
142 | |
143 public void listenerAdd(ActionEvent event){ | |
144 this.add(this.lo.entity); | |
145 } | |
146 | |
147 public void listenerRemoveSelection(ActionEvent event){ | |
148 for(Entity remove : getSelectedEntities()){ | |
149 this.remove(remove.getId()); | |
150 } | |
151 } | |
152 | |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
153 /** |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
154 * Add an Entity to the list. |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
155 * |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
156 * @param e |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
157 */ |
1 | 158 public void add(Entity e){ |
159 if(e != null && e.isPersistent()){ | |
160 if(!selections.containsKey(e.getId())){ | |
161 this.entities.add(e); | |
162 this.selections.put(e.getId(), false); | |
163 Collections.sort(this.entities); | |
164 if(useCalendar){ | |
165 Calendar cal = new Calendar(); | |
166 this.calendarMap.put(e.getId(), cal); | |
167 } | |
168 } | |
169 } | |
170 } | |
171 | |
112
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
172 /** |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
173 * Add an Entity with a calendar Attribute to the list. |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
174 * |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
175 * @param e |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
176 * @param calendarAtt |
59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
casties
parents:
1
diff
changeset
|
177 */ |
1 | 178 public void add(Entity e, Attribute calendarAtt){ |
179 if(e != null && e.isPersistent()){ | |
180 if(!selections.containsKey(e.getId())){ | |
181 this.entities.add(e); | |
182 this.selections.put(e.getId(), false); | |
183 Collections.sort(this.entities); | |
184 if(useCalendar){ | |
185 if(calendarAtt == null){ | |
186 this.calendarMap.put(e.getId(), new Calendar()); | |
187 }else{ | |
188 this.calendarMap.put(e.getId(), AbstractISMIBean.updateCalendar(calendarAtt)); | |
189 } | |
190 } | |
191 } | |
192 } | |
193 } | |
194 | |
195 public Calendar getCalendar(Long entId){ | |
196 if(calendarMap != null){ | |
197 return calendarMap.get(entId); | |
198 } | |
199 return null; | |
200 } | |
201 | |
202 public void addList(List<Entity> list){ | |
203 for(Entity e : list){ | |
204 this.add(e); | |
205 } | |
206 } | |
207 | |
208 public void remove(Long id){ | |
209 this.selections.remove(id); | |
210 Entity e = null; | |
211 for(Entity ent : entities){ | |
212 if(ent.getId().intValue() == id){ | |
213 e = ent; | |
214 break; | |
215 } | |
216 } | |
217 this.entities.remove(e); | |
218 } | |
219 | |
220 | |
221 | |
222 private List<Entity> getSelectedEntities(){ | |
223 List<Entity> list = new ArrayList<Entity>(); | |
224 for(Entity e : entities){ | |
225 if(selections.get(e.getId())){ | |
226 list.add(e); | |
227 } | |
228 } | |
229 return list; | |
230 } | |
231 | |
232 | |
233 public List<Entity> getEntities() { | |
234 return entities; | |
235 } | |
236 public void setEntities(List<Entity> entities) { | |
237 this.entities = entities; | |
238 } | |
239 public Map<Long, Boolean> getSelections() { | |
240 return selections; | |
241 } | |
242 | |
243 public void setSelections(Map<Long, Boolean> selections) { | |
244 this.selections = selections; | |
245 } | |
246 | |
247 public ListenerObject getLo() { | |
248 return lo; | |
249 } | |
250 | |
251 public void setLo(ListenerObject lo) { | |
252 this.lo = lo; | |
253 } | |
254 | |
255 public String getInput() { | |
256 return input; | |
257 } | |
258 | |
259 public void setInput(String input) { | |
260 this.input = input; | |
261 } | |
262 | |
263 public Long getId() { | |
264 return id; | |
265 } | |
266 | |
267 public void setId(Long id) { | |
268 this.id = id; | |
269 } | |
270 | |
271 public Map<Long, Calendar> getCalendarMap() { | |
272 return calendarMap; | |
273 } | |
274 | |
275 public void setCalendarMap(Map<Long, Calendar> calendarMap) { | |
276 this.calendarMap = calendarMap; | |
277 } | |
278 | |
279 public boolean isUseCalendar() { | |
280 return useCalendar; | |
281 } | |
282 | |
283 public String getTitle() { | |
284 return title; | |
285 } | |
286 } |