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