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 Constants.STUDY_MENU, "false", 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
135 * Remove the scenario functionality.
138 * if the scenario has been successfully removed
140 * if the user can not delete the scenario
142 public String doRemoveScenario() {
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());
153 _openStudy.setSelection("0.1"); // Default selection
157 // ==============================================================================================================================
159 // ==============================================================================================================================
162 * Get current scenario editor or author if the scenario is not checked out.
164 * @return the scenario editor or author
166 public User getAuthor() {
168 if (_myscenario.isCheckedout()) {
169 author = _myscenario.getUser();
171 author = _myscenario.getAuthor();
176 public String getLastModificationDate() {
180 public StepRights getSelectedStep() {
181 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
184 public String getSubject() {
188 public boolean isCheckedout() {
189 return _myscenario.isCheckedout();
193 * Get the selectedScenarioTitle.
195 * @return the selectedScenarioTitle
197 public String getSelectedScenarioTitle() {
198 return _selectedScenarioTitle;
202 * Set the selectedScenarioTitle.
204 * @param selectedScenarioTitle
205 * the selectedScenarioTitle to set
207 public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
208 _selectedScenarioTitle = selectedScenarioTitle;
212 * Get the scenarioService.
214 * @return the scenarioService
216 public ScenarioService getScenarioService() {
217 return _scenarioService;
221 * Set the scenarioService.
223 * @param scenarioService
224 * the scenarioService to set
226 public void setScenarioService(final ScenarioService scenarioService) {
227 _scenarioService = scenarioService;
231 * Get the projectElementService.
233 * @return the projectElementService
235 public ProjectElementService getProjectElementService() {
236 return _projectElementService;
240 * Set the projectElementService.
242 * @param projectElementService
243 * the projectElementService to set
245 public void setProjectElementService(
246 final ProjectElementService projectElementService) {
247 _projectElementService = projectElementService;