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 // Re-opening (refreshing) the currently open study
54 _openStudy = open(getStudyService().selectStudy(
55 _openStudy.getIndex())); // Closes the previously open study
56 _openStudy.setSelection(_selection);
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());
68 } else { // - The selected study is new
69 _openStudy = open(getStudyService().selectStudy(index));
70 _openStudy.setSelection(_openStudy.getSelection());
71 _selection = _openStudy.getSelection(); // Default selection
73 } catch (Exception error) {
74 LOG.error("Reason:", error);
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);
86 menu.disables(Constants.PROP_SCENARIO);
87 menu.selects("prop-general");
89 getSession().put("menu.study", _openStudy.getMenu());
99 protected void setMenu() {
100 if (Constants.TRUE.equals(getWriteAccess())
101 && getUserRights().canCreateDocument()) {
102 setToolProperty(Constants.STUDY_MENU);
104 setToolProperty(Constants.STANDARD_MENU);
107 initializationFullScreenContext(Constants.STUDY_MENU,
108 Constants.STUDY_MENU, "false", getToolProperty(),
109 Constants.STUDY_MENU);
112 public String doSelectStep() {
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);
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);
127 menu.disables(Constants.PROP_SCENARIO);
128 menu.selects("prop-general");
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);
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);
167 * Close the currently open study.
171 public String doClose() {
173 initializationScreenContext("none");
177 // ==============================================================================================================================
179 // ==============================================================================================================================
181 public String getAction() {
185 public List<DocumentFacade> getDocuments() {
186 return _openStudy.getDisplayedDocuments();
189 public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
190 return _openStudy.getDisplayedKnowledges();
193 public List<SimulationContextFacade> getSimulationContexts() {
194 return _openStudy.getDisplayedSimulationContexts();
197 public PopupMenu getPopup() {
198 return _openStudy.getPopup();
201 public int getStepNumber() {
202 return _openStudy.getSelectedStep().getNumber();
205 public String getStepEnabled() {
206 return String.valueOf(_openStudy.isStepEnabled());
209 public StepRights getUserRights() {
210 return _openStudy.getSelectedStepRights();
214 public String getWriteAccess() {
215 return String.valueOf(_openStudy.isOpenForWriting());
219 * Get the studyService.
221 * @return the studyService
223 public StudyService getStudyService() {
224 return _studyService;
228 * Set the studyService.
230 * @param studyService
231 * the studyService to set
233 public void setStudyService(final StudyService studyService) {
234 _studyService = studyService;
240 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
243 public void setOpenStudy(final OpenStudy study) {
244 super.setOpenStudy(study);