]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/AbstractOpenObject.java
Salome HOME
Modifications to respect PMD rules.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / AbstractOpenObject.java
1 package org.splat.simer;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.splat.dal.bo.kernel.User;
10 import org.splat.dal.bo.som.Document;
11 import org.splat.dal.bo.som.DocumentType;
12 import org.splat.dal.bo.som.KnowledgeElement;
13 import org.splat.dal.bo.som.KnowledgeElementType;
14 import org.splat.dal.bo.som.ProgressState;
15 import org.splat.dal.bo.som.Publication;
16 import org.splat.dal.bo.som.Scenario;
17 import org.splat.service.KnowledgeElementTypeService;
18 import org.splat.service.ProjectElementService;
19 import org.splat.service.PublicationService;
20 import org.splat.service.dto.KnowledgeElementDTO;
21 import org.splat.service.dto.Proxy;
22 import org.splat.service.technical.ProjectSettingsService;
23 import org.splat.som.Step;
24 import org.splat.util.BeanHelper;
25 import org.splat.wapp.Menu;
26 import org.splat.wapp.PopupMenu;
27
28 /**
29  * Open study or knowledge.
30  */
31 public abstract class AbstractOpenObject implements Proxy {
32
33         protected static Map<Long, DocumentFacade> docpres = null;
34         protected static Map<Long, KnowledgeElementFacade> knowpres = null;
35
36         /**
37          * Connected user.
38          */
39         protected transient User _cuser = null;
40         /**
41          * Menu selected by the user.
42          */
43         protected transient String _selection = null;
44         /**
45          * Corresponding selected step.
46          */
47         protected transient Step _ustep = null;
48         /**
49          * Object description (rich text).
50          */
51         protected transient String _description = null;
52         protected transient List<Step> _involving = new ArrayList<Step>();
53         /**
54          * Simulation Context display representations.
55          */
56         protected transient List<SimulationContextFacade> _context = new ArrayList<SimulationContextFacade>();
57         /**
58          * Document display representations.
59          */
60         protected transient List<DocumentFacade> _contents = null;
61         /**
62          * Knowledge Element display representations structured by knowledge types.
63          */
64         protected transient List<KnowledgeIterator> _knowledge = null;
65
66         /**
67          * Left pane menu of this object.
68          */
69         protected Menu _menu = null;
70         /**
71          * Pop-up menu of this object, if the user has write access.
72          */
73         protected transient PopupMenu _popup = null;
74         /**
75          * Injected project settings service.
76          */
77         private ProjectSettingsService _projectSettings;
78         /**
79          * Injected application settings bean.
80          */
81         private ApplicationSettings _applicationSettings;
82         /**
83          * Injected publication service.
84          */
85         private PublicationService _publicationService;
86         /**
87          * Injected knowledge element service.
88          */
89         private KnowledgeElementTypeService _knowledgeElementTypeService;
90         /**
91          * Injected project element service.
92          */
93         private ProjectElementService _projectElementService;
94
95         public class KnowledgeIterator {
96                 protected transient KnowledgeElementType _type;
97                 protected transient List<KnowledgeElementFacade> _list;
98
99                 public KnowledgeIterator(final KnowledgeElementType type,
100                                 final List<KnowledgeElementFacade> list) {
101                         this._type = type;
102                         this._list = list;
103                 }
104
105                 public String getIndex() {
106                         return String.valueOf(_type.getIndex());
107                 }
108
109                 public String getType() {
110                         return _type.getName();
111                 }
112
113                 public List<KnowledgeElementFacade> getKnowledgeElements() {
114                         return _list;
115                 }
116         }
117
118         // ==============================================================================================================================
119         // Constructor
120         // ==============================================================================================================================
121
122         protected AbstractOpenObject() {
123                 // All member fields are supposed initialized by subclasses
124                 if (docpres == null) {
125                         docpres = new HashMap<Long, DocumentFacade>();
126                 }
127                 if (knowpres == null) {
128                         knowpres = new HashMap<Long, KnowledgeElementFacade>();
129                 }
130         }
131
132         // ==============================================================================================================================
133         // Public member functions
134         // ==============================================================================================================================
135
136         public void developDocument(final String index) {
137                 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
138                         DocumentFacade doc = i.next();
139                         if (!doc.getIndex().equals(index)) {
140                                 continue;
141                         }
142                         doc.develop();
143                         return;
144                 }
145         }
146
147         public void developKnowledge(final String index) {
148                 for (Iterator<KnowledgeIterator> i = _knowledge.iterator(); i.hasNext();) {
149                         List<KnowledgeElementFacade> knowelms = i.next()
150                                         .getKnowledgeElements();
151                         for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
152                                         .hasNext();) {
153                                 KnowledgeElementFacade kelm = j.next();
154                                 if (!kelm.getIndex().equals(index)) {
155                                         continue;
156                                 }
157                                 kelm.develop();
158                                 return;
159                         }
160                 }
161         }
162
163         public void clearFacades() {
164                 docpres.clear(); // For eventually reopening the knowledge from a fresh context
165                 knowpres.clear(); // For eventually reopening the knowledge from a fresh context
166         }
167
168         public List<Document> collectInvolvedDocuments(final DocumentType type) {
169                 List<Document> found = new ArrayList<Document>();
170                 for (Iterator<Step> i = _involving.iterator(); i.hasNext();) {
171                         Step step = i.next();
172                         List<Publication> exist = step.getAllDocuments();
173                         for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
174                                 Document doc = j.next().value();
175                                 if (doc.getType().equals(type)) {
176                                         found.add(doc);
177                                 }
178                         }
179                 }
180                 return found;
181         }
182
183         public String getDisplayedDescription() {
184                 return _description;
185         }
186
187         public List<DocumentFacade> getDisplayedDocuments() {
188                 return _contents;
189         }
190
191         public List<SimulationContextFacade> getDisplayedSimulationContexts() {
192                 return _context;
193         }
194
195         public List<KnowledgeIterator> getDisplayedKnowledges() {
196                 return _knowledge;
197         }
198
199         public List<Step> getInvolvedSteps() {
200                 return _involving;
201         }
202
203         public Menu getMenu() {
204                 return _menu;
205         }
206
207         public PopupMenu getPopup() {
208                 return _popup;
209         }
210
211         public Step getSelectedStep() {
212                 return _ustep;
213         }
214
215         public String getSelection() {
216                 return _selection;
217         }
218
219         public User getUser() {
220                 return _cuser;
221         }
222
223         public boolean isOpenForWriting() {
224                 return (_popup != null); // The pop-up is supposed existed when the user is staffed on the study
225         }
226
227         public void reduceDocument(final String index) {
228                 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
229                         DocumentFacade doc = i.next();
230                         if (!doc.getIndex().equals(index)) {
231                                 continue;
232                         }
233                         doc.reduceAll();
234                         return;
235                 }
236         }
237
238         public void reduceHistory(final String index) {
239                 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
240                         DocumentFacade doc = i.next();
241                         if (!doc.getIndex().equals(index)) {
242                                 continue;
243                         }
244                         doc.reduce();
245                         return;
246                 }
247         }
248
249         public void reduceKnowledge(final String index) {
250                 for (Iterator<KnowledgeIterator> i = _knowledge.iterator(); i.hasNext();) {
251                         List<KnowledgeElementFacade> knowelms = i.next()
252                                         .getKnowledgeElements();
253                         for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
254                                         .hasNext();) {
255                                 KnowledgeElementFacade kelm = j.next();
256                                 if (!kelm.getIndex().equals(index)) {
257                                         continue;
258                                 }
259                                 kelm.reduce();
260                                 return;
261                         }
262                 }
263         }
264
265         // ==============================================================================================================================
266         // Protected services
267         // ==============================================================================================================================
268
269         protected void setupContents() {
270                 // Description
271                 // Initialized in subclasses
272
273                 // Knowledge elements supposed ordered by type
274                 if (_ustep.mayContain(KnowledgeElement.class)) {
275                         Scenario scene = (Scenario) _ustep.getOwner();
276                         List<KnowledgeElementType> types = getKnowledgeElementTypeService()
277                                         .selectTypesWhere(ProgressState.APPROVED);
278                         List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
279                         Iterator<KnowledgeElement> more = kelms.iterator();
280                         KnowledgeElement current = null;
281                         if (more.hasNext()) {
282                                 current = more.next();
283                         }
284
285                         _knowledge = new ArrayList<KnowledgeIterator>(types.size());
286                         for (Iterator<KnowledgeElementType> i = types.iterator(); i
287                                         .hasNext();) {
288                                 KnowledgeElementType type = i.next();
289                                 List<KnowledgeElementFacade> display = new ArrayList<KnowledgeElementFacade>(
290                                                 kelms.size());
291                                 while (current != null && current.getType().equals(type)) {
292                                         KnowledgeElementFacade facade = knowpres.get(current
293                                                         .getIndex());
294                                         if (facade == null) {
295                                                 facade = new KnowledgeElementFacade(BeanHelper
296                                                                 .copyBean(current, KnowledgeElementDTO.class));
297                                                 knowpres.put(current.getIndex(), facade);
298                                         }
299                                         display.add(facade);
300                                         if (more.hasNext()) {
301                                                 current = more.next();
302                                         } else {
303                                                 current = null;
304                                         }
305                                 }
306                                 _knowledge.add(new KnowledgeIterator(type, display));
307                         }
308                 } else {
309                         _knowledge = null;
310                 }
311                 // Documents
312                 if (_ustep.mayContain(Document.class)) {
313                         List<Publication> list = _ustep.getAllDocuments();
314
315                         _contents = new ArrayList<DocumentFacade>(list.size());
316                         for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
317                                 Publication present = i.next();
318                                 Long index = present.getIndex();
319                                 DocumentFacade facade = docpres.get(index);
320                                 if (facade == null) {
321                                         facade = new DocumentFacade(this, present,
322                                                         getProjectSettings(), getPublicationService());
323                                         docpres.put(index, facade);
324                                 }
325                                 _contents.add(facade);
326                         }
327                 } else {
328                         _contents = null;
329                 }
330         }
331
332         /**
333          * Get project settings.
334          * 
335          * @return Project settings service
336          */
337         public ProjectSettingsService getProjectSettings() {
338                 return _projectSettings;
339         }
340
341         /**
342          * Get the publicationService.
343          * 
344          * @return the publicationService
345          */
346         public PublicationService getPublicationService() {
347                 return _publicationService;
348         }
349
350         /**
351          * Set project settings service.
352          * 
353          * @param projectSettingsService
354          *            project settings service
355          */
356         public void setProjectSettings(
357                         final ProjectSettingsService projectSettingsService) {
358                 _projectSettings = projectSettingsService;
359         }
360
361         /**
362          * Set the publicationService.
363          * 
364          * @param publicationService
365          *            the publicationService to set
366          */
367         public void setPublicationService(
368                         final PublicationService publicationService) {
369                 _publicationService = publicationService;
370         }
371
372         /**
373          * Set the menu.
374          * 
375          * @param menu
376          *            the menu to set
377          */
378         public void setMenu(final Menu menu) {
379                 this._menu = menu;
380         }
381
382         /**
383          * Get the projectElementService.
384          * 
385          * @return the projectElementService
386          */
387         public ProjectElementService getProjectElementService() {
388                 return _projectElementService;
389         }
390
391         /**
392          * Set the projectElementService.
393          * 
394          * @param projectElementService
395          *            the projectElementService to set
396          */
397         public void setProjectElementService(
398                         final ProjectElementService projectElementService) {
399                 _projectElementService = projectElementService;
400         }
401
402         /**
403          * Get the knowledgeElementTypeService.
404          * 
405          * @return the knowledgeElementTypeService
406          */
407         public KnowledgeElementTypeService getKnowledgeElementTypeService() {
408                 return _knowledgeElementTypeService;
409         }
410
411         /**
412          * Set the knowledgeElementTypeService.
413          * 
414          * @param knowledgeElementTypeService
415          *            the knowledgeElementTypeService to set
416          */
417         public void setKnowledgeElementTypeService(
418                         final KnowledgeElementTypeService knowledgeElementTypeService) {
419                 _knowledgeElementTypeService = knowledgeElementTypeService;
420         }
421
422         /**
423          * Get the applicationSettings.
424          * 
425          * @return the applicationSettings
426          */
427         public ApplicationSettings getApplicationSettings() {
428                 return _applicationSettings;
429         }
430
431         /**
432          * Set the applicationSettings.
433          * 
434          * @param applicationSettings
435          *            the applicationSettings to set
436          */
437         public void setApplicationSettings(
438                         final ApplicationSettings applicationSettings) {
439                 _applicationSettings = applicationSettings;
440         }
441 }