]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Salome HOME
88603ff7cd3cb7f456311d68435e15b982070312
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / DisplayStudyStepAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4
5 import org.splat.dal.bo.som.ProjectElement;
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.service.StudyService;
8 import org.splat.som.StepRights;
9 import org.splat.dal.bo.som.Study;
10 import org.splat.wapp.PopupMenu;
11 import org.splat.wapp.SimpleMenu;
12
13 public class DisplayStudyStepAction extends DisplayBaseAction {
14
15         /**
16          * Serial version ID.
17          */
18         private static final long serialVersionUID = 6467920934724352021L;
19
20         /**
21          * Presented study.
22          */
23         protected OpenStudy mystudy = null;
24
25         /**
26          * Injected study service.
27          */
28         private StudyService _studyService;
29         
30         /**
31          * Value of the menu property. 
32          * It can be: none, create, open, study, knowledge, sysadmin, help.
33          */
34         private String _menuProperty;
35
36         // ==============================================================================================================================
37         // Action methods
38         // ==============================================================================================================================
39
40         public String doOpen() {
41                 Study study;
42                 mystudy = getOpenStudy();
43                 if (myindex != null)
44                         try { // Opening a study from the search result
45                                 int index = Integer.valueOf(myindex);
46                                 if (mystudy != null && mystudy.getStudyObject() != null
47                                                 && mystudy.getIndex() == index) { // - The selected study is currently open
48                                         selection = mystudy.getSelection(); // Current selection
49                                         study = mystudy.getStudyObject(); // Current Study object
50                                         // RKV:BEGIN: put in session if necessary
51                                         if (!getSession().containsKey("study.open")) {
52                                                 open(study);
53                                         }
54                                         // RKV:END
55                                 } else { // - The selected study is new
56                                         study = getStudyService().selectStudy(index);
57                                         mystudy = open(study);
58                                         selection = mystudy.getSelection(); // Default selection
59                                 }
60                         } catch (Exception error) {
61                                 logger.error("Reason:", error);
62                                 return ERROR;
63                         }
64                 else if (selection == null) { // Opening a study just newed
65                         selection = mystudy.getSelection(); // Default selection
66                         study = mystudy.getStudyObject();
67                 } else { // Re-opening (refreshing) the currently open study
68                         study = getStudyService().selectStudy(mystudy.getIndex());
69                         mystudy = open(study); // Closes the previously open study
70                         mystudy.setSelection(selection);
71                 }
72                 // Initialization of menus
73                 ProjectElement owner = mystudy.getSelectedStep().getOwner();
74                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
75                 if (owner instanceof Scenario) {
76                         menu.enables("prop-scenario");
77                         menu.selects("prop-scenario");
78                 } else {
79                         menu.disables("prop-scenario");
80                         menu.selects("prop-general");
81                 }
82                 getSession().put("menu.study", mystudy.getMenu());
83                 
84                 setMenuProperty("study");
85                 initializationScreenContext(_menuProperty);
86
87                 return SUCCESS;
88         }
89
90         public String doSelectStep() {
91
92                 mystudy = getOpenStudy();
93                 if (selection == null) { // Switch back to the current study
94                         selection = mystudy.getSelection();
95                 } else { // Selection of a step of current study
96                         mystudy.setSelection(selection);
97                 }
98                 // Re-initialization of the properties menu according to the selected step
99                 ProjectElement owner = mystudy.getSelectedStep().getOwner();
100                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
101                 if (owner instanceof Scenario) {
102                         menu.enables("prop-scenario");
103                         menu.selects("prop-scenario");
104                 } else {
105                         menu.disables("prop-scenario");
106                         menu.selects("prop-general");
107                 }
108                 
109                 setMenuProperty("study");
110                 initializationScreenContext(_menuProperty);
111                 
112                 return SUCCESS;
113         }
114
115         public String doSelectDocument() {
116                 mystudy = getOpenStudy();
117                 Execute todo = Execute.valueOf(action);
118                 if (todo == Execute.develop)
119                         mystudy.developDocument(myindex);
120                 else if (todo == Execute.reduce)
121                         mystudy.reduceHistory(myindex);
122                 else if (todo == Execute.reduceall)
123                         mystudy.reduceDocument(myindex);
124                 
125                 setMenuProperty("study");
126                 initializationScreenContext(_menuProperty);
127                 
128                 return SUCCESS;
129         }
130
131         public String doSelectKnowledge() {
132                 mystudy = getOpenStudy();
133                 Execute todo = Execute.valueOf(action);
134                 if (todo == Execute.develop)
135                         mystudy.developKnowledge(myindex);
136                 else if (todo == Execute.reduce)
137                         mystudy.reduceKnowledge(myindex);
138                 
139                 setMenuProperty("study");
140                 initializationScreenContext(_menuProperty);
141                 
142                 return SUCCESS;
143         }
144
145         public String doClose() {
146                 closeStudy();
147                 
148                 setMenuProperty("none");
149                 initializationScreenContext(_menuProperty);
150                 
151                 return SUCCESS;
152         }
153
154         // ==============================================================================================================================
155         // Getters
156         // ==============================================================================================================================
157
158         public String getAction() {
159                 return action;
160         }
161
162         public List<DocumentFacade> getDocuments() {
163                 return mystudy.getDisplayedDocuments();
164         }
165
166         public List<OpenObject.KnowledgeIterator> getKnowledges() {
167                 return mystudy.getDisplayedKnowledges();
168         }
169
170         public List<SimulationContextFacade> getSimulationContexts() {
171                 return mystudy.getDisplayedSimulationContexts();
172         }
173
174         public PopupMenu getPopup() {
175                 return mystudy.getPopup();
176         }
177
178         public int getStepNumber() {
179                 return mystudy.getSelectedStep().getNumber();
180         }
181
182         public String getStepEnabled() {
183                 return String.valueOf(mystudy.isStepEnabled());
184         }
185
186         public StepRights getUserRights() {
187                 return mystudy.getSelectedStepRights();
188         }
189
190         public String getWriteAccess() {
191                 return String.valueOf(mystudy.isOpenForWriting());
192         }
193
194         /**
195          * Get the studyService.
196          * 
197          * @return the studyService
198          */
199         public StudyService getStudyService() {
200                 return _studyService;
201         }
202
203         /**
204          * Set the studyService.
205          * 
206          * @param studyService
207          *            the studyService to set
208          */
209         public void setStudyService(StudyService studyService) {
210                 _studyService = studyService;
211         }
212
213         /**
214          * {@inheritDoc}
215          * 
216          * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
217          */
218         @Override
219         public void setOpenStudy(OpenStudy study) {
220                 super.setOpenStudy(study);
221                 mystudy = study;
222         }
223         
224         /**
225          * Get the menuProperty.
226          * @return the menuProperty
227          */
228         public String getMenuProperty() {
229                 return _menuProperty;
230         }
231
232         /**
233          * Set the menuProperty.
234          * @param menuProperty the menuProperty to set
235          */
236         public void setMenuProperty(String menuProperty) {
237                 this._menuProperty = menuProperty;
238         }
239 }