View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.referential.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.referential.Vessel;
26  import fr.ifremer.tutti.service.referential.ReferentialImportResult;
27  import fr.ifremer.tutti.service.referential.ReferentialTemporaryVesselService;
28  import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler;
29  
30  import java.io.File;
31  
32  import static org.nuiton.i18n.I18n.t;
33  
34  /**
35   * Import temporary vessel referential.
36   *
37   * @author Tony Chemit - chemit@codelutin.com
38   * @since 1.0
39   */
40  public class ImportTemporaryVesselAction extends ImportTemporaryActionSupport<Vessel> {
41  
42  
43      public ImportTemporaryVesselAction(ManageTemporaryReferentialUIHandler handler) {
44          super(handler);
45      }
46  
47      @Override
48      protected File chooseImportFile() {
49  
50          return chooseFile(
51                  t("tutti.manageTemporaryReferential.title.choose.importTemporaryVesselFile"),
52                  t("tutti.manageTemporaryReferential.action.chooseReferentialVesselFile.import"),
53                  "^.*\\.csv", t("tutti.common.file.csv"));
54  
55      }
56  
57      @Override
58      protected ReferentialImportResult<Vessel> doImport(File file) {
59  
60          ReferentialTemporaryVesselService service = getContext().getReferentialTemporaryVesselService();
61          return service.importTemporaryVessel(file);
62  
63      }
64  
65      @Override
66      protected void postSuccessAction(File file, ReferentialImportResult<Vessel> result) {
67  
68          int nbRef = getModel().getNbTemporaryVessels();
69          getModel().setNbTemporaryVessels(nbRef + result.getNbRefAdded() - result.getNbRefDeleted());
70  
71          // reset ui cache
72          getDataContext().resetVessels();
73          reloadCruise();
74          reloadFishingOperation();
75  
76          getHandler().resetComboBoxAction(getUI().getVesselActionComboBox());
77  
78          String title = t("tutti.manageTemporaryReferential.action.chooseReferentialVesselFile.import.dialog.title");
79          String message = t("tutti.manageTemporaryReferential.action.chooseReferentialVesselFile.import.dialog.message",
80                             result.getNbRefAdded(), result.getNbRefUpdated(), result.getNbRefDeleted());
81          displayInfoMessage(title, message);
82  
83          sendMessage(t("tutti.manageTemporaryReferential.action.chooseReferentialVesselFile.import.success", file));
84  
85      }
86  }