]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/NewScenarioMenu.java
Salome HOME
7fcc9e473247e05d8cd340a2d75a3445f223d22f
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / NewScenarioMenu.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.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;
13
14 public class NewScenarioMenu extends SlidMenu {
15
16         private Study study;
17         private Scenario scopen; // Currently "open" scenario
18         private Step stopen; // Currently selected step
19         private ProjectElementService _projectElementService;
20         private ScenarioService _scenarioService;
21
22         // ==============================================================================================================================
23         // Constructor
24         // ==============================================================================================================================
25
26         public NewScenarioMenu() {
27                 super("scenarii", "study");
28                 scopen = null;
29         }
30
31         public NewScenarioMenu init(Study context) {
32                 study = context;
33                 scopen = null;
34                 return this;
35         }
36
37         public NewScenarioMenu(Study context) {
38                 // -----------------------------------
39                 super("scenarii", "study");
40                 study = context;
41                 scopen = null;
42         }
43
44         // ==============================================================================================================================
45         // Member functions
46         // ==============================================================================================================================
47
48         public void selects(String name) {
49                 // ---------------------------------
50                 String[] parse = name.split("\\x2E");
51                 Scenario[] scenes = study.getScenarii();
52                 Scenario scenew = scopen;
53                 int askid = 0;
54
55                 // Initialization
56                 if (scenew == null && scenes.length == 1)
57                         scenew = scenes[0];
58                 try {
59                         int askdex = Integer.valueOf(parse[0]);
60                         if (askdex > 0) {
61                                 while (askid < scenes.length) {
62                                         if (scenes[askid].getIndex() == askdex)
63                                                 break;
64                                         askid += 1;
65                                 }
66                                 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
67                         }
68                 } catch (Exception error) {
69                         return;
70                 }
71                 if (scenew == null) {
72
73                         // Study with several scenarii, non of them open
74
75                         // Collection of steps to be displayed
76                         Vector<Step> steps = new Vector<Step>();
77                         Step[] newstep = getProjectElementService().getSteps(scenes[0]); // All scenarii have the same steps
78
79                         for (int i = 0; i < scenes.length; i++)
80                                 steps.add(getProjectElementService().getFirstStep(scenes[i]));
81                         newstep = getProjectElementService().getSteps(study);
82                         stopen = newstep[0]; // Default selected step
83
84                         // Creation of the menu
85                         for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
86                                 Step step = i.next();
87                                 int number = step.getNumber();
88                                 Scenario group = (Scenario) step.getOwner(); // The menu includes first scenario steps only
89                                 long index = group.getIndex();
90                                 String value = index + "." + number;
91                                 String icon;
92                                 if (getScenarioService().isEmpty(group))
93                                         icon = "icon.empty.png";
94                                 // else if (group.isFinished()) icon = "icon.checked.png";
95                                 else
96                                         icon = "icon.done.png";
97                                 addGroup(value, group.getTitle(), icon,
98                                                 "select-step?selection=" + value + "&title=%{title}");
99                         }
100                 } else if (scopen == null || !scenew.equals(scopen)) {
101
102                         // Opening a scenario
103                         this.clear();
104                         // Collection of steps to be displayed
105                         Vector<Step> steps = new Vector<Step>();
106                         Step[] newstep = getProjectElementService().getSteps(scenew);
107
108                         for (int i = 0; i < newstep.length; i++) {
109                                 steps.add(newstep[i]);
110                         }
111                         for (int i = askid - 1; i > -1; i--)
112                                 steps.add(0, getProjectElementService().getFirstStep(scenes[i]));
113                         newstep = getProjectElementService().getSteps(study);
114                         for (int i = askid + 1; i < scenes.length; i++)
115                                 steps.add(getProjectElementService().getFirstStep(scenes[i]));
116
117                         // Creation of the menu
118                         boolean first = true; // For differentiating the first scenario step
119                         int askdex = Integer.valueOf(parse[1]);
120                         for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
121                                 Step step = i.next();
122                                 int number = step.getNumber();
123                                 String icon;
124                                 if (!step.isStarted())
125                                         icon = "icon.empty.png";
126                                 else if (step.isFinished())
127                                         icon = "icon.checked.png";
128                                 else
129                                         icon = "icon.done.png";
130                                 if (number == askdex)
131                                         stopen = step;
132                                 Scenario group = (Scenario) step.getOwner();
133                                 long index = group.getIndex();
134                                 String value = index + "." + number;
135                                 if (index != scenew.getIndex()) {
136                                         if (getScenarioService().isEmpty(group))
137                                                 icon = "icon.empty.png";
138                                         // else if (group.isFinished()) icon = "icon.checked.png";
139                                         else
140                                                 icon = "icon.done.png";
141                                         addGroup(value, group.getTitle(), icon,
142                                                         "select-step?selection=" + value
143                                                                         + "&title=%{title}");
144                                 } else if (first) {
145                                         addGroup(value, scenew.getTitle(), icon,
146                                                         "select-step?selection=" + value
147                                                                         + "&title=%{title}");
148                                         first = false;
149                                 } else {
150                                         addSubItem(value, "menu.step." + number, icon,
151                                                         "select-step?selection=" + value
152                                                                         + "&title=%{title}");
153                                 }
154                         }
155                         scopen = scenew;
156                 }
157                 super.selects(name);
158         }
159
160         public void refreshSelectedItem() {
161                 // ----------------------------------
162                 MenuItem item = this.getSelectedItem();
163                 String icon;
164                 if (!stopen.isStarted())
165                         icon = "icon.empty.png";
166                 else if (stopen.isFinished())
167                         icon = "icon.checked.png";
168                 else
169                         icon = "icon.done.png";
170                 item.icon(icon);
171         }
172
173         /**
174          * Get the scenarioService.
175          * 
176          * @return the scenarioService
177          */
178         public ScenarioService getScenarioService() {
179                 return _scenarioService;
180         }
181
182         /**
183          * Set the scenarioService.
184          * 
185          * @param scenarioService
186          *            the scenarioService to set
187          */
188         public void setScenarioService(ScenarioService scenarioService) {
189                 _scenarioService = scenarioService;
190         }
191
192         /**
193          * Get the projectElementService.
194          * 
195          * @return the projectElementService
196          */
197         public ProjectElementService getProjectElementService() {
198                 return _projectElementService;
199         }
200
201         /**
202          * Set the projectElementService.
203          * 
204          * @param projectElementService
205          *            the projectElementService to set
206          */
207         public void setProjectElementService(
208                         ProjectElementService projectElementService) {
209                 _projectElementService = projectElementService;
210         }
211 }