Salome HOME
Fix of "Me" user option presentation. getDisplayName is added to UserOption.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ValidationFacade.java
1 package org.splat.simer;
2
3 import java.util.Locale;
4 import java.util.ResourceBundle;
5
6 import org.splat.dal.bo.kernel.User;
7 import org.splat.dal.bo.som.ValidationCycle;
8 import org.splat.dal.bo.som.ValidationStep;
9 import org.splat.kernel.Name;
10
11 /**
12  * Validation cycle presentation facade.
13  */
14 public class ValidationFacade {
15
16         /**
17          * Icon name.
18          */
19         private transient String _myicon;
20         /**
21          * Document type name.
22          */
23         private transient String _myname;
24         /**
25          * Publisher name.
26          */
27         private transient Name _mypublisher;
28         /**
29          * Reviewer name.
30          */
31         private transient Name _myreviewer;
32         /**
33          * Approver name.
34          */
35         private transient Name _myapprover;
36
37         /**
38          * Option presentation in users lists.
39          */
40         protected static class UserOption implements Name {
41                 /**
42                  * User name.
43                  */
44                 protected transient String _name;
45                 /**
46                  * User id.
47                  */
48                 protected transient long _index;
49
50                 /**
51                  * Create a localized named user option.
52                  * 
53                  * @param key
54                  *            option label key
55                  * @param locale
56                  *            current locale
57                  */
58                 public UserOption(final String key, final Locale locale) {
59                         super();
60                         _name = ResourceBundle.getBundle("labels", locale).getString(key);
61                 }
62
63                 /**
64                  * {@inheritDoc}
65                  * 
66                  * @see org.splat.kernel.Name#getIndex()
67                  */
68                 public long getIndex() {
69                         return _index;
70                 }
71
72                 /**
73                  * {@inheritDoc}
74                  * 
75                  * @see java.lang.Object#toString()
76                  */
77                 @Override
78                 public String toString() {
79                         return _name;
80                 }
81
82                 /**
83                  * Get user's display name.
84                  * 
85                  * @return user's display name
86                  */
87                 public String getDisplayName() {
88                         return _name;
89                 }
90         }
91
92         /**
93          * Not applicable user option presentation. For example, if there is no review<BR>
94          * step, then reviewer will be undefined.
95          */
96         protected static class NotRequired extends UserOption {
97                 /**
98                  * Constructor.
99                  * 
100                  * @param locale
101                  *            current locale
102                  */
103                 protected NotRequired(final Locale locale) {
104                         super("label.skipped", locale);
105                         _index = 0;
106                 }
107         }
108
109         /**
110          * Author presentation.
111          */
112         protected static class ByAuthor extends UserOption {
113                 /**
114                  * Constructor.
115                  * 
116                  * @param locale
117                  *            current locale
118                  */
119                 protected ByAuthor(final Locale locale) {
120                         super("label.bytheauthor", locale);
121                         _index = 0;
122                 }
123         }
124
125         /**
126          * Current user presentation ("Me").
127          */
128         protected static class ByManager extends UserOption {
129                 /**
130                  * Constructor.
131                  * 
132                  * @param manager
133                  *            current user
134                  * @param locale
135                  *            current locale
136                  */
137                 protected ByManager(final User manager, final Locale locale) {
138                         super("label.me", locale);
139                         _index = manager.getIndex();
140                 }
141         }
142
143         // ==============================================================================================================================
144         // Constructors
145         // ==============================================================================================================================
146
147         /**
148          * Constructor.
149          * 
150          * @param cycle
151          *            the presented validation cycle
152          * @param locale
153          *            the current locale
154          */
155         public ValidationFacade(final ValidationCycle cycle, final Locale locale) {
156                 _myicon = "icon.empty.png";
157                 if (cycle.isDefault()) {
158                         _myname = "default";
159                 } else {
160                         if (cycle.isAssigned()) {
161                                 _myicon = "icon.done.png";
162                         }
163                         _myname = cycle.getDocumentType().getName();
164                 }
165                 _mypublisher = cycle.getActor(ValidationStep.PROMOTION);
166                 _myreviewer = cycle.getActor(ValidationStep.REVIEW);
167                 _myapprover = cycle.getActor(ValidationStep.APPROVAL);
168                 if (_mypublisher == null) {
169                         _mypublisher = new ByAuthor(locale);
170                 }
171                 if (_myreviewer == null || _myapprover == null) {
172                         Name skipped = new NotRequired(locale);
173                         if (_myreviewer == null) {
174                                 _myreviewer = skipped;
175                         }
176                         if (_myapprover == null) {
177                                 _myapprover = skipped;
178                         }
179                 }
180         }
181
182         // ==============================================================================================================================
183         // Getters
184         // ==============================================================================================================================
185
186         /**
187          * Get the document type of the validation cycle.
188          * 
189          * @return document type name
190          */
191         public String getDocumentType() {
192                 return _myname;
193         }
194
195         /**
196          * Get the approver id.
197          * 
198          * @return user id
199          */
200         public long getApproverIndex() {
201                 return _myapprover.getIndex();
202         }
203
204         /**
205          * Get the approver name.
206          * 
207          * @return user name
208          */
209         public String getApproverName() {
210                 return _myapprover.toString();
211         }
212
213         /**
214          * Get icon name.
215          * 
216          * @return the icon name
217          */
218         public String getIcon() {
219                 return _myicon;
220         }
221
222         /**
223          * Get the publisher id.
224          * 
225          * @return user id
226          */
227         public String getPublisherName() {
228                 return _mypublisher.toString();
229         }
230
231         /**
232          * Get the publisher id.
233          * 
234          * @return user id
235          */
236         public long getPublisherIndex() {
237                 return _mypublisher.getIndex();
238         }
239
240         /**
241          * Get the reviewer id.
242          * 
243          * @return user id
244          */
245         public String getReviewerName() {
246                 return _myreviewer.toString();
247         }
248
249         /**
250          * Get the reviewer id.
251          * 
252          * @return user id
253          */
254         public long getReviewerIndex() {
255                 return _myreviewer.getIndex();
256         }
257 }