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.dal.bo.som.Study;
8 import org.splat.service.StudyService;
9 import org.splat.som.StepRights;
10 import org.splat.wapp.Constants;
11 import org.splat.wapp.PopupMenu;
12 import org.splat.wapp.SimpleMenu;
15 * 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;
37 * Value of the menu property.
38 * It can be: none, create, open, study, knowledge, sysadmin, help.
40 private String _menuProperty;
43 * Value of the title bar property.
44 * It can be: study, knowledge.
46 private String _titleProperty;
49 * Value of the tool bar property.
50 * It can be: none, standard, study, back.
52 private String _toolProperty;
55 * Value of the left menu property.
56 * It can be: open, study, knowledge, scenario.
58 private String _leftMenuProperty;
61 * Property that indicates whether the current open study is editable or not.
62 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
63 * It is necessary for correct building the title bar.
65 private String _editDisabledProperty = "false";
67 // ==============================================================================================================================
69 // ==============================================================================================================================
71 public String doOpen() {
74 _openStudy = getOpenStudy();
75 if (_myindex == null) {
76 if (_selection == null) { // Opening a study just newed
77 _selection = _openStudy.getSelection(); // Default selection
78 study = _openStudy.getStudyObject();
79 } else { // Re-opening (refreshing) the currently open study
80 study = getStudyService().selectStudy(_openStudy.getIndex());
81 _openStudy = open(study); // Closes the previously open study
82 _openStudy.setSelection(_selection);
85 try { // Opening a study from the search result
86 int index = Integer.valueOf(_myindex);
87 if (_openStudy != null && _openStudy.getStudyObject() != null
88 && _openStudy.getIndex() == index) { // - The selected study is currently open
89 _selection = _openStudy.getSelection(); // Current selection
90 study = _openStudy.getStudyObject(); // Current Study object
91 // RKV:BEGIN: put in session if necessary
92 if (!getSession().containsKey("study.open")) {
96 } else { // - The selected study is new
97 study = getStudyService().selectStudy(index);
98 _openStudy = open(study);
99 _selection = _openStudy.getSelection(); // Default selection
101 } catch (Exception error) {
102 LOG.error("Reason:", error);
106 if (!ERROR.equals(res)){
107 // Initialization of menus
108 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
109 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
110 if (owner instanceof Scenario) {
111 menu.enables(Constants.PROP_SCENARIO);
112 menu.selects(Constants.PROP_SCENARIO);
114 menu.disables(Constants.PROP_SCENARIO);
115 menu.selects("prop-general");
117 getSession().put("menu.study", _openStudy.getMenu());
119 setMenuProperty(Constants.STUDY_MENU);
120 setTitleProperty(Constants.STUDY_MENU);
121 if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
122 setToolProperty(Constants.STUDY_MENU);
124 setToolProperty(Constants.STANDARD_MENU);
127 setLeftMenuProperty(Constants.STUDY_MENU);
129 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
134 public String doSelectStep() {
136 _openStudy = getOpenStudy();
137 if (_selection == null) { // Switch back to the current study
138 _selection = _openStudy.getSelection();
139 } else { // Selection of a step of current study
140 _openStudy.setSelection(_selection);
142 // Re-initialization of the properties menu according to the selected step
143 ProjectElement owner = _openStudy.getSelectedStep().getOwner();
144 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
145 if (owner instanceof Scenario) {
146 menu.enables(Constants.PROP_SCENARIO);
147 menu.selects(Constants.PROP_SCENARIO);
149 menu.disables(Constants.PROP_SCENARIO);
150 menu.selects("prop-general");
153 setMenuProperty(Constants.STUDY_MENU);
154 setTitleProperty(Constants.STUDY_MENU);
155 if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
156 setToolProperty(Constants.STUDY_MENU);
158 setToolProperty(Constants.STANDARD_MENU);
161 setLeftMenuProperty(Constants.STUDY_MENU);
162 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
167 public String doSelectDocument() {
168 _openStudy = getOpenStudy();
169 Execute todo = Execute.valueOf(_action);
170 if (todo == Execute.develop) {
171 _openStudy.developDocument(_myindex);
172 } else if (todo == Execute.reduce) {
173 _openStudy.reduceHistory(_myindex);
174 } else if (todo == Execute.reduceall) {
175 _openStudy.reduceDocument(_myindex);
178 setMenuProperty(Constants.STUDY_MENU);
179 setTitleProperty(Constants.STUDY_MENU);
180 if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
181 setToolProperty(Constants.STUDY_MENU);
183 setToolProperty(Constants.STANDARD_MENU);
185 setLeftMenuProperty(Constants.STUDY_MENU);
186 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
191 public String doSelectKnowledge() {
192 _openStudy = getOpenStudy();
193 Execute todo = Execute.valueOf(_action);
194 if (todo == Execute.develop) {
195 _openStudy.developKnowledge(_myindex);
196 } else if (todo == Execute.reduce) {
197 _openStudy.reduceKnowledge(_myindex);
200 setMenuProperty(Constants.STUDY_MENU);
201 setTitleProperty(Constants.STUDY_MENU);
202 if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
203 setToolProperty(Constants.STUDY_MENU);
205 setToolProperty(Constants.STANDARD_MENU);
207 setLeftMenuProperty(Constants.STUDY_MENU);
208 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
213 public String doClose() {
216 setMenuProperty("none");
217 initializationScreenContext(_menuProperty);
222 // ==============================================================================================================================
224 // ==============================================================================================================================
226 public String getAction() {
230 public List<DocumentFacade> getDocuments() {
231 return _openStudy.getDisplayedDocuments();
234 public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
235 return _openStudy.getDisplayedKnowledges();
238 public List<SimulationContextFacade> getSimulationContexts() {
239 return _openStudy.getDisplayedSimulationContexts();
242 public PopupMenu getPopup() {
243 return _openStudy.getPopup();
246 public int getStepNumber() {
247 return _openStudy.getSelectedStep().getNumber();
250 public String getStepEnabled() {
251 return String.valueOf(_openStudy.isStepEnabled());
254 public StepRights getUserRights() {
255 return _openStudy.getSelectedStepRights();
259 public String getWriteAccess() {
260 return String.valueOf(_openStudy.isOpenForWriting());
264 * Get the studyService.
266 * @return the studyService
268 public StudyService getStudyService() {
269 return _studyService;
273 * Set the studyService.
275 * @param studyService
276 * the studyService to set
278 public void setStudyService(final StudyService studyService) {
279 _studyService = studyService;
285 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
288 public void setOpenStudy(final OpenStudy study) {
289 super.setOpenStudy(study);
294 * Get the menuProperty.
295 * @return the menuProperty
297 public String getMenuProperty() {
298 return _menuProperty;
302 * Set the menuProperty.
303 * @param menuProperty the menuProperty to set
305 public void setMenuProperty(final String menuProperty) {
306 this._menuProperty = menuProperty;
310 * Get the _titleProperty.
311 * @return the _titleProperty
313 public String getTitleProperty() {
314 return _titleProperty;
318 * Set the _titleProperty.
319 * @param _titleProperty the titleProperty to set
321 public void setTitleProperty(final String titleProperty) {
322 _titleProperty = titleProperty;
326 * Get the editDisabledProperty.
327 * @return the editDisabledProperty
329 public String getEditDisabledProperty() {
330 return _editDisabledProperty;
334 * Set the editDisabledProperty.
335 * @param editDisabledProperty the editDisabledProperty to set
337 public void setEditDisabledProperty(final String editDisabledProperty) {
338 _editDisabledProperty = editDisabledProperty;
342 * Get the toolProperty.
343 * @return the toolProperty
345 public String getToolProperty() {
346 return _toolProperty;
350 * Set the toolProperty.
351 * @param toolProperty the toolProperty to set
353 public void setToolProperty(final String toolProperty) {
354 _toolProperty = toolProperty;
358 * Get the leftMenuProperty.
359 * @return the leftMenuProperty
361 public String getLeftMenuProperty() {
362 return _leftMenuProperty;
366 * Set the leftMenuProperty.
367 * @param leftMenuProperty the leftMenuProperty to set
369 public void setLeftMenuProperty(final String leftMenuProperty) {
370 _leftMenuProperty = leftMenuProperty;