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) {
38 public NewScenarioMenu(Study context) {
39 // -----------------------------------
40 super("scenarii", "study");
45 // ==============================================================================================================================
47 // ==============================================================================================================================
49 public void selects(String name) {
50 // ---------------------------------
51 String[] parse = name.split("\\x2E");
52 Scenario[] scenes = study.getScenarii();
53 Scenario scenew = scopen;
57 if (scenew == null && scenes.length == 1)
60 int askdex = Integer.valueOf(parse[0]);
62 while (askid < scenes.length) {
63 if (scenes[askid].getIndex() == askdex)
67 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
69 } catch (Exception error) {
74 // Study with several scenarii, non of them open
76 // Collection of steps to be displayed
77 Vector<Step> steps = new Vector<Step>();
78 Step[] newstep = getProjectElementService().getSteps(scenes[0]); // All scenarii have the same steps
80 for (int i = 0; i < scenes.length; i++)
81 steps.add(getProjectElementService().getFirstStep(scenes[i]));
82 newstep = getProjectElementService().getSteps(study);
83 stopen = newstep[0]; // Default selected step
85 // Creation of the menu
86 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
88 int number = step.getNumber();
89 Scenario group = (Scenario) step.getOwner(); // The menu includes first scenario steps only
90 long index = group.getIndex();
91 String value = index + "." + number;
93 if (getScenarioService().isEmpty(group))
94 icon = "icon.empty.png";
95 // else if (group.isFinished()) icon = "icon.checked.png";
97 icon = "icon.done.png";
98 addGroup(value, group.getTitle(), icon,
99 "select-step?selection=" + value + "&title=%{title}");
101 } else if (scopen == null || !scenew.equals(scopen)) {
103 // Opening a scenario
105 // Collection of steps to be displayed
106 Vector<Step> steps = new Vector<Step>();
107 Step[] newstep = getProjectElementService().getSteps(scenew);
109 for (int i = 0; i < newstep.length; i++) {
110 steps.add(newstep[i]);
112 for (int i = askid - 1; i > -1; i--)
113 steps.add(0, getProjectElementService().getFirstStep(scenes[i]));
114 newstep = getProjectElementService().getSteps(study);
115 for (int i = askid + 1; i < scenes.length; i++)
116 steps.add(getProjectElementService().getFirstStep(scenes[i]));
118 // Creation of the menu
119 boolean first = true; // For differentiating the first scenario step
120 int askdex = Integer.valueOf(parse[1]);
121 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
122 Step step = i.next();
123 int number = step.getNumber();
125 if (!step.isStarted())
126 icon = "icon.empty.png";
127 else if (step.isFinished())
128 icon = "icon.checked.png";
130 icon = "icon.done.png";
131 if (number == askdex)
133 Scenario group = (Scenario) step.getOwner();
134 long index = group.getIndex();
135 String value = index + "." + number;
136 if (index != scenew.getIndex()) {
137 if (getScenarioService().isEmpty(group))
138 icon = "icon.empty.png";
139 // else if (group.isFinished()) icon = "icon.checked.png";
141 icon = "icon.done.png";
142 addGroup(value, group.getTitle(), icon,
143 "select-step?selection=" + value
144 + "&title=%{title}");
146 addGroup(value, scenew.getTitle(), icon,
147 "select-step?selection=" + value
148 + "&title=%{title}");
151 addSubItem(value, "menu.step." + number, icon,
152 "select-step?selection=" + value
153 + "&title=%{title}");
161 public void refreshSelectedItem() {
162 // ----------------------------------
163 MenuItem item = this.getSelectedItem();
165 if (!stopen.isStarted())
166 icon = "icon.empty.png";
167 else if (stopen.isFinished())
168 icon = "icon.checked.png";
170 icon = "icon.done.png";
175 * Get the scenarioService.
177 * @return the scenarioService
179 public ScenarioService getScenarioService() {
180 return _scenarioService;
184 * Set the scenarioService.
186 * @param scenarioService
187 * the scenarioService to set
189 public void setScenarioService(ScenarioService scenarioService) {
190 _scenarioService = scenarioService;
194 * Get the projectElementService.
196 * @return the projectElementService
198 public ProjectElementService getProjectElementService() {
199 return _projectElementService;
203 * Set the projectElementService.
205 * @param projectElementService
206 * the projectElementService to set
208 public void setProjectElementService(
209 ProjectElementService projectElementService) {
210 _projectElementService = projectElementService;