]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Salome HOME
b0852f0d6ca3989a5d7fe1c6a72a80fd34212d34
[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.dal.bo.som.Study;
8 import org.splat.service.StudyService;
9 import org.splat.som.StepRights;
10 import org.splat.wapp.Constants;
11 import org.splat.wapp.PopupMenu;
12 import org.splat.wapp.SimpleMenu;
13
14 /**
15  * Presents the current open study information.
16  * @author Daniel Brunier-Coulin.
17  *
18  */
19 public class DisplayStudyStepAction extends AbstractDisplayAction {
20
21         /**
22          * Serial version ID.
23          */
24         private static final long serialVersionUID = 6467920934724352021L;
25
26         /**
27          * Presented study.
28          */
29         protected transient OpenStudy _openStudy = null;
30
31         /**
32          * Injected study service.
33          */
34         private StudyService _studyService;
35         
36         /**
37          * Value of the menu property. 
38          * It can be: none, create, open, study, knowledge, sysadmin, help.
39          */
40         private String _menuProperty;
41         
42         /**
43          * Value of the title bar property. 
44          * It can be: study, knowledge.
45          */
46         private String _titleProperty;
47         
48         /**
49          * Value of the tool bar property. 
50          * It can be: none, standard, study, back.
51          */
52         private String _toolProperty;
53         
54         /**
55          * Value of the left menu property. 
56          * It can be: open, study, knowledge, scenario.
57          */
58         private String _leftMenuProperty;
59         
60         /**
61          * Property that indicates whether the current open study is editable or not.
62          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
63          * It is necessary for correct building the title bar.
64          */
65         private String _editDisabledProperty = "false";
66
67         // ==============================================================================================================================
68         // Action methods
69         // ==============================================================================================================================
70
71         public String doOpen() {
72                 Study study;
73                 String res = SUCCESS;
74                 _openStudy = getOpenStudy();
75                 if (_myindex == null) {
76                         if (_selection == null) { // Opening a study just newed
77                                 _selection = _openStudy.getSelection(); // Default selection
78                                 study = _openStudy.getStudyObject();
79                         } else { // Re-opening (refreshing) the currently open study
80                                 study = getStudyService().selectStudy(_openStudy.getIndex());
81                                 _openStudy = open(study); // Closes the previously open study
82                                 _openStudy.setSelection(_selection);
83                         }
84                 } else {
85                         try { // Opening a study from the search result
86                                 int index = Integer.valueOf(_myindex);
87                                 if (_openStudy != null && _openStudy.getStudyObject() != null
88                                                 && _openStudy.getIndex() == index) { // - The selected study is currently open
89                                         _selection = _openStudy.getSelection(); // Current selection
90                                         study = _openStudy.getStudyObject(); // Current Study object
91                                         // RKV:BEGIN: put in session if necessary
92                                         if (!getSession().containsKey("study.open")) {
93                                                 open(study);
94                                         }
95                                         // RKV:END
96                                 } else { // - The selected study is new
97                                         study = getStudyService().selectStudy(index);
98                                         _openStudy = open(study);
99                                         _selection = _openStudy.getSelection(); // Default selection
100                                 }
101                         } catch (Exception error) {
102                                 LOG.error("Reason:", error);
103                                 res = ERROR;
104                         }
105                 }
106                 if (!ERROR.equals(res)){
107                         // Initialization of menus
108                         ProjectElement owner = _openStudy.getSelectedStep().getOwner();
109                         SimpleMenu menu = ApplicationSettings.getMenu("configuration");
110                         if (owner instanceof Scenario) {
111                                 menu.enables(Constants.PROP_SCENARIO);
112                                 menu.selects(Constants.PROP_SCENARIO);
113                         } else {
114                                 menu.disables(Constants.PROP_SCENARIO);
115                                 menu.selects("prop-general");
116                         }
117                         getSession().put("menu.study", _openStudy.getMenu());
118                         
119                         setMenuProperty(Constants.STUDY_MENU);
120                         setTitleProperty(Constants.STUDY_MENU);
121                         if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
122                                 setToolProperty(Constants.STUDY_MENU);
123                         } else {
124                                 setToolProperty(Constants.STANDARD_MENU);
125                         }
126                         
127                         setLeftMenuProperty(Constants.STUDY_MENU);
128         
129                         initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
130                 }
131                 return res;
132         }
133
134         public String doSelectStep() {
135
136                 _openStudy = getOpenStudy();
137                 if (_selection == null) { // Switch back to the current study
138                         _selection = _openStudy.getSelection();
139                 } else { // Selection of a step of current study
140                         _openStudy.setSelection(_selection);
141                 }
142                 // Re-initialization of the properties menu according to the selected step
143                 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
144                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
145                 if (owner instanceof Scenario) {
146                         menu.enables(Constants.PROP_SCENARIO);
147                         menu.selects(Constants.PROP_SCENARIO);
148                 } else {
149                         menu.disables(Constants.PROP_SCENARIO);
150                         menu.selects("prop-general");
151                 }
152                 
153                 setMenuProperty(Constants.STUDY_MENU);
154                 setTitleProperty(Constants.STUDY_MENU);
155                 if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
156                         setToolProperty(Constants.STUDY_MENU);
157                 } else {
158                         setToolProperty(Constants.STANDARD_MENU);
159                 }
160                 
161                 setLeftMenuProperty(Constants.STUDY_MENU);
162                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
163                 
164                 return SUCCESS;
165         }
166
167         public String doSelectDocument() {
168                 _openStudy = getOpenStudy();
169                 Execute todo = Execute.valueOf(_action);
170                 if (todo == Execute.develop) {
171                         _openStudy.developDocument(_myindex);
172                 } else if (todo == Execute.reduce) {
173                         _openStudy.reduceHistory(_myindex);
174                 } else if (todo == Execute.reduceall) {
175                         _openStudy.reduceDocument(_myindex);
176                 }
177                 
178                 setMenuProperty(Constants.STUDY_MENU);
179                 setTitleProperty(Constants.STUDY_MENU);
180                 if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
181                         setToolProperty(Constants.STUDY_MENU);
182                 } else {
183                         setToolProperty(Constants.STANDARD_MENU);
184                 }
185                 setLeftMenuProperty(Constants.STUDY_MENU);
186                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
187                 
188                 return SUCCESS;
189         }
190
191         public String doSelectKnowledge() {
192                 _openStudy = getOpenStudy();
193                 Execute todo = Execute.valueOf(_action);
194                 if (todo == Execute.develop) {
195                         _openStudy.developKnowledge(_myindex);
196                 } else if (todo == Execute.reduce) {
197                         _openStudy.reduceKnowledge(_myindex);
198                 }
199                 
200                 setMenuProperty(Constants.STUDY_MENU);
201                 setTitleProperty(Constants.STUDY_MENU);
202                 if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
203                         setToolProperty(Constants.STUDY_MENU);
204                 } else {
205                         setToolProperty(Constants.STANDARD_MENU);
206                 }
207                 setLeftMenuProperty(Constants.STUDY_MENU);
208                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
209                 
210                 return SUCCESS;
211         }
212
213         public String doClose() {
214                 closeStudy();
215                 
216                 setMenuProperty("none");
217                 initializationScreenContext(_menuProperty);
218                 
219                 return SUCCESS;
220         }
221
222         // ==============================================================================================================================
223         // Getters
224         // ==============================================================================================================================
225
226         public String getAction() {
227                 return _action;
228         }
229
230         public List<DocumentFacade> getDocuments() {
231                 return _openStudy.getDisplayedDocuments();
232         }
233
234         public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
235                 return _openStudy.getDisplayedKnowledges();
236         }
237
238         public List<SimulationContextFacade> getSimulationContexts() {
239                 return _openStudy.getDisplayedSimulationContexts();
240         }
241
242         public PopupMenu getPopup() {
243                 return _openStudy.getPopup();
244         }
245
246         public int getStepNumber() {
247                 return _openStudy.getSelectedStep().getNumber();
248         }
249
250         public String getStepEnabled() {
251                 return String.valueOf(_openStudy.isStepEnabled());
252         }
253
254         public StepRights getUserRights() {
255                 return _openStudy.getSelectedStepRights();
256         }
257
258         @Override
259         public String getWriteAccess() {
260                 return String.valueOf(_openStudy.isOpenForWriting());
261         }
262
263         /**
264          * Get the studyService.
265          * 
266          * @return the studyService
267          */
268         public StudyService getStudyService() {
269                 return _studyService;
270         }
271
272         /**
273          * Set the studyService.
274          * 
275          * @param studyService
276          *            the studyService to set
277          */
278         public void setStudyService(final StudyService studyService) {
279                 _studyService = studyService;
280         }
281
282         /**
283          * {@inheritDoc}
284          * 
285          * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
286          */
287         @Override
288         public void setOpenStudy(final OpenStudy study) {
289                 super.setOpenStudy(study);
290                 _openStudy = study;
291         }
292         
293         /**
294          * Get the menuProperty.
295          * @return the menuProperty
296          */
297         public String getMenuProperty() {
298                 return _menuProperty;
299         }
300
301         /**
302          * Set the menuProperty.
303          * @param menuProperty the menuProperty to set
304          */
305         public void setMenuProperty(final String menuProperty) {
306                 this._menuProperty = menuProperty;
307         }
308         
309         /**
310          * Get the _titleProperty.
311          * @return the _titleProperty
312          */
313         public String getTitleProperty() {
314                 return _titleProperty;
315         }
316
317         /**
318          * Set the _titleProperty.
319          * @param _titleProperty the titleProperty to set
320          */
321         public void setTitleProperty(final String titleProperty) {
322                 _titleProperty = titleProperty;
323         }
324
325         /**
326          * Get the editDisabledProperty.
327          * @return the editDisabledProperty
328          */
329         public String getEditDisabledProperty() {
330                 return _editDisabledProperty;
331         }
332
333         /**
334          * Set the editDisabledProperty.
335          * @param editDisabledProperty the editDisabledProperty to set
336          */
337         public void setEditDisabledProperty(final String editDisabledProperty) {
338                 _editDisabledProperty = editDisabledProperty;
339         }
340         
341         /**
342          * Get the toolProperty.
343          * @return the toolProperty
344          */
345         public String getToolProperty() {
346                 return _toolProperty;
347         }
348
349         /**
350          * Set the toolProperty.
351          * @param toolProperty the toolProperty to set
352          */
353         public void setToolProperty(final String toolProperty) {
354                 _toolProperty = toolProperty;
355         }
356         
357         /**
358          * Get the leftMenuProperty.
359          * @return the leftMenuProperty
360          */
361         public String getLeftMenuProperty() {
362                 return _leftMenuProperty;
363         }
364
365         /**
366          * Set the leftMenuProperty.
367          * @param leftMenuProperty the leftMenuProperty to set
368          */
369         public void setLeftMenuProperty(final String leftMenuProperty) {
370                 _leftMenuProperty = leftMenuProperty;
371         }
372 }