]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/NewScenarioMenu.java
Salome HOME
SIMAN Eclipse workspace first version
[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.som.Scenario;
7 import org.splat.som.Step;
8 import org.splat.som.Study;
9 import org.splat.wapp.MenuItem;
10 import org.splat.wapp.SlidMenu;
11
12
13 public class NewScenarioMenu extends SlidMenu {
14
15     private  Study    study;
16     private  Scenario scopen;     // Currently "open" scenario
17     private  Step     stopen;     // Currently selected step
18     
19 //  ==============================================================================================================================
20 //  Constructor
21 //  ==============================================================================================================================
22  
23     public NewScenarioMenu (Study context) {
24 //  -----------------------------------
25           super("scenarii", "study");
26       study  = context;
27       scopen = null;
28    }
29
30 //  ==============================================================================================================================
31 //  Member functions
32 //  ==============================================================================================================================
33
34     public void selects (String name) {
35 //  ---------------------------------
36       String[]   parse  = name.split("\\x2E");
37       Scenario[] scenes = study.getScenarii();
38       Scenario   scenew = scopen;
39       int        askid  = 0;
40
41 //    Initialization
42       if (scenew == null && scenes.length == 1) scenew = scenes[0];
43       try {
44         int askdex = Integer.valueOf(parse[0]);
45         if (askdex > 0) {
46           while (askid < scenes.length) {
47             if (scenes[askid].getIndex() == askdex) break;
48             askid += 1;
49           }
50           scenew = scenes[askid];  // Throws an exception if the scenario does not exist (that is, if name is not correct)
51         }
52       } catch (Exception error) {
53         return;
54       }
55       if (scenew == null) {
56
57 //    Study with several scenarii, non of them open
58
59 //      Collection of steps to be displayed
60         Vector<Step> steps   = new Vector<Step>();
61         Step[]       newstep = scenes[0].getSteps();   // All scenarii have the same steps
62           
63         for (int i=0; i<scenes.length; i++) steps.add(scenes[i].getFirstStep());
64         newstep = study.getSteps();
65         stopen  = newstep[0];                          // Default selected step
66
67 //      Creation of the menu
68         for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
69           Step     step   = i.next();
70           int      number = step.getNumber();
71           Scenario group  = (Scenario)step.getOwner(); // The menu includes first scenario steps only
72           int      index  = group.getIndex();
73           String   value  = index + "." + number;
74           String   icon;
75           if      (group.isEmpty())    icon = "icon.empty.png";
76 //        else if (group.isFinished()) icon = "icon.checked.png";
77           else                         icon = "icon.done.png";
78           addGroup(value, group.getTitle(),  icon, "select-step?selection=" + value + "&title=%{title}");                       
79         }
80       } else
81       if (scopen == null || !scenew.equals(scopen)) {
82
83 //    Opening a scenario
84         this.clear();
85 //      Collection of steps to be displayed
86         Vector<Step> steps   = new Vector<Step>();
87         Step[]       newstep = scenew.getSteps();
88         
89         for (int i=0; i<newstep.length; i++) {
90                 steps.add(newstep[i]);
91         }
92         for (int i=askid-1; i>-1; i--) steps.add(0, scenes[i].getFirstStep());
93         newstep = study.getSteps();
94         for (int i=askid+1; i<scenes.length; i++) steps.add(scenes[i].getFirstStep());
95
96 //      Creation of the menu
97         boolean   first  = true;   // For differentiating the first scenario step
98         int       askdex = Integer.valueOf(parse[1]);
99         for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
100           Step    step   = i.next();
101           int     number = step.getNumber();
102           String  icon;
103           if      (!step.isStarted()) icon   = "icon.empty.png";
104           else if (step.isFinished()) icon   = "icon.checked.png";
105           else                        icon   = "icon.done.png";
106           if (number == askdex)       stopen = step;
107           Scenario group = (Scenario)step.getOwner();
108           int      index = group.getIndex();
109           String   value = index + "." + number;
110           if (index != scenew.getIndex()) {
111             if      (group.isEmpty())    icon = "icon.empty.png";
112 //          else if (group.isFinished()) icon = "icon.checked.png";
113             else                         icon = "icon.done.png";
114             addGroup(value, group.getTitle(),  icon, "select-step?selection=" + value + "&title=%{title}");                     
115           } else if (first) {
116             addGroup(value, scenew.getTitle(), icon, "select-step?selection=" + value + "&title=%{title}");
117             first = false;
118           } else {
119            addSubItem(value, "menu.step." + number, icon, "select-step?selection=" + value + "&title=%{title}");
120           }
121         }
122         scopen = scenew;
123       }
124       super.selects(name);
125     }
126
127     public void refreshSelectedItem () {
128 //  ----------------------------------
129       MenuItem item = this.getSelectedItem();
130       String   icon;
131       if      (!stopen.isStarted()) icon = "icon.empty.png";
132       else if (stopen.isFinished()) icon = "icon.checked.png";
133       else                          icon = "icon.done.png";
134       item.icon(icon);
135     }
136 }