1 package org.splat.simer;
3 import java.util.HashMap;
4 import java.util.Iterator;
6 import java.util.Vector;
8 import org.splat.dal.bo.kernel.User;
9 import org.splat.dal.bo.som.Document;
10 import org.splat.dal.bo.som.DocumentType;
11 import org.splat.dal.bo.som.KnowledgeElement;
12 import org.splat.dal.bo.som.KnowledgeElementType;
13 import org.splat.dal.bo.som.ProgressState;
14 import org.splat.service.KnowledgeElementService;
15 import org.splat.service.KnowledgeElementTypeService;
16 import org.splat.service.ProjectElementService;
17 import org.splat.service.PublicationService;
18 import org.splat.service.dto.Proxy;
19 import org.splat.service.technical.ProjectSettingsService;
20 import org.splat.dal.bo.som.Publication;
21 import org.splat.dal.bo.som.Scenario;
22 import org.splat.som.Step;
23 import org.splat.wapp.Menu;
24 import org.splat.wapp.PopupMenu;
26 public abstract class OpenObject implements Proxy {
28 protected static HashMap<Long, DocumentFacade> docpres = null;
29 protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
31 protected User cuser = null; // Connected user
32 protected String selection = null; // Menu selected by the user
33 protected Step ustep = null; // Corresponding selected step
34 protected String description = null; // Object description (rich text)
35 protected List<Step> involving = null;
36 protected List<SimulationContextFacade> context = null; // Simulation Context display representations
37 protected List<DocumentFacade> contents = null; // Document display representations
38 protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
40 protected Menu menu = null; // Left pane menu of this object
41 protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access
43 * Injected project settings service.
45 private ProjectSettingsService _projectSettingsService;
47 * Injected application settings bean.
49 private ApplicationSettings _applicationSettings;
51 * Injected publication service.
53 private PublicationService _publicationService;
55 * Injected knowledge element service.
57 private KnowledgeElementTypeService _knowledgeElementTypeService;
59 * Injected project element service.
61 private ProjectElementService _projectElementService;
63 public class KnowledgeIterator {
64 protected KnowledgeElementType type;
65 protected List<KnowledgeElementFacade> list;
67 public KnowledgeIterator(KnowledgeElementType type,
68 List<KnowledgeElementFacade> list) {
73 public String getIndex() {
74 return String.valueOf(type.getIndex());
77 public String getType() {
78 return type.getName();
81 public List<KnowledgeElementFacade> getKnowledgeElements() {
86 // ==============================================================================================================================
88 // ==============================================================================================================================
90 protected OpenObject() {
91 // -----------------------
92 // All member fields are supposed initialized by subclasses
94 docpres = new HashMap<Long, DocumentFacade>();
96 knowpres = new HashMap<Long, KnowledgeElementFacade>();
99 // ==============================================================================================================================
100 // Public member functions
101 // ==============================================================================================================================
103 public void developDocument(String index) {
104 // ------------------------------------------
105 for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
106 DocumentFacade doc = i.next();
107 if (!doc.getIndex().equals(index))
114 public void developKnowledge(String index) {
115 // -------------------------------------------
116 for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
117 List<KnowledgeElementFacade> knowelms = i.next()
118 .getKnowledgeElements();
119 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
121 KnowledgeElementFacade kelm = j.next();
122 if (!kelm.getIndex().equals(index))
130 public void clearFacades() {
131 // ---------------------------
132 docpres.clear(); // For eventually reopening the knowledge from a fresh context
133 knowpres.clear(); // For eventually reopening the knowledge from a fresh context
136 public List<Document> collectInvolvedDocuments(DocumentType type) {
137 // ------------------------------------------------------------------
138 List<Document> found = new Vector<Document>();
139 for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
140 Step step = i.next();
141 List<Publication> exist = step.getAllDocuments();
142 for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
143 Document doc = j.next().value();
144 if (doc.getType().equals(type))
151 public String getDisplayedDescription() {
152 // ----------------------------------------
156 public List<DocumentFacade> getDisplayedDocuments() {
157 // -----------------------------------------------------
161 public List<SimulationContextFacade> getDisplayedSimulationContexts() {
162 // ----------------------------------------------------------------------
166 public List<KnowledgeIterator> getDisplayedKnowledges() {
167 // --------------------------------------------------------
171 public List<Step> getInvolvedSteps() {
172 // -------------------------------------
176 public Menu getMenu() {
177 // ----------------------
181 public PopupMenu getPopup() {
182 // ----------------------------
186 public Step getSelectedStep() {
187 // ------------------------------
191 public String getSelection() {
192 // -----------------------------
196 public User getUser() {
197 // ----------------------
201 public boolean isOpenForWriting() {
202 // ----------------------------------
203 return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
206 public void reduceDocument(String index) {
207 // -----------------------------------------
208 for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
209 DocumentFacade doc = i.next();
210 if (!doc.getIndex().equals(index))
217 public void reduceHistory(String index) {
218 // ----------------------------------------
219 for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
220 DocumentFacade doc = i.next();
221 if (!doc.getIndex().equals(index))
228 public void reduceKnowledge(String index) {
229 // ------------------------------------------
230 for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
231 List<KnowledgeElementFacade> knowelms = i.next()
232 .getKnowledgeElements();
233 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
235 KnowledgeElementFacade kelm = j.next();
236 if (!kelm.getIndex().equals(index))
244 // ==============================================================================================================================
245 // Protected services
246 // ==============================================================================================================================
248 protected void setupContents() {
249 // -------------------------------
251 // Initialized in subclasses
253 // Knowledge elements supposed ordered by type
254 if (ustep.mayContain(KnowledgeElement.class)) {
255 Scenario scene = (Scenario) ustep.getOwner();
256 List<KnowledgeElementType> types = getKnowledgeElementTypeService()
257 .selectTypesWhere(ProgressState.APPROVED);
258 List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
259 Iterator<KnowledgeElement> more = kelms.iterator();
260 KnowledgeElement current = null;
262 current = more.next();
264 knowledge = new Vector<KnowledgeIterator>(types.size());
265 for (Iterator<KnowledgeElementType> i = types.iterator(); i
267 KnowledgeElementType type = i.next();
268 List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(
270 while (current != null && current.getType().equals(type)) {
271 KnowledgeElementFacade facade = knowpres.get(current
273 if (facade == null) {
274 facade = new KnowledgeElementFacade(current);
275 knowpres.put(current.getIndex(), facade);
279 current = more.next();
283 knowledge.add(new KnowledgeIterator(type, display));
289 if (ustep.mayContain(Document.class)) {
290 List<Publication> list = ustep.getAllDocuments();
292 contents = new Vector<DocumentFacade>(list.size());
293 for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
294 Publication present = i.next();
295 Long index = present.getIndex();
296 DocumentFacade facade = docpres.get(index);
297 if (facade == null) {
298 facade = new DocumentFacade(this, present,
299 getProjectSettings(), getPublicationService());
300 docpres.put(index, facade);
302 contents.add(facade);
310 * Get project settings.
312 * @return Project settings service
314 public ProjectSettingsService getProjectSettings() {
315 return _projectSettingsService;
319 * Get the publicationService.
321 * @return the publicationService
323 public PublicationService getPublicationService() {
324 return _publicationService;
328 * Set project settings service.
330 * @param projectSettingsService
331 * project settings service
333 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
334 _projectSettingsService = projectSettingsService;
338 * Set the publicationService.
340 * @param publicationService
341 * the publicationService to set
343 public void setPublicationService(PublicationService publicationService) {
344 _publicationService = publicationService;
353 public void setMenu(Menu menu) {
358 * Get the projectElementService.
360 * @return the projectElementService
362 public ProjectElementService getProjectElementService() {
363 return _projectElementService;
367 * Set the projectElementService.
369 * @param projectElementService
370 * the projectElementService to set
372 public void setProjectElementService(
373 ProjectElementService projectElementService) {
374 _projectElementService = projectElementService;
378 * Get the knowledgeElementTypeService.
379 * @return the knowledgeElementTypeService
381 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
382 return _knowledgeElementTypeService;
386 * Set the knowledgeElementTypeService.
387 * @param knowledgeElementTypeService the knowledgeElementTypeService to set
389 public void setKnowledgeElementTypeService(
390 KnowledgeElementTypeService knowledgeElementTypeService) {
391 _knowledgeElementTypeService = knowledgeElementTypeService;
395 * Get the applicationSettings.
396 * @return the applicationSettings
398 public ApplicationSettings getApplicationSettings() {
399 return _applicationSettings;
403 * Set the applicationSettings.
404 * @param applicationSettings the applicationSettings to set
406 public void setApplicationSettings(ApplicationSettings applicationSettings) {
407 _applicationSettings = applicationSettings;