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);
130 // ==============================================================================================================================
132 // ==============================================================================================================================
135 * Get current scenario editor or author if the scenario is not checked out.
137 * @return the scenario editor or author
139 public User getAuthor() {
141 if (_myscenario.isCheckedout()) {
142 author = _myscenario.getUser();
144 author = _myscenario.getAuthor();
149 public String getLastModificationDate() {
153 public StepRights getSelectedStep() {
154 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
157 public String getSubject() {
161 public boolean isCheckedout() {
162 return _myscenario.isCheckedout();
166 * Get the selectedScenarioTitle.
168 * @return the selectedScenarioTitle
170 public String getSelectedScenarioTitle() {
171 return _selectedScenarioTitle;
175 * Set the selectedScenarioTitle.
177 * @param selectedScenarioTitle
178 * the selectedScenarioTitle to set
180 public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
181 _selectedScenarioTitle = selectedScenarioTitle;
185 * Get the scenarioService.
187 * @return the scenarioService
189 public ScenarioService getScenarioService() {
190 return _scenarioService;
194 * Set the scenarioService.
196 * @param scenarioService
197 * the scenarioService to set
199 public void setScenarioService(final ScenarioService scenarioService) {
200 _scenarioService = scenarioService;
204 * Get the projectElementService.
206 * @return the projectElementService
208 public ProjectElementService getProjectElementService() {
209 return _projectElementService;
213 * Set the projectElementService.
215 * @param projectElementService
216 * the projectElementService to set
218 public void setProjectElementService(
219 final ProjectElementService projectElementService) {
220 _projectElementService = projectElementService;