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 number = Integer.valueOf(parse[1]);
114 Scenario[] scene = study.getScenarii();
115 Scenario bascene = scene[0];
116 for(Scenario scenario : scene) {
118 if(bascene.getIndex() == _scindex) {
123 Scenario.Properties sprop = new Scenario.Properties().setManager(
124 getConnectedUser()).setTitle(_title)
125 .setInsertAfter(bascene);
128 long selectedScenarioId = Long.valueOf(parse[0]);
129 Scenario selectedScenario = scene[0];
130 for(Scenario scenario : scene) {
131 if(scenario.getIndex() == selectedScenarioId) {
132 selectedScenario = scenario;
135 _bastep = getProjectElementService().getFirstStep(selectedScenario)
137 if (this.sharesStep()) {
138 step = getProjectElementService().getSteps(selectedScenario);
139 sprop.setBaseStep(step[number - _bastep]);
141 Scenario createdScenario = getScenarioService().addScenario(study, sprop);
144 // Update of the display
146 for (int i = 0; i < number - _bastep + 1; i++) {
147 List<Publication> contents = step[i].getAllDocuments();
148 for (Iterator<Publication> j = contents.iterator(); j
150 _mystudy.update(j.next());
154 _mystudy.setSelection(createdScenario.getIndex() + "." + number);
155 getSession().remove("menu.scenario");
157 } catch (RuntimeException saverror) {
158 LOG.error("Reason:", saverror);
160 initializationFullScreenContext(Constants.STUDY_MENU,
161 Constants.STUDY_MENU, Constants.FALSE,
162 Constants.STANDARD_MENU, Constants.STUDY_MENU);
165 } catch (Exception error) {
170 // ==============================================================================================================================
171 // Getters and setters
172 // ==============================================================================================================================
174 public List<Scenario> getScenarii() {
178 public long getSelectedScenarioIndex() {
182 public String getSelection() {
186 public String getSharedStep() {
187 String[] parse = _selection.split("\\x2E");
191 public String getTitle() {
195 public void setCancel(final boolean cancel) {
196 _action = ToDo.cancel;
199 public void setSave(final boolean save) {
203 public void setSelectedScenario(final String index) {
204 _scindex = Integer.valueOf(index);
207 public void setSelection(final String step) {
211 public void setTitle(final String title) {
215 public Boolean sharesStep() {
216 return (Integer.valueOf(getSharedStep()) > _bastep);
220 * Get the projectElementService.
222 * @return the projectElementService
224 public ProjectElementService getProjectElementService() {
225 return _projectElementService;
229 * Set the projectElementService.
231 * @param projectElementService
232 * the projectElementService to set
234 public void setProjectElementService(
235 final ProjectElementService projectElementService) {
236 _projectElementService = projectElementService;
244 public Menu getMenu() {
254 public void setMenu(final Menu menu) {
259 * Get the scenarioService.
261 * @return the scenarioService
263 public ScenarioService getScenarioService() {
264 return _scenarioService;
268 * Set the scenarioService.
270 * @param scenarioService
271 * the scenarioService to set
273 public void setScenarioService(final ScenarioService scenarioService) {
274 _scenarioService = scenarioService;