]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java
Salome HOME
e29124ff7fe621e1edaeebbdb5665a20aa0d15cc
[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         /**
18          * Serial version ID.
19          */
20         private static final long serialVersionUID = 4964740932426016171L;
21
22         private transient Scenario _myscenario;
23         private transient String _lasdate;
24         private transient String _subject;
25
26         /**
27          * The Scenario service.
28          */
29         private ScenarioService _scenarioService;
30
31         /**
32          * The PojectElement service.
33          */
34         private ProjectElementService _projectElementService;
35
36         // ==============================================================================================================================
37         // Action methods
38         // ==============================================================================================================================
39
40         public String doInitialize() {
41                 ResourceBundle label = ResourceBundle.getBundle("labels",
42                                 getApplicationSettings().getCurrentLocale());
43                 ResourceBundle custom = ResourceBundle.getBundle("som",
44                                 getApplicationSettings().getCurrentLocale());
45                 SimpleDateFormat datstring = new SimpleDateFormat(custom
46                                 .getString("date.format")); // Locale date display format
47                 Step step;
48
49                 _openStudy = getOpenStudy();
50                 step = _openStudy.getSelectedStep();
51                 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
52                 _lasdate = datstring.format(_myscenario.getLastModificationDate());
53                 _subject = label.getString("label.study") + " " + _openStudy.getTitle();
54
55                 initializationFullScreenContext(Constants.STUDY_MENU,
56                                 Constants.STUDY_MENU, "true", "back", "open");
57
58                 return SUCCESS;
59         }
60
61         /**
62          * Mark the scenario as checked in.
63          * 
64          * @return SUCCESS
65          * @throws InvalidPropertyException
66          *             if scenario is not found in the database
67          */
68         public String doCheckin() throws InvalidPropertyException {
69                 Step step;
70
71                 _openStudy = getOpenStudy();
72                 _selection = _openStudy.getSelection();
73                 step = _openStudy.getSelectedStep();
74                 _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
75
76                 getScenarioService().checkin(_myscenario.getIndex());
77                 // TODO: Do it in the business service after moving to DTO instead of id parameter
78                 // or reread the scenario.
79                 _myscenario.setUser(null);
80
81                 _openStudy.getMenu().refreshGivenStepItem(
82                                 getProjectElementService().getFirstStep(_myscenario)); // For updating the scenario icon
83
84                 if ("true".equals(getWriteAccess())
85                                 && getUserRights().canCreateDocument()) {
86                         setToolProperty(Constants.STUDY_MENU);
87                 } else {
88                         setToolProperty(Constants.STANDARD_MENU);
89                 }
90                 initializationFullScreenContext(Constants.STUDY_MENU,
91                                 getToolProperty(), Constants.STUDY_MENU);
92
93                 return SUCCESS;
94         }
95
96         // ==============================================================================================================================
97         // Getters
98         // ==============================================================================================================================
99
100         /**
101          * Get current scenario editor or author if the scenario is not checked out.
102          * 
103          * @return the scenario editor or author
104          */
105         public User getAuthor() {
106                 User author;
107                 if (_myscenario.isCheckedout()) {
108                         author = _myscenario.getUser();
109                 } else {
110                         author = _myscenario.getAuthor();
111                 }
112                 return author;
113         }
114
115         public String getLastModificationDate() {
116                 return _lasdate;
117         }
118
119         public StepRights getSelectedStep() {
120                 return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
121         }
122
123         public String getSubject() {
124                 return _subject;
125         }
126
127         public String getTitle() {
128                 return _myscenario.getTitle();
129         }
130
131         public boolean isCheckedout() {
132                 return _myscenario.isCheckedout();
133         }
134
135         /**
136          * Get the scenarioService.
137          * 
138          * @return the scenarioService
139          */
140         public ScenarioService getScenarioService() {
141                 return _scenarioService;
142         }
143
144         /**
145          * Set the scenarioService.
146          * 
147          * @param scenarioService
148          *            the scenarioService to set
149          */
150         public void setScenarioService(final ScenarioService scenarioService) {
151                 _scenarioService = scenarioService;
152         }
153
154         /**
155          * Get the projectElementService.
156          * 
157          * @return the projectElementService
158          */
159         public ProjectElementService getProjectElementService() {
160                 return _projectElementService;
161         }
162
163         /**
164          * Set the projectElementService.
165          * 
166          * @param projectElementService
167          *            the projectElementService to set
168          */
169         public void setProjectElementService(
170                         final ProjectElementService projectElementService) {
171                 _projectElementService = projectElementService;
172         }
173 }