Salome HOME
<jsp:param ... > parameters are removed from the title bar
[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          * Property that indicates whether the current open study is editable or not.
49          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
50          * It is necessary for correct building the title bar.
51          */
52         private String _editDisabledProperty = "false";
53
54         // ==============================================================================================================================
55         // Action methods
56         // ==============================================================================================================================
57
58         public String doOpen() {
59                 Study study;
60                 mystudy = getOpenStudy();
61                 if (myindex != null)
62                         try { // Opening a study from the search result
63                                 int index = Integer.valueOf(myindex);
64                                 if (mystudy != null && mystudy.getStudyObject() != null
65                                                 && mystudy.getIndex() == index) { // - The selected study is currently open
66                                         selection = mystudy.getSelection(); // Current selection
67                                         study = mystudy.getStudyObject(); // Current Study object
68                                         // RKV:BEGIN: put in session if necessary
69                                         if (!getSession().containsKey("study.open")) {
70                                                 open(study);
71                                         }
72                                         // RKV:END
73                                 } else { // - The selected study is new
74                                         study = getStudyService().selectStudy(index);
75                                         mystudy = open(study);
76                                         selection = mystudy.getSelection(); // Default selection
77                                 }
78                         } catch (Exception error) {
79                                 logger.error("Reason:", error);
80                                 return ERROR;
81                         }
82                 else if (selection == null) { // Opening a study just newed
83                         selection = mystudy.getSelection(); // Default selection
84                         study = mystudy.getStudyObject();
85                 } else { // Re-opening (refreshing) the currently open study
86                         study = getStudyService().selectStudy(mystudy.getIndex());
87                         mystudy = open(study); // Closes the previously open study
88                         mystudy.setSelection(selection);
89                 }
90                 // Initialization of menus
91                 ProjectElement owner = mystudy.getSelectedStep().getOwner();
92                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
93                 if (owner instanceof Scenario) {
94                         menu.enables("prop-scenario");
95                         menu.selects("prop-scenario");
96                 } else {
97                         menu.disables("prop-scenario");
98                         menu.selects("prop-general");
99                 }
100                 getSession().put("menu.study", mystudy.getMenu());
101                 
102                 setMenuProperty("study");
103                 setTitleProperty("study");
104                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
105
106                 return SUCCESS;
107         }
108
109         public String doSelectStep() {
110
111                 mystudy = getOpenStudy();
112                 if (selection == null) { // Switch back to the current study
113                         selection = mystudy.getSelection();
114                 } else { // Selection of a step of current study
115                         mystudy.setSelection(selection);
116                 }
117                 // Re-initialization of the properties menu according to the selected step
118                 ProjectElement owner = mystudy.getSelectedStep().getOwner();
119                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
120                 if (owner instanceof Scenario) {
121                         menu.enables("prop-scenario");
122                         menu.selects("prop-scenario");
123                 } else {
124                         menu.disables("prop-scenario");
125                         menu.selects("prop-general");
126                 }
127                 
128                 setMenuProperty("study");
129                 setTitleProperty("study");
130                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
131                 
132                 return SUCCESS;
133         }
134
135         public String doSelectDocument() {
136                 mystudy = getOpenStudy();
137                 Execute todo = Execute.valueOf(action);
138                 if (todo == Execute.develop)
139                         mystudy.developDocument(myindex);
140                 else if (todo == Execute.reduce)
141                         mystudy.reduceHistory(myindex);
142                 else if (todo == Execute.reduceall)
143                         mystudy.reduceDocument(myindex);
144                 
145                 setMenuProperty("study");
146                 setTitleProperty("study");
147                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
148                 
149                 return SUCCESS;
150         }
151
152         public String doSelectKnowledge() {
153                 mystudy = getOpenStudy();
154                 Execute todo = Execute.valueOf(action);
155                 if (todo == Execute.develop)
156                         mystudy.developKnowledge(myindex);
157                 else if (todo == Execute.reduce)
158                         mystudy.reduceKnowledge(myindex);
159                 
160                 setMenuProperty("study");
161                 setTitleProperty("study");
162                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
163                 
164                 return SUCCESS;
165         }
166
167         public String doClose() {
168                 closeStudy();
169                 
170                 setMenuProperty("none");
171                 initializationScreenContext(_menuProperty);
172                 
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 mystudy.getDisplayedDocuments();
186         }
187
188         public List<OpenObject.KnowledgeIterator> getKnowledges() {
189                 return mystudy.getDisplayedKnowledges();
190         }
191
192         public List<SimulationContextFacade> getSimulationContexts() {
193                 return mystudy.getDisplayedSimulationContexts();
194         }
195
196         public PopupMenu getPopup() {
197                 return mystudy.getPopup();
198         }
199
200         public int getStepNumber() {
201                 return mystudy.getSelectedStep().getNumber();
202         }
203
204         public String getStepEnabled() {
205                 return String.valueOf(mystudy.isStepEnabled());
206         }
207
208         public StepRights getUserRights() {
209                 return mystudy.getSelectedStepRights();
210         }
211
212         public String getWriteAccess() {
213                 return String.valueOf(mystudy.isOpenForWriting());
214         }
215
216         /**
217          * Get the studyService.
218          * 
219          * @return the studyService
220          */
221         public StudyService getStudyService() {
222                 return _studyService;
223         }
224
225         /**
226          * Set the studyService.
227          * 
228          * @param studyService
229          *            the studyService to set
230          */
231         public void setStudyService(StudyService studyService) {
232                 _studyService = studyService;
233         }
234
235         /**
236          * {@inheritDoc}
237          * 
238          * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
239          */
240         @Override
241         public void setOpenStudy(OpenStudy study) {
242                 super.setOpenStudy(study);
243                 mystudy = study;
244         }
245         
246         /**
247          * Get the menuProperty.
248          * @return the menuProperty
249          */
250         public String getMenuProperty() {
251                 return _menuProperty;
252         }
253
254         /**
255          * Set the menuProperty.
256          * @param menuProperty the menuProperty to set
257          */
258         public void setMenuProperty(String menuProperty) {
259                 this._menuProperty = menuProperty;
260         }
261         
262         /**
263          * Get the _titleProperty.
264          * @return the _titleProperty
265          */
266         public String getTitleProperty() {
267                 return _titleProperty;
268         }
269
270         /**
271          * Set the _titleProperty.
272          * @param _titleProperty the titleProperty to set
273          */
274         public void setTitleProperty(String titleProperty) {
275                 _titleProperty = titleProperty;
276         }
277
278         /**
279          * Get the editDisabledProperty.
280          * @return the editDisabledProperty
281          */
282         public String getEditDisabledProperty() {
283                 return _editDisabledProperty;
284         }
285
286         /**
287          * Set the editDisabledProperty.
288          * @param editDisabledProperty the editDisabledProperty to set
289          */
290         public void setEditDisabledProperty(String editDisabledProperty) {
291                 _editDisabledProperty = editDisabledProperty;
292         }
293         
294 }