View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches.actions;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
26  import fr.ifremer.tutti.service.PersistenceService;
27  import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI;
28  import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler;
29  import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
30  import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor;
31  import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  /**
36   * To save a {@link CatchBatch}.
37   *
38   * @author Tony Chemit - chemit@codelutin.com
39   * @since 1.0
40   */
41  public class SaveCatchBatchAction extends LongActionSupport<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> {
42  
43      /** Logger. */
44      private static final Log log = LogFactory.getLog(SaveCatchBatchAction.class);
45  
46      /**
47       * A flag to update ui after create or save the edit catch batch.
48       *
49       * @since 1.0
50       */
51      protected boolean updateUI;
52  
53      public SaveCatchBatchAction(EditCatchesUIHandler handler) {
54          super(handler, true);
55      }
56  
57      public void setUpdateUI(boolean updateUI) {
58          this.updateUI = updateUI;
59      }
60  
61      @Override
62      public void releaseAction() {
63          updateUI = true;
64          super.releaseAction();
65      }
66  
67      @Override
68      public void doAction() throws Exception {
69  
70          TuttiBeanMonitor<EditCatchesUIModel> monitor = handler.getCatchBatchMonitor();
71  
72          // previous fishingOperation was modified, let's save it
73          EditCatchesUIModel beanToSave = monitor.getBean();
74  
75          // must save when bean is new or was modifiy and is valid
76          boolean mustSave = (beanToSave.isCreate() || beanToSave.isModify()) && beanToSave.isValid();
77  
78          if (mustSave) {
79  
80              PersistenceService persistenceService = getContext().getPersistenceService();
81  
82              CatchBatch catchBatch = beanToSave.toEntity();
83  
84              if (log.isInfoEnabled()) {
85                  log.info("FishingOperation " + catchBatch.getId() + " was modified, will save it.");
86              }
87  
88              //FIXME I18n
89              sendMessage("[ Captures - Caractéristiques générales ] Sauvegarde des modifications du résumé de la capture.");
90  
91              persistenceService.saveCatchBatch(catchBatch);
92  
93              monitor.clearModified();
94              getModel().setModify(false);
95          }
96  
97          getUI().getSpeciesTabPanel().getEditBatchesUI().getHandler().clearTableSelection();
98          getUI().getBenthosTabPanel().getEditBatchesUI().getHandler().clearTableSelection();
99  
100     }
101 
102 }