View Javadoc
1   package fr.ifremer.dali.ui.swing.content.extraction.list;
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.DaliBeans;
27  import fr.ifremer.dali.dto.system.extraction.ExtractionDTO;
28  import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
29  import fr.ifremer.dali.ui.swing.content.extraction.ExtractionUI;
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  
33  import java.util.Collection;
34  import java.util.List;
35  
36  import static org.nuiton.i18n.I18n.t;
37  
38  /**
39   * Delete extractions Action
40   */
41  public class DeleteExtractionAction extends AbstractDaliAction<ExtractionsTableUIModel, ExtractionsTableUI, ExtractionsTableUIHandler> {
42  
43      private static final Log LOG = LogFactory.getLog(DeleteExtractionAction.class);
44  
45      private Collection<? extends ExtractionDTO> extractionsToDelete;
46  
47      /**
48       * Constructor.
49       *
50       * @param handler Handler
51       */
52      public DeleteExtractionAction(ExtractionsTableUIHandler handler) {
53          super(handler, false);
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public boolean prepareAction() throws Exception {
59          if (!super.prepareAction()) {
60              return false;
61          }
62  
63          if (getModel().getSelectedRows().isEmpty()) {
64              LOG.warn("no selected extraction");
65              return false;
66          }
67  
68          extractionsToDelete = getModel().getSelectedRows();
69  
70          return askBeforeDelete(t("dali.action.delete.extraction.titre"), t("dali.action.delete.extraction.message"));
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public void doAction() throws Exception {
76  
77          // Selected observation ID
78          List<Integer> idExtractionToDelete = DaliBeans.collectIds(extractionsToDelete);
79  
80          // Remove observations service
81          getContext().getExtractionService().deleteExtractions(idExtractionToDelete);
82  
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public void postSuccessAction() {
88  
89          // Remove form model
90          getModel().deleteSelectedRows();
91  
92          getUI().getParentContainer(ExtractionUI.class).getHandler().reloadComboBox();
93  
94          super.postSuccessAction();
95      }
96  }