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.som.StepRights;
11 import org.splat.dal.bo.som.Study;
12 import org.splat.wapp.PopupMenu;
13 import org.splat.wapp.SimpleMenu;
16 public class DisplayStudyStepAction extends DisplayBaseAction {
18 protected OpenStudy mystudy = null; // Presented study
20 private static final long serialVersionUID = 6467920934724352021L;
22 // ==============================================================================================================================
24 // ==============================================================================================================================
26 public String doOpen () {
27 // -----------------------
28 Session connex = Database.getSession();
29 Transaction transax = connex.beginTransaction();
32 mystudy = getOpenStudy();
33 if (myindex != null) try { // Opening a study from the search result
34 int index = Integer.valueOf(myindex);
35 if (mystudy != null && mystudy.getIndex() == index) { // - The selected study is currently open
36 selection = mystudy.getSelection(); // Current selection
37 study = mystudy.getStudyObject(); // Current Study object
38 } else { // - The selected study is new
39 study = Database.selectStudy(index);
40 mystudy = open(study);
41 selection = mystudy.getSelection(); // Default selection
44 catch (Exception error) {
45 logger.error("Reason:", error);
48 else if (selection == null) { // Opening a study just newed
49 selection = mystudy.getSelection(); // Default selection
50 study = mystudy.getStudyObject();
52 else { // Re-opening (refreshing) the currently open study
53 study = Database.selectStudy(mystudy.getIndex());
54 mystudy = open(study); // Closes the previously open study
55 mystudy.setSelection(selection);
57 // Initialization of menus
58 ProjectElement owner = mystudy.getSelectedStep().getOwner();
59 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
60 if (owner instanceof Scenario) {
61 menu.enables("prop-scenario");
62 menu.selects("prop-scenario");
64 menu.disables("prop-scenario");
65 menu.selects("prop-general");
67 getSession().put("menu.study", mystudy.getMenu());
73 public String doSelectStep () {
74 // -----------------------------
75 Session connex = Database.getSession();
76 Transaction transax = connex.beginTransaction();
78 mystudy = getOpenStudy();
79 if (selection == null) { // Switch back to the current study
80 selection = mystudy.getSelection();
81 } else { // Selection of a step of current study
82 mystudy.setSelection(selection);
84 // Re-initialization of the properties menu according to the selected step
85 ProjectElement owner = mystudy.getSelectedStep().getOwner();
86 SimpleMenu menu = ApplicationSettings.getMenu("configuration");
87 if (owner instanceof Scenario) {
88 menu.enables("prop-scenario");
89 menu.selects("prop-scenario");
91 menu.disables("prop-scenario");
92 menu.selects("prop-general");
98 public String doSelectDocument () {
99 // ---------------------------------
100 mystudy = getOpenStudy();
102 Execute todo = Execute.valueOf(action);
103 if (todo == Execute.develop) mystudy.developDocument(myindex);
104 else if (todo == Execute.reduce) mystudy.reduceHistory(myindex);
105 else if (todo == Execute.reduceall) mystudy.reduceDocument(myindex);
109 public String doSelectKnowledge () {
110 // ----------------------------------
111 mystudy = getOpenStudy();
113 Execute todo = Execute.valueOf(action);
114 if (todo == Execute.develop) mystudy.developKnowledge(myindex);
115 else if (todo == Execute.reduce) mystudy.reduceKnowledge(myindex);
119 public String doClose () {
120 // ------------------------
124 // ==============================================================================================================================
126 // ==============================================================================================================================
128 public String getAction () {
129 // --------------------------
132 public List<DocumentFacade> getDocuments () {
133 // -------------------------------------------
134 return mystudy.getDisplayedDocuments();
136 public List<OpenObject.KnowledgeIterator> getKnowledges () {
137 // ----------------------------------------------------------
138 return mystudy.getDisplayedKnowledges();
140 public List<SimulationContextFacade> getSimulationContexts () {
141 // -------------------------------------------------------------
142 return mystudy.getDisplayedSimulationContexts();
144 public PopupMenu getPopup () {
145 // ----------------------------
146 return mystudy.getPopup();
148 public int getStepNumber () {
149 // ---------------------------
150 return mystudy.getSelectedStep().getNumber();
152 public String getStepEnabled () {
153 // -------------------------------
154 return String.valueOf(mystudy.isStepEnabled());
156 public StepRights getUserRights () {
157 // ----------------------------------
158 return mystudy.getSelectedStepRights();
160 public String getWriteAccess () {
161 // -------------------------------
162 return String.valueOf(mystudy.isOpenForWriting());