Salome HOME
065042a7e5d704e3558b1e8d90dbcc9a8c76e4f7
[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 public class ValidationFacade {
12
13         private transient String _myicon;
14         private transient String _myname;
15         private transient Name _mypublisher;
16         private transient Name _myreviewer;
17         private transient Name _myapprover;
18
19         protected static class UserOption implements Name {
20                 protected transient String _name;
21                 protected transient long _index;
22
23                 /**
24                  * Create a localized named user option.
25                  * @param key option label key
26                  * @param locale current locale
27                  */
28                 public UserOption(final String key, final Locale locale) {
29                         super();
30                         _name = ResourceBundle.getBundle("labels", locale).getString(key);
31                 }
32
33                 public long getIndex() {
34                         return _index;
35                 }
36
37                 @Override
38                 public String toString() {
39                         return _name;
40                 }
41         }
42
43         protected static class NotRequired extends UserOption {
44                 protected NotRequired(final Locale locale) {
45                         super("label.skipped", locale);
46                         _index = 0;
47                 }
48         }
49
50         protected static class ByAuthor extends UserOption {
51                 protected ByAuthor(final Locale locale) {
52                         super("label.bytheauthor", locale);
53                         _index = 0;
54                 }
55         }
56
57         protected static class ByManager extends UserOption {
58                 protected ByManager(final User manager, final Locale locale) {
59                         super("label.me", locale);
60                         _index = manager.getIndex();
61                 }
62         }
63
64         // ==============================================================================================================================
65         // Constructors
66         // ==============================================================================================================================
67
68         public ValidationFacade(final ValidationCycle cycle, final Locale locale) {
69                 _myicon = "icon.empty.png";
70                 if (cycle.isDefault()) {
71                         _myname = "default";
72                 } else {
73                         if (cycle.isAssigned()) {
74                                 _myicon = "icon.done.png";
75                         }
76                         _myname = cycle.getDocumentType().getName();
77                 }
78                 _mypublisher = cycle.getActor(ValidationStep.PROMOTION);
79                 _myreviewer = cycle.getActor(ValidationStep.REVIEW);
80                 _myapprover = cycle.getActor(ValidationStep.APPROVAL);
81                 if (_mypublisher == null) {
82                         _mypublisher = new ByAuthor(locale);
83                 }
84                 if (_myreviewer == null || _myapprover == null) {
85                         Name skipped = new NotRequired(locale);
86                         if (_myreviewer == null) {
87                                 _myreviewer = skipped;
88                         }
89                         if (_myapprover == null) {
90                                 _myapprover = skipped;
91                         }
92                 }
93         }
94
95         // ==============================================================================================================================
96         // Getters
97         // ==============================================================================================================================
98
99         public String getDocumentType() {
100                 return _myname;
101         }
102
103         public long getApproverIndex() {
104                 return _myapprover.getIndex();
105         }
106
107         public String getApproverName() {
108                 return _myapprover.toString();
109         }
110
111         public String getIcon() {
112                 return _myicon;
113         }
114
115         public long getPublisherIndex() {
116                 return _mypublisher.getIndex();
117         }
118
119         public String getPublisherName() {
120                 return _mypublisher.toString();
121         }
122
123         public long getReviewerIndex() {
124                 return _myreviewer.getIndex();
125         }
126
127         public String getReviewerName() {
128                 return _myreviewer.toString();
129         }
130 }