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