Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditScenarioPropertiesAction.java
1 package org.splat.simer;
2
3 import java.text.SimpleDateFormat;
4 import java.util.ResourceBundle;
5
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.splat.dal.bo.kernel.User;
9 import org.splat.dal.dao.som.Database;
10 import org.splat.dal.bo.som.Scenario;
11 import org.splat.service.ProjectElementService;
12 import org.splat.service.ScenarioService;
13 import org.splat.som.Step;
14 import org.splat.som.StepRights;
15
16 public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
17
18         private Scenario myscenario;
19         private String lasdate;
20         private String subject;
21         private ScenarioService _scenarioService;
22         private ProjectElementService _projectElementService;
23
24         private static final long serialVersionUID = 4964740932426016171L;
25
26         // ==============================================================================================================================
27         // Action methods
28         // ==============================================================================================================================
29
30         public String doInitialize() {
31                 // -----------------------------
32                 ResourceBundle label = ResourceBundle.getBundle("labels",
33                                 ApplicationSettings.getCurrentLocale());
34                 ResourceBundle custom = ResourceBundle.getBundle("som",
35                                 ApplicationSettings.getCurrentLocale());
36                 SimpleDateFormat datstring = new SimpleDateFormat(
37                                 custom.getString("date.format")); // Locale date display format
38                 Step step;
39
40                 mystudy = getOpenStudy();
41                 step = mystudy.getSelectedStep();
42                 myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
43                 lasdate = datstring.format(myscenario.getLastModificationDate());
44                 subject = label.getString("label.study") + " " + mystudy.getTitle();
45
46                 return SUCCESS;
47         }
48
49         public String doCheckin() {
50                 // --------------------------
51                 Session connex = Database.getSession();
52                 Transaction transax = connex.beginTransaction();
53                 Step step;
54
55                 mystudy = getOpenStudy();
56                 selection = mystudy.getSelection();
57                 step = mystudy.getSelectedStep();
58                 myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
59
60                 getScenarioService().checkin(myscenario);
61                 transax.commit();
62
63                 mystudy.getMenu().refreshGivenStepItem(
64                                 getProjectElementService().getFirstStep(myscenario)); // For updating the scenario icon
65                 return SUCCESS;
66         }
67
68         // ==============================================================================================================================
69         // Getters
70         // ==============================================================================================================================
71
72         public User getAuthor() {
73                 // ------------------------
74                 if (myscenario.isCheckedout())
75                         return myscenario.getUser();
76                 else
77                         return myscenario.getAuthor();
78         }
79
80         public String getLastModificationDate() {
81                 // ----------------------------------------
82                 return lasdate;
83         }
84
85         public StepRights getSelectedStep() {
86                 // ------------------------------------
87                 return mystudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
88         }
89
90         public String getSubject() {
91                 // ---------------------------
92                 return subject;
93         }
94
95         public String getTitle() {
96                 // -------------------------
97                 return myscenario.getTitle();
98         }
99
100         public boolean isCheckedout() {
101                 // ------------------------------
102                 return myscenario.isCheckedout();
103         }
104
105         /**
106          * Get the scenarioService.
107          * 
108          * @return the scenarioService
109          */
110         public ScenarioService getScenarioService() {
111                 return _scenarioService;
112         }
113
114         /**
115          * Set the scenarioService.
116          * 
117          * @param scenarioService
118          *            the scenarioService to set
119          */
120         public void setScenarioService(ScenarioService scenarioService) {
121                 _scenarioService = scenarioService;
122         }
123
124         /**
125          * Get the projectElementService.
126          * 
127          * @return the projectElementService
128          */
129         public ProjectElementService getProjectElementService() {
130                 return _projectElementService;
131         }
132
133         /**
134          * Set the projectElementService.
135          * 
136          * @param projectElementService
137          *            the projectElementService to set
138          */
139         public void setProjectElementService(
140                         ProjectElementService projectElementService) {
141                 _projectElementService = projectElementService;
142         }
143 }