]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java
Salome HOME
Left menu is improved
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditKnowledgeElementAction.java
1 package org.splat.simer;
2
3 import org.splat.dal.bo.kernel.User;
4 import org.splat.dal.bo.som.KnowledgeElement;
5 import org.splat.dal.bo.som.KnowledgeElementType;
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.service.KnowledgeElementService;
8 import org.splat.service.KnowledgeElementTypeService;
9 import org.splat.service.ScenarioService;
10 import org.splat.som.Step;
11
12 /**
13  * Action for addition and modification of knowledge elements in the selected scenario.
14  */
15 public class EditKnowledgeElementAction extends DisplayStudyStepAction {
16
17         /**
18          * Serial version ID.
19          */
20         private static final long serialVersionUID = 4636919137087687068L;
21
22         /**
23          * Edited knowledge element type.
24          */
25         private String type = null; // Edited knowledge type
26         /**
27          * Edited knowledge element title.
28          */
29         private String title = null;
30         /**
31          * Edited knowledge element value.
32          */
33         private String value = null;
34         /**
35          * Injected scenario service.
36          */
37         private ScenarioService _scenarioService;
38         /**
39          * Injected knowledge element service.
40          */
41         private KnowledgeElementService _knowledgeElementService;
42         /**
43          * Injected knowledge element type service.
44          */
45         private KnowledgeElementTypeService _knowledgeElementTypeService;
46
47         /**
48          * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
49          */
50         private String _menuProperty;
51
52         /**
53          * Value of the title bar property. 
54          * It can be: study, knowledge.
55          */
56         private String _titleProperty;
57
58         /**
59          * Property that indicates whether the current open study is editable or not.
60          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
61          * It is necessary for correct building the title bar.
62          */
63         private String _editDisabledProperty = "false";
64
65         /**
66          * Value of the tool bar property. 
67          * It can be: none, standard, study, back.
68          */
69         private String _toolProperty;
70         
71         /**
72          * Value of the left menu property. 
73          * It can be: open, study, knowledge, scenario.
74          */
75         private String _leftMenuProperty;
76
77         // ==============================================================================================================================
78         // Action methods
79         // ==============================================================================================================================
80
81         /**
82          * Initialize the action. Get selected study from the session.
83          * 
84          * @return SUCCESS if no exceptions
85          */
86         public String doInitialize() {
87                 mystudy = getOpenStudy();
88
89                 setMenuProperty("study");
90                 setTitleProperty("study");
91                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
92                         setToolProperty("study");
93                 } else {
94                         setToolProperty("standard");
95                 }
96                 setLeftMenuProperty("study");
97                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
98
99                 return SUCCESS;
100         }
101
102         /**
103          * Add a new or update an existing knowledge element of the selected scenario in the open study.
104          * 
105          * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
106          */
107         public String doSetKnowledge() {
108
109                 setMenuProperty("study");
110                 setTitleProperty("study");
111                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
112                         setToolProperty("study");
113                 } else {
114                         setToolProperty("standard");
115                 }
116                 setLeftMenuProperty("study");
117                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
118
119                 try {
120                         User user = getConnectedUser();
121                         mystudy = getOpenStudy();
122
123                         Step step = mystudy.getSelectedStep();
124                         Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
125
126                         if (title != null && value != null) { // Addition of a new Knowledge Element
127                                 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
128                                 KnowledgeElementType ktype = getKnowledgeElementTypeService()
129                                                 .selectType(Integer.valueOf(type));
130                                 kprop.setType(ktype).setTitle(title).setValue(value).setAuthor(
131                                                 user);
132                                 mystudy.add(getScenarioService().addKnowledgeElement(scene,
133                                                 kprop));
134                                 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
135                         } else if (title != null) { // Renaming of an existing Knowledge Element
136                                 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
137                                                 .valueOf(type));
138                                 getKnowledgeElementService().rename(kelm, title);
139                                 // Useless to update the open study
140                         } else if (value != null) { // Edition of a knowledge
141                                 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
142                                                 .valueOf(type));
143                                 getKnowledgeElementService().update(kelm, value);
144                                 mystudy.update(kelm); // For updating the truncated value
145                         }
146                         return SUCCESS;
147                 } catch (RuntimeException saverror) {
148                         logger.error("Reason:", saverror);
149                         return ERROR;
150                 } catch (Exception error) {
151                         logger.error("Exception while saving a knowledge: ", error);
152                         return INPUT;
153                 }
154         }
155
156         /**
157          * Delete a knowledge element from the current scenario.
158          * 
159          * @return SUCCESS if no exceptions
160          */
161         public String doDeleteKnowledge() {
162                 mystudy = getOpenStudy();
163                 Step step = mystudy.getSelectedStep();
164                 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
165
166                 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
167                                 .valueOf(myindex));
168                 getScenarioService().removeKnowledgeElement(scene, kelm); // The knowledge element necessarily exists
169
170                 mystudy.remove(kelm);
171                 updateMenu();
172
173                 return SUCCESS;
174         }
175
176         /**
177          * Promote a knowledge element from the current scenario.
178          * 
179          * @return SUCCESS if no exceptions
180          */
181         public String doPromoteKnowledge() {
182                 getKnowledgeElementService().promote(getKnowledgeElement()); // The knowledge element necessarily exists
183                 updateMenu();
184                 return SUCCESS;
185         }
186
187         /**
188          * Demote a knowledge element from the current scenario.
189          * 
190          * @return SUCCESS if no exceptions
191          */
192         public String doDemoteKnowledge() {
193                 getKnowledgeElementService().demote(getKnowledgeElement()); // The knowledge element necessarily exists
194                 updateMenu();
195                 return SUCCESS;
196         }
197
198         /**
199          * Get selected knowledge element.
200          * 
201          * @return the selected knowledge element
202          */
203         private KnowledgeElement getKnowledgeElement() {
204                 mystudy = getOpenStudy();
205                 Step step = mystudy.getSelectedStep();
206                 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
207                 return scene.getKnowledgeElement(Integer.valueOf(myindex));
208         }
209
210         /**
211          * Update current menu.
212          */
213         private void updateMenu() {
214                 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
215
216                 setMenuProperty("study");
217                 setTitleProperty("study");
218                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
219                         setToolProperty("study");
220                 } else {
221                         setToolProperty("standard");
222                 }
223                 setLeftMenuProperty("study");
224                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
225
226         }
227
228         // ==============================================================================================================================
229         // Getters and setters
230         // ==============================================================================================================================
231
232         /**
233          * Get the type of the modified knowledge element.
234          * 
235          * @return the knowledge type name
236          */
237         public String getKnowledgeType() {
238                 // ---------------------------------
239                 return type;
240         }
241
242         /**
243          * Get the id of the modified knowledge element.
244          * 
245          * @return the knowledge element id
246          */
247         public String getSelectedKnowledge() {
248                 // -------------------------------------
249                 return myindex;
250         }
251
252         /**
253          * Set the type of the modified knowledge element.
254          * 
255          * @param type
256          *            the knowledge type name
257          */
258         public void setKnowledgeType(String type) {
259                 // ------------------------------------------
260                 this.type = type;
261         }
262
263         /**
264          * Set the title of the modified knowledge element.
265          * 
266          * @param title
267          *            the new knowledge title
268          */
269         public void setKnowledgeTitle(String title) {
270                 // --------------------------------------------
271                 this.title = title;
272         }
273
274         /**
275          * Set the value of the modified knowledge element.
276          * 
277          * @param value
278          *            the knowledge value
279          */
280         public void setKnowledgeValue(String value) {
281                 // --------------------------------------------
282                 this.value = value;
283         }
284
285         /**
286          * Get the scenarioService.
287          * 
288          * @return the scenarioService
289          */
290         public ScenarioService getScenarioService() {
291                 return _scenarioService;
292         }
293
294         /**
295          * Set the scenarioService.
296          * 
297          * @param scenarioService
298          *            the scenarioService to set
299          */
300         public void setScenarioService(ScenarioService scenarioService) {
301                 _scenarioService = scenarioService;
302         }
303
304         /**
305          * Get the knowledgeElementService.
306          * 
307          * @return the knowledgeElementService
308          */
309         public KnowledgeElementService getKnowledgeElementService() {
310                 return _knowledgeElementService;
311         }
312
313         /**
314          * Set the knowledgeElementService.
315          * 
316          * @param knowledgeElementService
317          *            the knowledgeElementService to set
318          */
319         public void setKnowledgeElementService(
320                         KnowledgeElementService knowledgeElementService) {
321                 _knowledgeElementService = knowledgeElementService;
322         }
323
324         /**
325          * Get the knowledgeElementTypeService.
326          * 
327          * @return the knowledgeElementTypeService
328          */
329         public KnowledgeElementTypeService getKnowledgeElementTypeService() {
330                 return _knowledgeElementTypeService;
331         }
332
333         /**
334          * Set the knowledgeElementTypeService.
335          * 
336          * @param knowledgeElementTypeService
337          *            the knowledgeElementTypeService to set
338          */
339         public void setKnowledgeElementTypeService(
340                         KnowledgeElementTypeService knowledgeElementTypeService) {
341                 _knowledgeElementTypeService = knowledgeElementTypeService;
342         }
343
344         /**
345          * Get the menuProperty.
346          * 
347          * @return the menuProperty
348          */
349         public String getMenuProperty() {
350                 return _menuProperty;
351         }
352
353         /**
354          * Set the menuProperty.
355          * 
356          * @param menuProperty
357          *            the menuProperty to set
358          */
359         public void setMenuProperty(final String menuProperty) {
360                 this._menuProperty = menuProperty;
361         }
362
363         /**
364          * Get the _titleProperty.
365          * 
366          * @return the _titleProperty
367          */
368         public String getTitleProperty() {
369                 return _titleProperty;
370         }
371
372         /**
373          * Set the titleProperty.
374          * 
375          * @param titleProperty
376          *            the titleProperty to set
377          */
378         public void setTitleProperty(final String titleProperty) {
379                 _titleProperty = titleProperty;
380         }
381
382         /**
383          * Get the editDisabledProperty.
384          * 
385          * @return the editDisabledProperty
386          */
387         public String getEditDisabledProperty() {
388                 return _editDisabledProperty;
389         }
390
391         /**
392          * Set the editDisabledProperty.
393          * 
394          * @param editDisabledProperty
395          *            the editDisabledProperty to set
396          */
397         public void setEditDisabledProperty(final String editDisabledProperty) {
398                 _editDisabledProperty = editDisabledProperty;
399         }
400
401         /**
402          * Get the toolProperty.
403          * 
404          * @return the toolProperty
405          */
406         public String getToolProperty() {
407                 return _toolProperty;
408         }
409
410         /**
411          * Set the toolProperty.
412          * 
413          * @param toolProperty
414          *            the toolProperty to set
415          */
416         public void setToolProperty(final String toolProperty) {
417                 _toolProperty = toolProperty;
418         }
419
420         /**
421          * Get the leftMenuProperty.
422          * @return the leftMenuProperty
423          */
424         public String getLeftMenuProperty() {
425                 return _leftMenuProperty;
426         }
427
428         /**
429          * Set the leftMenuProperty.
430          * @param leftMenuProperty the leftMenuProperty to set
431          */
432         public void setLeftMenuProperty(final String leftMenuProperty) {
433                 _leftMenuProperty = leftMenuProperty;
434         }
435
436         
437 }