]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Salome HOME
Correct redirect end of session during check-out operation
[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.wapp.Constants;
10 import org.splat.wapp.PopupMenu;
11 import org.splat.wapp.SimpleMenu;
12
13 /**
14  * Presents the current open study information.
15  *
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         // Action methods
38         // ==============================================================================================================================
39
40         /**
41          * Open the selected study.
42          *
43          * @return SUCCESS if succeeded or ERROR if can't open
44          */
45         public String doOpen() {
46                 _simanContext = "#Edit_Study_.htm";
47                 String res = SUCCESS;
48                 _openStudy = getOpenStudy();
49                 if (_myindex == null) {
50                         if (_selection == null) { // Opening a study just newed
51                                 _selection = _openStudy.getSelection(); // Default selection
52                         }
53                         if(_openStudy.getStudyObject() == null) {
54                                 // Nothing to open or re-open
55                                 res = ERROR;
56                         } else {
57                                 // Re-opening (refreshing) the currently open study
58                                 _openStudy = open(getStudyService().selectStudy(
59                                                 _openStudy.getIndex())); // Closes the previously open study
60                                 _openStudy.setSelection(_selection);
61                         }
62                 } else {
63                         try { // Opening a study from the search result
64                                 int index = Integer.valueOf(_myindex);
65                                 if (_openStudy != null && _openStudy.getStudyObject() != null
66                                                 && _openStudy.getIndex() == index) { // - The selected study is currently open
67                                         _selection = _openStudy.getSelection(); // Current selection
68                                         // RKV:BEGIN: put in session if necessary
69                                         if (!getSession().containsKey("study.open")) {
70                                                 open(_openStudy.getStudyObject());
71                                         }
72                                         // RKV:END
73                                 } else { // - The selected study is new
74                                         _openStudy = open(getStudyService().selectStudy(index));
75                                         _openStudy.setSelection(_openStudy.getSelection());
76                                         _selection = _openStudy.getSelection(); // Default selection
77                                 }
78                         } catch (Exception error) {
79                                 LOG.error("Reason:", error);
80                                 res = ERROR;
81                         }
82                 }
83                 if (!ERROR.equals(res)) {
84                         // Initialization of menus
85                         ProjectElement owner = _openStudy.getSelectedStep().getOwner();
86                         SimpleMenu menu = getApplicationSettings().getMenu("configuration");
87                         if (owner instanceof Scenario) {
88                                 menu.enables(Constants.PROP_SCENARIO);
89                                 menu.selects(Constants.PROP_SCENARIO);
90                         } else {
91                                 menu.disables(Constants.PROP_SCENARIO);
92                                 menu.selects("prop-general");
93                         }
94                         getSession().put("menu.study", _openStudy.getMenu());
95
96                         setMenu();
97                 }
98                 return res;
99         }
100
101         /**
102          * Set context menu.
103          */
104         protected void setMenu() {
105                 if (Constants.TRUE.equals(getWriteAccess())
106                                 && getUserRights().canCreateDocument()) {
107                         setToolProperty(Constants.STUDY_MENU);
108                 } else {
109                         setToolProperty(Constants.STANDARD_MENU);
110                 }
111
112                 initializationFullScreenContext(Constants.STUDY_MENU,
113                                 Constants.STUDY_MENU, "false", getToolProperty(),
114                                 Constants.STUDY_MENU);
115         }
116
117         public String doSelectStep() {
118
119                 _openStudy = getOpenStudy();
120                 if (_selection == null) { // Switch back to the current study
121                         _selection = _openStudy.getSelection();
122                 } else { // Selection of a step of current study
123                         _openStudy.setSelection(_selection);
124                 }
125                 // Re-initialization of the properties menu according to the selected step
126                 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
127                 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
128                 if (owner instanceof Scenario) {
129                         menu.enables(Constants.PROP_SCENARIO);
130                         menu.selects(Constants.PROP_SCENARIO);
131                 } else {
132                         menu.disables(Constants.PROP_SCENARIO);
133                         menu.selects("prop-general");
134                 }
135
136                 setMenu();
137
138                 return SUCCESS;
139         }
140
141         public String doSelectDocument() {
142                 _openStudy = getOpenStudy();
143                 Execute todo = Execute.valueOf(_action);
144                 if (todo == Execute.develop) {
145                         _openStudy.developDocument(_myindex);
146                 } else if (todo == Execute.reduce) {
147                         _openStudy.reduceHistory(_myindex);
148                 } else if (todo == Execute.reduceall) {
149                         _openStudy.reduceDocument(_myindex);
150                 }
151
152                 setMenu();
153
154                 return SUCCESS;
155         }
156
157         public String doSelectKnowledge() {
158                 _openStudy = getOpenStudy();
159                 Execute todo = Execute.valueOf(_action);
160                 if (todo == Execute.develop) {
161                         _openStudy.developKnowledge(_myindex);
162                 } else if (todo == Execute.reduce) {
163                         _openStudy.reduceKnowledge(_myindex);
164                 }
165
166                 setMenu();
167
168                 return SUCCESS;
169         }
170
171         /**
172          * Close the currently open study.
173          *
174          * @return SUCCESS
175          */
176         public String doClose() {
177                 closeStudy();
178                 initializationScreenContext("none");
179                 return SUCCESS;
180         }
181         
182         // ==============================================================================================================================
183         // Getters
184         // ==============================================================================================================================
185
186         public String getAction() {
187                 return _action;
188         }
189
190         public List<DocumentFacade> getDocuments() {
191                 return _openStudy.getDisplayedDocuments();
192         }
193
194         public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
195                 return _openStudy.getDisplayedKnowledges();
196         }
197
198         public List<SimulationContextFacade> getSimulationContexts() {
199                 return _openStudy.getDisplayedSimulationContexts();
200         }
201
202         public PopupMenu getPopup() {
203                 return _openStudy.getPopup();
204         }
205
206         public int getStepNumber() {
207                 return _openStudy.getSelectedStep().getNumber();
208         }
209
210         public String getStepEnabled() {
211                 return String.valueOf(_openStudy.isStepEnabled());
212         }
213
214         public StepRights getUserRights() {
215                 return _openStudy.getSelectedStepRights();
216         }
217
218         @Override
219         public String getWriteAccess() {
220                 return String.valueOf(_openStudy.isOpenForWriting());
221         }
222
223         /**
224          * Get the studyService.
225          *
226          * @return the studyService
227          */
228         public StudyService getStudyService() {
229                 return _studyService;
230         }
231
232         /**
233          * Set the studyService.
234          *
235          * @param studyService
236          *            the studyService to set
237          */
238         public void setStudyService(final StudyService studyService) {
239                 _studyService = studyService;
240         }
241
242         /**
243          * {@inheritDoc}
244          *
245          * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
246          */
247         @Override
248         public void setOpenStudy(final OpenStudy study) {
249                 super.setOpenStudy(study);
250                 _openStudy = study;
251         }
252 }