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  import fr.ifremer.dali.dto.data.photo.PhotoDTO;
27  import fr.ifremer.dali.ui.swing.content.observation.ObservationUIModel;
28  import fr.ifremer.dali.ui.swing.util.table.AbstractDaliTableUIModel;
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 AbstractDaliTableUIModel<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.dali.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.dali.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      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public boolean isEmpty() {
77          return false; // getRowCount() == 0;
78      }
79  
80      /**
81       * {@inheritDoc}
82       */
83      @Override
84      public String getTitle() {
85          return n("dali.photo.title");
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public String getIcon() {
93          return null;
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public boolean isCloseable() {
101         return false;
102     }
103 
104     public PhotosTableRowModel getSelectedPhoto() {
105         return getPhotoIndex() != null ? getRows().get(getPhotoIndex()) : null;
106     }
107 
108     /**
109      * <p>Getter for the field <code>photoIndex</code>.</p>
110      *
111      * @return a {@link java.lang.Integer} object.
112      */
113     public Integer getPhotoIndex() {
114         return photoIndex;
115     }
116 
117     /**
118      * <p>Setter for the field <code>photoIndex</code>.</p>
119      *
120      * @param photoIndex a {@link java.lang.Integer} object.
121      */
122     public void setPhotoIndex(Integer photoIndex) {
123         Integer oldValue = getPhotoIndex();
124         this.photoIndex = photoIndex != null
125                 ? Math.max(getFirstPhotoIndex(), Math.min(getLastPhotoIndex(), photoIndex))
126                 : null;
127         firePropertyChange(PROPERTY_PHOTO_INDEX, oldValue, photoIndex);
128     }
129 
130     /**
131      * <p>getFirstPhotoIndex.</p>
132      *
133      * @return a int.
134      */
135     public int getFirstPhotoIndex() {
136         return 0;
137     }
138 
139     /**
140      * <p>getLastPhotoIndex.</p>
141      *
142      * @return a int.
143      */
144     public int getLastPhotoIndex() {
145         return getRowCount() - 1;
146     }
147 
148     /**
149      * <p>isModelAdjusting.</p>
150      *
151      * @return a boolean.
152      */
153     public boolean isModelAdjusting() {
154         return modelAdjusting;
155     }
156 
157     /**
158      * <p>Setter for the field <code>modelAdjusting</code>.</p>
159      *
160      * @param modelAdjusting a boolean.
161      */
162     public void setModelAdjusting(boolean modelAdjusting) {
163         this.modelAdjusting = modelAdjusting;
164     }
165 
166     public boolean isExportEnabled() {
167         return getSelectedRows().stream().anyMatch(PhotosTableRowModel::isFileExists);
168     }
169 
170     public boolean isDownloadEnabled() {
171         return getSelectedRows().stream().anyMatch(PhotosTableRowModel::isFileDownloadable);
172     }
173 }