]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java
Salome HOME
Tool bar is improved.
[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
14 public abstract class UploadBaseNextAction extends Action {
15
16     protected OpenStudy      mystudy  = null;
17     protected String         filename = null;   // Uploaded file name
18     protected DocumentType   deftype  = null;
19     protected List<Document> defuses  = null;
20     protected String         docname  = null;
21     protected ProgressState  state    = null;
22     protected String         docuses  = null;
23     protected ToDo           action   = null;
24
25         /**
26          * Serial version ID.
27          */
28     private static final long serialVersionUID = -6925961099244461039L;
29
30     protected enum  ToDo { cancel, save };
31
32 //  ==============================================================================================================================
33 //  Getters and setters
34 //  ==============================================================================================================================
35
36     public DocumentType getDefaultDocumentType () {
37 //  ---------------------------------------------
38       return deftype;
39     }
40     public List<Document> getDefaultDocumentUses () {
41 //  -----------------------------------------------
42       return defuses;
43     }
44     public String getDocumentName () {
45 //  --------------------------------
46       return docname;
47     }
48     public String getDocumentState () {
49 //  ---------------------------------
50       return state.toString();
51     }
52     public String getFileName () {
53 //  ----------------------------
54       return filename;
55     }
56
57     public void setCancel (boolean cancel) {
58 //  --------------------------------------
59       this.action = ToDo.cancel;
60     }
61     public void setDocumentState (String state) {
62 //  -------------------------------------------
63       this.state = ProgressState.valueOf(state);
64     }
65     public void setFileName (String path) {
66 //  -------------------------------------
67       this.filename = path;
68     }
69     public void setUses (String list) {
70 //  ---------------------------------
71       this.docuses = list;
72     }
73     public void setSave (boolean save) {
74 //  ----------------------------------
75       this.action = ToDo.save;
76     }
77     
78     public String getWriteAccess() {
79         if (mystudy == null) {
80                 return "false";
81         }
82                 return String.valueOf(mystudy.isOpenForWriting());
83         }
84 //  ==============================================================================================================================
85 //  Protected services
86 //  ==============================================================================================================================
87
88     protected void setupDefaultUses (DocumentType type) {
89 //  -------------------------------------------------
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()) setupDefaultUses(usetype);
96         else                  defuses.addAll(usedoc);
97       }
98     }
99
100     protected Publication getPublication (int index) {
101 //  ------------------------------------------------
102       List<Step> steps = mystudy.getInvolvedSteps();
103       
104       for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
105         List<Publication> published = i.next().getAllDocuments();
106         for (Iterator<Publication> j=published.iterator(); j.hasNext();) {
107           Publication found = j.next();                          // In a given study step,
108           if (found.value().getIndex() == index) return found;   // there is only one publication of a given document
109         }
110       }
111       return null;
112     }
113 }