]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/AbstractOpenObject.java
Salome HOME
Applet is working now and calls runSalome with appropriate parameters. New ant target...
[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 String getSelectedScenarioId() {
220                 String res;
221                 if (_selection == null) {
222                         res = "0";
223                 } else {
224                         res = _selection.substring(0, _selection.indexOf('.'));
225                 }
226                 return res;
227         }
228
229         public User getUser() {
230                 return _cuser;
231         }
232
233         public boolean isOpenForWriting() {
234                 return (_popup != null); // The pop-up is supposed existed when the user is staffed on the study
235         }
236
237         public void reduceDocument(final String index) {
238                 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
239                         DocumentFacade doc = i.next();
240                         if (!doc.getIndex().equals(index)) {
241                                 continue;
242                         }
243                         doc.reduceAll();
244                         return;
245                 }
246         }
247
248         public void reduceHistory(final String index) {
249                 for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
250                         DocumentFacade doc = i.next();
251                         if (!doc.getIndex().equals(index)) {
252                                 continue;
253                         }
254                         doc.reduce();
255                         return;
256                 }
257         }
258
259         public void reduceKnowledge(final String index) {
260                 for (Iterator<KnowledgeIterator> i = _knowledge.iterator(); i.hasNext();) {
261                         List<KnowledgeElementFacade> knowelms = i.next()
262                                         .getKnowledgeElements();
263                         for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
264                                         .hasNext();) {
265                                 KnowledgeElementFacade kelm = j.next();
266                                 if (!kelm.getIndex().equals(index)) {
267                                         continue;
268                                 }
269                                 kelm.reduce();
270                                 return;
271                         }
272                 }
273         }
274
275         // ==============================================================================================================================
276         // Protected services
277         // ==============================================================================================================================
278
279         protected void setupContents() {
280                 // Description
281                 // Initialized in subclasses
282
283                 // Knowledge elements supposed ordered by type
284                 if (_ustep.mayContain(KnowledgeElement.class)) {
285                         Scenario scene = (Scenario) _ustep.getOwner();
286                         List<KnowledgeElementType> types = getKnowledgeElementTypeService()
287                                         .selectTypesWhere(ProgressState.APPROVED);
288                         List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
289                         Iterator<KnowledgeElement> more = kelms.iterator();
290                         KnowledgeElement current = null;
291                         if (more.hasNext()) {
292                                 current = more.next();
293                         }
294
295                         _knowledge = new ArrayList<KnowledgeIterator>(types.size());
296                         for (Iterator<KnowledgeElementType> i = types.iterator(); i
297                                         .hasNext();) {
298                                 KnowledgeElementType type = i.next();
299                                 List<KnowledgeElementFacade> display = new ArrayList<KnowledgeElementFacade>(
300                                                 kelms.size());
301                                 while (current != null && current.getType().equals(type)) {
302                                         KnowledgeElementFacade facade = knowpres.get(current
303                                                         .getIndex());
304                                         if (facade == null) {
305                                                 facade = new KnowledgeElementFacade(BeanHelper
306                                                                 .copyBean(current, KnowledgeElementDTO.class));
307                                                 knowpres.put(current.getIndex(), facade);
308                                         }
309                                         display.add(facade);
310                                         if (more.hasNext()) {
311                                                 current = more.next();
312                                         } else {
313                                                 current = null;
314                                         }
315                                 }
316                                 _knowledge.add(new KnowledgeIterator(type, display));
317                         }
318                 } else {
319                         _knowledge = null;
320                 }
321                 // Documents
322                 if (_ustep.mayContain(Document.class)) {
323                         List<Publication> list = _ustep.getAllDocuments();
324
325                         _contents = new ArrayList<DocumentFacade>(list.size());
326                         for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
327                                 Publication present = i.next();
328                                 Long index = present.getIndex();
329                                 DocumentFacade facade = docpres.get(index);
330                                 if (facade == null) {
331                                         facade = new DocumentFacade(this, present,
332                                                         getProjectSettings(), getPublicationService());
333                                         docpres.put(index, facade);
334                                 }
335                                 _contents.add(facade);
336                         }
337                 } else {
338                         _contents = null;
339                 }
340         }
341
342         /**
343          * Get project settings.
344          * 
345          * @return Project settings service
346          */
347         public ProjectSettingsService getProjectSettings() {
348                 return _projectSettings;
349         }
350
351         /**
352          * Get the publicationService.
353          * 
354          * @return the publicationService
355          */
356         public PublicationService getPublicationService() {
357                 return _publicationService;
358         }
359
360         /**
361          * Set project settings service.
362          * 
363          * @param projectSettingsService
364          *            project settings service
365          */
366         public void setProjectSettings(
367                         final ProjectSettingsService projectSettingsService) {
368                 _projectSettings = projectSettingsService;
369         }
370
371         /**
372          * Set the publicationService.
373          * 
374          * @param publicationService
375          *            the publicationService to set
376          */
377         public void setPublicationService(
378                         final PublicationService publicationService) {
379                 _publicationService = publicationService;
380         }
381
382         /**
383          * Set the menu.
384          * 
385          * @param menu
386          *            the menu to set
387          */
388         public void setMenu(final Menu menu) {
389                 this._menu = menu;
390         }
391
392         /**
393          * Get the projectElementService.
394          * 
395          * @return the projectElementService
396          */
397         public ProjectElementService getProjectElementService() {
398                 return _projectElementService;
399         }
400
401         /**
402          * Set the projectElementService.
403          * 
404          * @param projectElementService
405          *            the projectElementService to set
406          */
407         public void setProjectElementService(
408                         final ProjectElementService projectElementService) {
409                 _projectElementService = projectElementService;
410         }
411
412         /**
413          * Get the knowledgeElementTypeService.
414          * 
415          * @return the knowledgeElementTypeService
416          */
417         public KnowledgeElementTypeService getKnowledgeElementTypeService() {
418                 return _knowledgeElementTypeService;
419         }
420
421         /**
422          * Set the knowledgeElementTypeService.
423          * 
424          * @param knowledgeElementTypeService
425          *            the knowledgeElementTypeService to set
426          */
427         public void setKnowledgeElementTypeService(
428                         final KnowledgeElementTypeService knowledgeElementTypeService) {
429                 _knowledgeElementTypeService = knowledgeElementTypeService;
430         }
431
432         /**
433          * Get the applicationSettings.
434          * 
435          * @return the applicationSettings
436          */
437         public ApplicationSettings getApplicationSettings() {
438                 return _applicationSettings;
439         }
440
441         /**
442          * Set the applicationSettings.
443          * 
444          * @param applicationSettings
445          *            the applicationSettings to set
446          */
447         public void setApplicationSettings(
448                         final ApplicationSettings applicationSettings) {
449                 _applicationSettings = applicationSettings;
450         }
451 }