Salome HOME
af15d5c86f42a624f245db90cc69ccc8a5a92b10
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / StepRights.java
1 package org.splat.som;
2 /**
3  * Class defining the default rights related to operations on study steps.
4  * 
5  * @author    Daniel Brunier-Coulin
6  * @copyright OPEN CASCADE 2012
7  */
8 //TODO: Review this rights according to the state of the owner study.
9
10 import org.splat.kernel.User;
11
12
13 public class StepRights {
14
15     private User     user;
16     private Step     operand;
17
18 //  ==============================================================================================================================
19 //  Construction
20 //  ==============================================================================================================================
21
22     public StepRights (User user, Step step) {
23 //  ----------------------------------------
24       this.user    = user;
25       this.operand = step;
26     }
27     public StepRights (Step step) {
28 //  -----------------------------
29       this.user    = step.getOwner().getAuthor();
30       this.operand = step;
31     }
32
33 //  ==============================================================================================================================
34 //  Public member functions
35 //  ==============================================================================================================================
36
37 /**
38  * Checks if the user has right to add a comment attached to the selected step.
39  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
40  * 
41  * @return true if the user has right to add a comment.
42  */
43     public boolean canAddComment () {
44 //  -------------------------------
45       Study   owner = operand.getOwnerStudy();
46       return (owner.getAuthor().equals(user) || owner.hasActor(user));
47     }
48
49 /**
50  * Checks if the user has right to create or import a document into the selected step.
51  * Only the author and contributors have such right, providing that the study step is enabled for writing.
52  * 
53  * @return true if the user has right to create or import a document.
54  */
55     public boolean canCreateDocument () {
56 //  -----------------------------------
57       if (!isEnabled()) return false;
58       return operand.getOwnerStudy().isStaffedBy(user);
59     }
60
61 /**
62  * Checks if the user has right to enter a knowledge into the selected step.
63  * Only the author and contributors have such right.
64  * 
65  * @return true if the user has right to enter a knowledge.
66  */
67     public boolean canCreateKnowledge () {
68 //  ------------------------------------
69       return operand.getOwnerStudy().isStaffedBy(user);
70     }
71
72 /**
73  * Checks if the user has right to edit the simulation contexts attached to the selected step.
74  * All actors of the study have such right, including the author, contributors, reviewers and approvers.
75  * 
76  * @return true if the user has right to edit the simulation contexts.
77  */
78     public boolean canEditSimulationContext () {
79 //  ------------------------------------------
80       Study   owner = operand.getOwnerStudy();
81       return (owner.getAuthor().equals(user) || owner.hasActor(user));
82     }
83
84 /**
85  * Checks if the selected step is enabled for writing.
86  * A step may be disabled for writing, or locked, following a check-out of the owner scenario.
87  * 
88  * @return true if the step is enabled for writing.
89  */
90     public boolean isEnabled () {
91 //  ---------------------------
92       ProjectElement  owner = operand.getOwner();
93       
94       if (owner instanceof Scenario) {
95         Scenario  scene = (Scenario)owner;
96         if (scene.isCheckedout()) return false;
97       }
98       return true;
99     }
100
101 //  ==============================================================================================================================
102 //  Getters
103 //  ==============================================================================================================================
104
105     public Step getOperand () {
106 //  -------------------------
107       return operand;
108     }
109 }