1 package org.splat.simer;
5 import org.hibernate.Session;
6 import org.hibernate.Transaction;
7 import org.splat.dal.dao.som.Database;
8 import org.splat.dal.bo.som.ProjectElement;
9 import org.splat.dal.bo.som.Scenario;
10 import org.splat.service.StudyService;
11 import org.splat.som.StepRights;
12 import org.splat.dal.bo.som.Study;
13 import org.splat.wapp.PopupMenu;
14 import org.splat.wapp.SimpleMenu;
17 public class DisplayStudyStepAction extends DisplayBaseAction {
19 protected OpenStudy mystudy = null; // Presented study
21 private StudyService _studyService;
23 private static final long serialVersionUID = 6467920934724352021L;
25 // ==============================================================================================================================
27 // ==============================================================================================================================
29 public String doOpen () {
30 // -----------------------
31 Session connex = Database.getCurSession();
32 Transaction transax = connex.beginTransaction();
35 mystudy = getOpenStudy();
36 if (myindex != null) try { // Opening a study from the search result
37 int index = Integer.valueOf(myindex);
38 if (mystudy != null && mystudy.getStudyObject() != null && mystudy.getIndex() == index) { // - The selected study is currently open
39 selection = mystudy.getSelection(); // Current selection
40 study = mystudy.getStudyObject(); // Current Study object
41 //RKV:BEGIN: put in session if necessary
42 if (!getSession().containsKey("study.open")) {
46 } else { // - The selected study is new
47 study = getStudyService().selectStudy(index);
48 mystudy = open(study);
49 selection = mystudy.getSelection(); // Default selection
52 catch (Exception error) {
53 logger.error("Reason:", error);
56 else if (selection == null) { // Opening a study just newed
57 selection = mystudy.getSelection(); // Default selection
58 study = mystudy.getStudyObject();
60 else { // Re-opening (refreshing) the currently open study
61 study = getStudyService().selectStudy(mystudy.getIndex());
62 mystudy = open(study); // Closes the previously open study
63 mystudy.setSelection(selection);
65 // Initialization of menus
66 ProjectElement owner = mystudy.getSelectedStep().getOwner();
67 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
68 if (owner instanceof Scenario) {
69 menu.enables("prop-scenario");
70 menu.selects("prop-scenario");
72 menu.disables("prop-scenario");
73 menu.selects("prop-general");
75 getSession().put("menu.study", mystudy.getMenu());
81 public String doSelectStep () {
82 // -----------------------------
83 Session connex = Database.getCurSession();
84 Transaction transax = connex.beginTransaction();
86 mystudy = getOpenStudy();
87 if (selection == null) { // Switch back to the current study
88 selection = mystudy.getSelection();
89 } else { // Selection of a step of current study
90 mystudy.setSelection(selection);
92 // Re-initialization of the properties menu according to the selected step
93 ProjectElement owner = mystudy.getSelectedStep().getOwner();
94 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
95 if (owner instanceof Scenario) {
96 menu.enables("prop-scenario");
97 menu.selects("prop-scenario");
99 menu.disables("prop-scenario");
100 menu.selects("prop-general");
106 public String doSelectDocument () {
107 // ---------------------------------
108 mystudy = getOpenStudy();
110 Execute todo = Execute.valueOf(action);
111 if (todo == Execute.develop) mystudy.developDocument(myindex);
112 else if (todo == Execute.reduce) mystudy.reduceHistory(myindex);
113 else if (todo == Execute.reduceall) mystudy.reduceDocument(myindex);
117 public String doSelectKnowledge () {
118 // ----------------------------------
119 mystudy = getOpenStudy();
121 Execute todo = Execute.valueOf(action);
122 if (todo == Execute.develop) mystudy.developKnowledge(myindex);
123 else if (todo == Execute.reduce) mystudy.reduceKnowledge(myindex);
127 public String doClose () {
128 // ------------------------
132 // ==============================================================================================================================
134 // ==============================================================================================================================
136 public String getAction () {
137 // --------------------------
140 public List<DocumentFacade> getDocuments () {
141 // -------------------------------------------
142 return mystudy.getDisplayedDocuments();
144 public List<OpenObject.KnowledgeIterator> getKnowledges () {
145 // ----------------------------------------------------------
146 return mystudy.getDisplayedKnowledges();
148 public List<SimulationContextFacade> getSimulationContexts () {
149 // -------------------------------------------------------------
150 return mystudy.getDisplayedSimulationContexts();
152 public PopupMenu getPopup () {
153 // ----------------------------
154 return mystudy.getPopup();
156 public int getStepNumber () {
157 // ---------------------------
158 return mystudy.getSelectedStep().getNumber();
160 public String getStepEnabled () {
161 // -------------------------------
162 return String.valueOf(mystudy.isStepEnabled());
164 public StepRights getUserRights () {
165 // ----------------------------------
166 return mystudy.getSelectedStepRights();
168 public String getWriteAccess () {
169 // -------------------------------
170 return String.valueOf(mystudy.isOpenForWriting());
174 * Get the studyService.
176 * @return the studyService
178 public StudyService getStudyService() {
179 return _studyService;
183 * Set the studyService.
185 * @param studyService
186 * the studyService to set
188 public void setStudyService(StudyService studyService) {
189 _studyService = studyService;
194 * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
197 public void setOpenStudy(OpenStudy study) {
198 super.setOpenStudy(study);