1 package fr.ifremer.tutti.ui.swing.content.operation.fishing.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
38
39
40
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
54
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
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 }