View Javadoc
1   package fr.ifremer.tutti.ui.swing.util.caracteristics;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
26  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
27  import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel;
28  
29  import java.util.ArrayList;
30  import java.util.Collection;
31  import java.util.List;
32  
33  /**
34   * @author Kevin Morin - kmorin@codelutin.com
35   * @since 1.4
36   */
37  public class CaracteristicMapEditorUIModel extends AbstractTuttiTableUIModel<Object, CaracteristicMapEditorRowModel, CaracteristicMapEditorUIModel> {
38  
39      public static final String PROPERTY_CARACTERISTIC_MAP = "caracteristicMap";
40  
41      public static final String PROPERTY_REMOVE_CARACTERISTIC_ENABLED = "removeCaracteristicEnabled";
42  
43      private static final long serialVersionUID = 1L;
44  
45      /**
46       * Original available caracteristics, can contain the default caracteristics
47       */
48      protected List<Caracteristic> allAvailableCaracteristics;
49  
50      /**
51       * The available caracteristics without the default caracteristics
52       */
53      protected List<Caracteristic> availableCaracteristics;
54  
55      /**
56       * Caracteristics
57       *
58       * @since 1.0
59       */
60      protected CaracteristicMap caracteristicMap;
61  
62      /**
63       * Can user remove a selected caracteristic?
64       *
65       * @since 1.0
66       */
67      protected boolean removeCaracteristicEnabled;
68  
69      public CaracteristicMapEditorUIModel() {
70          super(Object.class, null, null);
71      }
72  
73      public void setAllAvailableCaracteristics(List<Caracteristic> allAvailableCaracteristics) {
74          this.allAvailableCaracteristics = allAvailableCaracteristics;
75          this.availableCaracteristics = new ArrayList<>(allAvailableCaracteristics);
76      }
77  
78      public List<Caracteristic> getAvailableCaracteristics() {
79          return availableCaracteristics;
80      }
81  
82      public void computeAvailableCaracteristics(Collection<Caracteristic> defaultCaracteristics) {
83          availableCaracteristics = new ArrayList<>(allAvailableCaracteristics);
84          availableCaracteristics.removeAll(defaultCaracteristics);
85      }
86  
87      public CaracteristicMap getCaracteristicMap() {
88          return caracteristicMap;
89      }
90  
91      public void setCaracteristicMap(CaracteristicMap caracteristicMap) {
92          Object oldValue = getCaracteristicMap();
93          this.caracteristicMap = caracteristicMap != null ? (CaracteristicMap) caracteristicMap.clone() : null;
94          firePropertyChange(PROPERTY_CARACTERISTIC_MAP, oldValue, this.caracteristicMap);
95      }
96  
97      public boolean isRemoveCaracteristicEnabled() {
98          return removeCaracteristicEnabled;
99      }
100 
101     public void setRemoveCaracteristicEnabled(boolean removeCaracteristicEnabled) {
102         Object oldValue = isRemoveCaracteristicEnabled();
103         this.removeCaracteristicEnabled = removeCaracteristicEnabled;
104         firePropertyChange(PROPERTY_REMOVE_CARACTERISTIC_ENABLED, oldValue, removeCaracteristicEnabled);
105     }
106 
107     @Override
108     protected Object newEntity() {
109         return null;
110     }
111 }