View Javadoc
1   package fr.ifremer.dali.ui.swing.content.extraction.filters;
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 com.google.common.collect.Lists;
27  import fr.ifremer.dali.dto.ErrorAware;
28  import fr.ifremer.dali.dto.ErrorDTO;
29  import fr.ifremer.quadrige3.ui.core.dto.QuadrigeBean;
30  import fr.ifremer.dali.dto.configuration.filter.FilterDTO;
31  import fr.ifremer.dali.dto.system.extraction.ExtractionDTO;
32  import fr.ifremer.dali.dto.system.extraction.FilterTypeDTO;
33  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliRowUIModel;
34  import org.apache.commons.collections4.CollectionUtils;
35  
36  import java.util.Collection;
37  import java.util.List;
38  
39  /**
40   * extractions table row model
41   */
42  public class ExtractionFiltersRowModel extends AbstractDaliRowUIModel<QuadrigeBean, ExtractionFiltersRowModel> implements ErrorAware {
43  
44      private FilterTypeDTO filterType;
45      /** Constant <code>PROPERTY_FILTER_TYPE="filterType"</code> */
46      public static final String PROPERTY_FILTER_TYPE = "filterType";
47  
48      private FilterDTO filter;
49      /** Constant <code>PROPERTY_FILTER="filter"</code> */
50      public static final String PROPERTY_FILTER = "filter";
51  
52      private final List<ErrorDTO> errors;
53  
54      /**
55       * <p>Constructor for ExtractionFiltersRowModel.</p>
56       */
57      public ExtractionFiltersRowModel() {
58          super(null, null);
59          errors = Lists.newArrayList();
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      protected ExtractionDTO newBean() {
65          return null;
66      }
67  
68      /**
69       * <p>getFilterTypeId.</p>
70       *
71       * @return a {@link java.lang.Integer} object.
72       */
73      public Integer getFilterTypeId() {
74          return filterType == null ? null : filterType.getId();
75      }
76  
77      /**
78       * <p>Getter for the field <code>filterType</code>.</p>
79       *
80       * @return a {@link fr.ifremer.dali.dto.system.extraction.FilterTypeDTO} object.
81       */
82      public FilterTypeDTO getFilterType() {
83          return filterType;
84      }
85  
86      /**
87       * <p>Setter for the field <code>filterType</code>.</p>
88       *
89       * @param filterType a {@link fr.ifremer.dali.dto.system.extraction.FilterTypeDTO} object.
90       */
91      public void setFilterType(FilterTypeDTO filterType) {
92          this.filterType = filterType;
93      }
94  
95      /**
96       * <p>Getter for the field <code>filter</code>.</p>
97       *
98       * @return a {@link fr.ifremer.dali.dto.configuration.filter.FilterDTO} object.
99       */
100     public FilterDTO getFilter() {
101         return filter;
102     }
103 
104     /**
105      * <p>Setter for the field <code>filter</code>.</p>
106      *
107      * @param filter a {@link fr.ifremer.dali.dto.configuration.filter.FilterDTO} object.
108      */
109     public void setFilter(FilterDTO filter) {
110         this.filter = filter;
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public Collection<ErrorDTO> getErrors() {
116         return errors;
117     }
118 
119     /**
120      * <p>isFilterEmpty.</p>
121      *
122      * @return a boolean.
123      */
124     public boolean isFilterEmpty() {
125         return getFilter() == null || CollectionUtils.isEmpty(getFilter().getElements());
126     }
127 
128     /**
129      * <p>getFilteredElements.</p>
130      *
131      * @return a {@link java.util.List} object.
132      */
133     public List<? extends QuadrigeBean> getFilteredElements() {
134         return isFilterEmpty() ? null : getFilter().getElements();
135     }
136 }