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