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.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;
14 * Presents the current open study information.
16 * @author Daniel Brunier-Coulin.
19 public class DisplayStudyStepAction extends AbstractDisplayAction {
24 private static final long serialVersionUID = 6467920934724352021L;
29 protected transient OpenStudy _openStudy = null;
32 * Injected study service.
34 private StudyService _studyService;
36 // ==============================================================================================================================
38 // ==============================================================================================================================
41 * Open the selected study.
43 * @return SUCCESS if succeeded or ERROR if can't open
45 public String doOpen() {
46 _simanContext = "#Edit_Study_.htm";
48 _openStudy = getOpenStudy();
49 if (_myindex == null) {
50 if (_selection == null) { // Opening a study just newed
51 _selection = _openStudy.getSelection(); // Default selection
53 if(_openStudy.getStudyObject() == null) {
54 // Nothing to open or re-open
57 // Re-opening (refreshing) the currently open study
58 _openStudy = open(getStudyService().selectStudy(
59 _openStudy.getIndex())); // Closes the previously open study
60 _openStudy.setSelection(_selection);
63 try { // Opening a study from the search result
64 int index = Integer.valueOf(_myindex);
65 if (_openStudy != null && _openStudy.getStudyObject() != null
66 && _openStudy.getIndex() == index) { // - The selected study is currently open
67 _selection = _openStudy.getSelection(); // Current selection
68 // RKV:BEGIN: put in session if necessary
69 if (!getSession().containsKey("study.open")) {
70 open(_openStudy.getStudyObject());
73 } else { // - The selected study is new
74 _openStudy = open(getStudyService().selectStudy(index));
75 _openStudy.setSelection(_openStudy.getSelection());
76 _selection = _openStudy.getSelection(); // Default selection
78 } catch (Exception error) {
79 LOG.error("Reason:", error);
83 if (!ERROR.equals(res)) {
84 // Initialization of menus
85 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
86 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
87 if (owner instanceof Scenario) {
88 menu.enables(Constants.PROP_SCENARIO);
89 menu.selects(Constants.PROP_SCENARIO);
91 menu.disables(Constants.PROP_SCENARIO);
92 menu.selects("prop-general");
94 getSession().put("menu.study", _openStudy.getMenu());
104 protected void setMenu() {
105 if (Constants.TRUE.equals(getWriteAccess())
106 && getUserRights().canCreateDocument()) {
107 setToolProperty(Constants.STUDY_MENU);
109 setToolProperty(Constants.STANDARD_MENU);
112 initializationFullScreenContext(Constants.STUDY_MENU,
113 Constants.STUDY_MENU, "false", getToolProperty(),
114 Constants.STUDY_MENU);
117 public String doSelectStep() {
119 _openStudy = getOpenStudy();
120 if (_selection == null) { // Switch back to the current study
121 _selection = _openStudy.getSelection();
122 } else { // Selection of a step of current study
123 _openStudy.setSelection(_selection);
125 // Re-initialization of the properties menu according to the selected step
126 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
127 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
128 if (owner instanceof Scenario) {
129 menu.enables(Constants.PROP_SCENARIO);
130 menu.selects(Constants.PROP_SCENARIO);
132 menu.disables(Constants.PROP_SCENARIO);
133 menu.selects("prop-general");
141 public String doSelectDocument() {
142 _openStudy = getOpenStudy();
143 Execute todo = Execute.valueOf(_action);
144 if (todo == Execute.develop) {
145 _openStudy.developDocument(_myindex);
146 } else if (todo == Execute.reduce) {
147 _openStudy.reduceHistory(_myindex);
148 } else if (todo == Execute.reduceall) {
149 _openStudy.reduceDocument(_myindex);
157 public String doSelectKnowledge() {
158 _openStudy = getOpenStudy();
159 Execute todo = Execute.valueOf(_action);
160 if (todo == Execute.develop) {
161 _openStudy.developKnowledge(_myindex);
162 } else if (todo == Execute.reduce) {
163 _openStudy.reduceKnowledge(_myindex);
172 * Close the currently open study.
176 public String doClose() {
178 initializationScreenContext("none");
182 // ==============================================================================================================================
184 // ==============================================================================================================================
186 public String getAction() {
190 public List<DocumentFacade> getDocuments() {
191 return _openStudy.getDisplayedDocuments();
194 public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
195 return _openStudy.getDisplayedKnowledges();
198 public List<SimulationContextFacade> getSimulationContexts() {
199 return _openStudy.getDisplayedSimulationContexts();
202 public PopupMenu getPopup() {
203 return _openStudy.getPopup();
206 public int getStepNumber() {
207 return _openStudy.getSelectedStep().getNumber();
210 public String getStepEnabled() {
211 return String.valueOf(_openStudy.isStepEnabled());
214 public StepRights getUserRights() {
215 return _openStudy.getSelectedStepRights();
219 public String getWriteAccess() {
220 return String.valueOf(_openStudy.isOpenForWriting());
224 * Get the studyService.
226 * @return the studyService
228 public StudyService getStudyService() {
229 return _studyService;
233 * Set the studyService.
235 * @param studyService
236 * the studyService to set
238 public void setStudyService(final StudyService studyService) {
239 _studyService = studyService;
245 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
248 public void setOpenStudy(final OpenStudy study) {
249 super.setOpenStudy(study);