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.dto.Proxy;
15 import org.splat.dal.bo.som.Publication;
16 import org.splat.dal.bo.som.Scenario;
17 import org.splat.som.Step;
18 import org.splat.wapp.Menu;
19 import org.splat.wapp.PopupMenu;
22 public abstract class OpenObject implements Proxy {
24 protected User cuser = null; // Connected user
25 protected String selection = null; // Menu selected by the user
26 protected Step ustep = null; // Corresponding selected step
27 protected String description = null; // Object description (rich text)
28 protected List<Step> involving = null;
29 protected List<SimulationContextFacade> context = null; // Simulation Context display representations
30 protected List<DocumentFacade> contents = null; // Document display representations
31 protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
33 protected Menu menu = null; // Left pane menu of this object
34 protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access
36 protected static HashMap<Integer, DocumentFacade> docpres = null;
37 protected static HashMap<Integer, KnowledgeElementFacade> knowpres = null;
39 public class KnowledgeIterator {
40 // ------------------------------
41 protected KnowledgeElementType type;
42 protected List<KnowledgeElementFacade> list;
44 public KnowledgeIterator (KnowledgeElementType type, List<KnowledgeElementFacade> list)
49 public String getIndex ()
51 return String.valueOf(type.getIndex());
53 public String getType ()
55 return type.getName();
57 public List<KnowledgeElementFacade> getKnowledgeElements ()
63 // ==============================================================================================================================
65 // ==============================================================================================================================
67 protected OpenObject () {
68 // -----------------------
69 // All member fields are supposed initialized by subclasses
70 if (docpres == null) docpres = new HashMap<Integer, DocumentFacade>();
71 if (knowpres == null) knowpres = new HashMap<Integer, KnowledgeElementFacade>();
74 // ==============================================================================================================================
75 // Public member functions
76 // ==============================================================================================================================
78 public void developDocument (String index) {
79 // ------------------------------------------
80 for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
81 DocumentFacade doc = i.next();
82 if (!doc.getIndex().equals(index)) continue;
88 public void developKnowledge (String index) {
89 // -------------------------------------------
90 for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
91 List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
92 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
93 KnowledgeElementFacade kelm = j.next();
94 if (!kelm.getIndex().equals(index)) continue;
101 public void clearFacades () {
102 // ---------------------------
103 docpres.clear(); // For eventually reopening the knowledge from a fresh context
104 knowpres.clear(); // For eventually reopening the knowledge from a fresh context
107 public List<Document> collectInvolvedDocuments (DocumentType type) {
108 // ------------------------------------------------------------------
109 List<Document> found = new Vector<Document>();
110 for (Iterator<Step> i=involving.iterator(); i.hasNext();) {
111 Step step = i.next();
112 List<Publication> exist = step.getAllDocuments();
113 for (Iterator<Publication> j=exist.iterator(); j.hasNext();) {
114 Document doc = j.next().value();
115 if (doc.getType().equals(type)) found.add(doc);
121 public String getDisplayedDescription () {
122 // ----------------------------------------
126 public List<DocumentFacade> getDisplayedDocuments () {
127 // -----------------------------------------------------
131 public List<SimulationContextFacade> getDisplayedSimulationContexts () {
132 // ----------------------------------------------------------------------
136 public List<KnowledgeIterator> getDisplayedKnowledges () {
137 // --------------------------------------------------------
141 public List<Step> getInvolvedSteps () {
142 // -------------------------------------
146 public Menu getMenu () {
147 // ----------------------
151 public PopupMenu getPopup () {
152 // ----------------------------
156 public Step getSelectedStep () {
157 // ------------------------------
161 public String getSelection () {
162 // -----------------------------
166 public User getUser () {
167 // ----------------------
171 public boolean isOpenForWriting () {
172 // ----------------------------------
173 return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
176 public void reduceDocument (String index) {
177 // -----------------------------------------
178 for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
179 DocumentFacade doc = i.next();
180 if (!doc.getIndex().equals(index)) continue;
186 public void reduceHistory (String index) {
187 // ----------------------------------------
188 for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
189 DocumentFacade doc = i.next();
190 if (!doc.getIndex().equals(index)) continue;
196 public void reduceKnowledge (String index) {
197 // ------------------------------------------
198 for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
199 List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
200 for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
201 KnowledgeElementFacade kelm = j.next();
202 if (!kelm.getIndex().equals(index)) continue;
209 // ==============================================================================================================================
210 // Protected services
211 // ==============================================================================================================================
213 protected void setupContents () {
214 // -------------------------------
216 // Initialized in subclasses
218 // Knowledge elements supposed ordered by type
219 if (ustep.mayContain(KnowledgeElement.class)) {
220 Scenario scene = (Scenario)ustep.getOwner();
221 List<KnowledgeElementType> types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
222 List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
223 Iterator<KnowledgeElement> more = kelms.iterator();
224 KnowledgeElement current = null;
225 if (more.hasNext()) current = more.next();
227 knowledge = new Vector<KnowledgeIterator>(types.size());
228 for (Iterator<KnowledgeElementType> i=types.iterator(); i.hasNext();) {
229 KnowledgeElementType type = i.next();
230 List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(kelms.size());
231 while (current != null && current.getType().equals(type)) {
232 KnowledgeElementFacade facade = knowpres.get(current.getIndex());
233 if (facade == null) {
234 facade = new KnowledgeElementFacade(current);
235 knowpres.put(current.getIndex(), facade);
238 if (more.hasNext()) current = more.next();
241 knowledge.add( new KnowledgeIterator(type, display) );
247 if (ustep.mayContain(Document.class)) {
248 List<Publication> list = ustep.getAllDocuments();
250 contents = new Vector<DocumentFacade>(list.size());
251 for (Iterator<Publication> i=list.iterator(); i.hasNext();) {
252 Publication present = i.next();
253 Integer index = present.getIndex();
254 DocumentFacade facade = docpres.get(index);
255 if (facade == null) {
256 facade = new DocumentFacade(this, present);
257 docpres.put(index, facade);
259 contents.add(facade);