]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Salome HOME
b2d468c878facb70c850d7bfa2448c5da8eb4408
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / DisplayStudyStepAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4
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;
15
16
17 public class DisplayStudyStepAction extends DisplayBaseAction {
18
19         protected OpenStudy   mystudy = null;    // Presented study
20
21         private StudyService _studyService;
22
23         private static final long serialVersionUID = 6467920934724352021L;
24
25 //  ==============================================================================================================================
26 //  Action methods
27 //  ==============================================================================================================================
28
29     public String doOpen () {
30 //  -----------------------
31       Session      connex  = Database.getSession();
32       Transaction  transax = connex.beginTransaction();
33       Study        study;
34
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
45         }
46       }
47       catch (Exception error) {
48         logger.error("Reason:", error);
49         return ERROR;
50       }
51       else if (selection == null) {                             // Opening a study just newed
52         selection = mystudy.getSelection();                     // Default selection
53         study     = mystudy.getStudyObject();
54       }
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);
59       }
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");
66       } else {
67         menu.disables("prop-scenario");
68         menu.selects("prop-general");
69       }
70       getSession().put("menu.study", mystudy.getMenu());
71
72       transax.commit();
73       return SUCCESS;
74     }
75     
76     public String doSelectStep () {
77 //  -----------------------------
78       Session      connex  = Database.getSession();
79       Transaction  transax = connex.beginTransaction();
80
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);
86       }
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");
93       } else {
94         menu.disables("prop-scenario");
95         menu.selects("prop-general");
96       }
97       transax.commit();
98       return SUCCESS;
99     }
100
101     public String doSelectDocument () {
102 //  ---------------------------------
103       mystudy = getOpenStudy();
104
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);
109       return SUCCESS;
110     }
111
112     public String doSelectKnowledge () {
113 //  ----------------------------------
114       mystudy = getOpenStudy();
115
116       Execute  todo = Execute.valueOf(action);
117       if      (todo == Execute.develop)   mystudy.developKnowledge(myindex);
118       else if (todo == Execute.reduce)    mystudy.reduceKnowledge(myindex);
119       return SUCCESS;
120     }
121
122     public String doClose () {
123 //  ------------------------
124       closeStudy();
125       return SUCCESS;
126     }
127 //  ==============================================================================================================================
128 //  Getters
129 //  ==============================================================================================================================
130
131     public String getAction () {
132 //  --------------------------
133       return action;
134     }
135     public List<DocumentFacade> getDocuments () {
136 //  -------------------------------------------
137       return mystudy.getDisplayedDocuments();
138     }
139     public List<OpenObject.KnowledgeIterator> getKnowledges () {
140 //  ----------------------------------------------------------
141       return mystudy.getDisplayedKnowledges();
142     }
143     public List<SimulationContextFacade> getSimulationContexts () {
144 //  -------------------------------------------------------------
145       return mystudy.getDisplayedSimulationContexts();
146     }
147     public PopupMenu getPopup () {
148 //  ----------------------------
149       return mystudy.getPopup();
150     }
151     public int getStepNumber () {
152 //  ---------------------------
153       return mystudy.getSelectedStep().getNumber();
154     }
155     public String getStepEnabled () {
156 //  -------------------------------
157       return String.valueOf(mystudy.isStepEnabled());
158     }
159     public StepRights getUserRights () {
160 //  ----------------------------------
161       return mystudy.getSelectedStepRights();
162     }
163     public String getWriteAccess () {
164 //  -------------------------------
165       return String.valueOf(mystudy.isOpenForWriting());
166     }
167
168         /**
169          * Get the studyService.
170          * 
171          * @return the studyService
172          */
173         public StudyService getStudyService() {
174                 return _studyService;
175         }
176
177         /**
178          * Set the studyService.
179          * 
180          * @param studyService
181          *            the studyService to set
182          */
183         public void setStudyService(StudyService studyService) {
184                 _studyService = studyService;
185         }
186 }