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() {
47 _openStudy = getOpenStudy();
48 if (_myindex == null) {
49 if (_selection == null) { // Opening a study just newed
50 _selection = _openStudy.getSelection(); // Default selection
52 // Re-opening (refreshing) the currently open study
53 _openStudy = open(getStudyService().selectStudy(
54 _openStudy.getIndex())); // Closes the previously open study
55 _openStudy.setSelection(_selection);
57 try { // Opening a study from the search result
58 int index = Integer.valueOf(_myindex);
59 if (_openStudy != null && _openStudy.getStudyObject() != null
60 && _openStudy.getIndex() == index) { // - The selected study is currently open
61 _selection = _openStudy.getSelection(); // Current selection
62 // RKV:BEGIN: put in session if necessary
63 if (!getSession().containsKey("study.open")) {
64 open(_openStudy.getStudyObject());
67 } else { // - The selected study is new
68 _openStudy = open(getStudyService().selectStudy(index));
69 _selection = _openStudy.getSelection(); // Default selection
71 } catch (Exception error) {
72 LOG.error("Reason:", error);
76 if (!ERROR.equals(res)) {
77 // Initialization of menus
78 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
79 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
80 if (owner instanceof Scenario) {
81 menu.enables(Constants.PROP_SCENARIO);
82 menu.selects(Constants.PROP_SCENARIO);
84 menu.disables(Constants.PROP_SCENARIO);
85 menu.selects("prop-general");
87 getSession().put("menu.study", _openStudy.getMenu());
97 protected void setMenu() {
98 if (Constants.TRUE.equals(getWriteAccess())
99 && getUserRights().canCreateDocument()) {
100 setToolProperty(Constants.STUDY_MENU);
102 setToolProperty(Constants.STANDARD_MENU);
105 initializationFullScreenContext(Constants.STUDY_MENU,
106 Constants.STUDY_MENU, "false", getToolProperty(),
107 Constants.STUDY_MENU);
110 public String doSelectStep() {
112 _openStudy = getOpenStudy();
113 if (_selection == null) { // Switch back to the current study
114 _selection = _openStudy.getSelection();
115 } else { // Selection of a step of current study
116 _openStudy.setSelection(_selection);
118 // Re-initialization of the properties menu according to the selected step
119 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
120 SimpleMenu menu = getApplicationSettings().getMenu("configuration");
121 if (owner instanceof Scenario) {
122 menu.enables(Constants.PROP_SCENARIO);
123 menu.selects(Constants.PROP_SCENARIO);
125 menu.disables(Constants.PROP_SCENARIO);
126 menu.selects("prop-general");
134 public String doSelectDocument() {
135 _openStudy = getOpenStudy();
136 Execute todo = Execute.valueOf(_action);
137 if (todo == Execute.develop) {
138 _openStudy.developDocument(_myindex);
139 } else if (todo == Execute.reduce) {
140 _openStudy.reduceHistory(_myindex);
141 } else if (todo == Execute.reduceall) {
142 _openStudy.reduceDocument(_myindex);
150 public String doSelectKnowledge() {
151 _openStudy = getOpenStudy();
152 Execute todo = Execute.valueOf(_action);
153 if (todo == Execute.develop) {
154 _openStudy.developKnowledge(_myindex);
155 } else if (todo == Execute.reduce) {
156 _openStudy.reduceKnowledge(_myindex);
165 * Close the currently open study.
169 public String doClose() {
171 initializationScreenContext("none");
175 // ==============================================================================================================================
177 // ==============================================================================================================================
179 public String getAction() {
183 public List<DocumentFacade> getDocuments() {
184 return _openStudy.getDisplayedDocuments();
187 public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
188 return _openStudy.getDisplayedKnowledges();
191 public List<SimulationContextFacade> getSimulationContexts() {
192 return _openStudy.getDisplayedSimulationContexts();
195 public PopupMenu getPopup() {
196 return _openStudy.getPopup();
199 public int getStepNumber() {
200 return _openStudy.getSelectedStep().getNumber();
203 public String getStepEnabled() {
204 return String.valueOf(_openStudy.isStepEnabled());
207 public StepRights getUserRights() {
208 return _openStudy.getSelectedStepRights();
212 public String getWriteAccess() {
213 return String.valueOf(_openStudy.isOpenForWriting());
217 * Get the studyService.
219 * @return the studyService
221 public StudyService getStudyService() {
222 return _studyService;
226 * Set the studyService.
228 * @param studyService
229 * the studyService to set
231 public void setStudyService(final StudyService studyService) {
232 _studyService = studyService;
238 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
241 public void setOpenStudy(final OpenStudy study) {
242 super.setOpenStudy(study);