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