View Javadoc
1   package fr.ifremer.dali.ui.swing.util.table;
2   
3   /*
4    * #%L
5    * Dali :: 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.dali.decorator.DecoratorService;
27  import fr.ifremer.dali.dto.DaliBeans;
28  import fr.ifremer.dali.dto.referential.pmfm.PmfmDTO;
29  import fr.ifremer.dali.service.DaliServiceLocator;
30  import fr.ifremer.quadrige3.core.dao.technical.decorator.Decorator;
31  
32  /**
33   * override version of DaliColumnIdentifier with property type
34   *
35   * @param <R>
36   * @author Ludovic Pecquot <ludovic.pecquot@e-is.pro>
37   */
38  public class DaliColumnIdentifier<R extends AbstractDaliRowUIModel> extends fr.ifremer.quadrige3.ui.swing.table.ColumnIdentifier<R> {
39  
40      /**
41       * <p>Constructor for DaliColumnIdentifier.</p>
42       *
43       * @param propertyName     a {@link String} object.
44       * @param headerI18nKey    a {@link String} object.
45       * @param headerTipI18nKey a {@link String} object.
46       * @param propertyType     a {@link Class} object.
47       * @param decoratorName    a {@link String} object.
48       * @param mandatory        a boolean.
49       */
50      protected DaliColumnIdentifier(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType, String decoratorName, boolean mandatory) {
51          super(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, mandatory);
52      }
53  
54      /**
55       * <p>newId.</p>
56       *
57       * @param propertyName     a {@link java.lang.String} object.
58       * @param headerI18nKey    a {@link java.lang.String} object.
59       * @param headerTipI18nKey a {@link java.lang.String} object.
60       * @param propertyType     a {@link java.lang.Class} object.
61       * @param <R>              a R object.
62       * @return a {@link DaliColumnIdentifier} object.
63       */
64      public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType) {
65          return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, null, false);
66      }
67  
68      /**
69       * <p>newId.</p>
70       *
71       * @param propertyName     a {@link java.lang.String} object.
72       * @param headerI18nKey    a {@link java.lang.String} object.
73       * @param headerTipI18nKey a {@link java.lang.String} object.
74       * @param propertyType     a {@link java.lang.Class} object.
75       * @param decoratorName    a {@link java.lang.String} object.
76       * @param <R>              a R object.
77       * @return a {@link DaliColumnIdentifier} object.
78       */
79      public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
80                                                                                     String decoratorName) {
81          return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, false);
82      }
83  
84      /**
85       * <p>newId.</p>
86       *
87       * @param propertyName     a {@link java.lang.String} object.
88       * @param headerI18nKey    a {@link java.lang.String} object.
89       * @param headerTipI18nKey a {@link java.lang.String} object.
90       * @param propertyType     a {@link java.lang.Class} object.
91       * @param mandatory        a boolean.
92       * @param <R>              a R object.
93       * @return a {@link DaliColumnIdentifier} object.
94       */
95      public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
96                                                                                     boolean mandatory) {
97          return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, null, mandatory);
98      }
99  
100     /**
101      * <p>newId.</p>
102      *
103      * @param propertyName     a {@link java.lang.String} object.
104      * @param headerI18nKey    a {@link java.lang.String} object.
105      * @param headerTipI18nKey a {@link java.lang.String} object.
106      * @param propertyType     a {@link java.lang.Class} object.
107      * @param decoratorName    a {@link java.lang.String} object.
108      * @param mandatory        a boolean.
109      * @param <R>              a R object.
110      * @return a {@link DaliColumnIdentifier} object.
111      */
112     public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
113                                                                                    String decoratorName, boolean mandatory) {
114         return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, mandatory);
115     }
116 
117     /**
118      * <p>newReadOnlyId.</p>
119      *
120      * @param propertyName     a {@link java.lang.String} object.
121      * @param headerI18nKey    a {@link java.lang.String} object.
122      * @param headerTipI18nKey a {@link java.lang.String} object.
123      * @param propertyType     a {@link java.lang.Class} object.
124      * @param <R>              a R object.
125      * @return a {@link DaliColumnIdentifier} object.
126      */
127     public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newReadOnlyId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType) {
128 
129         return newReadOnlyId(propertyName, headerI18nKey, headerTipI18nKey, propertyType, null);
130     }
131 
132     /**
133      * <p>newReadOnlyId.</p>
134      *
135      * @param propertyName     a {@link java.lang.String} object.
136      * @param headerI18nKey    a {@link java.lang.String} object.
137      * @param headerTipI18nKey a {@link java.lang.String} object.
138      * @param propertyType     a {@link java.lang.Class} object.
139      * @param decoratorName    a {@link java.lang.String} object.
140      * @param <R>              a R object.
141      * @return a {@link DaliColumnIdentifier} object.
142      */
143     public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newReadOnlyId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
144                                                                                            String decoratorName) {
145         return new DaliColumnIdentifier<R>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, false) {
146 
147             private static final long serialVersionUID = 1L;
148 
149             @Override
150             public void setValue(R entry, Object value) {
151                 // no set
152             }
153         };
154     }
155 
156     /**
157      * <p>newPmfmNameId.</p>
158      *
159      * @param headerI18nKey    a {@link java.lang.String} object.
160      * @param headerTipI18nKey a {@link java.lang.String} object.
161      * @param <R>              a R object.
162      * @return a {@link DaliColumnIdentifier} object.
163      */
164     public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newPmfmNameId(String headerI18nKey, String headerTipI18nKey) {
165 
166         return newPmfmNameId(null, headerI18nKey, headerTipI18nKey);
167     }
168 
169     /**
170      * <p>newPmfmNameId.</p>
171      *
172      * @param parentPropertyName a {@link java.lang.String} object.
173      * @param headerI18nKey      a {@link java.lang.String} object.
174      * @param headerTipI18nKey   a {@link java.lang.String} object.
175      * @param <R>                a R object.
176      * @return a {@link DaliColumnIdentifier} object.
177      */
178     public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newPmfmNameId(final String parentPropertyName, String headerI18nKey, String headerTipI18nKey) {
179 
180         final DecoratorService decoratorService = DaliServiceLocator.instance().getDecoratorService();
181 
182         return new DaliColumnIdentifier<R>(PmfmDTO.PROPERTY_NAME, headerI18nKey, headerTipI18nKey, String.class, null, false) {
183 
184             @Override
185             public Object getValue(R entry) {
186 
187                 PmfmDTO pmfm = null;
188                 if (parentPropertyName != null) {
189                     pmfm = DaliBeans.getProperty(entry, parentPropertyName);
190                 } else if (entry instanceof PmfmDTO) {
191                     pmfm = (PmfmDTO) entry;
192                 }
193 
194                 if (pmfm != null) {
195 
196                     Decorator decorator = decoratorService.getDecoratorByType(PmfmDTO.class, DecoratorService.NAME);
197                     if (decorator != null) {
198                         return decorator.toString(pmfm);
199                     }
200                 }
201 
202                 return null;
203             }
204 
205             @Override
206             public void setValue(R entry, Object value) {
207                 // do nothing
208             }
209 
210         };
211     }
212 
213 }