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 _selection = _openStudy.getSelection(); // Default selection
72 } catch (Exception error) {
73 LOG.error("Reason:", error);
77 if (!ERROR.equals(res)) {
78 // Initialization of menus
79 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
80 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
81 if (owner instanceof Scenario) {
82 menu.enables(Constants.PROP_SCENARIO);
83 menu.selects(Constants.PROP_SCENARIO);
85 menu.disables(Constants.PROP_SCENARIO);
86 menu.selects("prop-general");
88 getSession().put("menu.study", _openStudy.getMenu());
98 protected void setMenu() {
99 if (Constants.TRUE.equals(getWriteAccess())
100 && getUserRights().canCreateDocument()) {
101 setToolProperty(Constants.STUDY_MENU);
103 setToolProperty(Constants.STANDARD_MENU);
106 initializationFullScreenContext(Constants.STUDY_MENU,
107 Constants.STUDY_MENU, "false", getToolProperty(),
108 Constants.STUDY_MENU);
111 public String doSelectStep() {
113 _openStudy = getOpenStudy();
114 if (_selection == null) { // Switch back to the current study
115 _selection = _openStudy.getSelection();
116 } else { // Selection of a step of current study
117 _openStudy.setSelection(_selection);
119 // Re-initialization of the properties menu according to the selected step
120 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
121 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
122 if (owner instanceof Scenario) {
123 menu.enables(Constants.PROP_SCENARIO);
124 menu.selects(Constants.PROP_SCENARIO);
126 menu.disables(Constants.PROP_SCENARIO);
127 menu.selects("prop-general");
135 public String doSelectDocument() {
136 _openStudy = getOpenStudy();
137 Execute todo = Execute.valueOf(_action);
138 if (todo == Execute.develop) {
139 _openStudy.developDocument(_myindex);
140 } else if (todo == Execute.reduce) {
141 _openStudy.reduceHistory(_myindex);
142 } else if (todo == Execute.reduceall) {
143 _openStudy.reduceDocument(_myindex);
151 public String doSelectKnowledge() {
152 _openStudy = getOpenStudy();
153 Execute todo = Execute.valueOf(_action);
154 if (todo == Execute.develop) {
155 _openStudy.developKnowledge(_myindex);
156 } else if (todo == Execute.reduce) {
157 _openStudy.reduceKnowledge(_myindex);
166 * Close the currently open study.
170 public String doClose() {
172 initializationScreenContext("none");
176 // ==============================================================================================================================
178 // ==============================================================================================================================
180 public String getAction() {
184 public List<DocumentFacade> getDocuments() {
185 return _openStudy.getDisplayedDocuments();
188 public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
189 return _openStudy.getDisplayedKnowledges();
192 public List<SimulationContextFacade> getSimulationContexts() {
193 return _openStudy.getDisplayedSimulationContexts();
196 public PopupMenu getPopup() {
197 return _openStudy.getPopup();
200 public int getStepNumber() {
201 return _openStudy.getSelectedStep().getNumber();
204 public String getStepEnabled() {
205 return String.valueOf(_openStudy.isStepEnabled());
208 public StepRights getUserRights() {
209 return _openStudy.getSelectedStepRights();
213 public String getWriteAccess() {
214 return String.valueOf(_openStudy.isOpenForWriting());
218 * Get the studyService.
220 * @return the studyService
222 public StudyService getStudyService() {
223 return _studyService;
227 * Set the studyService.
229 * @param studyService
230 * the studyService to set
232 public void setStudyService(final StudyService studyService) {
233 _studyService = studyService;
239 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
242 public void setOpenStudy(final OpenStudy study) {
243 super.setOpenStudy(study);