]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/som/SimulationContextType.java
Salome HOME
Refactoring: configuration files are moved into Siman web project.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / SimulationContextType.java
1 package org.splat.som;
2 /**
3  * 
4  * @author    Daniel Brunier-Coulin
5  * @copyright OPEN CASCADE 2012
6  */
7
8 import java.io.Serializable;
9
10 import org.splat.kernel.InvalidPropertyException;
11 import org.splat.kernel.Persistent;
12
13
14 public class SimulationContextType extends Persistent implements Serializable {
15         
16 //  Persistent fields
17     private String         name;
18     private ProgressState  state;
19     private int            step;
20
21 //  Required by the serialization
22         private static final long serialVersionUID = 4819425038576161242L;
23
24 //  ==============================================================================================================================
25 //  Constructors
26 //  ==============================================================================================================================
27
28 //  Search properties class
29     public static class Properties {
30 //  ------------------------------
31       private ProgressState         state = null;
32       private ProjectSettings.Step  step  = null;
33
34       protected ProgressState getProgressState () {
35         return state;
36       }
37       protected ProjectSettings.Step getStep () {
38         return step;
39       }
40       public Properties setState (ProgressState state) {
41         this.state = state;
42         return this;
43       }
44       public Properties setStep (ProjectSettings.Step  step) {
45         this.step = step;
46         return this;
47       }
48     }
49 //  Database fetch constructor
50     protected SimulationContextType () {
51     }
52 //  Initialization constructor
53     protected SimulationContextType (String name, ProjectSettings.Step step) throws InvalidPropertyException {
54 //  ------------------------------------------------------------------------
55       super();
56       this.name  = name;
57       this.state = ProgressState.inCHECK;
58       this.step  = step.getNumber();
59     }
60
61 //  ==============================================================================================================================
62 //  Public member functions
63 //  ==============================================================================================================================
64
65     public boolean approve () {
66 //  -------------------------
67       if  (state != ProgressState.inCHECK) return false;      
68       this.state =  ProgressState.APPROVED;     // The type name is supposed being localized
69       Database.getSession().update(this);
70           return true;
71     }
72
73     public boolean equals(Object entity) {
74 //  ------------------------------------
75       if (entity == null) return false;
76       if (entity instanceof String) {
77         return this.name.equals((String)entity);   // Names are unique
78       } else
79       if (entity instanceof SimulationContextType) {
80           SimulationContextType object = (SimulationContextType)entity;
81         int   he = object.getIndex();
82         int   me = this.getIndex();
83         if (me*he != 0) return (he == me);
84         else            return this.getName().equals(object.getName());
85       } else {
86         return false;
87       }
88     }
89
90     public ProjectSettings.Step getAttachedStep () {
91 //  ----------------------------------------------
92       return ProjectSettings.getStep(step);
93     }
94
95     public String getName () {
96 //  ------------------------
97       return name;
98     }
99
100     public boolean isAttachedTo (ProjectSettings.Step step) {
101 //  -------------------------------------------------------
102       if (this.step == step.getNumber()) return true;
103       return false;
104     }
105
106     public boolean isApproved () {
107 //  ----------------------------
108       return (state == ProgressState.APPROVED);
109     }
110 }