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.PublicationService;
15 import org.splat.service.dto.Proxy;
16 import org.splat.service.technical.ProjectSettingsService;
17 import org.splat.dal.bo.som.Publication;
18 import org.splat.dal.bo.som.Scenario;
19 import org.splat.som.Step;
20 import org.splat.wapp.Menu;
21 import org.splat.wapp.PopupMenu;
24 public abstract class OpenObject implements Proxy {
26 protected User cuser = null; // Connected user
27 protected String selection = null; // Menu selected by the user
28 protected Step ustep = null; // Corresponding selected step
29 protected String description = null; // Object description (rich text)
30 protected List<Step> involving = null;
31 protected List<SimulationContextFacade> context = null; // Simulation Context display representations
32 protected List<DocumentFacade> contents = null; // Document display representations
33 protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
35 protected Menu menu = null; // Left pane menu of this object
36 protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access
37 private ProjectSettingsService _projectSettingsService;
38 private PublicationService _publicationService;
40 protected static HashMap<Long, DocumentFacade> docpres = null;
41 protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
43 public class KnowledgeIterator {
44 // ------------------------------
45 protected KnowledgeElementType type;
46 protected List<KnowledgeElementFacade> list;
48 public KnowledgeIterator (KnowledgeElementType type, List<KnowledgeElementFacade> list)
53 public String getIndex ()
55 return String.valueOf(type.getIndex());
57 public String getType ()
59 return type.getName();
61 public List<KnowledgeElementFacade> getKnowledgeElements ()
67 // ==============================================================================================================================
69 // ==============================================================================================================================
71 protected OpenObject () {
72 // -----------------------
73 // All member fields are supposed initialized by subclasses
74 if (docpres == null) docpres = new HashMap<Long, DocumentFacade>();
75 if (knowpres == null) knowpres = new HashMap<Long, KnowledgeElementFacade>();
78 // ==============================================================================================================================
79 // Public member functions
80 // ==============================================================================================================================
82 public void developDocument (String index) {
83 // ------------------------------------------
84 for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
85 DocumentFacade doc = i.next();
86 if (!doc.getIndex().equals(index)) continue;
92 public void developKnowledge (String index) {
93 // -------------------------------------------
94 for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
95 List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
96 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
97 KnowledgeElementFacade kelm = j.next();
98 if (!kelm.getIndex().equals(index)) continue;
105 public void clearFacades () {
106 // ---------------------------
107 docpres.clear(); // For eventually reopening the knowledge from a fresh context
108 knowpres.clear(); // For eventually reopening the knowledge from a fresh context
111 public List<Document> collectInvolvedDocuments (DocumentType type) {
112 // ------------------------------------------------------------------
113 List<Document> found = new Vector<Document>();
114 for (Iterator<Step> i=involving.iterator(); i.hasNext();) {
115 Step step = i.next();
116 List<Publication> exist = step.getAllDocuments();
117 for (Iterator<Publication> j=exist.iterator(); j.hasNext();) {
118 Document doc = j.next().value();
119 if (doc.getType().equals(type)) found.add(doc);
125 public String getDisplayedDescription () {
126 // ----------------------------------------
130 public List<DocumentFacade> getDisplayedDocuments () {
131 // -----------------------------------------------------
135 public List<SimulationContextFacade> getDisplayedSimulationContexts () {
136 // ----------------------------------------------------------------------
140 public List<KnowledgeIterator> getDisplayedKnowledges () {
141 // --------------------------------------------------------
145 public List<Step> getInvolvedSteps () {
146 // -------------------------------------
150 public Menu getMenu () {
151 // ----------------------
155 public PopupMenu getPopup () {
156 // ----------------------------
160 public Step getSelectedStep () {
161 // ------------------------------
165 public String getSelection () {
166 // -----------------------------
170 public User getUser () {
171 // ----------------------
175 public boolean isOpenForWriting () {
176 // ----------------------------------
177 return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
180 public void reduceDocument (String index) {
181 // -----------------------------------------
182 for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
183 DocumentFacade doc = i.next();
184 if (!doc.getIndex().equals(index)) continue;
190 public void reduceHistory (String index) {
191 // ----------------------------------------
192 for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
193 DocumentFacade doc = i.next();
194 if (!doc.getIndex().equals(index)) continue;
200 public void reduceKnowledge (String index) {
201 // ------------------------------------------
202 for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
203 List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
204 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
205 KnowledgeElementFacade kelm = j.next();
206 if (!kelm.getIndex().equals(index)) continue;
213 // ==============================================================================================================================
214 // Protected services
215 // ==============================================================================================================================
217 protected void setupContents () {
218 // -------------------------------
220 // Initialized in subclasses
222 // Knowledge elements supposed ordered by type
223 if (ustep.mayContain(KnowledgeElement.class)) {
224 Scenario scene = (Scenario)ustep.getOwner();
225 List<KnowledgeElementType> types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
226 List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
227 Iterator<KnowledgeElement> more = kelms.iterator();
228 KnowledgeElement current = null;
229 if (more.hasNext()) current = more.next();
231 knowledge = new Vector<KnowledgeIterator>(types.size());
232 for (Iterator<KnowledgeElementType> i=types.iterator(); i.hasNext();) {
233 KnowledgeElementType type = i.next();
234 List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(kelms.size());
235 while (current != null && current.getType().equals(type)) {
236 KnowledgeElementFacade facade = knowpres.get(current.getIndex());
237 if (facade == null) {
238 facade = new KnowledgeElementFacade(current);
239 knowpres.put(current.getIndex(), facade);
242 if (more.hasNext()) current = more.next();
245 knowledge.add( new KnowledgeIterator(type, display) );
251 if (ustep.mayContain(Document.class)) {
252 List<Publication> list = ustep.getAllDocuments();
254 contents = new Vector<DocumentFacade>(list.size());
255 for (Iterator<Publication> i=list.iterator(); i.hasNext();) {
256 Publication present = i.next();
257 Long index = present.getIndex();
258 DocumentFacade facade = docpres.get(index);
259 if (facade == null) {
260 facade = new DocumentFacade(this, present, getProjectSettings(), getPublicationService());
261 docpres.put(index, facade);
263 contents.add(facade);
271 * Get project settings.
272 * @return Project settings service
274 public ProjectSettingsService getProjectSettings() {
275 return _projectSettingsService;
279 * Get the publicationService.
281 * @return the publicationService
283 public PublicationService getPublicationService() {
284 return _publicationService;
288 * Set project settings service.
289 * @param projectSettingsService project settings service
291 public void setProjectSettings(
292 ProjectSettingsService projectSettingsService) {
293 _projectSettingsService = projectSettingsService;
297 * Set the publicationService.
299 * @param publicationService
300 * the publicationService to set
302 public void setPublicationService(PublicationService publicationService) {
303 _publicationService = publicationService;
308 * @param menu the menu to set
310 public void setMenu(Menu menu) {