1 package org.splat.simer;
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
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;
28 public abstract class OpenObject implements Proxy {
30 protected static Map<Long, DocumentFacade> docpres = null;
31 protected static Map<Long, KnowledgeElementFacade> knowpres = null;
36 protected User cuser = null;
38 * Menu selected by the user.
40 protected String selection = null;
42 * Corresponding selected step.
44 protected Step ustep = null;
46 * Object description (rich text).
48 protected String description = null;
49 protected List<Step> involving = new ArrayList<Step>();
51 * Simulation Context display representations.
53 protected List<SimulationContextFacade> context = new ArrayList<SimulationContextFacade>(); // Simulation Context display representations
55 * Document display representations.
57 protected List<DocumentFacade> contents = null;
59 * Knowledge Element display representations structured by knowledge types.
61 protected List<KnowledgeIterator> knowledge = null;
64 * Left pane menu of this object.
66 protected Menu menu = null;
68 * Pop-up menu of this object, if the user has write access.
70 protected PopupMenu popup = null;
72 * Injected project settings service.
74 private ProjectSettingsService _projectSettingsService;
76 * Injected application settings bean.
78 private ApplicationSettings _applicationSettings;
80 * Injected publication service.
82 private PublicationService _publicationService;
84 * Injected knowledge element service.
86 private KnowledgeElementTypeService _knowledgeElementTypeService;
88 * Injected project element service.
90 private ProjectElementService _projectElementService;
92 public class KnowledgeIterator {
93 protected KnowledgeElementType type;
94 protected List<KnowledgeElementFacade> list;
96 public KnowledgeIterator(final KnowledgeElementType type,
97 final List<KnowledgeElementFacade> list) {
102 public String getIndex() {
103 return String.valueOf(type.getIndex());
106 public String getType() {
107 return type.getName();
110 public List<KnowledgeElementFacade> getKnowledgeElements() {
115 // ==============================================================================================================================
117 // ==============================================================================================================================
119 protected OpenObject() {
120 // -----------------------
121 // All member fields are supposed initialized by subclasses
122 if (docpres == null) {
123 docpres = new HashMap<Long, DocumentFacade>();
125 if (knowpres == null) {
126 knowpres = new HashMap<Long, KnowledgeElementFacade>();
130 // ==============================================================================================================================
131 // Public member functions
132 // ==============================================================================================================================
134 public void developDocument(final String index) {
135 // ------------------------------------------
136 for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
137 DocumentFacade doc = i.next();
138 if (!doc.getIndex().equals(index)) {
146 public void developKnowledge(final String index) {
147 // -------------------------------------------
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
153 KnowledgeElementFacade kelm = j.next();
154 if (!kelm.getIndex().equals(index)) {
163 public void clearFacades() {
164 // ---------------------------
165 docpres.clear(); // For eventually reopening the knowledge from a fresh context
166 knowpres.clear(); // For eventually reopening the knowledge from a fresh context
169 public List<Document> collectInvolvedDocuments(final DocumentType type) {
170 // ------------------------------------------------------------------
171 List<Document> found = new ArrayList<Document>();
172 for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
173 Step step = i.next();
174 List<Publication> exist = step.getAllDocuments();
175 for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
176 Document doc = j.next().value();
177 if (doc.getType().equals(type)) {
185 public String getDisplayedDescription() {
186 // ----------------------------------------
190 public List<DocumentFacade> getDisplayedDocuments() {
191 // -----------------------------------------------------
195 public List<SimulationContextFacade> getDisplayedSimulationContexts() {
196 // ----------------------------------------------------------------------
200 public List<KnowledgeIterator> getDisplayedKnowledges() {
201 // --------------------------------------------------------
205 public List<Step> getInvolvedSteps() {
206 // -------------------------------------
210 public Menu getMenu() {
211 // ----------------------
215 public PopupMenu getPopup() {
216 // ----------------------------
220 public Step getSelectedStep() {
221 // ------------------------------
225 public String getSelection() {
226 // -----------------------------
230 public User getUser() {
231 // ----------------------
235 public boolean isOpenForWriting() {
236 // ----------------------------------
237 return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
240 public void reduceDocument(final String index) {
241 // -----------------------------------------
242 for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
243 DocumentFacade doc = i.next();
244 if (!doc.getIndex().equals(index)) {
252 public void reduceHistory(final String index) {
253 // ----------------------------------------
254 for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
255 DocumentFacade doc = i.next();
256 if (!doc.getIndex().equals(index)) {
264 public void reduceKnowledge(final String index) {
265 // ------------------------------------------
266 for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
267 List<KnowledgeElementFacade> knowelms = i.next()
268 .getKnowledgeElements();
269 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
271 KnowledgeElementFacade kelm = j.next();
272 if (!kelm.getIndex().equals(index)) {
281 // ==============================================================================================================================
282 // Protected services
283 // ==============================================================================================================================
285 protected void setupContents() {
286 // -------------------------------
288 // Initialized in subclasses
290 // Knowledge elements supposed ordered by type
291 if (ustep.mayContain(KnowledgeElement.class)) {
292 Scenario scene = (Scenario) ustep.getOwner();
293 List<KnowledgeElementType> types = getKnowledgeElementTypeService()
294 .selectTypesWhere(ProgressState.APPROVED);
295 List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
296 Iterator<KnowledgeElement> more = kelms.iterator();
297 KnowledgeElement current = null;
298 if (more.hasNext()) {
299 current = more.next();
302 knowledge = new ArrayList<KnowledgeIterator>(types.size());
303 for (Iterator<KnowledgeElementType> i = types.iterator(); i
305 KnowledgeElementType type = i.next();
306 List<KnowledgeElementFacade> display = new ArrayList<KnowledgeElementFacade>(
308 while (current != null && current.getType().equals(type)) {
309 KnowledgeElementFacade facade = knowpres.get(current
311 if (facade == null) {
312 facade = new KnowledgeElementFacade(BeanHelper.copyBean(current, KnowledgeElementDTO.class));
313 knowpres.put(current.getIndex(), facade);
316 if (more.hasNext()) {
317 current = more.next();
322 knowledge.add(new KnowledgeIterator(type, display));
328 if (ustep.mayContain(Document.class)) {
329 List<Publication> list = ustep.getAllDocuments();
331 contents = new ArrayList<DocumentFacade>(list.size());
332 for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
333 Publication present = i.next();
334 Long index = present.getIndex();
335 DocumentFacade facade = docpres.get(index);
336 if (facade == null) {
337 facade = new DocumentFacade(this, present,
338 getProjectSettings(), getPublicationService());
339 docpres.put(index, facade);
341 contents.add(facade);
349 * Get project settings.
351 * @return Project settings service
353 public ProjectSettingsService getProjectSettings() {
354 return _projectSettingsService;
358 * Get the publicationService.
360 * @return the publicationService
362 public PublicationService getPublicationService() {
363 return _publicationService;
367 * Set project settings service.
369 * @param projectSettingsService
370 * project settings service
372 public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
373 _projectSettingsService = projectSettingsService;
377 * Set the publicationService.
379 * @param publicationService
380 * the publicationService to set
382 public void setPublicationService(final PublicationService publicationService) {
383 _publicationService = publicationService;
392 public void setMenu(final Menu menu) {
397 * Get the projectElementService.
399 * @return the projectElementService
401 public ProjectElementService getProjectElementService() {
402 return _projectElementService;
406 * Set the projectElementService.
408 * @param projectElementService
409 * the projectElementService to set
411 public void setProjectElementService(
412 final ProjectElementService projectElementService) {
413 _projectElementService = projectElementService;
417 * Get the knowledgeElementTypeService.
418 * @return the knowledgeElementTypeService
420 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
421 return _knowledgeElementTypeService;
425 * Set the knowledgeElementTypeService.
426 * @param knowledgeElementTypeService the knowledgeElementTypeService to set
428 public void setKnowledgeElementTypeService(
429 final KnowledgeElementTypeService knowledgeElementTypeService) {
430 _knowledgeElementTypeService = knowledgeElementTypeService;
434 * Get the applicationSettings.
435 * @return the applicationSettings
437 public ApplicationSettings getApplicationSettings() {
438 return _applicationSettings;
442 * Set the applicationSettings.
443 * @param applicationSettings the applicationSettings to set
445 public void setApplicationSettings(final ApplicationSettings applicationSettings) {
446 _applicationSettings = applicationSettings;