]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/StudyMenu.java
Salome HOME
ff571ab78825ea1898a70900fc914a5c3f61ffc8
[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
16 public class StudyMenu extends SlidMenu {
17
18     private  Study    study;
19     private  Scenario scopen;     // Currently "open" scenario
20     private  Step     stopen;     // Currently selected step
21         private ScenarioService _scenarioService;
22         private ProjectElementService _projectElementService;
23     
24 //  ==============================================================================================================================
25 //  Constructor
26 //  ==============================================================================================================================
27  
28     public StudyMenu (Study context) {
29 //  --------------------------------
30           super("activities", "study");
31       study  = context;
32       scopen = null;
33    }
34
35 //  ==============================================================================================================================
36 //  Member functions
37 //  ==============================================================================================================================
38
39     public void selects (String name) {
40 //  ---------------------------------
41       String[]   parse  = name.split("\\x2E");
42       Scenario[] scenes = study.getScenarii();
43       Scenario   scenew = scopen;
44       int        askid  = 0;
45
46 //    Initialization
47       if (scenew == null && scenes.length == 1) scenew = scenes[0];
48       try {
49         int askdex = Integer.valueOf(parse[0]);
50         if (askdex > 0) {
51           while (askid < scenes.length) {
52             if (scenes[askid].getIndex() == askdex) break;
53             askid += 1;
54           }
55           scenew = scenes[askid];  // Throws an exception if the scenario does not exist (that is, if name is not correct)
56         }
57       } catch (Exception error) {
58         return;
59       }
60       if (scenew == null) {
61
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
66           
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]));
70
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]);
76         }
77         for (int i=0; i<newstep.length; i++) {
78           if(newstep[i].getNumber() <= last) continue;
79           steps.add(newstep[i]);
80         }
81 //      Creation of the menu
82         for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
83           Step    step   = i.next();
84           int     number = step.getNumber();
85           String  icon;
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()
92           } else {
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);                  
101           }
102         }
103       } else
104       if (scopen == null || !scenew.equals(scopen)) {
105
106 //    Opening a scenario
107         this.clear();
108 //      Collection of steps to be displayed
109         Vector<Step> steps   = new Vector<Step>();
110         Step[]       newstep = getProjectElementService().getSteps(scenew);
111         
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]);
116         }
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]);
122         }
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]);
127         }
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();
134           String  icon;
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);
141           } else {
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);                        
151                 } else if (first) {
152               if      (group.isCheckedout()) icon = "icon.checkedout.png";
153               addGroup(value, scenew.getTitle(), icon, "step-study?selection=" + value);
154               first = false;
155             } else {
156                   addSubItem(value, "menu.step." + number, icon, "step-study?selection=" + value);
157             }
158           }
159         }
160         scopen = scenew;
161       }
162       else {
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;
167           stopen = step[i];
168           break;
169         }
170       }
171       super.selects(name);
172     }
173
174     public void refreshGivenStepItem (Step step) {
175 //  --------------------------------------------
176       String          number = "." + step.getNumber();
177       ProjectElement  owner  = step.getOwner();
178       int             range  = 0;
179
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;
184
185         String   icon;
186         if (owner instanceof Scenario) {
187           if (range == 0 && ((Scenario)owner).isCheckedout()) icon = "icon.checkedout.png";
188           range += 1;
189         }
190         if      (!step.isStarted()) icon = "icon.empty.png";
191         else if (step.isFinished()) icon = "icon.checked.png";
192         else                        icon = "icon.done.png";
193         item.icon(icon);
194       }
195     }
196
197     public void refreshSelectedItem () {
198 //  ----------------------------------
199       MenuItem item = this.getSelectedItem();
200       String   icon;
201       if      (!stopen.isStarted()) icon = "icon.empty.png";
202       else if (stopen.isFinished()) icon = "icon.checked.png";
203       else                          icon = "icon.done.png";
204       item.icon(icon);
205     }
206         /**
207          * Get the scenarioService.
208          * 
209          * @return the scenarioService
210          */
211         public ScenarioService getScenarioService() {
212                 return _scenarioService;
213         }
214
215         /**
216          * Set the scenarioService.
217          * 
218          * @param scenarioService
219          *            the scenarioService to set
220          */
221         public void setScenarioService(ScenarioService scenarioService) {
222                 _scenarioService = scenarioService;
223         }
224
225         /**
226          * Get the projectElementService.
227          * 
228          * @return the projectElementService
229          */
230         public ProjectElementService getProjectElementService() {
231                 return _projectElementService;
232         }
233
234         /**
235          * Set the projectElementService.
236          * 
237          * @param projectElementService
238          *            the projectElementService to set
239          */
240         public void setProjectElementService(
241                         ProjectElementService projectElementService) {
242                 _projectElementService = projectElementService;
243         }
244 }