]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Salome HOME
ab478c7eaa38d8c4a3deb686c6a58f52750cc51e
[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.getCurSession();
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.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")) {
43                   open(study);
44           }
45           //RKV:END
46         } else {                                                // - The selected study is new
47           study     = getStudyService().selectStudy(index);
48           mystudy   = open(study);
49           selection = mystudy.getSelection();                   // Default selection
50         }
51       }
52       catch (Exception error) {
53         logger.error("Reason:", error);
54         return ERROR;
55       }
56       else if (selection == null) {                             // Opening a study just newed
57         selection = mystudy.getSelection();                     // Default selection
58         study     = mystudy.getStudyObject();
59       }
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);
64       }
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");
71       } else {
72         menu.disables("prop-scenario");
73         menu.selects("prop-general");
74       }
75       getSession().put("menu.study", mystudy.getMenu());
76
77       transax.commit();
78       return SUCCESS;
79     }
80     
81     public String doSelectStep () {
82 //  -----------------------------
83       Session      connex  = Database.getCurSession();
84       Transaction  transax = connex.beginTransaction();
85
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);
91       }
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");
98       } else {
99         menu.disables("prop-scenario");
100         menu.selects("prop-general");
101       }
102       transax.commit();
103       return SUCCESS;
104     }
105
106     public String doSelectDocument () {
107 //  ---------------------------------
108       mystudy = getOpenStudy();
109
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);
114       return SUCCESS;
115     }
116
117     public String doSelectKnowledge () {
118 //  ----------------------------------
119       mystudy = getOpenStudy();
120
121       Execute  todo = Execute.valueOf(action);
122       if      (todo == Execute.develop)   mystudy.developKnowledge(myindex);
123       else if (todo == Execute.reduce)    mystudy.reduceKnowledge(myindex);
124       return SUCCESS;
125     }
126
127     public String doClose () {
128 //  ------------------------
129       closeStudy();
130       return SUCCESS;
131     }
132 //  ==============================================================================================================================
133 //  Getters
134 //  ==============================================================================================================================
135
136     public String getAction () {
137 //  --------------------------
138       return action;
139     }
140     public List<DocumentFacade> getDocuments () {
141 //  -------------------------------------------
142       return mystudy.getDisplayedDocuments();
143     }
144     public List<OpenObject.KnowledgeIterator> getKnowledges () {
145 //  ----------------------------------------------------------
146       return mystudy.getDisplayedKnowledges();
147     }
148     public List<SimulationContextFacade> getSimulationContexts () {
149 //  -------------------------------------------------------------
150       return mystudy.getDisplayedSimulationContexts();
151     }
152     public PopupMenu getPopup () {
153 //  ----------------------------
154       return mystudy.getPopup();
155     }
156     public int getStepNumber () {
157 //  ---------------------------
158       return mystudy.getSelectedStep().getNumber();
159     }
160     public String getStepEnabled () {
161 //  -------------------------------
162       return String.valueOf(mystudy.isStepEnabled());
163     }
164     public StepRights getUserRights () {
165 //  ----------------------------------
166       return mystudy.getSelectedStepRights();
167     }
168     public String getWriteAccess () {
169 //  -------------------------------
170       return String.valueOf(mystudy.isOpenForWriting());
171     }
172
173         /**
174          * Get the studyService.
175          * 
176          * @return the studyService
177          */
178         public StudyService getStudyService() {
179                 return _studyService;
180         }
181
182         /**
183          * Set the studyService.
184          * 
185          * @param studyService
186          *            the studyService to set
187          */
188         public void setStudyService(StudyService studyService) {
189                 _studyService = studyService;
190         }
191
192         /** 
193          * {@inheritDoc}
194          * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
195          */
196         @Override
197         public void setOpenStudy(OpenStudy study) {
198                 super.setOpenStudy(study);
199                 mystudy = study;
200         }
201 }