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