]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/NewStudyAction.java
Salome HOME
Tiles is added
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / NewStudyAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4 import java.util.ResourceBundle;
5
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.dal.bo.som.SimulationContext;
8 import org.splat.dal.bo.som.SimulationContextType;
9 import org.splat.dal.bo.som.Study;
10 import org.splat.kernel.InvalidPropertyException;
11 import org.splat.kernel.MissedPropertyException;
12 import org.splat.kernel.MultiplyDefinedException;
13 import org.splat.service.ScenarioService;
14 import org.splat.service.SimulationContextService;
15
16 /**
17  * Action for creation of a new study.
18  */
19 public class NewStudyAction extends Action {
20
21         /**
22          * Serial version ID.
23          */
24         private static final long serialVersionUID = 693943641800113782L;
25         /**
26          * Sequential number of the new study for appending to its default title.
27          */
28         private static int number = 0;
29
30         /**
31          * Title of the new study.
32          */
33         private String _title = null;
34         /**
35          * List of available project contexts for selection for the new study.
36          */
37         private transient List<SimulationContext> _contelm = null;
38         /**
39          * Project context.
40          */
41         private String _projectContext = null;
42
43         /**
44          * Injected simulation context service.
45          */
46         private SimulationContextService _simulationContextService;
47         /**
48          * Injected scenario service.
49          */
50         private ScenarioService _scenarioService;
51
52         /**
53          * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
54          */
55         private String _menuProperty;
56
57         /**
58          * Value of the tool bar property. It can be: none, standard, study, back.
59          */
60         private String _toolProperty;
61
62         /**
63          * Value of the left menu property. It can be: open, study, knowledge, scenario.
64          */
65         private String _leftMenuProperty;
66
67         // ==============================================================================================================================
68         // Action methods
69         // ==============================================================================================================================
70
71         /**
72          * Fill the values of the drop-down list, and initialize a menu.
73          * 
74          * @return SUCCESS
75          */
76         public String doInitialize() {
77
78                 // get the list of the simulation contexts of the study
79                 _contelm = getSimulationContextService().getSimulationContextList();
80
81                 // set the default name of the new study
82                 ResourceBundle locale = ResourceBundle.getBundle("labels",
83                                 getApplicationSettings().getCurrentLocale());
84                 _title = locale.getString("label.study") + " "
85                                 + String.valueOf(number + 1);
86
87                 setMenuProperty("create");
88                 setToolProperty("none");
89                 setLeftMenuProperty("open");
90                 initializationFullScreenContext(_menuProperty, _toolProperty,
91                                 _leftMenuProperty);
92
93                 return SUCCESS;
94         }
95
96         /**
97          * Create a new study.
98          * 
99          * @return SUCCESS if the new study is created, INPUT if project context is not defined, ERROR if failed
100          * @throws InvalidPropertyException
101          *             if some property has invalid value
102          * @throws MultiplyDefinedException
103          *             if some property is defined several times
104          * @throws MissedPropertyException
105          *             if properties of the new study are invalid
106          */
107         public String doCreate() throws InvalidPropertyException,
108                         MissedPropertyException, MultiplyDefinedException {
109                 String[] input = _projectContext.split(",");
110                 int valid = Integer.valueOf(input[0]);
111                 String value = ""; // input[1] if exists
112
113                 Study.Properties sprop = new Study.Properties();
114
115                 // Check arguments and creation of the study
116                 if (valid == -1) {
117                         SimulationContext.Properties cprop = new SimulationContext.Properties();
118                         SimulationContextType product = getSimulationContextService()
119                                         .selectType("product");
120                         _contelm = getSimulationContextService()
121                                         .selectSimulationContextsWhere(cprop.setType(product));
122                         return INPUT; // Title empty, simply wait for input without error message
123                 }
124                 if (valid == 0) {
125                         value = input[1].trim();
126                         if (value.length() == 0) {
127                                 setMenuProperty("create");
128                                 initializationScreenContext(_menuProperty);
129                                 return INPUT; // No need to reinitialize the list of existing products
130                         }
131                 }
132                 sprop.setTitle(_title).setManager(getConnectedUser());
133                 sprop.checkValidity();
134                 sprop.disableCheck();
135                 try {
136                         // Addition of a default scenario
137                         ResourceBundle locale = ResourceBundle.getBundle("labels",
138                                         getApplicationSettings().getCurrentLocale());
139                         Scenario.Properties oprop = new Scenario.Properties();
140                         oprop.setTitle(locale.getString("label.scenario") + " 1");
141
142                         // Addition of the entered project context
143                         SimulationContext.Properties cprop = new SimulationContext.Properties();
144                         if (valid == 0) { // Input of new project context
145                                 cprop.setType(
146                                                 getSimulationContextService().selectType("product"))
147                                                 .setValue(value);
148                         } else { // Selection of existing project context
149                                 cprop.setIndex(valid);
150                         }
151                         Study study = getScenarioService().createStudy(sprop, oprop, cprop);
152                         // Update of the session
153                         number += 1;
154                         open(study); // Opens the study,
155
156                         setMenuProperty("study");
157                         setToolProperty("none");
158                         setLeftMenuProperty("open");
159                         initializationFullScreenContext(_menuProperty, _toolProperty,
160                                         _leftMenuProperty);
161
162                         return SUCCESS;
163                 } catch (Exception error) {
164                         LOG.error("Unable to save the study, reason:", error);
165                         setErrorCode("message.error.newstudy");
166                         setMenuProperty("none");
167                         initializationScreenContext(_menuProperty);
168                         return ERROR;
169                 }
170         }
171
172         // ==============================================================================================================================
173         // Getters and setters
174         // ==============================================================================================================================
175
176         /**
177          * Get the selected project context for the new study.
178          * 
179          * @return the selected project context
180          */
181         public String getProjectContext() {
182                 return _projectContext;
183         }
184
185         /**
186          * Get the list of available project contexts.
187          * 
188          * @return the list of context values
189          */
190         public List<SimulationContext> getProjectContextValues() {
191                 return _contelm;
192         }
193
194         /**
195          * Get the title of the new study.
196          * 
197          * @return the title
198          */
199         public String getTitle() {
200                 return _title;
201         }
202
203         /**
204          * Set the project context for the new study.
205          * 
206          * @param value
207          *            the project context value.
208          */
209         public void setProjectContext(final String value) {
210                 this._projectContext = value;
211         }
212
213         /**
214          * Set the title of the new study.
215          * 
216          * @param value
217          *            the title to set
218          */
219         public void setTitle(final String value) {
220                 this._title = value;
221         }
222
223         /**
224          * Get the simulationContextService.
225          * 
226          * @return the simulationContextService
227          */
228         public SimulationContextService getSimulationContextService() {
229                 return _simulationContextService;
230         }
231
232         /**
233          * Set the simulationContextService.
234          * 
235          * @param simulationContextService
236          *            the simulationContextService to set
237          */
238         public void setSimulationContextService(
239                         final SimulationContextService simulationContextService) {
240                 _simulationContextService = simulationContextService;
241         }
242
243         /**
244          * Get the scenarioService.
245          * 
246          * @return the scenarioService
247          */
248         public ScenarioService getScenarioService() {
249                 return _scenarioService;
250         }
251
252         /**
253          * Set the scenarioService.
254          * 
255          * @param scenarioService
256          *            the scenarioService to set
257          */
258         public void setScenarioService(final ScenarioService scenarioService) {
259                 _scenarioService = scenarioService;
260         }
261
262         /**
263          * Get the menuProperty.
264          * 
265          * @return the menuProperty
266          */
267         public String getMenuProperty() {
268                 return _menuProperty;
269         }
270
271         /**
272          * Set the menuProperty.
273          * 
274          * @param menuProperty
275          *            the menuProperty to set
276          */
277         public void setMenuProperty(final String menuProperty) {
278                 this._menuProperty = menuProperty;
279         }
280
281         /**
282          * Get the toolProperty.
283          * 
284          * @return the toolProperty
285          */
286         public String getToolProperty() {
287                 return _toolProperty;
288         }
289
290         /**
291          * Set the toolProperty.
292          * 
293          * @param toolProperty
294          *            the toolProperty to set
295          */
296         public void setToolProperty(final String toolProperty) {
297                 _toolProperty = toolProperty;
298         }
299
300         /**
301          * Get the leftMenuProperty.
302          * 
303          * @return the leftMenuProperty
304          */
305         public String getLeftMenuProperty() {
306                 return _leftMenuProperty;
307         }
308
309         /**
310          * Set the leftMenuProperty.
311          * 
312          * @param leftMenuProperty
313          *            the leftMenuProperty to set
314          */
315         public void setLeftMenuProperty(final String leftMenuProperty) {
316                 _leftMenuProperty = leftMenuProperty;
317         }
318 }