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