Salome HOME
e2094b9b6ea8e8c9650f46612e2024bf21a4f9ff
[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.splat.dal.bo.kernel.User;
7 import org.splat.dal.bo.som.Scenario;
8 import org.splat.kernel.InvalidPropertyException;
9 import org.splat.service.ProjectElementService;
10 import org.splat.service.ScenarioService;
11 import org.splat.som.Step;
12 import org.splat.som.StepRights;
13 import org.splat.wapp.Constants;
14
15 public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
16
17         private Scenario myscenario;
18         private String lasdate;
19         private String subject;
20
21         /**
22          * The Scenario service.
23          */
24         private ScenarioService _scenarioService;
25
26         /**
27          * The PojectElement service.
28          */
29         private ProjectElementService _projectElementService;
30
31         /**
32          * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
33          */
34         private String _menuProperty;
35
36         /**
37          * Value of the title bar property. It can be: study, knowledge.
38          */
39         private String _titleProperty;
40
41         /**
42          * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
43          * menu also can be called. It is necessary for correct building the title bar.
44          */
45         private String _editDisabledProperty = "false";
46
47         /**
48          * Value of the tool bar property. It can be: none, standard, study, back.
49          */
50         private String _toolProperty;
51
52         /**
53          * Value of the left menu property. It can be: open, study, knowledge, scenario.
54          */
55         private String _leftMenuProperty;
56
57         /**
58          * Serial version ID.
59          */
60         private static final long serialVersionUID = 4964740932426016171L;
61
62         // ==============================================================================================================================
63         // Action methods
64         // ==============================================================================================================================
65
66         public String doInitialize() {
67                 // -----------------------------
68                 ResourceBundle label = ResourceBundle.getBundle("labels",
69                                 getApplicationSettings().getCurrentLocale());
70                 ResourceBundle custom = ResourceBundle.getBundle("som",
71                                 getApplicationSettings().getCurrentLocale());
72                 SimpleDateFormat datstring = new SimpleDateFormat(custom
73                                 .getString("date.format")); // Locale date display format
74                 Step step;
75
76                 _openStudy = getOpenStudy();
77                 step = _openStudy.getSelectedStep();
78                 myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
79                 lasdate = datstring.format(myscenario.getLastModificationDate());
80                 subject = label.getString("label.study") + " " + _openStudy.getTitle();
81
82                 setMenuProperty(Constants.STUDY_MENU);
83                 setTitleProperty(Constants.STUDY_MENU);
84                 setEditDisabledProperty("true");
85                 setToolProperty("back");
86                 setLeftMenuProperty("open");
87                 initializationFullScreenContext(_menuProperty, _titleProperty,
88                                 _editDisabledProperty, _toolProperty, _leftMenuProperty);
89
90                 return SUCCESS;
91         }
92
93         /**
94          * Mark the scenario as checked in.
95          * 
96          * @return SUCCESS
97          * @throws InvalidPropertyException
98          *             if scenario is not found in the database
99          */
100         public String doCheckin() throws InvalidPropertyException {
101                 Step step;
102
103                 _openStudy = getOpenStudy();
104                 _selection = _openStudy.getSelection();
105                 step = _openStudy.getSelectedStep();
106                 myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
107
108                 getScenarioService().checkin(myscenario.getIndex());
109                 // TODO: Do it in the business service after moving to DTO instead of id parameter
110                 // or reread the scenario.
111                 myscenario.setUser(null);
112
113                 _openStudy.getMenu().refreshGivenStepItem(
114                                 getProjectElementService().getFirstStep(myscenario)); // For updating the scenario icon
115
116                 setMenuProperty(Constants.STUDY_MENU);
117                 if ("true".equals(getWriteAccess())
118                                 && getUserRights().canCreateDocument()) {
119                         setToolProperty(Constants.STUDY_MENU);
120                 } else {
121                         setToolProperty("standard");
122                 }
123                 setLeftMenuProperty(Constants.STUDY_MENU);
124                 initializationFullScreenContext(_menuProperty, _toolProperty,
125                                 _leftMenuProperty);
126
127                 return SUCCESS;
128         }
129
130         // ==============================================================================================================================
131         // Getters
132         // ==============================================================================================================================
133
134         /**
135          * Get current scenario editor or author if the scenario is not checked out.
136          * 
137          * @return the scenario editor or author
138          */
139         public User getAuthor() {
140                 User author;
141                 if (myscenario.isCheckedout()) {
142                         author = myscenario.getUser();
143                 } else {
144                         author = myscenario.getAuthor();
145                 }
146                 return author;
147         }
148
149         public String getLastModificationDate() {
150                 return lasdate;
151         }
152
153         public StepRights getSelectedStep() {
154                 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
155         }
156
157         public String getSubject() {
158                 return subject;
159         }
160
161         public String getTitle() {
162                 return myscenario.getTitle();
163         }
164
165         public boolean isCheckedout() {
166                 return myscenario.isCheckedout();
167         }
168
169         /**
170          * Get the scenarioService.
171          * 
172          * @return the scenarioService
173          */
174         public ScenarioService getScenarioService() {
175                 return _scenarioService;
176         }
177
178         /**
179          * Set the scenarioService.
180          * 
181          * @param scenarioService
182          *            the scenarioService to set
183          */
184         public void setScenarioService(final ScenarioService scenarioService) {
185                 _scenarioService = scenarioService;
186         }
187
188         /**
189          * Get the projectElementService.
190          * 
191          * @return the projectElementService
192          */
193         public ProjectElementService getProjectElementService() {
194                 return _projectElementService;
195         }
196
197         /**
198          * Set the projectElementService.
199          * 
200          * @param projectElementService
201          *            the projectElementService to set
202          */
203         public void setProjectElementService(
204                         final ProjectElementService projectElementService) {
205                 _projectElementService = projectElementService;
206         }
207
208         /**
209          * Get the menuProperty.
210          * 
211          * @return the menuProperty
212          */
213         @Override
214         public String getMenuProperty() {
215                 return _menuProperty;
216         }
217
218         /**
219          * Set the menuProperty.
220          * 
221          * @param menuProperty
222          *            the menuProperty to set
223          */
224         @Override
225         public void setMenuProperty(final String menuProperty) {
226                 this._menuProperty = menuProperty;
227         }
228
229         /**
230          * Get the _titleProperty.
231          * 
232          * @return the _titleProperty
233          */
234         @Override
235         public String getTitleProperty() {
236                 return _titleProperty;
237         }
238
239         /**
240          * Set the _titleProperty.
241          * 
242          * @param _titleProperty
243          *            the titleProperty to set
244          */
245         @Override
246         public void setTitleProperty(final String titleProperty) {
247                 _titleProperty = titleProperty;
248         }
249
250         /**
251          * Get the editDisabledProperty.
252          * 
253          * @return the editDisabledProperty
254          */
255         @Override
256         public final String getEditDisabledProperty() {
257                 return _editDisabledProperty;
258         }
259
260         /**
261          * Set the editDisabledProperty.
262          * 
263          * @param editDisabledProperty
264          *            the editDisabledProperty to set
265          */
266         @Override
267         public final void setEditDisabledProperty(final String editDisabledProperty) {
268                 _editDisabledProperty = editDisabledProperty;
269         }
270
271         /**
272          * Get the toolProperty.
273          * 
274          * @return the toolProperty
275          */
276         @Override
277         public String getToolProperty() {
278                 return _toolProperty;
279         }
280
281         /**
282          * Set the toolProperty.
283          * 
284          * @param toolProperty
285          *            the toolProperty to set
286          */
287         @Override
288         public void setToolProperty(final String toolProperty) {
289                 _toolProperty = toolProperty;
290         }
291
292         /**
293          * Get the leftMenuProperty.
294          * 
295          * @return the leftMenuProperty
296          */
297         @Override
298         public String getLeftMenuProperty() {
299                 return _leftMenuProperty;
300         }
301
302         /**
303          * Set the leftMenuProperty.
304          * 
305          * @param leftMenuProperty
306          *            the leftMenuProperty to set
307          */
308         @Override
309         public void setLeftMenuProperty(final String leftMenuProperty) {
310                 _leftMenuProperty = leftMenuProperty;
311         }
312 }