View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.observation.photo;
2   
3   /*
4    * #%L
5    * Reef DB :: 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 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   * Modele des lignes pour le tableau des photos.
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  	 * Constructor.
60  	 *
61  	 * @param readOnly a boolean.
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      /** {@inheritDoc} */
78      @Override
79      public boolean isEditable() {
80          return !readOnly && super.isEditable();
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85  	protected PhotoDTO newBean() {
86  		return ReefDbBeanFactory.newPhotoDTO();
87  	}
88  
89  	/** {@inheritDoc} */
90  	@Override
91  	public String getName() {
92  		return delegateObject.getName();
93  	}
94  
95  	/** {@inheritDoc} */
96  	@Override
97  	public void setName(String name) {
98  		delegateObject.setName(name);
99  	}
100 
101 	/** {@inheritDoc} */
102 	@Override
103 	public String getCaption() {
104 		return delegateObject.getCaption();
105 	}
106 
107 	/** {@inheritDoc} */
108 	@Override
109 	public void setCaption(String caption) {
110 		delegateObject.setCaption(caption);
111 	}
112 
113 	/** {@inheritDoc} */
114 	@Override
115 	public Date getDate() {
116 		return delegateObject.getDate();
117 	}
118 
119 	/** {@inheritDoc} */
120 	@Override
121 	public void setDate(Date date) {
122 		delegateObject.setDate(date);
123 	}
124 
125 	/** {@inheritDoc} */
126 	@Override
127 	public String getDirection() {
128 		return delegateObject.getDirection();
129 	}
130 
131 	/** {@inheritDoc} */
132 	@Override
133 	public void setDirection(String direction) {
134 		delegateObject.setDirection(direction);
135 	}
136 
137 	/** {@inheritDoc} */
138 	@Override
139 	public String getPath() {
140 		return delegateObject.getPath();
141 	}
142 
143 	/** {@inheritDoc} */
144 	@Override
145 	public void setPath(String path) {
146 		delegateObject.setPath(path);
147 	}
148 
149 	/** {@inheritDoc} */
150 	@Override
151 	public String getFullPath() {
152 		return delegateObject.getFullPath();
153 	}
154 
155 	/** {@inheritDoc} */
156 	@Override
157 	public void setFullPath(String tempPath) {
158 		delegateObject.setFullPath(tempPath);
159 	}
160 
161 	/** {@inheritDoc} */
162 	@Override
163 	public boolean isDirty() {
164 		return delegateObject.isDirty();
165 	}
166 
167 	/** {@inheritDoc} */
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 	/** {@inheritDoc} */
184 	@Override
185 	public SamplingOperationDTO getSamplingOperation() {
186 		return delegateObject.getSamplingOperation();
187 	}
188 
189 	/** {@inheritDoc} */
190 	@Override
191 	public void setSamplingOperation(SamplingOperationDTO samplingOperation) {
192 		delegateObject.setSamplingOperation(samplingOperation);
193 	}
194 
195 	/** {@inheritDoc} */
196 	@Override
197 	public PhotoTypeDTO getPhotoType() {
198 		return delegateObject.getPhotoType();
199 	}
200 
201 	/** {@inheritDoc} */
202 	@Override
203 	public void setPhotoType(PhotoTypeDTO photoType) {
204 		delegateObject.setPhotoType(photoType);
205 	}
206 
207     /** {@inheritDoc} */
208     @Override
209     public Collection<ErrorDTO> getErrors() {
210         return errors;
211     }
212 }