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.getSession();
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.getIndex() == index) { // - The selected study is currently open
39 selection = mystudy.getSelection(); // Current selection
40 study = mystudy.getStudyObject(); // Current Study object
41 } else { // - The selected study is new
42 study = getStudyService().selectStudy(index);
43 mystudy = open(study);
44 selection = mystudy.getSelection(); // Default selection
47 catch (Exception error) {
48 logger.error("Reason:", error);
51 else if (selection == null) { // Opening a study just newed
52 selection = mystudy.getSelection(); // Default selection
53 study = mystudy.getStudyObject();
55 else { // Re-opening (refreshing) the currently open study
56 study = getStudyService().selectStudy(mystudy.getIndex());
57 mystudy = open(study); // Closes the previously open study
58 mystudy.setSelection(selection);
60 // Initialization of menus
61 ProjectElement owner = mystudy.getSelectedStep().getOwner();
62 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
63 if (owner instanceof Scenario) {
64 menu.enables("prop-scenario");
65 menu.selects("prop-scenario");
67 menu.disables("prop-scenario");
68 menu.selects("prop-general");
70 getSession().put("menu.study", mystudy.getMenu());
76 public String doSelectStep () {
77 // -----------------------------
78 Session connex = Database.getSession();
79 Transaction transax = connex.beginTransaction();
81 mystudy = getOpenStudy();
82 if (selection == null) { // Switch back to the current study
83 selection = mystudy.getSelection();
84 } else { // Selection of a step of current study
85 mystudy.setSelection(selection);
87 // Re-initialization of the properties menu according to the selected step
88 ProjectElement owner = mystudy.getSelectedStep().getOwner();
89 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
90 if (owner instanceof Scenario) {
91 menu.enables("prop-scenario");
92 menu.selects("prop-scenario");
94 menu.disables("prop-scenario");
95 menu.selects("prop-general");
101 public String doSelectDocument () {
102 // ---------------------------------
103 mystudy = getOpenStudy();
105 Execute todo = Execute.valueOf(action);
106 if (todo == Execute.develop) mystudy.developDocument(myindex);
107 else if (todo == Execute.reduce) mystudy.reduceHistory(myindex);
108 else if (todo == Execute.reduceall) mystudy.reduceDocument(myindex);
112 public String doSelectKnowledge () {
113 // ----------------------------------
114 mystudy = getOpenStudy();
116 Execute todo = Execute.valueOf(action);
117 if (todo == Execute.develop) mystudy.developKnowledge(myindex);
118 else if (todo == Execute.reduce) mystudy.reduceKnowledge(myindex);
122 public String doClose () {
123 // ------------------------
127 // ==============================================================================================================================
129 // ==============================================================================================================================
131 public String getAction () {
132 // --------------------------
135 public List<DocumentFacade> getDocuments () {
136 // -------------------------------------------
137 return mystudy.getDisplayedDocuments();
139 public List<OpenObject.KnowledgeIterator> getKnowledges () {
140 // ----------------------------------------------------------
141 return mystudy.getDisplayedKnowledges();
143 public List<SimulationContextFacade> getSimulationContexts () {
144 // -------------------------------------------------------------
145 return mystudy.getDisplayedSimulationContexts();
147 public PopupMenu getPopup () {
148 // ----------------------------
149 return mystudy.getPopup();
151 public int getStepNumber () {
152 // ---------------------------
153 return mystudy.getSelectedStep().getNumber();
155 public String getStepEnabled () {
156 // -------------------------------
157 return String.valueOf(mystudy.isStepEnabled());
159 public StepRights getUserRights () {
160 // ----------------------------------
161 return mystudy.getSelectedStepRights();
163 public String getWriteAccess () {
164 // -------------------------------
165 return String.valueOf(mystudy.isOpenForWriting());
169 * Get the studyService.
171 * @return the studyService
173 public StudyService getStudyService() {
174 return _studyService;
178 * Set the studyService.
180 * @param studyService
181 * the studyService to set
183 public void setStudyService(StudyService studyService) {
184 _studyService = studyService;