1 package org.splat.simer;
3 import java.util.Iterator;
4 import java.util.Vector;
6 import org.splat.dal.bo.som.ProjectElement;
7 import org.splat.dal.bo.som.Scenario;
8 import org.splat.service.ProjectElementService;
9 import org.splat.service.ScenarioService;
10 import org.splat.som.Step;
11 import org.splat.dal.bo.som.Study;
12 import org.splat.wapp.MenuItem;
13 import org.splat.wapp.SlidMenu;
15 public class StudyMenu extends SlidMenu {
18 private Scenario scopen; // Currently "open" scenario
19 private Step stopen; // Currently selected step
20 private ScenarioService _scenarioService;
21 private ProjectElementService _projectElementService;
23 // ==============================================================================================================================
25 // ==============================================================================================================================
28 super("activities", "study");
32 public StudyMenu init(Study context) {
39 public StudyMenu(Study context) {
40 // --------------------------------
41 super("activities", "study");
46 // ==============================================================================================================================
48 // ==============================================================================================================================
50 public void selects(String name) {
51 // ---------------------------------
52 String[] parse = name.split("\\x2E");
53 Scenario[] scenes = study.getScenarii();
54 Scenario scenew = scopen;
58 if (scenew == null && scenes.length == 1)
61 int askdex = Integer.valueOf(parse[0]);
63 while (askid < scenes.length) {
64 if (scenes[askid].getIndex() == askdex)
68 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
70 } catch (Exception error) {
75 // 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 int base = newstep[0].getNumber();
81 int last = newstep[newstep.length - 1].getNumber();
82 for (int i = 0; i < scenes.length; i++)
83 steps.add(getProjectElementService().getFirstStep(scenes[i]));
85 newstep = getProjectElementService().getSteps(study);
86 stopen = newstep[0]; // Default selected step
87 for (int i = newstep.length - 1; i > -1; i--) {
88 if (newstep[i].getNumber() >= base)
90 steps.add(0, newstep[i]);
92 for (int i = 0; i < newstep.length; i++) {
93 if (newstep[i].getNumber() <= last)
95 steps.add(newstep[i]);
97 // Creation of the menu
98 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
100 int number = step.getNumber();
102 if (step.getOwner() instanceof Study) {
103 if (!step.isStarted())
104 icon = "icon.empty.png";
105 else if (step.isFinished())
106 icon = "icon.checked.png";
108 icon = "icon.done.png";
109 addItem("0." + number, "menu.step." + number, icon,
110 "step-study?selection=0." + number);
111 // WARNING: The selection number must end the action's parameters for the need of refreshGivenStepItem()
113 Scenario group = (Scenario) step.getOwner();
114 long index = group.getIndex();
115 String value = index + "." + number;
116 if (group.isCheckedout())
117 icon = "icon.checkedout.png";
118 else if (getScenarioService().isEmpty(group))
119 icon = "icon.empty.png";
120 // else if (group.isFinished()) icon = "icon.checked.png";
122 icon = "icon.done.png";
123 addGroup(value, group.getTitle(), icon,
124 "step-study?selection=" + value);
127 } else if (scopen == null || !scenew.equals(scopen)) {
129 // Opening a scenario
131 // Collection of steps to be displayed
132 Vector<Step> steps = new Vector<Step>();
133 Step[] newstep = getProjectElementService().getSteps(scenew);
135 int base = newstep[0].getNumber();
136 int last = newstep[newstep.length - 1].getNumber();
137 for (int i = 0; i < newstep.length; i++) {
138 steps.add(newstep[i]);
140 for (int i = askid - 1; i > -1; i--)
142 .add(0, getProjectElementService().getFirstStep(
144 newstep = getProjectElementService().getSteps(study);
145 for (int i = newstep.length - 1; i > -1; i--) {
146 if (newstep[i].getNumber() >= base)
148 steps.add(0, newstep[i]);
150 for (int i = askid + 1; i < scenes.length; i++)
151 steps.add(getProjectElementService().getFirstStep(scenes[i]));
152 for (int i = 0; i < newstep.length; i++) {
153 if (newstep[i].getNumber() <= last)
155 steps.add(newstep[i]);
157 // Creation of the menu
158 boolean first = true; // For differentiating the first scenario step
159 int askdex = Integer.valueOf(parse[1]);
160 for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
161 Step step = i.next();
162 int number = step.getNumber();
164 if (!step.isStarted())
165 icon = "icon.empty.png";
166 else if (step.isFinished())
167 icon = "icon.checked.png";
169 icon = "icon.done.png";
170 if (number == askdex)
172 if (step.getOwner() instanceof Study) {
173 addItem("0." + number, "menu.step." + number, icon,
174 "step-study?selection=0." + number);
176 Scenario group = (Scenario) step.getOwner();
177 long index = group.getIndex();
178 String value = index + "." + number;
179 if (index != scenew.getIndex()) {
180 if (group.isCheckedout())
181 icon = "icon.checkedout.png";
182 else if (getScenarioService().isEmpty(group))
183 icon = "icon.empty.png";
184 // else if (group.isFinished()) icon = "icon.checked.png";
186 icon = "icon.done.png";
187 addGroup(value, group.getTitle(), icon,
188 "step-study?selection=" + value);
190 if (group.isCheckedout())
191 icon = "icon.checkedout.png";
192 addGroup(value, scenew.getTitle(), icon,
193 "step-study?selection=" + value);
196 addSubItem(value, "menu.step." + number, icon,
197 "step-study?selection=" + value);
203 Step[] step = getProjectElementService().getSteps(scopen);
204 int selected = Integer.valueOf(parse[1]);
205 for (int i = 0; i < step.length; i++) {
206 if (step[i].getNumber() != selected)
215 public void refreshGivenStepItem(Step step) {
216 // --------------------------------------------
217 String number = "." + step.getNumber();
218 ProjectElement owner = step.getOwner();
221 for (Iterator<MenuItem> action = menu.iterator(); action.hasNext();) {
222 MenuItem item = action.next();
223 String index = item.getAction(); // Returns the above string ended by the selection number
224 if (!index.endsWith(number))
228 if (owner instanceof Scenario) {
229 if (range == 0 && ((Scenario) owner).isCheckedout())
230 icon = "icon.checkedout.png";
233 if (!step.isStarted())
234 icon = "icon.empty.png";
235 else if (step.isFinished())
236 icon = "icon.checked.png";
238 icon = "icon.done.png";
243 public void refreshSelectedItem() {
244 // ----------------------------------
245 MenuItem item = this.getSelectedItem();
247 if (!stopen.isStarted())
248 icon = "icon.empty.png";
249 else if (stopen.isFinished())
250 icon = "icon.checked.png";
252 icon = "icon.done.png";
257 * Get the scenarioService.
259 * @return the scenarioService
261 public ScenarioService getScenarioService() {
262 return _scenarioService;
266 * Set the scenarioService.
268 * @param scenarioService
269 * the scenarioService to set
271 public void setScenarioService(ScenarioService scenarioService) {
272 _scenarioService = scenarioService;
276 * Get the projectElementService.
278 * @return the projectElementService
280 public ProjectElementService getProjectElementService() {
281 return _projectElementService;
285 * Set the projectElementService.
287 * @param projectElementService
288 * the projectElementService to set
290 public void setProjectElementService(
291 ProjectElementService projectElementService) {
292 _projectElementService = projectElementService;