1 package org.splat.simer;
3 import java.util.Iterator;
4 import java.util.Vector;
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.service.ProjectElementService;
8 import org.splat.service.ScenarioService;
9 import org.splat.som.Step;
10 import org.splat.dal.bo.som.Study;
11 import org.splat.wapp.MenuItem;
12 import org.splat.wapp.SlidMenu;
14 public class NewScenarioMenu extends SlidMenu {
17 private Scenario scopen; // Currently "open" scenario
18 private Step stopen; // Currently selected step
19 private ProjectElementService _projectElementService;
20 private ScenarioService _scenarioService;
22 // ==============================================================================================================================
24 // ==============================================================================================================================
26 public NewScenarioMenu() {
27 super("scenarii", "study");
31 public NewScenarioMenu init(Study context) {
37 public NewScenarioMenu(Study context) {
38 // -----------------------------------
39 super("scenarii", "study");
44 // ==============================================================================================================================
46 // ==============================================================================================================================
48 public void selects(String name) {
49 // ---------------------------------
50 String[] parse = name.split("\\x2E");
51 Scenario[] scenes = study.getScenarii();
52 Scenario scenew = scopen;
56 if (scenew == null && scenes.length == 1)
59 int askdex = Integer.valueOf(parse[0]);
61 while (askid < scenes.length) {
62 if (scenes[askid].getIndex() == askdex)
66 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
68 } catch (Exception error) {
73 // Study with several scenarii, non of them open
75 // Collection of steps to be displayed
76 Vector<Step> steps = new Vector<Step>();
77 Step[] newstep = getProjectElementService().getSteps(scenes[0]); // All scenarii have the same steps
79 for (int i = 0; i < scenes.length; i++)
80 steps.add(getProjectElementService().getFirstStep(scenes[i]));
81 newstep = getProjectElementService().getSteps(study);
82 stopen = newstep[0]; // Default selected step
84 // Creation of the menu
85 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
87 int number = step.getNumber();
88 Scenario group = (Scenario) step.getOwner(); // The menu includes first scenario steps only
89 long index = group.getIndex();
90 String value = index + "." + number;
92 if (getScenarioService().isEmpty(group))
93 icon = "icon.empty.png";
94 // else if (group.isFinished()) icon = "icon.checked.png";
96 icon = "icon.done.png";
97 addGroup(value, group.getTitle(), icon,
98 "select-step?selection=" + value + "&title=%{title}");
100 } else if (scopen == null || !scenew.equals(scopen)) {
102 // Opening a scenario
104 // Collection of steps to be displayed
105 Vector<Step> steps = new Vector<Step>();
106 Step[] newstep = getProjectElementService().getSteps(scenew);
108 for (int i = 0; i < newstep.length; i++) {
109 steps.add(newstep[i]);
111 for (int i = askid - 1; i > -1; i--)
112 steps.add(0, getProjectElementService().getFirstStep(scenes[i]));
113 newstep = getProjectElementService().getSteps(study);
114 for (int i = askid + 1; i < scenes.length; i++)
115 steps.add(getProjectElementService().getFirstStep(scenes[i]));
117 // Creation of the menu
118 boolean first = true; // For differentiating the first scenario step
119 int askdex = Integer.valueOf(parse[1]);
120 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
121 Step step = i.next();
122 int number = step.getNumber();
124 if (!step.isStarted())
125 icon = "icon.empty.png";
126 else if (step.isFinished())
127 icon = "icon.checked.png";
129 icon = "icon.done.png";
130 if (number == askdex)
132 Scenario group = (Scenario) step.getOwner();
133 long index = group.getIndex();
134 String value = index + "." + number;
135 if (index != scenew.getIndex()) {
136 if (getScenarioService().isEmpty(group))
137 icon = "icon.empty.png";
138 // else if (group.isFinished()) icon = "icon.checked.png";
140 icon = "icon.done.png";
141 addGroup(value, group.getTitle(), icon,
142 "select-step?selection=" + value
143 + "&title=%{title}");
145 addGroup(value, scenew.getTitle(), icon,
146 "select-step?selection=" + value
147 + "&title=%{title}");
150 addSubItem(value, "menu.step." + number, icon,
151 "select-step?selection=" + value
152 + "&title=%{title}");
160 public void refreshSelectedItem() {
161 // ----------------------------------
162 MenuItem item = this.getSelectedItem();
164 if (!stopen.isStarted())
165 icon = "icon.empty.png";
166 else if (stopen.isFinished())
167 icon = "icon.checked.png";
169 icon = "icon.done.png";
174 * Get the scenarioService.
176 * @return the scenarioService
178 public ScenarioService getScenarioService() {
179 return _scenarioService;
183 * Set the scenarioService.
185 * @param scenarioService
186 * the scenarioService to set
188 public void setScenarioService(ScenarioService scenarioService) {
189 _scenarioService = scenarioService;
193 * Get the projectElementService.
195 * @return the projectElementService
197 public ProjectElementService getProjectElementService() {
198 return _projectElementService;
202 * Set the projectElementService.
204 * @param projectElementService
205 * the projectElementService to set
207 public void setProjectElementService(
208 ProjectElementService projectElementService) {
209 _projectElementService = projectElementService;