1 package org.splat.simer;
3 import java.util.Arrays;
4 import java.util.Iterator;
6 import java.util.ResourceBundle;
8 import org.splat.dal.bo.som.Publication;
9 import org.splat.dal.bo.som.Scenario;
10 import org.splat.dal.bo.som.Study;
11 import org.splat.service.ProjectElementService;
12 import org.splat.service.ScenarioService;
13 import org.splat.som.Step;
14 import org.splat.wapp.Constants;
15 import org.splat.wapp.Menu;
17 public class NewScenarioAction extends Action {
19 private transient OpenStudy _mystudy;
20 private transient List<Scenario> _myscene;
21 private String _title;
22 private String _selection;
23 private transient long _scindex;
24 private transient int _bastep;
25 private transient ToDo _action;
27 * Injected scenario service.
29 private ScenarioService _scenarioService;
31 * Injected project element service.
33 private ProjectElementService _projectElementService;
39 private static final long serialVersionUID = -5586724442986956861L;
45 // ==============================================================================================================================
47 // ==============================================================================================================================
49 public String doInitialize() {
50 _mystudy = getOpenStudy();
51 Study study = _mystudy.getStudyObject();
52 Scenario[] scene = study.getScenarii();
53 Scenario base = scene[scene.length - 1]; // Default base scenario
54 ResourceBundle locale = ResourceBundle.getBundle("labels",
55 getApplicationSettings().getCurrentLocale());
57 _myscene = Arrays.asList(scene);
58 _scindex = base.getIndex();
59 _title = locale.getString("label.scenario") + " "
60 + String.valueOf(scene.length + 1);
61 _bastep = getProjectElementService().getFirstStep(base).getNumber(); // Better use the last current step ?
62 _selection = _scindex + "." + _bastep;
65 // RKV Menu menu = new NewScenarioMenu(study);
66 Menu menu = ((NewScenarioMenu) getMenu()).init(study); // RKV
67 menu.selects(_selection);
68 getSession().put("menu.scenario", menu);
70 initializationFullScreenContext(Constants.STUDY_MENU,
71 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
72 Constants.SCENARIO_MENU);
74 setActionType("focus");
79 public String doSelectStep() {
80 _mystudy = getOpenStudy();
81 Study study = _mystudy.getStudyObject();
82 Scenario[] scene = study.getScenarii();
84 _myscene = Arrays.asList(scene);
85 _bastep = getProjectElementService().getFirstStep(scene[0]).getNumber(); // All scenarios have the same first step number
88 getMenu("scenario").selects(_selection);
90 initializationFullScreenContext(Constants.STUDY_MENU,
91 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
92 Constants.SCENARIO_MENU);
94 setActionType("none");
99 public String doCreate() {
100 if (_action == ToDo.cancel) {
105 _mystudy = getOpenStudy();
106 _selection = getMenu("scenario").getSelection();
107 Study study = _mystudy.getStudyObject();
108 String[] parse = _selection.split("\\x2E");
109 int scindex = Integer.valueOf(parse[0]);
110 int number = Integer.valueOf(parse[1]);
112 Scenario[] scene = study.getScenarii();
113 Scenario bascene = scene[0];
114 for (int i = 1; i < scene.length; i++) {
116 if (bascene.getIndex() == scindex) {
121 Scenario.Properties sprop = new Scenario.Properties().setManager(
122 getConnectedUser()).setTitle(_title)
123 .setInsertAfter(bascene);
125 _bastep = getProjectElementService().getFirstStep(bascene)
127 if (this.sharesStep()) {
128 step = getProjectElementService().getSteps(bascene);
129 sprop.setBaseStep(step[number - _bastep]);
131 bascene = getScenarioService().addScenario(study, sprop);
134 // Update of the display
136 for (int i = 0; i < number - _bastep + 1; i++) {
137 List<Publication> contents = step[i].getAllDocuments();
138 for (Iterator<Publication> j = contents.iterator(); j
140 _mystudy.update(j.next());
144 _mystudy.setSelection(bascene.getIndex() + "." + number);
145 getSession().remove("menu.scenario");
147 } catch (RuntimeException saverror) {
148 LOG.error("Reason:", saverror);
150 initializationFullScreenContext(Constants.STUDY_MENU,
151 Constants.STUDY_MENU, Constants.FALSE,
152 Constants.STANDARD_MENU, Constants.STUDY_MENU);
155 } catch (Exception error) {
160 // ==============================================================================================================================
161 // Getters and setters
162 // ==============================================================================================================================
164 public List<Scenario> getScenarii() {
168 public long getSelectedScenarioIndex() {
172 public String getSelection() {
176 public String getSharedStep() {
177 String[] parse = _selection.split("\\x2E");
181 public String getTitle() {
185 public void setCancel(final boolean cancel) {
186 _action = ToDo.cancel;
189 public void setSave(final boolean save) {
193 public void setSelectedScenario(final String index) {
194 _scindex = Integer.valueOf(index);
197 public void setSelection(final String step) {
201 public void setTitle(final String title) {
205 public Boolean sharesStep() {
206 return (Integer.valueOf(getSharedStep()) > _bastep);
210 * Get the projectElementService.
212 * @return the projectElementService
214 public ProjectElementService getProjectElementService() {
215 return _projectElementService;
219 * Set the projectElementService.
221 * @param projectElementService
222 * the projectElementService to set
224 public void setProjectElementService(
225 final ProjectElementService projectElementService) {
226 _projectElementService = projectElementService;
234 public Menu getMenu() {
244 public void setMenu(final Menu menu) {
249 * Get the scenarioService.
251 * @return the scenarioService
253 public ScenarioService getScenarioService() {
254 return _scenarioService;
258 * Set the scenarioService.
260 * @param scenarioService
261 * the scenarioService to set
263 public void setScenarioService(final ScenarioService scenarioService) {
264 _scenarioService = scenarioService;