]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/StudyMenu.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / StudyMenu.java
1 package org.splat.simer;
2
3 import java.util.Iterator;
4 import java.util.Vector;
5
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;
14
15 public class StudyMenu extends SlidMenu {
16
17         private Study study;
18         private Scenario scopen; // Currently "open" scenario
19         private Step stopen; // Currently selected step
20         private ScenarioService _scenarioService;
21         private ProjectElementService _projectElementService;
22
23         // ==============================================================================================================================
24         // Constructor
25         // ==============================================================================================================================
26
27         public StudyMenu() {
28                 super("activities", "study");
29                 scopen = null;
30         }
31
32         public StudyMenu init(Study context) {
33                 study = context;
34                 scopen = null;
35                 init();
36                 return this;
37         }
38
39         public StudyMenu(Study context) {
40                 // --------------------------------
41                 super("activities", "study");
42                 study = context;
43                 scopen = null;
44         }
45
46         // ==============================================================================================================================
47         // Member functions
48         // ==============================================================================================================================
49
50         public void selects(String name) {
51                 // ---------------------------------
52                 String[] parse = name.split("\\x2E");
53                 Scenario[] scenes = study.getScenarii();
54                 Scenario scenew = scopen;
55                 int askid = 0;
56
57                 // Initialization
58                 if (scenew == null && scenes.length == 1)
59                         scenew = scenes[0];
60                 try {
61                         int askdex = Integer.valueOf(parse[0]);
62                         if (askdex > 0) {
63                                 while (askid < scenes.length) {
64                                         if (scenes[askid].getIndex() == askdex)
65                                                 break;
66                                         askid += 1;
67                                 }
68                                 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
69                         }
70                 } catch (Exception error) {
71                         return;
72                 }
73                 if (scenew == null) {
74
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
79
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]));
84
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)
89                                         continue;
90                                 steps.add(0, newstep[i]);
91                         }
92                         for (int i = 0; i < newstep.length; i++) {
93                                 if (newstep[i].getNumber() <= last)
94                                         continue;
95                                 steps.add(newstep[i]);
96                         }
97                         // Creation of the menu
98                         for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
99                                 Step step = i.next();
100                                 int number = step.getNumber();
101                                 String icon;
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";
107                                         else
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()
112                                 } else {
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";
121                                         else
122                                                 icon = "icon.done.png";
123                                         addGroup(value, group.getTitle(), icon,
124                                                         "step-study?selection=" + value);
125                                 }
126                         }
127                 } else if (scopen == null || !scenew.equals(scopen)) {
128
129                         // Opening a scenario
130                         this.clear();
131                         // Collection of steps to be displayed
132                         Vector<Step> steps = new Vector<Step>();
133                         Step[] newstep = getProjectElementService().getSteps(scenew);
134
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]);
139                         }
140                         for (int i = askid - 1; i > -1; i--)
141                                 steps
142                                                 .add(0, getProjectElementService().getFirstStep(
143                                                                 scenes[i]));
144                         newstep = getProjectElementService().getSteps(study);
145                         for (int i = newstep.length - 1; i > -1; i--) {
146                                 if (newstep[i].getNumber() >= base)
147                                         continue;
148                                 steps.add(0, newstep[i]);
149                         }
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)
154                                         continue;
155                                 steps.add(newstep[i]);
156                         }
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();
163                                 String icon;
164                                 if (!step.isStarted())
165                                         icon = "icon.empty.png";
166                                 else if (step.isFinished())
167                                         icon = "icon.checked.png";
168                                 else
169                                         icon = "icon.done.png";
170                                 if (number == askdex)
171                                         stopen = step;
172                                 if (step.getOwner() instanceof Study) {
173                                         addItem("0." + number, "menu.step." + number, icon,
174                                                         "step-study?selection=0." + number);
175                                 } else {
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";
185                                                 else
186                                                         icon = "icon.done.png";
187                                                 addGroup(value, group.getTitle(), icon,
188                                                                 "step-study?selection=" + value);
189                                         } else if (first) {
190                                                 if (group.isCheckedout())
191                                                         icon = "icon.checkedout.png";
192                                                 addGroup(value, scenew.getTitle(), icon,
193                                                                 "step-study?selection=" + value);
194                                                 first = false;
195                                         } else {
196                                                 addSubItem(value, "menu.step." + number, icon,
197                                                                 "step-study?selection=" + value);
198                                         }
199                                 }
200                         }
201                         scopen = scenew;
202                 } else {
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)
207                                         continue;
208                                 stopen = step[i];
209                                 break;
210                         }
211                 }
212                 super.selects(name);
213         }
214
215         public void refreshGivenStepItem(Step step) {
216                 // --------------------------------------------
217                 String number = "." + step.getNumber();
218                 ProjectElement owner = step.getOwner();
219                 int range = 0;
220
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))
225                                 continue;
226
227                         String icon;
228                         if (owner instanceof Scenario) {
229                                 if (range == 0 && ((Scenario) owner).isCheckedout())
230                                         icon = "icon.checkedout.png";
231                                 range += 1;
232                         }
233                         if (!step.isStarted())
234                                 icon = "icon.empty.png";
235                         else if (step.isFinished())
236                                 icon = "icon.checked.png";
237                         else
238                                 icon = "icon.done.png";
239                         item.icon(icon);
240                 }
241         }
242
243         public void refreshSelectedItem() {
244                 // ----------------------------------
245                 MenuItem item = this.getSelectedItem();
246                 String icon;
247                 if (!stopen.isStarted())
248                         icon = "icon.empty.png";
249                 else if (stopen.isFinished())
250                         icon = "icon.checked.png";
251                 else
252                         icon = "icon.done.png";
253                 item.icon(icon);
254         }
255
256         /**
257          * Get the scenarioService.
258          * 
259          * @return the scenarioService
260          */
261         public ScenarioService getScenarioService() {
262                 return _scenarioService;
263         }
264
265         /**
266          * Set the scenarioService.
267          * 
268          * @param scenarioService
269          *            the scenarioService to set
270          */
271         public void setScenarioService(ScenarioService scenarioService) {
272                 _scenarioService = scenarioService;
273         }
274
275         /**
276          * Get the projectElementService.
277          * 
278          * @return the projectElementService
279          */
280         public ProjectElementService getProjectElementService() {
281                 return _projectElementService;
282         }
283
284         /**
285          * Set the projectElementService.
286          * 
287          * @param projectElementService
288          *            the projectElementService to set
289          */
290         public void setProjectElementService(
291                         ProjectElementService projectElementService) {
292                 _projectElementService = projectElementService;
293         }
294 }