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;
18 * New scenario creation action.
20 public class NewScenarioAction extends Action {
22 private transient OpenStudy _mystudy;
23 private transient List<Scenario> _myscene;
24 private String _title;
25 private String _selection;
26 private transient long _scindex;
27 private transient int _bastep;
28 private transient ToDo _action;
30 * Injected scenario service.
32 private ScenarioService _scenarioService;
34 * Injected project element service.
36 private ProjectElementService _projectElementService;
42 private static final long serialVersionUID = -5586724442986956861L;
48 // ==============================================================================================================================
50 // ==============================================================================================================================
52 public String doInitialize() {
53 _mystudy = getOpenStudy();
54 Study study = _mystudy.getStudyObject();
55 Scenario[] scene = study.getScenarii();
56 Scenario base = scene[scene.length - 1]; // Default base scenario
57 ResourceBundle locale = ResourceBundle.getBundle("labels",
58 getApplicationSettings().getCurrentLocale());
60 _myscene = Arrays.asList(scene);
61 _scindex = base.getIndex();
62 _title = locale.getString("label.scenario") + " "
63 + String.valueOf(scene.length + 1);
64 _bastep = getProjectElementService().getFirstStep(base).getNumber(); // Better use the last current step ?
65 _selection = _scindex + "." + _bastep;
68 // RKV Menu menu = new NewScenarioMenu(study);
69 Menu menu = ((NewScenarioMenu) getMenu()).init(study); // RKV
70 menu.selects(_selection);
71 getSession().put("menu.scenario", menu);
73 initializationFullScreenContext(Constants.STUDY_MENU,
74 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
75 Constants.SCENARIO_MENU);
77 setActionType("focus");
82 public String doSelectStep() {
83 _mystudy = getOpenStudy();
84 Study study = _mystudy.getStudyObject();
85 Scenario[] scene = study.getScenarii();
87 _myscene = Arrays.asList(scene);
88 _bastep = getProjectElementService().getFirstStep(scene[0]).getNumber(); // All scenarios have the same first step number
91 getMenu("scenario").selects(_selection);
93 initializationFullScreenContext(Constants.STUDY_MENU,
94 Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
95 Constants.SCENARIO_MENU);
97 setActionType("none");
102 public String doCreate() {
103 if (_action == ToDo.cancel) {
108 _mystudy = getOpenStudy();
109 _selection = getMenu("scenario").getSelection();
110 Study study = _mystudy.getStudyObject();
111 String[] parse = _selection.split("\\x2E");
112 int scindex = Integer.valueOf(parse[0]);
113 int number = Integer.valueOf(parse[1]);
115 Scenario[] scene = study.getScenarii();
116 Scenario bascene = scene[0];
117 for (int i = 1; i < scene.length; i++) {
119 if (bascene.getIndex() == scindex) {
124 Scenario.Properties sprop = new Scenario.Properties().setManager(
125 getConnectedUser()).setTitle(_title)
126 .setInsertAfter(bascene);
128 _bastep = getProjectElementService().getFirstStep(bascene)
130 if (this.sharesStep()) {
131 step = getProjectElementService().getSteps(bascene);
132 sprop.setBaseStep(step[number - _bastep]);
134 bascene = getScenarioService().addScenario(study, sprop);
137 // Update of the display
139 for (int i = 0; i < number - _bastep + 1; i++) {
140 List<Publication> contents = step[i].getAllDocuments();
141 for (Iterator<Publication> j = contents.iterator(); j
143 _mystudy.update(j.next());
147 _mystudy.setSelection(bascene.getIndex() + "." + number);
148 getSession().remove("menu.scenario");
150 } catch (RuntimeException saverror) {
151 LOG.error("Reason:", saverror);
153 initializationFullScreenContext(Constants.STUDY_MENU,
154 Constants.STUDY_MENU, Constants.FALSE,
155 Constants.STANDARD_MENU, Constants.STUDY_MENU);
158 } catch (Exception error) {
163 // ==============================================================================================================================
164 // Getters and setters
165 // ==============================================================================================================================
167 public List<Scenario> getScenarii() {
171 public long getSelectedScenarioIndex() {
175 public String getSelection() {
179 public String getSharedStep() {
180 String[] parse = _selection.split("\\x2E");
184 public String getTitle() {
188 public void setCancel(final boolean cancel) {
189 _action = ToDo.cancel;
192 public void setSave(final boolean save) {
196 public void setSelectedScenario(final String index) {
197 _scindex = Integer.valueOf(index);
200 public void setSelection(final String step) {
204 public void setTitle(final String title) {
208 public Boolean sharesStep() {
209 return (Integer.valueOf(getSharedStep()) > _bastep);
213 * Get the projectElementService.
215 * @return the projectElementService
217 public ProjectElementService getProjectElementService() {
218 return _projectElementService;
222 * Set the projectElementService.
224 * @param projectElementService
225 * the projectElementService to set
227 public void setProjectElementService(
228 final ProjectElementService projectElementService) {
229 _projectElementService = projectElementService;
237 public Menu getMenu() {
247 public void setMenu(final Menu menu) {
252 * Get the scenarioService.
254 * @return the scenarioService
256 public ScenarioService getScenarioService() {
257 return _scenarioService;
261 * Set the scenarioService.
263 * @param scenarioService
264 * the scenarioService to set
266 public void setScenarioService(final ScenarioService scenarioService) {
267 _scenarioService = scenarioService;