Salome HOME
Rename the scenario functionality is implemented
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditScenarioPropertiesAction.java
1 package org.splat.simer;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.ResourceBundle;
7
8 import org.splat.dal.bo.kernel.User;
9 import org.splat.dal.bo.som.Scenario;
10 import org.splat.dal.bo.som.Study;
11 import org.splat.kernel.InvalidPropertyException;
12 import org.splat.service.ProjectElementService;
13 import org.splat.service.ScenarioService;
14 import org.splat.som.Step;
15 import org.splat.som.StepRights;
16 import org.splat.wapp.Constants;
17
18 public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
19
20         /**
21          * Serial version ID.
22          */
23         private static final long serialVersionUID = 4964740932426016171L;
24
25         private transient Scenario _myscenario;
26         private transient String _lasdate;
27         private transient String _subject;
28         
29         /**
30          * Title of the selected scenario.
31          */
32         private String _selectedScenarioTitle;
33
34         /**
35          * The Scenario service.
36          */
37         private ScenarioService _scenarioService;
38
39         /**
40          * The PojectElement service.
41          */
42         private ProjectElementService _projectElementService;
43
44         // ==============================================================================================================================
45         // Action methods
46         // ==============================================================================================================================
47
48         public String doInitialize() {
49                 ResourceBundle label = ResourceBundle.getBundle("labels",
50                                 getApplicationSettings().getCurrentLocale());
51                 ResourceBundle custom = ResourceBundle.getBundle("som",
52                                 getApplicationSettings().getCurrentLocale());
53                 SimpleDateFormat datstring = new SimpleDateFormat(custom
54                                 .getString("date.format")); // Locale date display format
55                 Step step;
56
57                 _openStudy = getOpenStudy();
58                 step = _openStudy.getSelectedStep();
59                 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
60                 _lasdate = datstring.format(_myscenario.getLastModificationDate());
61                 _subject = label.getString("label.study") + " " + _openStudy.getTitle();
62                 _selectedScenarioTitle = _myscenario.getTitle();
63
64                 initializationFullScreenContext(Constants.STUDY_MENU,
65                                 Constants.STUDY_MENU, "true", "back", "open");
66
67                 return SUCCESS;
68         }
69
70         /**
71          * Mark the scenario as checked in.
72          * 
73          * @return SUCCESS
74          * @throws InvalidPropertyException
75          *             if scenario is not found in the database
76          */
77         public String doCheckin() throws InvalidPropertyException {
78                 Step step;
79
80                 _openStudy = getOpenStudy();
81                 _selection = _openStudy.getSelection();
82                 step = _openStudy.getSelectedStep();
83                 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
84
85                 getScenarioService().checkin(_myscenario.getIndex());
86                 // TODO: Do it in the business service after moving to DTO instead of id parameter
87                 // or reread the scenario.
88                 _myscenario.setUser(null);
89
90                 _openStudy.getMenu().refreshGivenStepItem(
91                                 getProjectElementService().getFirstStep(_myscenario)); // For updating the scenario icon
92
93                 if ("true".equals(getWriteAccess())
94                                 && getUserRights().canCreateDocument()) {
95                         setToolProperty(Constants.STUDY_MENU);
96                 } else {
97                         setToolProperty(Constants.STANDARD_MENU);
98                 }
99                 initializationFullScreenContext(Constants.STUDY_MENU,
100                                 getToolProperty(), Constants.STUDY_MENU);
101
102                 return SUCCESS;
103         }
104
105         /**
106          * Rename the scenario functionality.
107          * @return SUCCESS
108          */
109         public String doEditScenarioTitle() {
110                 OpenStudy openStudy = getOpenStudy();
111                 Study study = openStudy.getStudyObject();
112                 List<Scenario> scenarios = study.getScenariiList();
113                 Iterator<Scenario> iter = scenarios.iterator();
114                 for (; iter.hasNext();) {
115                         Scenario scenario = iter.next();
116                         if (openStudy.getSelectedScenarioId().equals(String.valueOf(scenario.getIndex()))) {
117                                 scenario.setTitle(getSelectedScenarioTitle());                          
118                                 _scenarioService.renameScenario(scenario);
119                         }
120                 }
121                 return SUCCESS;
122         }
123         
124         // ==============================================================================================================================
125         // Getters
126         // ==============================================================================================================================
127
128         /**
129          * Get current scenario editor or author if the scenario is not checked out.
130          * 
131          * @return the scenario editor or author
132          */
133         public User getAuthor() {
134                 User author;
135                 if (_myscenario.isCheckedout()) {
136                         author = _myscenario.getUser();
137                 } else {
138                         author = _myscenario.getAuthor();
139                 }
140                 return author;
141         }
142
143         public String getLastModificationDate() {
144                 return _lasdate;
145         }
146
147         public StepRights getSelectedStep() {
148                 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
149         }
150
151         public String getSubject() {
152                 return _subject;
153         }
154
155
156         public boolean isCheckedout() {
157                 return _myscenario.isCheckedout();
158         }
159         
160         
161
162         /**
163          * Get the selectedScenarioTitle.
164          * @return the selectedScenarioTitle
165          */
166         public String getSelectedScenarioTitle() {
167                 return _selectedScenarioTitle;
168         }
169
170         /**
171          * Set the selectedScenarioTitle.
172          * @param selectedScenarioTitle the selectedScenarioTitle to set
173          */
174         public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
175                 _selectedScenarioTitle = selectedScenarioTitle;
176         }
177
178         /**
179          * Get the scenarioService.
180          * 
181          * @return the scenarioService
182          */
183         public ScenarioService getScenarioService() {
184                 return _scenarioService;
185         }
186
187         /**
188          * Set the scenarioService.
189          * 
190          * @param scenarioService
191          *            the scenarioService to set
192          */
193         public void setScenarioService(final ScenarioService scenarioService) {
194                 _scenarioService = scenarioService;
195         }
196
197         /**
198          * Get the projectElementService.
199          * 
200          * @return the projectElementService
201          */
202         public ProjectElementService getProjectElementService() {
203                 return _projectElementService;
204         }
205
206         /**
207          * Set the projectElementService.
208          * 
209          * @param projectElementService
210          *            the projectElementService to set
211          */
212         public void setProjectElementService(
213                         final ProjectElementService projectElementService) {
214                 _projectElementService = projectElementService;
215         }
216 }