View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.report;
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.data.FishingOperation;
26  import fr.ifremer.tutti.service.report.ReportGenerationRequest;
27  import fr.ifremer.tutti.service.report.ReportGenerationResult;
28  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
29  import org.nuiton.util.beans.Binder;
30  import org.nuiton.util.beans.BinderFactory;
31  
32  import java.io.File;
33  import java.util.List;
34  
35  /**
36   * Model of {@link ReportUI} screen.
37   *
38   * @author Tony Chemit - chemit@codelutin.com
39   * @since 2.9
40   */
41  public class ReportUIModel extends AbstractTuttiBeanUIModel<ReportGenerationRequest, ReportUIModel> {
42  
43      private static final long serialVersionUID = 1L;
44  
45      public static final String PROPERTY_REPORTS = "reports";
46  
47      public static final String PROPERTY_REPORT = "report";
48  
49      public static final String PROPERTY_FISHING_OPERATION = "fishingOperation";
50  
51      public static final String PROPERTY_REPORT_DONE = "reportDone";
52  
53      protected static Binder<ReportUIModel, ReportGenerationRequest> toBeanBinder =
54              BinderFactory.newBinder(ReportUIModel.class,
55                                      ReportGenerationRequest.class);
56  
57      protected List<File> reports;
58  
59      protected List<FishingOperation> fishingOperations;
60  
61      protected ReportGenerationResult reportGenerationResult;
62  
63      /** Report to use. */
64      protected File report;
65  
66      protected String programId;
67  
68      protected Integer cruiseId;
69  
70      protected FishingOperation fishingOperation;
71  
72      public ReportUIModel() {
73          super(null, toBeanBinder);
74      }
75  
76      public List<File> getReports() {
77          return reports;
78      }
79  
80      public void setReports(List<File> reports) {
81          Object oldValue = getReports();
82          this.reports = reports;
83          firePropertyChange(PROPERTY_REPORTS, oldValue, reports);
84      }
85  
86      public List<FishingOperation> getFishingOperations() {
87          return fishingOperations;
88      }
89  
90      public void setFishingOperations(List<FishingOperation> fishingOperations) {
91          this.fishingOperations = fishingOperations;
92      }
93  
94      public File getReport() {
95          return report;
96      }
97  
98      public void setReport(File report) {
99          Object oldValue = getReport();
100         this.report = report;
101         firePropertyChange(PROPERTY_REPORT, oldValue, report);
102     }
103 
104     public String getProgramId() {
105         return programId;
106     }
107 
108     public void setProgramId(String programId) {
109         this.programId = programId;
110     }
111 
112     public Integer getCruiseId() {
113         return cruiseId;
114     }
115 
116     public void setCruiseId(Integer cruiseId) {
117         this.cruiseId = cruiseId;
118     }
119 
120     public Integer getFishingOperationId() {
121         return fishingOperation == null ? null : fishingOperation.getIdAsInt();
122     }
123 
124     public FishingOperation getFishingOperation() {
125         return fishingOperation;
126     }
127 
128     public void setFishingOperation(FishingOperation fishingOperation) {
129         Object oldValue = this.fishingOperation;
130         this.fishingOperation = fishingOperation;
131         firePropertyChange(PROPERTY_FISHING_OPERATION, oldValue, fishingOperation);
132     }
133 
134     public void setReportGenerationResult(ReportGenerationResult reportGenerationResult) {
135         this.reportGenerationResult = reportGenerationResult;
136         firePropertyChange(PROPERTY_REPORT_DONE, null, isReportDone());
137     }
138 
139     public File getOutputFile() {
140         return reportGenerationResult.getOutputFile();
141     }
142 
143     public boolean isReportDone() {
144         return reportGenerationResult != null;
145     }
146 
147     @Override
148     protected ReportGenerationRequest newEntity() {
149         return new ReportGenerationRequest();
150     }
151 }