View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.genericformat;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (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 General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import fr.ifremer.tutti.persistence.entities.data.Program;
28  import fr.ifremer.tutti.persistence.model.ProgramDataModel;
29  import fr.ifremer.tutti.service.genericformat.GenericFormatExportConfiguration;
30  import fr.ifremer.tutti.ui.swing.content.genericformat.tree.ProgramSelectTreeNode;
31  import org.jdesktop.beans.AbstractSerializableBean;
32  
33  /**
34   * Created on 3/29/15.
35   *
36   * @author Tony Chemit - chemit@codelutin.com
37   * @since 3.14.3
38   */
39  public class GenericFormatExportUIModel extends AbstractSerializableBean {
40  
41      private static final long serialVersionUID = 1L;
42  
43      public static final String PROPERTY_PROGRAM = "program";
44  
45      public static final String PROPERTY_EXPORT_ATTACHMENTS = "exportAttachments";
46  
47      public static final String PROPERTY_EXPORT_SPECIES = "exportSpecies";
48  
49      public static final String PROPERTY_EXPORT_BENTHOS = "exportBenthos";
50  
51      public static final String PROPERTY_EXPORT_MARINE_LITTER = "exportMarineLitter";
52  
53      public static final String PROPERTY_EXPORT_ACCIDENTAL_CATCH = "exportAccidentalCatch";
54  
55      public static final String PROPERTY_EXPORT_INDIVIDUAL_OBSERVATION = "exportIndividualObservation";
56  
57      public static final String PROPERTY_DATA_SELECTED= "dataSelected";
58  
59      public static final String PROPERTY_CAN_EXPORT = "canExport";
60  
61      private Program program;
62  
63      private boolean exportSpecies = true;
64  
65      private boolean exportBenthos = true;
66  
67      private boolean exportMarineLitter = true;
68  
69      private boolean exportAccidentalCatch = true;
70  
71      private boolean exportIndividualObservation = true;
72  
73      private boolean exportAttachments = true;
74  
75      private boolean canExport;
76  
77      private boolean dataSelected;
78  
79      private ProgramSelectTreeNode rootNode;
80  
81      public GenericFormatExportConfiguration toExportConfiguration() {
82  
83          GenericFormatExportConfiguration configuration = new GenericFormatExportConfiguration();
84  
85          configuration.setExportSpecies(exportSpecies);
86          configuration.setExportBenthos(exportBenthos);
87          configuration.setExportMarineLitter(exportMarineLitter);
88          configuration.setExportAccidentalCatch(exportAccidentalCatch);
89          configuration.setExportIndividualObservation(exportIndividualObservation);
90          configuration.setExportAttachments(exportAttachments);
91  
92          ProgramDataModel selectedDataModel = rootNode.getSelectedDataModel();
93          configuration.setDataToExport(selectedDataModel);
94  
95          return configuration;
96  
97      }
98  
99      public Program getProgram() {
100         return program;
101     }
102 
103     public void setProgram(Program program) {
104         Object oldValue = getProgram();
105         this.program = program;
106         firePropertyChange(PROPERTY_PROGRAM, oldValue, program);
107     }
108 
109     public boolean isExportSpecies() {
110         return exportSpecies;
111     }
112 
113     public void setExportSpecies(boolean exportSpecies) {
114         this.exportSpecies = exportSpecies;
115         firePropertyChange(PROPERTY_EXPORT_SPECIES, null, exportSpecies);
116     }
117 
118     public boolean isExportBenthos() {
119         return exportBenthos;
120     }
121 
122     public void setExportBenthos(boolean exportBenthos) {
123         this.exportBenthos = exportBenthos;
124         firePropertyChange(PROPERTY_EXPORT_BENTHOS, null, exportBenthos);
125     }
126 
127     public boolean isExportMarineLitter() {
128         return exportMarineLitter;
129     }
130 
131     public void setExportMarineLitter(boolean exportMarineLitter) {
132         this.exportMarineLitter = exportMarineLitter;
133         firePropertyChange(PROPERTY_EXPORT_MARINE_LITTER, null, exportMarineLitter);
134     }
135 
136     public boolean isExportAccidentalCatch() {
137         return exportAccidentalCatch;
138     }
139 
140     public void setExportAccidentalCatch(boolean exportAccidentalCatch) {
141         this.exportAccidentalCatch = exportAccidentalCatch;
142         firePropertyChange(PROPERTY_EXPORT_ACCIDENTAL_CATCH, null, exportAccidentalCatch);
143     }
144 
145     public boolean isExportIndividualObservation() {
146         return exportIndividualObservation;
147     }
148 
149     public void setExportIndividualObservation(boolean exportIndividualObservation) {
150         this.exportIndividualObservation = exportIndividualObservation;
151         firePropertyChange(PROPERTY_EXPORT_INDIVIDUAL_OBSERVATION, null, exportIndividualObservation);
152     }
153 
154     public boolean isExportAttachments() {
155         return exportAttachments;
156     }
157 
158     public void setExportAttachments(boolean exportAttachments) {
159         this.exportAttachments = exportAttachments;
160         firePropertyChange(PROPERTY_EXPORT_ATTACHMENTS, null, exportAttachments);
161     }
162 
163     public boolean isCanExport() {
164         return canExport;
165     }
166 
167     public void setCanExport(boolean canExport) {
168         this.canExport = canExport;
169         firePropertyChange(PROPERTY_CAN_EXPORT, null, canExport);
170     }
171 
172     public boolean isDataSelected() {
173         return dataSelected;
174     }
175 
176     public void setDataSelected(boolean dataSelected) {
177         this.dataSelected = dataSelected;
178         firePropertyChange(PROPERTY_DATA_SELECTED, null, dataSelected);
179     }
180 
181     public boolean computeIsCanExport() {
182         //TODO select data
183         return getProgram() != null && isDataSelected();
184     }
185 
186     public void setRootNode(ProgramSelectTreeNode rootNode) {
187         this.rootNode = rootNode;
188     }
189 
190     public ProgramSelectTreeNode getRootNode() {
191         return rootNode;
192     }
193 }