View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.fishing.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.Cruise;
26  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
27  import fr.ifremer.tutti.persistence.entities.data.FishingOperations;
28  import fr.ifremer.tutti.persistence.entities.referential.GearWithOriginalRankOrder;
29  import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUIHandler;
30  import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUIModel;
31  import org.nuiton.util.DateUtil;
32  
33  import java.util.Date;
34  import java.util.List;
35  
36  /**
37   * To create a new fishing operation.
38   *
39   * @author Tony Chemit - chemit@codelutin.com
40   * @since 1.0
41   */
42  public class NewFishingOperationAction extends EditFishingOperationAction {
43  
44      public NewFishingOperationAction(FishingOperationsUIHandler handler) {
45          super(handler);
46      }
47  
48      @Override
49      public void doAction() throws Exception {
50  
51          FishingOperationsUIModel model = getModel();
52  
53          // deselect selected fishingOperation
54          // Will remove the selection fishing operation from the comboBox
55  
56          model.setCatchEnabled(true);
57  
58          model.setEditionAdjusting(true);
59          try {
60              model.setSelectedFishingOperation(null);
61          } finally {
62              model.setEditionAdjusting(false);
63          }
64  
65          // creates a empty bean
66  
67          FishingOperation newFishingOperation =
68                  FishingOperations.newFishingOperation();
69          Cruise cruise = getDataContext().getCruise();
70          newFishingOperation.setCruise(cruise);
71          newFishingOperation.setVessel(cruise.getVessel());
72  
73          List<GearWithOriginalRankOrder> gears = cruise.getGear();
74          if (gears.size() == 1) {
75              newFishingOperation.setGear(gears.get(0));
76          }
77  
78          if (cruise.getMultirigNumber() == 1) {
79              newFishingOperation.setMultirigAggregation("1");
80          }
81  
82          Date today = DateUtil.getDay(new Date());
83          newFishingOperation.setGearShootingStartDate(today);
84          newFishingOperation.setGearShootingEndDate(today);
85          newFishingOperation.setFishingOperationValid(true);
86          setFishingOperation(newFishingOperation);
87  
88          super.doAction();
89      }
90  }