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