1 package org.splat.simer;
3 import java.text.SimpleDateFormat;
4 import java.util.Iterator;
6 import java.util.ResourceBundle;
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;
19 * Action for scenario properties modification.
21 public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
26 private static final long serialVersionUID = 4964740932426016171L;
28 private transient Scenario _myscenario;
29 private transient String _lasdate;
30 private transient String _subject;
33 * Title of the selected scenario.
35 private String _selectedScenarioTitle;
38 * The Scenario service.
40 private ScenarioService _scenarioService;
43 * The PojectElement service.
45 private ProjectElementService _projectElementService;
47 // ==============================================================================================================================
49 // ==============================================================================================================================
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
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();
68 initializationFullScreenContext(Constants.STUDY_MENU,
69 Constants.STUDY_MENU, "true", "back", "open");
75 * Mark the scenario as checked in.
78 * @throws InvalidPropertyException
79 * if scenario is not found in the database
81 public String doCheckin() throws InvalidPropertyException {
84 _openStudy = getOpenStudy();
85 _selection = _openStudy.getSelection();
86 step = _openStudy.getSelectedStep();
87 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
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);
94 _openStudy.getMenu().refreshGivenStepItem(
95 getProjectElementService().getFirstStep(_myscenario)); // For updating the scenario icon
97 if ("true".equals(getWriteAccess())
98 && getUserRights().canCreateDocument()) {
99 setToolProperty(Constants.STUDY_MENU);
101 setToolProperty(Constants.STANDARD_MENU);
103 initializationFullScreenContext(Constants.STUDY_MENU,
104 getToolProperty(), Constants.STUDY_MENU);
110 * Rename the scenario functionality.
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);
129 _selection = _openStudy.getSelection(); //actually, value doesn't matter, it just has to be not null
134 // ==============================================================================================================================
136 // ==============================================================================================================================
139 * Get current scenario editor or author if the scenario is not checked out.
141 * @return the scenario editor or author
143 public User getAuthor() {
145 if (_myscenario.isCheckedout()) {
146 author = _myscenario.getUser();
148 author = _myscenario.getAuthor();
153 public String getLastModificationDate() {
157 public StepRights getSelectedStep() {
158 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
161 public String getSubject() {
165 public boolean isCheckedout() {
166 return _myscenario.isCheckedout();
170 * Get the selectedScenarioTitle.
172 * @return the selectedScenarioTitle
174 public String getSelectedScenarioTitle() {
175 return _selectedScenarioTitle;
179 * Set the selectedScenarioTitle.
181 * @param selectedScenarioTitle
182 * the selectedScenarioTitle to set
184 public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
185 _selectedScenarioTitle = selectedScenarioTitle;
189 * Get the scenarioService.
191 * @return the scenarioService
193 public ScenarioService getScenarioService() {
194 return _scenarioService;
198 * Set the scenarioService.
200 * @param scenarioService
201 * the scenarioService to set
203 public void setScenarioService(final ScenarioService scenarioService) {
204 _scenarioService = scenarioService;
208 * Get the projectElementService.
210 * @return the projectElementService
212 public ProjectElementService getProjectElementService() {
213 return _projectElementService;
217 * Set the projectElementService.
219 * @param projectElementService
220 * the projectElementService to set
222 public void setProjectElementService(
223 final ProjectElementService projectElementService) {
224 _projectElementService = projectElementService;