]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Salome HOME
Code is cleaned.
[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 public class DisplayStudyStepAction extends DisplayBaseAction {
14
15         /**
16          * Serial version ID.
17          */
18         private static final long serialVersionUID = 6467920934724352021L;
19
20         /**
21          * Presented study.
22          */
23         protected OpenStudy mystudy = null;
24
25         /**
26          * Injected study service.
27          */
28         private StudyService _studyService;
29
30         // ==============================================================================================================================
31         // Action methods
32         // ==============================================================================================================================
33
34         public String doOpen() {
35                 Study study;
36                 mystudy = getOpenStudy();
37                 if (myindex != null)
38                         try { // Opening a study from the search result
39                                 int index = Integer.valueOf(myindex);
40                                 if (mystudy != null && mystudy.getStudyObject() != null
41                                                 && mystudy.getIndex() == index) { // - The selected study is currently open
42                                         selection = mystudy.getSelection(); // Current selection
43                                         study = mystudy.getStudyObject(); // Current Study object
44                                         // RKV:BEGIN: put in session if necessary
45                                         if (!getSession().containsKey("study.open")) {
46                                                 open(study);
47                                         }
48                                         // RKV:END
49                                 } else { // - The selected study is new
50                                         study = getStudyService().selectStudy(index);
51                                         mystudy = open(study);
52                                         selection = mystudy.getSelection(); // Default selection
53                                 }
54                         } catch (Exception error) {
55                                 logger.error("Reason:", error);
56                                 return ERROR;
57                         }
58                 else if (selection == null) { // Opening a study just newed
59                         selection = mystudy.getSelection(); // Default selection
60                         study = mystudy.getStudyObject();
61                 } else { // Re-opening (refreshing) the currently open study
62                         study = getStudyService().selectStudy(mystudy.getIndex());
63                         mystudy = open(study); // Closes the previously open study
64                         mystudy.setSelection(selection);
65                 }
66                 // Initialization of menus
67                 ProjectElement owner = mystudy.getSelectedStep().getOwner();
68                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
69                 if (owner instanceof Scenario) {
70                         menu.enables("prop-scenario");
71                         menu.selects("prop-scenario");
72                 } else {
73                         menu.disables("prop-scenario");
74                         menu.selects("prop-general");
75                 }
76                 getSession().put("menu.study", mystudy.getMenu());
77
78                 return SUCCESS;
79         }
80
81         public String doSelectStep() {
82
83                 mystudy = getOpenStudy();
84                 if (selection == null) { // Switch back to the current study
85                         selection = mystudy.getSelection();
86                 } else { // Selection of a step of current study
87                         mystudy.setSelection(selection);
88                 }
89                 // Re-initialization of the properties menu according to the selected step
90                 ProjectElement owner = mystudy.getSelectedStep().getOwner();
91                 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
92                 if (owner instanceof Scenario) {
93                         menu.enables("prop-scenario");
94                         menu.selects("prop-scenario");
95                 } else {
96                         menu.disables("prop-scenario");
97                         menu.selects("prop-general");
98                 }
99                 return SUCCESS;
100         }
101
102         public String doSelectDocument() {
103                 mystudy = getOpenStudy();
104                 Execute todo = Execute.valueOf(action);
105                 if (todo == Execute.develop)
106                         mystudy.developDocument(myindex);
107                 else if (todo == Execute.reduce)
108                         mystudy.reduceHistory(myindex);
109                 else if (todo == Execute.reduceall)
110                         mystudy.reduceDocument(myindex);
111                 return SUCCESS;
112         }
113
114         public String doSelectKnowledge() {
115                 mystudy = getOpenStudy();
116                 Execute todo = Execute.valueOf(action);
117                 if (todo == Execute.develop)
118                         mystudy.developKnowledge(myindex);
119                 else if (todo == Execute.reduce)
120                         mystudy.reduceKnowledge(myindex);
121                 return SUCCESS;
122         }
123
124         public String doClose() {
125                 closeStudy();
126                 return SUCCESS;
127         }
128
129         // ==============================================================================================================================
130         // Getters
131         // ==============================================================================================================================
132
133         public String getAction() {
134                 return action;
135         }
136
137         public List<DocumentFacade> getDocuments() {
138                 return mystudy.getDisplayedDocuments();
139         }
140
141         public List<OpenObject.KnowledgeIterator> getKnowledges() {
142                 return mystudy.getDisplayedKnowledges();
143         }
144
145         public List<SimulationContextFacade> getSimulationContexts() {
146                 return mystudy.getDisplayedSimulationContexts();
147         }
148
149         public PopupMenu getPopup() {
150                 return mystudy.getPopup();
151         }
152
153         public int getStepNumber() {
154                 return mystudy.getSelectedStep().getNumber();
155         }
156
157         public String getStepEnabled() {
158                 return String.valueOf(mystudy.isStepEnabled());
159         }
160
161         public StepRights getUserRights() {
162                 return mystudy.getSelectedStepRights();
163         }
164
165         public String getWriteAccess() {
166                 return String.valueOf(mystudy.isOpenForWriting());
167         }
168
169         /**
170          * Get the studyService.
171          * 
172          * @return the studyService
173          */
174         public StudyService getStudyService() {
175                 return _studyService;
176         }
177
178         /**
179          * Set the studyService.
180          * 
181          * @param studyService
182          *            the studyService to set
183          */
184         public void setStudyService(StudyService studyService) {
185                 _studyService = studyService;
186         }
187
188         /**
189          * {@inheritDoc}
190          * 
191          * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
192          */
193         @Override
194         public void setOpenStudy(OpenStudy study) {
195                 super.setOpenStudy(study);
196                 mystudy = study;
197         }
198 }