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