View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.rule;
2   
3   /*
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.reefdb.ui.swing.content.manage.rule.controlrule.ControlRuleTableUIModel;
27  import fr.ifremer.reefdb.ui.swing.content.manage.rule.department.ControlDepartmentTableUIModel;
28  import fr.ifremer.reefdb.ui.swing.content.manage.rule.pmfm.ControlPmfmTableUIModel;
29  import fr.ifremer.reefdb.ui.swing.content.manage.rule.program.ControlProgramTableUIModel;
30  import fr.ifremer.reefdb.ui.swing.content.manage.rule.rulelist.RuleListRowModel;
31  import fr.ifremer.reefdb.ui.swing.content.manage.rule.rulelist.RuleListUIModel;
32  import fr.ifremer.quadrige3.ui.swing.model.AbstractEmptyUIModel;
33  
34  /**
35   * Modele pour l administration de contextes.
36   */
37  public class RulesUIModel extends AbstractEmptyUIModel<RulesUIModel> {
38  
39      /**
40       * Liste regles model.
41       */
42      private RuleListUIModel ruleListUIModel;
43  
44      /**
45       * Programmes model.
46       */
47      private ControlProgramTableUIModel programsUIModel;
48  
49      /**
50       * Services model.
51       */
52      private ControlDepartmentTableUIModel departmentsUIModel;
53  
54      /**
55       * ReEgles model.
56       */
57      private ControlRuleTableUIModel controlRuleUIModel;
58  
59      /**
60       * PSFMs model.
61       */
62      private ControlPmfmTableUIModel pmfmUIModel;
63  
64      private RuleListRowModel selectedRuleList;
65  
66      private boolean userIsAdmin;
67  
68      public static final String PROPERTY_RULE_MESSAGE = "ruleMessage";
69      public static final String PROPERTY_RULE_DESCRIPTION = "ruleDescription";
70      private String ruleMessage;
71      private String ruleDescription;
72  
73      private boolean saveEnabled;
74      public static final String PROPERTY_SAVE_ENABLED = "saveEnabled";
75  
76      /** {@inheritDoc} */
77      @Override
78      public void setModify(boolean modify) {
79  
80          if (!modify) {
81              ruleListUIModel.setModify(false);
82              programsUIModel.setModify(false);
83              departmentsUIModel.setModify(false);
84              controlRuleUIModel.setModify(false);
85              pmfmUIModel.setModify(false);
86          }
87          super.setModify(modify);
88      }
89  
90      /**
91       * <p>Getter for the field <code>ruleListUIModel</code>.</p>
92       *
93       * @return a {@link RuleListUIModel} object.
94       */
95      public RuleListUIModel getRuleListUIModel() {
96          return ruleListUIModel;
97      }
98  
99      /**
100      * <p>Setter for the field <code>ruleListUIModel</code>.</p>
101      *
102      * @param ruleListUIModel a {@link RuleListUIModel} object.
103      */
104     public void setRuleListUIModel(RuleListUIModel ruleListUIModel) {
105         this.ruleListUIModel = ruleListUIModel;
106         this.ruleListUIModel.setParentModel(this);
107     }
108 
109     /**
110      * <p>Getter for the field <code>programsUIModel</code>.</p>
111      *
112      * @return a {@link fr.ifremer.reefdb.ui.swing.content.manage.rule.program.ControlProgramTableUIModel} object.
113      */
114     public ControlProgramTableUIModel getProgramsUIModel() {
115         return programsUIModel;
116     }
117 
118     /**
119      * <p>Setter for the field <code>programsUIModel</code>.</p>
120      *
121      * @param programsUIModel a {@link fr.ifremer.reefdb.ui.swing.content.manage.rule.program.ControlProgramTableUIModel} object.
122      */
123     public void setProgramsUIModel(ControlProgramTableUIModel programsUIModel) {
124         this.programsUIModel = programsUIModel;
125         this.programsUIModel.setParentModel(this);
126     }
127 
128     /**
129      * <p>Getter for the field <code>departmentsUIModel</code>.</p>
130      *
131      * @return a {@link fr.ifremer.reefdb.ui.swing.content.manage.rule.department.ControlDepartmentTableUIModel} object.
132      */
133     public ControlDepartmentTableUIModel getDepartmentsUIModel() {
134         return departmentsUIModel;
135     }
136 
137     /**
138      * <p>Setter for the field <code>departmentsUIModel</code>.</p>
139      *
140      * @param departmentsUIModel a {@link fr.ifremer.reefdb.ui.swing.content.manage.rule.department.ControlDepartmentTableUIModel} object.
141      */
142     public void setDepartmentsUIModel(ControlDepartmentTableUIModel departmentsUIModel) {
143         this.departmentsUIModel = departmentsUIModel;
144         this.departmentsUIModel.setParentModel(this);
145     }
146 
147     /**
148      * <p>Getter for the field <code>controlRuleUIModel</code>.</p>
149      *
150      * @return a {@link fr.ifremer.reefdb.ui.swing.content.manage.rule.controlrule.ControlRuleTableUIModel} object.
151      */
152     public ControlRuleTableUIModel getControlRuleUIModel() {
153         return controlRuleUIModel;
154     }
155 
156     /**
157      * <p>Setter for the field <code>controlRuleUIModel</code>.</p>
158      *
159      * @param controlRuleUIModel a {@link fr.ifremer.reefdb.ui.swing.content.manage.rule.controlrule.ControlRuleTableUIModel} object.
160      */
161     public void setControlRuleUIModel(ControlRuleTableUIModel controlRuleUIModel) {
162         this.controlRuleUIModel = controlRuleUIModel;
163         this.controlRuleUIModel.setParentModel(this);
164     }
165 
166     /**
167      * <p>Getter for the field <code>pmfmUIModel</code>.</p>
168      *
169      * @return a {@link ControlPmfmTableUIModel} object.
170      */
171     public ControlPmfmTableUIModel getPmfmUIModel() {
172         return pmfmUIModel;
173     }
174 
175     /**
176      * <p>Setter for the field <code>pmfmUIModel</code>.</p>
177      *
178      * @param pmfmUIModel a {@link ControlPmfmTableUIModel} object.
179      */
180     public void setPmfmUIModel(ControlPmfmTableUIModel pmfmUIModel) {
181         this.pmfmUIModel = pmfmUIModel;
182         this.pmfmUIModel.setParentModel(this);
183     }
184 
185     public RuleListRowModel getSelectedRuleList() {
186         return selectedRuleList;
187     }
188 
189     public void setSelectedRuleList(RuleListRowModel selectedRuleList) {
190         this.selectedRuleList = selectedRuleList;
191     }
192 
193     public boolean isEditable() {
194         return userIsAdmin && selectedRuleList != null && selectedRuleList.isEditable();
195     }
196 
197     public boolean isUserIsAdmin() {
198         return userIsAdmin;
199     }
200 
201     public void setUserIsAdmin(boolean userIsAdmin) {
202         this.userIsAdmin = userIsAdmin;
203     }
204 
205     public String getRuleMessage() {
206         return ruleMessage;
207     }
208 
209     public void setRuleMessage(String ruleMessage) {
210         String oldValue = getRuleMessage();
211         this.ruleMessage = ruleMessage;
212         firePropertyChange(PROPERTY_RULE_MESSAGE, oldValue, ruleMessage);
213     }
214 
215     public String getRuleDescription() {
216         return ruleDescription;
217     }
218 
219     public void setRuleDescription(String ruleDescription) {
220         String oldValue = getRuleDescription();
221         this.ruleDescription = ruleDescription;
222         firePropertyChange(PROPERTY_RULE_DESCRIPTION, oldValue, ruleDescription);
223     }
224 
225     public boolean isSaveEnabled() {
226         return saveEnabled;
227     }
228 
229     public void setSaveEnabled(boolean saveEnabled) {
230         boolean oldValue = isSaveEnabled();
231         this.saveEnabled = saveEnabled;
232         firePropertyChange(PROPERTY_SAVE_ENABLED, oldValue, saveEnabled);
233     }
234 }