]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java
Salome HOME
2aacb56d64d172b6a13c0fa381b211833b8553cc
[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     private static final long serialVersionUID = -6925961099244461039L;
26
27     protected enum  ToDo { cancel, save };
28
29 //  ==============================================================================================================================
30 //  Getters and setters
31 //  ==============================================================================================================================
32
33     public DocumentType getDefaultDocumentType () {
34 //  ---------------------------------------------
35       return deftype;
36     }
37     public List<Document> getDefaultDocumentUses () {
38 //  -----------------------------------------------
39       return defuses;
40     }
41     public String getDocumentName () {
42 //  --------------------------------
43       return docname;
44     }
45     public String getDocumentState () {
46 //  ---------------------------------
47       return state.toString();
48     }
49     public String getFileName () {
50 //  ----------------------------
51       return filename;
52     }
53
54     public void setCancel (boolean cancel) {
55 //  --------------------------------------
56       this.action = ToDo.cancel;
57     }
58     public void setDocumentState (String state) {
59 //  -------------------------------------------
60       this.state = ProgressState.valueOf(state);
61     }
62     public void setFileName (String path) {
63 //  -------------------------------------
64       this.filename = path;
65     }
66     public void setUses (String list) {
67 //  ---------------------------------
68       this.docuses = list;
69     }
70     public void setSave (boolean save) {
71 //  ----------------------------------
72       this.action = ToDo.save;
73     }
74 //  ==============================================================================================================================
75 //  Protected services
76 //  ==============================================================================================================================
77
78     protected void setupDefaultUses (DocumentType type) {
79 //  -------------------------------------------------
80       Set<DocumentType> uses = type.getDefaultUses();
81       
82       for (Iterator<DocumentType> i=uses.iterator(); i.hasNext();) {
83         DocumentType   usetype = i.next();
84         List<Document> usedoc  = mystudy.collectInvolvedDocuments(usetype);
85         if (usedoc.isEmpty()) setupDefaultUses(usetype);
86         else                  defuses.addAll(usedoc);
87       }
88     }
89
90     protected Publication getPublication (int index) {
91 //  ------------------------------------------------
92       List<Step> steps = mystudy.getInvolvedSteps();
93       
94       for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
95         List<Publication> published = i.next().getAllDocuments();
96         for (Iterator<Publication> j=published.iterator(); j.hasNext();) {
97           Publication found = j.next();                          // In a given study step,
98           if (found.value().getIndex() == index) return found;   // there is only one publication of a given document
99         }
100       }
101       return null;
102     }
103 }