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