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