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