Salome HOME
Each document type now uses itself. So default uses iincludes documents of the type...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / UploadBaseNextAction.java
1 package org.splat.simer;
2
3 import java.util.Iterator;
4 import java.util.List;
5 import java.util.Set;
6
7 import org.splat.dal.bo.som.Document;
8 import org.splat.dal.bo.som.DocumentType;
9 import org.splat.dal.bo.som.ProgressState;
10 import org.splat.dal.bo.som.Publication;
11 import org.splat.som.Step;
12
13 public abstract class UploadBaseNextAction extends Action {
14
15         protected OpenStudy mystudy = null;
16         protected String filename = null; // Uploaded file name
17         protected DocumentType deftype = null;
18         protected List<Document> defuses = null;
19         protected String docname = null;
20         protected ProgressState state = null;
21         protected String docuses = null;
22         protected ToDo action = null;
23
24         /**
25          * Serial version ID.
26          */
27         private static final long serialVersionUID = -6925961099244461039L;
28
29         protected enum ToDo {
30                 cancel, save
31         };
32
33         // ==============================================================================================================================
34         // Getters and setters
35         // ==============================================================================================================================
36
37         public DocumentType getDefaultDocumentType() {
38                 return deftype;
39         }
40
41         public List<Document> getDefaultDocumentUses() {
42                 return defuses;
43         }
44
45         public String getDocumentName() {
46                 return docname;
47         }
48
49         public String getDocumentState() {
50                 return state.toString();
51         }
52
53         public String getFileName() {
54                 return filename;
55         }
56
57         public void setCancel(final boolean cancel) {
58                 this.action = ToDo.cancel;
59         }
60
61         public void setDocumentState(final String state) {
62                 this.state = ProgressState.valueOf(state);
63         }
64
65         public void setFileName(final String path) {
66                 this.filename = path;
67         }
68
69         public void setUses(final String list) {
70                 this.docuses = list;
71         }
72
73         public void setSave(final boolean save) {
74                 this.action = ToDo.save;
75         }
76
77         public String getWriteAccess() {
78                 Boolean res = (mystudy != null);
79                 if (res) {
80                         res = mystudy.isOpenForWriting();
81                 }
82                 return res.toString();
83         }
84
85         // ==============================================================================================================================
86         // Protected services
87         // ==============================================================================================================================
88
89         protected void setupDefaultUses(final DocumentType type) {
90                 Set<DocumentType> uses = type.getDefaultUses();
91
92                 for (Iterator<DocumentType> i = uses.iterator(); i.hasNext();) {
93                         DocumentType usetype = i.next();
94                         List<Document> usedoc = mystudy.collectInvolvedDocuments(usetype);
95                         if (usedoc.isEmpty() && (!usetype.equals(type))) {
96                                 setupDefaultUses(usetype);
97                         } else {
98                                 defuses.addAll(usedoc);
99                         }
100                 }
101         }
102
103         protected Publication getPublication(final int index) {
104                 List<Step> steps = mystudy.getInvolvedSteps();
105                 Publication found = null, pub;
106                 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
107                         List<Publication> published = i.next().getAllDocuments();
108                         for (Iterator<Publication> j = published.iterator(); j.hasNext();) {
109                                 pub = j.next(); // In a given study step,
110                                 if (pub.value().getIndex() == index) {
111                                         found = pub; // there is only one publication of a given document
112                                         break;
113                                 }
114                         }
115                 }
116                 return found;
117         }
118 }