1 package org.splat.simer;
5 import org.splat.dal.bo.som.ProjectElement;
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.exception.InvalidParameterException;
8 import org.splat.service.StepService;
9 import org.splat.service.StudyService;
10 import org.splat.service.dto.StepCommentDTO;
11 import org.splat.som.StepRights;
12 import org.splat.wapp.Constants;
13 import org.splat.wapp.PopupMenu;
14 import org.splat.wapp.SimpleMenu;
17 * Presents the current open study information.
19 * @author Daniel Brunier-Coulin.
22 public class DisplayStudyStepAction extends AbstractDisplayAction {
27 private static final long serialVersionUID = 6467920934724352021L;
32 protected transient OpenStudy _openStudy = null;
35 * Injected study service.
37 private StudyService _studyService;
42 private List<StepCommentDTO> _comments = null;
45 * Injected Step Service.
47 private StepService _stepService;
49 // ==============================================================================================================================
51 // ==============================================================================================================================
54 * Open the selected study.
56 * @return SUCCESS if succeeded or ERROR if can't open
58 public String doOpen() {
60 _openStudy = getOpenStudy();
61 if (_myindex == null) {
62 if (_selection == null) { // Opening a study just newed
63 _selection = _openStudy.getSelection(); // Default selection
64 } else { // Re-opening (refreshing) the currently open study
65 _openStudy = open(getStudyService().selectStudy(
66 _openStudy.getIndex())); // Closes the previously open study
67 _openStudy.setSelection(_selection);
70 try { // Opening a study from the search result
71 int index = Integer.valueOf(_myindex);
72 if (_openStudy != null && _openStudy.getStudyObject() != null
73 && _openStudy.getIndex() == index) { // - The selected study is currently open
74 _selection = _openStudy.getSelection(); // Current selection
75 // RKV:BEGIN: put in session if necessary
76 if (!getSession().containsKey("study.open")) {
77 open(_openStudy.getStudyObject());
80 } else { // - The selected study is new
81 _openStudy = open(getStudyService().selectStudy(index));
82 _selection = _openStudy.getSelection(); // Default selection
84 } catch (Exception error) {
85 LOG.error("Reason:", error);
89 if (!ERROR.equals(res)) {
90 // Initialization of menus
91 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
92 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
93 if (owner instanceof Scenario) {
94 menu.enables(Constants.PROP_SCENARIO);
95 menu.selects(Constants.PROP_SCENARIO);
97 menu.disables(Constants.PROP_SCENARIO);
98 menu.selects("prop-general");
100 getSession().put("menu.study", _openStudy.getMenu());
111 protected void setMenu() {
112 if (Constants.TRUE.equals(getWriteAccess())
113 && getUserRights().canCreateDocument()) {
114 setToolProperty(Constants.STUDY_MENU);
116 setToolProperty(Constants.STANDARD_MENU);
119 initializationFullScreenContext(Constants.STUDY_MENU,
120 Constants.STUDY_MENU, "false", getToolProperty(),
121 Constants.STUDY_MENU);
124 public String doSelectStep() {
126 _openStudy = getOpenStudy();
127 if (_selection == null) { // Switch back to the current study
128 _selection = _openStudy.getSelection();
129 } else { // Selection of a step of current study
130 _openStudy.setSelection(_selection);
132 // Re-initialization of the properties menu according to the selected step
133 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
134 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
135 if (owner instanceof Scenario) {
136 menu.enables(Constants.PROP_SCENARIO);
137 menu.selects(Constants.PROP_SCENARIO);
139 menu.disables(Constants.PROP_SCENARIO);
140 menu.selects("prop-general");
148 public String doSelectDocument() {
149 _openStudy = getOpenStudy();
150 Execute todo = Execute.valueOf(_action);
151 if (todo == Execute.develop) {
152 _openStudy.developDocument(_myindex);
153 } else if (todo == Execute.reduce) {
154 _openStudy.reduceHistory(_myindex);
155 } else if (todo == Execute.reduceall) {
156 _openStudy.reduceDocument(_myindex);
164 public String doSelectKnowledge() {
165 _openStudy = getOpenStudy();
166 Execute todo = Execute.valueOf(_action);
167 if (todo == Execute.develop) {
168 _openStudy.developKnowledge(_myindex);
169 } else if (todo == Execute.reduce) {
170 _openStudy.reduceKnowledge(_myindex);
179 * Close the currently open study.
183 public String doClose() {
185 initializationScreenContext("none");
190 * Loads step comments (if already loaded - reloads).
192 public void loadComments() {
194 _comments = _stepService.getStepComments(_openStudy.getSelectedStep());
195 } catch(InvalidParameterException exception) {
197 LOG.debug("Error while trying to add comment: " + exception.getMessage());
201 // ==============================================================================================================================
203 // ==============================================================================================================================
205 public String getAction() {
209 public List<DocumentFacade> getDocuments() {
210 return _openStudy.getDisplayedDocuments();
213 public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
214 return _openStudy.getDisplayedKnowledges();
217 public List<SimulationContextFacade> getSimulationContexts() {
218 return _openStudy.getDisplayedSimulationContexts();
221 public PopupMenu getPopup() {
222 return _openStudy.getPopup();
225 public int getStepNumber() {
226 return _openStudy.getSelectedStep().getNumber();
229 public String getStepEnabled() {
230 return String.valueOf(_openStudy.isStepEnabled());
233 public StepRights getUserRights() {
234 return _openStudy.getSelectedStepRights();
238 public String getWriteAccess() {
239 return String.valueOf(_openStudy.isOpenForWriting());
243 * Get the studyService.
245 * @return the studyService
247 public StudyService getStudyService() {
248 return _studyService;
252 * Set the studyService.
254 * @param studyService
255 * the studyService to set
257 public void setStudyService(final StudyService studyService) {
258 _studyService = studyService;
264 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
267 public void setOpenStudy(final OpenStudy study) {
268 super.setOpenStudy(study);
274 * @return the comments
276 public List<StepCommentDTO> getComments() {
282 * @param comments the comments to set
284 public void setComments(final List<StepCommentDTO> comments) {
285 _comments = comments;
289 * Get the stepService.
290 * @return the stepService
292 public StepService getStepService() {
297 * Set the stepService.
298 * @param stepService the stepService to set
300 public void setStepService(final StepService stepService) {
301 _stepService = stepService;