Salome HOME
Tool bar is improved.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / UploadAction.java
1 package org.splat.simer;
2
3 import java.io.File;
4
5 import org.splat.kernel.Do;
6 import org.splat.service.technical.RepositoryService;
7 import org.splat.dal.dao.som.Database;
8
9
10 public class UploadAction extends Action {
11
12         private File    upload         = null;
13         private String  uploadMimeType = null;
14     private String  uploadFileName = null;
15
16     private ToDo    action;                  // Action to do
17     private String  next           = null;   // Action to which the uploaded file is passed
18         private String  index          = null;   // Depending on the next action, document index to which the action applies
19         /**
20          * Injected repository service.
21          */
22         private RepositoryService _repositoryService;
23         
24         /**
25          * Value of the menu property. 
26          * It can be: none, create, open, study, knowledge, sysadmin, help.
27          */
28         private String _menuProperty;
29         
30         /**
31          * Value of the title bar property. 
32          * It can be: study, knowledge.
33          */
34         private String _titleProperty;
35         
36         /**
37          * Value of the tool bar property. 
38          * It can be: none, standard, study, back.
39          */
40         private String _toolProperty;
41         /**
42          * Property that indicates whether the current open study is editable or not.
43          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
44          * It is necessary for correct building the title bar.
45          */
46         private String _editDisabledProperty = "false";
47
48         private static final long serialVersionUID = 6003880772275115923L;
49
50     private enum ToDo { cancel, upload };
51
52 //  ==============================================================================================================================
53 //  Action methods
54 //  ==============================================================================================================================
55
56     public String doInitialize () {
57 //  -----------------------------
58         setMenuProperty("study");
59         setToolProperty("none");
60         initializationScreenContext(_menuProperty, _toolProperty);
61                 
62       return SUCCESS;
63     }
64
65     public String doUpload () {
66 //  -------------------------
67       setMenuProperty("study");
68       setTitleProperty("study");
69       setEditDisabledProperty("true");
70       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
71       
72       if (action == ToDo.cancel) return "cancel";
73       try {
74         File    udir = getRepositoryService().getDownloadDirectory(getConnectedUser());
75         String  path = udir.getPath() + "/" + uploadFileName;
76         File    file = new File(path);
77
78         if (!udir.exists()) udir.mkdir();
79         if (file.exists())  file.delete();
80         Do.copy(upload, file);
81         logger.info("Uploading \"" + uploadFileName + "\" " + uploadMimeType + " file.");
82         /*if (next == null || next.isEmpty()) {
83                 next = "import";
84         }*/
85         
86         logger.info("MKA next = " + next);
87         return next;
88       }
89       catch (OutOfMemoryError error) {
90           
91         setMenuProperty("none");
92         setTitleProperty("study");
93         setEditDisabledProperty("true");
94         setToolProperty("none");
95         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
96                 
97         return "outofmemory";
98       }
99       catch (Exception error) {
100         logger.error("Reason: ", error);
101         return ERROR;
102       }
103     }
104 //  ==============================================================================================================================
105 //  Getters and setters
106 //  ==============================================================================================================================
107
108     public String getIndex () {
109 //  -------------------------
110       return index;
111     }
112     public String getFileName () {
113 //  ----------------------------
114       return uploadFileName;
115     }
116     public String getNextAction () {
117 //  ------------------------------
118       return next;
119     }
120
121     public void setCancel (boolean back) {
122 //  ------------------------------------
123       this.action = ToDo.cancel;
124     }
125     public void setDoIt (boolean upload) {
126 //  --------------------------------
127       this.action = ToDo.upload;
128     }
129     public void setIndex (String index) {
130 //  -----------------------------------
131       this.index = index;
132     }
133     public void setNextAction (String next) {
134 //  ---------------------------------------
135       this.next = next;
136     }
137     public void setUpload (File upload) {
138 //  -----------------------------------
139       this.upload = upload;
140     }
141     public void setUploadFileName (String name) {
142 //  -------------------------------------------
143       this.uploadFileName = name;
144     }
145     public void setUploadContentType (String mime) {
146 //  ----------------------------------------------
147       this.uploadMimeType = mime;
148     }
149
150         /**
151          * Get the repositoryService.
152          * @return the repositoryService
153          */
154         public RepositoryService getRepositoryService() {
155                 return _repositoryService;
156         }
157
158         /**
159          * Set the repositoryService.
160          * @param repositoryService the repositoryService to set
161          */
162         public void setRepositoryService(RepositoryService repositoryService) {
163                 _repositoryService = repositoryService;
164         }
165         
166         /**
167          * Get the menuProperty.
168          * @return the menuProperty
169          */
170         public String getMenuProperty() {
171                 return _menuProperty;
172         }
173
174         /**
175          * Set the menuProperty.
176          * @param menuProperty the menuProperty to set
177          */
178         public void setMenuProperty(String menuProperty) {
179                 this._menuProperty = menuProperty;
180         }
181         
182         /**
183          * Get the _titleProperty.
184          * @return the _titleProperty
185          */
186         public String getTitleProperty() {
187                 return _titleProperty;
188         }
189
190         /**
191          * Set the _titleProperty.
192          * @param _titleProperty the titleProperty to set
193          */
194         public void setTitleProperty(String titleProperty) {
195                 _titleProperty = titleProperty;
196         }
197
198         /**
199          * Get the _editDisabledProperty.
200          * @return the _editDisabledProperty
201          */
202         public String getEditDisabledProperty() {
203                 return _editDisabledProperty;
204         }
205
206         /**
207          * Set the _editDisabledProperty.
208          * @param _editDisabledProperty the _editDisabledProperty to set
209          */
210         public void setEditDisabledProperty(String _editDisabledProperty) {
211                 this._editDisabledProperty = _editDisabledProperty;
212         }
213
214         /**
215          * Get the toolProperty.
216          * @return the toolProperty
217          */
218         public String getToolProperty() {
219                 return _toolProperty;
220         }
221
222         /**
223          * Set the toolProperty.
224          * @param toolProperty the toolProperty to set
225          */
226         public void setToolProperty(final String toolProperty) {
227                 _toolProperty = toolProperty;
228         }
229 }