]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java
Salome HOME
Copyrights update 2015.
[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                                 Constants.STUDY_MENU, "false", 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          * Remove the scenario functionality.
136          * 
137          * @return SUCCESS
138          *                      if the scenario has been successfully removed
139          *         ERROR
140          *                      if the user can not delete the scenario
141          */
142         public String doRemoveScenario() {
143                 String res = ERROR;
144                 List<Scenario> scenarios = getOpenStudy().getStudyObject().getScenariiList();
145                 if (_openStudy.getStudyRights().canRemoveScenario()) {
146                         for (Scenario scenario : scenarios) {
147                                 if (scenario.getIndex() == Long.valueOf(getOpenStudy().getSelectedScenarioId())) {
148                                         _scenarioService.removeScenario(scenario.getIndex());
149                                         res = SUCCESS;
150                                 }
151                         }
152                 }
153                 _openStudy.setSelection("0.1"); // Default selection
154                 return res;
155         }
156
157         // ==============================================================================================================================
158         // Getters
159         // ==============================================================================================================================
160
161         /**
162          * Get current scenario editor or author if the scenario is not checked out.
163          * 
164          * @return the scenario editor or author
165          */
166         public User getAuthor() {
167                 User author;
168                 if (_myscenario.isCheckedout()) {
169                         author = _myscenario.getUser();
170                 } else {
171                         author = _myscenario.getAuthor();
172                 }
173                 return author;
174         }
175
176         public String getLastModificationDate() {
177                 return _lasdate;
178         }
179
180         public StepRights getSelectedStep() {
181                 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
182         }
183
184         public String getSubject() {
185                 return _subject;
186         }
187
188         public boolean isCheckedout() {
189                 return _myscenario.isCheckedout();
190         }
191
192         /**
193          * Get the selectedScenarioTitle.
194          * 
195          * @return the selectedScenarioTitle
196          */
197         public String getSelectedScenarioTitle() {
198                 return _selectedScenarioTitle;
199         }
200
201         /**
202          * Set the selectedScenarioTitle.
203          * 
204          * @param selectedScenarioTitle
205          *            the selectedScenarioTitle to set
206          */
207         public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
208                 _selectedScenarioTitle = selectedScenarioTitle;
209         }
210
211         /**
212          * Get the scenarioService.
213          * 
214          * @return the scenarioService
215          */
216         public ScenarioService getScenarioService() {
217                 return _scenarioService;
218         }
219
220         /**
221          * Set the scenarioService.
222          * 
223          * @param scenarioService
224          *            the scenarioService to set
225          */
226         public void setScenarioService(final ScenarioService scenarioService) {
227                 _scenarioService = scenarioService;
228         }
229
230         /**
231          * Get the projectElementService.
232          * 
233          * @return the projectElementService
234          */
235         public ProjectElementService getProjectElementService() {
236                 return _projectElementService;
237         }
238
239         /**
240          * Set the projectElementService.
241          * 
242          * @param projectElementService
243          *            the projectElementService to set
244          */
245         public void setProjectElementService(
246                         final ProjectElementService projectElementService) {
247                 _projectElementService = projectElementService;
248         }
249 }