Salome HOME
Copyrights update 2015.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / SimulationContextType.java
1 package org.splat.dal.bo.som;
2
3 /**
4  * 
5  * @author    Daniel Brunier-Coulin
6  * @copyright OPEN CASCADE 2012-2015
7  */
8
9 import java.io.Serializable;
10
11 import org.splat.dal.bo.kernel.Persistent;
12 import org.splat.kernel.InvalidPropertyException;
13 import org.splat.service.technical.ProjectSettingsService;
14
15 /**
16  * Persistent simulation context type.
17  */
18 public class SimulationContextType extends Persistent implements Serializable {
19
20         /**
21          * Serialization version id.
22          */
23         private static final long serialVersionUID = 4819425038576161242L;
24
25         // Persistent fields
26         /**
27          * Context type name.
28          */
29         private String name;
30         /**
31          * Context progress state.
32          */
33         private ProgressState state;
34         /**
35          * Context type first applicable step.
36          */
37         private int step;
38
39         // ==============================================================================================================================
40         // Constructors
41         // ==============================================================================================================================
42
43         /**
44          * Search properties class.
45          */
46         public static class Properties {
47                 private ProgressState state = null;
48                 private ProjectSettingsService.Step step = null;
49
50                 public ProgressState getProgressState() {
51                         return state;
52                 }
53
54                 public ProjectSettingsService.Step getStep() {
55                         return step;
56                 }
57
58                 public Properties setProgressState(final ProgressState state) {
59                         this.state = state;
60                         return this;
61                 }
62
63                 public Properties setStep(final ProjectSettingsService.Step step) {
64                         this.step = step;
65                         return this;
66                 }
67         }
68
69         /**
70          * Database fetch constructor.
71          */
72         protected SimulationContextType() {
73                 super();
74         }
75
76         /**
77          * Initialization constructor.
78          * 
79          * @param name
80          *            context type name
81          * @param step
82          *            first applicable step for this type of context
83          * @throws InvalidPropertyException
84          *             from constructor of parent class
85          */
86         public SimulationContextType(final String name,
87                         final ProjectSettingsService.Step step)
88                         throws InvalidPropertyException {
89                 super();
90                 this.name = name;
91                 this.state = ProgressState.inCHECK;
92                 this.step = step.getNumber();
93         }
94
95         // ==============================================================================================================================
96         // Public member functions
97         // ==============================================================================================================================
98
99         /**
100          * Saved context types are equal if their persistent ids are equal. <BR>
101          * Before becoming persistent context types are compared by their names.
102          * 
103          * @param entity
104          *            object to compare with
105          * @return true if this context type equals to the given object
106          * @see org.splat.dal.bo.kernel.Persistent#equals(java.lang.Object)
107          */
108         @Override
109         public boolean equals(final Object entity) {
110
111                 if (entity == null) {
112                         return false;
113                 }
114                 if (entity instanceof String) {
115                         return this.name.equals(entity); // Names are unique
116                 } else if (entity instanceof SimulationContextType) {
117                         SimulationContextType object = (SimulationContextType) entity;
118                         long he = object.getIndex();
119                         long me = this.getIndex();
120                         if (me * he == 0) {
121                                 return this.getName().equals(object.getName());
122                         } else {
123                                 return (he == me);
124                         }
125                 } else {
126                         return false;
127                 }
128         }
129
130         /**
131          * Get context type name.
132          * 
133          * @return context type name
134          */
135         public String getName() {
136                 return name;
137         }
138
139         /**
140          * Check if contexts of this type are attached to the given study step.
141          * 
142          * @param step
143          *            the study step
144          * @return true if contexts of this type are attached to the given study step
145          */
146         public boolean isAttachedTo(final ProjectSettingsService.Step step) {
147                 return (this.step == step.getNumber());
148         }
149
150         /**
151          * Check if the context is approved.
152          * 
153          * @return true if the context is approved
154          */
155         public boolean isApproved() {
156                 return (state == ProgressState.APPROVED);
157         }
158
159         /**
160          * Get the state.
161          * 
162          * @return the state
163          */
164         public ProgressState getState() {
165                 return state;
166         }
167
168         /**
169          * Set the state.
170          * 
171          * @param state
172          *            the state to set
173          */
174         public void setState(final ProgressState state) {
175                 this.state = state;
176         }
177
178         /**
179          * Get the step.
180          * 
181          * @return the step
182          */
183         public int getStep() {
184                 return step;
185         }
186
187         /**
188          * Set the step.
189          * 
190          * @param step
191          *            the step to set
192          */
193         public void setStep(final int step) {
194                 this.step = step;
195         }
196
197 }