Salome HOME
SIMAN Eclipse workspace first version
[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.som.Database;
8 import org.splat.som.ProjectElement;
9 import org.splat.som.Scenario;
10 import org.splat.som.StepRights;
11 import org.splat.som.Study;
12 import org.splat.wapp.PopupMenu;
13 import org.splat.wapp.SimpleMenu;
14
15
16 public class DisplayStudyStepAction extends DisplayBaseAction {
17
18         protected OpenStudy   mystudy = null;    // Presented study
19
20         private static final long serialVersionUID = 6467920934724352021L;
21
22 //  ==============================================================================================================================
23 //  Action methods
24 //  ==============================================================================================================================
25
26     public String doOpen () {
27 //  -----------------------
28       Session      connex  = Database.getSession();
29       Transaction  transax = connex.beginTransaction();
30       Study        study;
31
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
42         }
43       }
44       catch (Exception error) {
45         logger.error("Reason:", error);
46         return ERROR;
47       }
48       else if (selection == null) {                             // Opening a study just newed
49         selection = mystudy.getSelection();                     // Default selection
50         study     = mystudy.getStudyObject();
51       }
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);
56       }
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");
63       } else {
64         menu.disables("prop-scenario");
65         menu.selects("prop-general");
66       }
67       getSession().put("menu.study", mystudy.getMenu());
68
69       transax.commit();
70       return SUCCESS;
71     }
72     
73     public String doSelectStep () {
74 //  -----------------------------
75       Session      connex  = Database.getSession();
76       Transaction  transax = connex.beginTransaction();
77
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);
83       }
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");
90       } else {
91         menu.disables("prop-scenario");
92         menu.selects("prop-general");
93       }
94       transax.commit();
95       return SUCCESS;
96     }
97
98     public String doSelectDocument () {
99 //  ---------------------------------
100       mystudy = getOpenStudy();
101
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);
106       return SUCCESS;
107     }
108
109     public String doSelectKnowledge () {
110 //  ----------------------------------
111       mystudy = getOpenStudy();
112
113       Execute  todo = Execute.valueOf(action);
114       if      (todo == Execute.develop)   mystudy.developKnowledge(myindex);
115       else if (todo == Execute.reduce)    mystudy.reduceKnowledge(myindex);
116       return SUCCESS;
117     }
118
119     public String doClose () {
120 //  ------------------------
121       closeStudy();
122       return SUCCESS;
123     }
124 //  ==============================================================================================================================
125 //  Getters
126 //  ==============================================================================================================================
127
128     public String getAction () {
129 //  --------------------------
130       return action;
131     }
132     public List<DocumentFacade> getDocuments () {
133 //  -------------------------------------------
134       return mystudy.getDisplayedDocuments();
135     }
136     public List<OpenObject.KnowledgeIterator> getKnowledges () {
137 //  ----------------------------------------------------------
138       return mystudy.getDisplayedKnowledges();
139     }
140     public List<SimulationContextFacade> getSimulationContexts () {
141 //  -------------------------------------------------------------
142       return mystudy.getDisplayedSimulationContexts();
143     }
144     public PopupMenu getPopup () {
145 //  ----------------------------
146       return mystudy.getPopup();
147     }
148     public int getStepNumber () {
149 //  ---------------------------
150       return mystudy.getSelectedStep().getNumber();
151     }
152     public String getStepEnabled () {
153 //  -------------------------------
154       return String.valueOf(mystudy.isStepEnabled());
155     }
156     public StepRights getUserRights () {
157 //  ----------------------------------
158       return mystudy.getSelectedStepRights();
159     }
160     public String getWriteAccess () {
161 //  -------------------------------
162       return String.valueOf(mystudy.isOpenForWriting());
163     }
164 }