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.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   * Modele pour l onglet photo.
35   */
36  public class PhotosTabUIModel extends AbstractReefDbTableUIModel<PhotoDTO, PhotosTableRowModel, PhotosTabUIModel> implements TabContentModel {
37  
38      /**
39       * Constant <code>PROPERTY_OBSERVATION_MODEL="observationModel"</code>
40       */
41      public static final String PROPERTY_OBSERVATION_MODEL = "observationModel";
42      /**
43       * Constant <code>PROPERTY_PHOTO_INDEX="selectedPhoto"</code>
44       */
45      public static final String PROPERTY_PHOTO_INDEX = "selectedPhoto";
46      private ObservationUIModel observationModel;
47      /**
48       * L'indice courant pour la photo.
49       */
50      private Integer photoIndex = null;
51      private boolean modelAdjusting;
52  
53      /**
54       * <p>Getter for the field <code>observationModel</code>.</p>
55       *
56       * @return a {@link fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIModel} object.
57       */
58      public ObservationUIModel getObservationModel() {
59          return observationModel;
60      }
61  
62      /**
63       * <p>Setter for the field <code>observationModel</code>.</p>
64       *
65       * @param observationModel a {@link fr.ifremer.reefdb.ui.swing.content.observation.ObservationUIModel} object.
66       */
67      public void setObservationModel(ObservationUIModel observationModel) {
68          this.observationModel = observationModel;
69          firePropertyChange(PROPERTY_OBSERVATION_MODEL, null, observationModel);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public boolean isEmpty() {
75          return false; // getRowCount() == 0;
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public String getTitle() {
81          return n("reefdb.photo.title");
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public String getIcon() {
87          return null;
88      }
89  
90      /** {@inheritDoc} */
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      * <p>Getter for the field <code>photoIndex</code>.</p>
102      *
103      * @return a {@link java.lang.Integer} object.
104      */
105     public Integer getPhotoIndex() {
106         return photoIndex;
107     }
108 
109     /**
110      * <p>Setter for the field <code>photoIndex</code>.</p>
111      *
112      * @param photoIndex a {@link java.lang.Integer} object.
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      * <p>getFirstPhotoIndex.</p>
124      *
125      * @return a int.
126      */
127     public int getFirstPhotoIndex() {
128         return 0;
129     }
130 
131     /**
132      * <p>getLastPhotoIndex.</p>
133      *
134      * @return a int.
135      */
136     public int getLastPhotoIndex() {
137         return getRowCount() - 1;
138     }
139 
140     /**
141      * <p>isModelAdjusting.</p>
142      *
143      * @return a boolean.
144      */
145     public boolean isModelAdjusting() {
146         return modelAdjusting;
147     }
148 
149     /**
150      * <p>Setter for the field <code>modelAdjusting</code>.</p>
151      *
152      * @param modelAdjusting a boolean.
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 }