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;
16 public class StudyMenu extends SlidMenu {
19 private Scenario scopen; // Currently "open" scenario
20 private Step stopen; // Currently selected step
21 private ScenarioService _scenarioService;
22 private ProjectElementService _projectElementService;
24 // ==============================================================================================================================
26 // ==============================================================================================================================
28 public StudyMenu (Study context) {
29 // --------------------------------
30 super("activities", "study");
35 // ==============================================================================================================================
37 // ==============================================================================================================================
39 public void selects (String name) {
40 // ---------------------------------
41 String[] parse = name.split("\\x2E");
42 Scenario[] scenes = study.getScenarii();
43 Scenario scenew = scopen;
47 if (scenew == null && scenes.length == 1) scenew = scenes[0];
49 int askdex = Integer.valueOf(parse[0]);
51 while (askid < scenes.length) {
52 if (scenes[askid].getIndex() == askdex) break;
55 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
57 } catch (Exception error) {
62 // Study with several scenarii, non of them open
63 // Collection of steps to be displayed
64 Vector<Step> steps = new Vector<Step>();
65 Step[] newstep = getProjectElementService().getSteps(scenes[0]); // All scenarii have the same steps
67 int base = newstep[0].getNumber();
68 int last = newstep[newstep.length-1].getNumber();
69 for (int i=0; i<scenes.length; i++) steps.add(getProjectElementService().getFirstStep(scenes[i]));
71 newstep = getProjectElementService().getSteps(study);
72 stopen = newstep[0]; // Default selected step
73 for (int i=newstep.length-1; i>-1; i--) {
74 if(newstep[i].getNumber() >= base) continue;
75 steps.add(0, newstep[i]);
77 for (int i=0; i<newstep.length; i++) {
78 if(newstep[i].getNumber() <= last) continue;
79 steps.add(newstep[i]);
81 // Creation of the menu
82 for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
84 int number = step.getNumber();
86 if (step.getOwner() instanceof Study) {
87 if (!step.isStarted()) icon = "icon.empty.png";
88 else if (step.isFinished()) icon = "icon.checked.png";
89 else icon = "icon.done.png";
90 addItem("0." + number, "menu.step." + number, icon, "step-study?selection=0." + number);
91 // WARNING: The selection number must end the action's parameters for the need of refreshGivenStepItem()
93 Scenario group = (Scenario)step.getOwner();
94 int index = group.getIndex();
95 String value = index + "." + number;
96 if (group.isCheckedout()) icon = "icon.checkedout.png";
97 else if (getScenarioService().isEmpty(group)) icon = "icon.empty.png";
98 // else if (group.isFinished()) icon = "icon.checked.png";
99 else icon = "icon.done.png";
100 addGroup(value, group.getTitle(), icon, "step-study?selection=" + value);
104 if (scopen == null || !scenew.equals(scopen)) {
106 // Opening a scenario
108 // Collection of steps to be displayed
109 Vector<Step> steps = new Vector<Step>();
110 Step[] newstep = getProjectElementService().getSteps(scenew);
112 int base = newstep[0].getNumber();
113 int last = newstep[newstep.length-1].getNumber();
114 for (int i=0; i<newstep.length; i++) {
115 steps.add(newstep[i]);
117 for (int i=askid-1; i>-1; i--) steps.add(0, getProjectElementService().getFirstStep(scenes[i]));
118 newstep = getProjectElementService().getSteps(study);
119 for (int i=newstep.length-1; i>-1; i--) {
120 if(newstep[i].getNumber() >= base) continue;
121 steps.add(0, newstep[i]);
123 for (int i=askid+1; i<scenes.length; i++) steps.add(getProjectElementService().getFirstStep(scenes[i]));
124 for (int i=0; i<newstep.length; i++) {
125 if(newstep[i].getNumber() <= last) continue;
126 steps.add(newstep[i]);
128 // Creation of the menu
129 boolean first = true; // For differentiating the first scenario step
130 int askdex = Integer.valueOf(parse[1]);
131 for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
132 Step step = i.next();
133 int number = step.getNumber();
135 if (!step.isStarted()) icon = "icon.empty.png";
136 else if (step.isFinished()) icon = "icon.checked.png";
137 else icon = "icon.done.png";
138 if (number == askdex) stopen = step;
139 if (step.getOwner() instanceof Study) {
140 addItem("0." + number, "menu.step." + number, icon, "step-study?selection=0." + number);
142 Scenario group = (Scenario)step.getOwner();
143 int index = group.getIndex();
144 String value = index + "." + number;
145 if (index != scenew.getIndex()) {
146 if (group.isCheckedout()) icon = "icon.checkedout.png";
147 else if (getScenarioService().isEmpty(group)) icon = "icon.empty.png";
148 // else if (group.isFinished()) icon = "icon.checked.png";
149 else icon = "icon.done.png";
150 addGroup(value, group.getTitle(), icon, "step-study?selection=" + value);
152 if (group.isCheckedout()) icon = "icon.checkedout.png";
153 addGroup(value, scenew.getTitle(), icon, "step-study?selection=" + value);
156 addSubItem(value, "menu.step." + number, icon, "step-study?selection=" + value);
163 Step[] step = getProjectElementService().getSteps(scopen);
164 int selected = Integer.valueOf(parse[1]);
165 for (int i=0; i<step.length; i++) {
166 if (step[i].getNumber() != selected) continue;
174 public void refreshGivenStepItem (Step step) {
175 // --------------------------------------------
176 String number = "." + step.getNumber();
177 ProjectElement owner = step.getOwner();
180 for (Iterator<MenuItem> action=menu.iterator(); action.hasNext(); ) {
181 MenuItem item = action.next();
182 String index = item.getAction(); // Returns the above string ended by the selection number
183 if (!index.endsWith(number)) continue;
186 if (owner instanceof Scenario) {
187 if (range == 0 && ((Scenario)owner).isCheckedout()) icon = "icon.checkedout.png";
190 if (!step.isStarted()) icon = "icon.empty.png";
191 else if (step.isFinished()) icon = "icon.checked.png";
192 else icon = "icon.done.png";
197 public void refreshSelectedItem () {
198 // ----------------------------------
199 MenuItem item = this.getSelectedItem();
201 if (!stopen.isStarted()) icon = "icon.empty.png";
202 else if (stopen.isFinished()) icon = "icon.checked.png";
203 else icon = "icon.done.png";
207 * Get the scenarioService.
209 * @return the scenarioService
211 public ScenarioService getScenarioService() {
212 return _scenarioService;
216 * Set the scenarioService.
218 * @param scenarioService
219 * the scenarioService to set
221 public void setScenarioService(ScenarioService scenarioService) {
222 _scenarioService = scenarioService;
226 * Get the projectElementService.
228 * @return the projectElementService
230 public ProjectElementService getProjectElementService() {
231 return _projectElementService;
235 * Set the projectElementService.
237 * @param projectElementService
238 * the projectElementService to set
240 public void setProjectElementService(
241 ProjectElementService projectElementService) {
242 _projectElementService = projectElementService;