1 package fr.ifremer.reefdb.ui.swing.content.observation.photo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import fr.ifremer.reefdb.dto.ErrorAware;
27 import fr.ifremer.reefdb.dto.ErrorDTO;
28 import fr.ifremer.reefdb.dto.ReefDbBeanFactory;
29 import fr.ifremer.reefdb.dto.data.photo.PhotoDTO;
30 import fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO;
31 import fr.ifremer.reefdb.dto.referential.PhotoTypeDTO;
32 import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbRowUIModel;
33 import org.nuiton.util.beans.Binder;
34 import org.nuiton.util.beans.BinderFactory;
35
36 import java.nio.file.Files;
37 import java.nio.file.Paths;
38 import java.util.ArrayList;
39 import java.util.Collection;
40 import java.util.Date;
41 import java.util.List;
42
43
44
45
46 public class PhotosTableRowModel extends AbstractReefDbRowUIModel<PhotoDTO, PhotosTableRowModel> implements PhotoDTO, ErrorAware {
47
48 private static final Binder<PhotoDTO, PhotosTableRowModel> FROM_BEAN_BINDER =
49 BinderFactory.newBinder(PhotoDTO.class, PhotosTableRowModel.class);
50
51 private static final Binder<PhotosTableRowModel, PhotoDTO> TO_BEAN_BINDER =
52 BinderFactory.newBinder(PhotosTableRowModel.class, PhotoDTO.class);
53
54 private final boolean readOnly;
55
56 private final List<ErrorDTO> errors;
57
58
59
60
61
62
63 public PhotosTableRowModel(boolean readOnly) {
64 super(FROM_BEAN_BINDER, TO_BEAN_BINDER);
65 this.readOnly = readOnly;
66 errors = new ArrayList<>();
67 }
68
69 boolean isFileExists() {
70 return getFullPath() != null && Files.isRegularFile(Paths.get(getFullPath()));
71 }
72
73 boolean isFileDownloadable() {
74 return !isFileExists() && getRemoteId() != null;
75 }
76
77
78 @Override
79 public boolean isEditable() {
80 return !readOnly && super.isEditable();
81 }
82
83
84 @Override
85 protected PhotoDTO newBean() {
86 return ReefDbBeanFactory.newPhotoDTO();
87 }
88
89
90 @Override
91 public String getName() {
92 return delegateObject.getName();
93 }
94
95
96 @Override
97 public void setName(String name) {
98 delegateObject.setName(name);
99 }
100
101
102 @Override
103 public String getCaption() {
104 return delegateObject.getCaption();
105 }
106
107
108 @Override
109 public void setCaption(String caption) {
110 delegateObject.setCaption(caption);
111 }
112
113
114 @Override
115 public Date getDate() {
116 return delegateObject.getDate();
117 }
118
119
120 @Override
121 public void setDate(Date date) {
122 delegateObject.setDate(date);
123 }
124
125
126 @Override
127 public String getDirection() {
128 return delegateObject.getDirection();
129 }
130
131
132 @Override
133 public void setDirection(String direction) {
134 delegateObject.setDirection(direction);
135 }
136
137
138 @Override
139 public String getPath() {
140 return delegateObject.getPath();
141 }
142
143
144 @Override
145 public void setPath(String path) {
146 delegateObject.setPath(path);
147 }
148
149
150 @Override
151 public String getFullPath() {
152 return delegateObject.getFullPath();
153 }
154
155
156 @Override
157 public void setFullPath(String tempPath) {
158 delegateObject.setFullPath(tempPath);
159 }
160
161
162 @Override
163 public boolean isDirty() {
164 return delegateObject.isDirty();
165 }
166
167
168 @Override
169 public void setDirty(boolean dirty) {
170 delegateObject.setDirty(dirty);
171 }
172
173 @Override
174 public Integer getRemoteId() {
175 return delegateObject.getRemoteId();
176 }
177
178 @Override
179 public void setRemoteId(Integer remoteId) {
180 delegateObject.setRemoteId(remoteId);
181 }
182
183
184 @Override
185 public SamplingOperationDTO getSamplingOperation() {
186 return delegateObject.getSamplingOperation();
187 }
188
189
190 @Override
191 public void setSamplingOperation(SamplingOperationDTO samplingOperation) {
192 delegateObject.setSamplingOperation(samplingOperation);
193 }
194
195
196 @Override
197 public PhotoTypeDTO getPhotoType() {
198 return delegateObject.getPhotoType();
199 }
200
201
202 @Override
203 public void setPhotoType(PhotoTypeDTO photoType) {
204 delegateObject.setPhotoType(photoType);
205 }
206
207
208 @Override
209 public Collection<ErrorDTO> getErrors() {
210 return errors;
211 }
212 }