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.data.photo.PhotoDTO;
27 import fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIModel;
28 import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableUIModel;
29 import org.nuiton.jaxx.application.swing.tab.TabContentModel;
30
31 import static org.nuiton.i18n.I18n.n;
32
33
34
35
36 public class PhotosTabUIModel extends AbstractReefDbTableUIModel<PhotoDTO, PhotosTableRowModel, PhotosTabUIModel> implements TabContentModel {
37
38
39
40
41 public static final String PROPERTY_OBSERVATION_MODEL = "observationModel";
42
43
44
45 public static final String PROPERTY_PHOTO_INDEX = "selectedPhoto";
46 private ObservationUIModel observationModel;
47
48
49
50 private Integer photoIndex = null;
51 private boolean modelAdjusting;
52
53
54
55
56
57
58 public ObservationUIModel getObservationModel() {
59 return observationModel;
60 }
61
62
63
64
65
66
67 public void setObservationModel(ObservationUIModel observationModel) {
68 this.observationModel = observationModel;
69 firePropertyChange(PROPERTY_OBSERVATION_MODEL, null, observationModel);
70 }
71
72
73 @Override
74 public boolean isEmpty() {
75 return false;
76 }
77
78
79 @Override
80 public String getTitle() {
81 return n("reefdb.photo.title");
82 }
83
84
85 @Override
86 public String getIcon() {
87 return null;
88 }
89
90
91 @Override
92 public boolean isCloseable() {
93 return false;
94 }
95
96 public PhotosTableRowModel getSelectedPhoto() {
97 return getPhotoIndex() != null ? getRows().get(getPhotoIndex()) : null;
98 }
99
100
101
102
103
104
105 public Integer getPhotoIndex() {
106 return photoIndex;
107 }
108
109
110
111
112
113
114 public void setPhotoIndex(Integer photoIndex) {
115 Integer oldValue = getPhotoIndex();
116 this.photoIndex = photoIndex != null
117 ? Math.max(getFirstPhotoIndex(), Math.min(getLastPhotoIndex(), photoIndex))
118 : null;
119 firePropertyChange(PROPERTY_PHOTO_INDEX, oldValue, photoIndex);
120 }
121
122
123
124
125
126
127 public int getFirstPhotoIndex() {
128 return 0;
129 }
130
131
132
133
134
135
136 public int getLastPhotoIndex() {
137 return getRowCount() - 1;
138 }
139
140
141
142
143
144
145 public boolean isModelAdjusting() {
146 return modelAdjusting;
147 }
148
149
150
151
152
153
154 public void setModelAdjusting(boolean modelAdjusting) {
155 this.modelAdjusting = modelAdjusting;
156 }
157
158 public boolean isExportEnabled() {
159 return getSelectedRows().stream().anyMatch(PhotosTableRowModel::isFileExists);
160 }
161
162 public boolean isDownloadEnabled() {
163 return getSelectedRows().stream().anyMatch(PhotosTableRowModel::isFileDownloadable);
164 }
165 }