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;
18 public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
23 private static final long serialVersionUID = 4964740932426016171L;
25 private transient Scenario _myscenario;
26 private transient String _lasdate;
27 private transient String _subject;
30 * Title of the selected scenario.
32 private String _selectedScenarioTitle;
35 * The Scenario service.
37 private ScenarioService _scenarioService;
40 * The PojectElement service.
42 private ProjectElementService _projectElementService;
44 // ==============================================================================================================================
46 // ==============================================================================================================================
48 public String doInitialize() {
49 ResourceBundle label = ResourceBundle.getBundle("labels",
50 getApplicationSettings().getCurrentLocale());
51 ResourceBundle custom = ResourceBundle.getBundle("som",
52 getApplicationSettings().getCurrentLocale());
53 SimpleDateFormat datstring = new SimpleDateFormat(custom
54 .getString("date.format")); // Locale date display format
57 _openStudy = getOpenStudy();
58 step = _openStudy.getSelectedStep();
59 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
60 _lasdate = datstring.format(_myscenario.getLastModificationDate());
61 _subject = label.getString("label.study") + " " + _openStudy.getTitle();
62 _selectedScenarioTitle = _myscenario.getTitle();
64 initializationFullScreenContext(Constants.STUDY_MENU,
65 Constants.STUDY_MENU, "true", "back", "open");
71 * Mark the scenario as checked in.
74 * @throws InvalidPropertyException
75 * if scenario is not found in the database
77 public String doCheckin() throws InvalidPropertyException {
80 _openStudy = getOpenStudy();
81 _selection = _openStudy.getSelection();
82 step = _openStudy.getSelectedStep();
83 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
85 getScenarioService().checkin(_myscenario.getIndex());
86 // TODO: Do it in the business service after moving to DTO instead of id parameter
87 // or reread the scenario.
88 _myscenario.setUser(null);
90 _openStudy.getMenu().refreshGivenStepItem(
91 getProjectElementService().getFirstStep(_myscenario)); // For updating the scenario icon
93 if ("true".equals(getWriteAccess())
94 && getUserRights().canCreateDocument()) {
95 setToolProperty(Constants.STUDY_MENU);
97 setToolProperty(Constants.STANDARD_MENU);
99 initializationFullScreenContext(Constants.STUDY_MENU,
100 getToolProperty(), Constants.STUDY_MENU);
106 * Rename the scenario functionality.
109 public String doEditScenarioTitle() {
110 OpenStudy openStudy = getOpenStudy();
111 Study study = openStudy.getStudyObject();
112 List<Scenario> scenarios = study.getScenariiList();
113 Iterator<Scenario> iter = scenarios.iterator();
114 for (; iter.hasNext();) {
115 Scenario scenario = iter.next();
116 if (openStudy.getSelectedScenarioId().equals(String.valueOf(scenario.getIndex()))) {
117 scenario.setTitle(getSelectedScenarioTitle());
118 _scenarioService.renameScenario(scenario);
124 // ==============================================================================================================================
126 // ==============================================================================================================================
129 * Get current scenario editor or author if the scenario is not checked out.
131 * @return the scenario editor or author
133 public User getAuthor() {
135 if (_myscenario.isCheckedout()) {
136 author = _myscenario.getUser();
138 author = _myscenario.getAuthor();
143 public String getLastModificationDate() {
147 public StepRights getSelectedStep() {
148 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
151 public String getSubject() {
156 public boolean isCheckedout() {
157 return _myscenario.isCheckedout();
163 * Get the selectedScenarioTitle.
164 * @return the selectedScenarioTitle
166 public String getSelectedScenarioTitle() {
167 return _selectedScenarioTitle;
171 * Set the selectedScenarioTitle.
172 * @param selectedScenarioTitle the selectedScenarioTitle to set
174 public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
175 _selectedScenarioTitle = selectedScenarioTitle;
179 * Get the scenarioService.
181 * @return the scenarioService
183 public ScenarioService getScenarioService() {
184 return _scenarioService;
188 * Set the scenarioService.
190 * @param scenarioService
191 * the scenarioService to set
193 public void setScenarioService(final ScenarioService scenarioService) {
194 _scenarioService = scenarioService;
198 * Get the projectElementService.
200 * @return the projectElementService
202 public ProjectElementService getProjectElementService() {
203 return _projectElementService;
207 * Set the projectElementService.
209 * @param projectElementService
210 * the projectElementService to set
212 public void setProjectElementService(
213 final ProjectElementService projectElementService) {
214 _projectElementService = projectElementService;