Salome HOME
Show URLs for previous versions of the document's files.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditStudyDescriptionAction.java
1 package org.splat.simer; 
2
3 import org.splat.exception.InvalidParameterException;
4 import org.splat.wapp.PopupMenu;
5
6 /**
7  * Description creation/modification action.
8  */
9 public class EditStudyDescriptionAction extends DisplayStudyStepAction {
10
11         /**
12          * Serial version ID.
13          */
14         private static final long serialVersionUID = 6467920934724352021L;
15         
16         /**
17          * Study description.
18          */
19         private String _descriptionValue;
20         
21         /**
22          * Description popup menu.
23          */
24         private transient PopupMenu _descriptionPopup = null;
25         
26         /**
27          * Study id.
28          */
29         private Long _studyId;
30         
31         /**
32          * Loads description (if already loaded - reloads).
33          * @return SUCCESS
34          */
35         public String doDisplayDescription() {
36                 try {
37                         _descriptionValue = getStudyService().getDescription(getOpenStudy().getIndex());
38                         _descriptionPopup = getApplicationSettings().getPopupMenu("description");
39                 } catch(InvalidParameterException exception) {
40                         _descriptionValue = null;
41                         LOG.debug("Error while trying to add description: " + exception.getMessage());
42                 }
43                 return SUCCESS;
44         }
45         
46         /**
47          * Checks if user can set description.
48          * @return true if user can set description
49          */
50         public boolean userCanModufyDescription() {
51                 return "true".equals(getWriteAccess())
52                         && _openStudy.getStudyRights().canEditDescription();
53         }
54         
55         /**
56          * Sets study description.
57          * @return SUCCESS
58          */
59         public String doSetDescription() {
60                 try {
61                         if (userCanModufyDescription() && _descriptionValue != null && _descriptionValue.length()>0) {
62                                 getStudyService().setDescription(_studyId, _descriptionValue);
63                         }
64                 } catch(InvalidParameterException exception) {
65                         LOG.debug("Error while trying to add description: " + exception.getMessage());
66                 }
67                 doDisplayDescription();
68                 return SUCCESS;
69         }
70         
71         /**
72          * Removes study description.
73          * @return SUCCESS
74          */
75         public String doRemoveDescription() {
76                 try {
77                         if(userCanModufyDescription()) {
78                                 getStudyService().removeDescription(_studyId);
79                         }
80                 } catch(InvalidParameterException exception) {
81                         LOG.debug("Error while trying to add description: " + exception.getMessage());
82                 }
83                 doDisplayDescription();
84                 return SUCCESS;
85         }
86
87         /**
88          * Get the descriptionValue.
89          * @return the descriptionValue
90          */
91         public String getDescriptionValue() {
92                 return _descriptionValue;
93         }
94
95         /**
96          * Set the descriptionValue.
97          * @param descriptionValue the descriptionValue to set
98          */
99         public void setDescriptionValue(final String descriptionValue) {
100                 _descriptionValue = descriptionValue;
101         }
102
103         /**
104          * Get the descriptionPopup. Should have this exact name since it is used in menupopup.jsp.
105          * @return the descriptionPopup
106          */
107         public PopupMenu getPopup() {
108                 return _descriptionPopup;
109         }
110
111         /**
112          * Get the studyId.
113          * @return the studyId
114          */
115         public Long getStudyId() {
116                 return _studyId;
117         }
118
119         /**
120          * Set the studyId.
121          * @param studyId the studyId to set
122          */
123         public void setStudyId(final Long studyId) {
124                 _studyId = studyId;
125         }
126 }