View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.cruise.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.CaracteristicMap;
26  import fr.ifremer.tutti.persistence.entities.referential.GearWithOriginalRankOrder;
27  import fr.ifremer.tutti.persistence.entities.referential.GearWithOriginalRankOrders;
28  import fr.ifremer.tutti.service.PersistenceService;
29  import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport;
30  import fr.ifremer.tutti.ui.swing.content.cruise.EditCruiseUI;
31  import fr.ifremer.tutti.ui.swing.content.cruise.EditCruiseUIHandler;
32  import fr.ifremer.tutti.ui.swing.content.cruise.EditCruiseUIModel;
33  import fr.ifremer.tutti.ui.swing.content.cruise.GearCaracteristicsEditorUI;
34  import org.apache.commons.logging.Log;
35  import org.apache.commons.logging.LogFactory;
36  
37  /**
38   * @author Kevin Morin - kmorin@codelutin.com
39   * @since 2.1
40   */
41  public class EditGearCaracteristicsAction extends LongActionSupport<EditCruiseUIModel, EditCruiseUI, EditCruiseUIHandler> {
42  
43      /** Logger. */
44      private static final Log log =
45              LogFactory.getLog(EditGearCaracteristicsAction.class);
46  
47      protected final PersistenceService persistenceService;
48  
49      public EditGearCaracteristicsAction(EditCruiseUIHandler handler) {
50          super(handler, false);
51          persistenceService = getContext().getPersistenceService();
52      }
53  
54      @Override
55      public void doAction() throws Exception {
56          GearCaracteristicsEditorUI editor = getUI().getGearCaracteristicsEditor();
57          editor.getModel().setEditable(true);
58  
59          GearWithOriginalRankOrder gear =
60                  EditCruiseUIHandler.GEAR_EDIT_CONTEXT.getContextValue(getUI());
61  
62          CaracteristicMap caracteristics =
63                  persistenceService.getGearCaracteristics(
64                          getDataContext().getCruise().getIdAsInt(),
65                          gear.getIdAsInt(),
66                          gear.getOriginalRankOrder());
67  
68          GearWithOriginalRankOrder gearToView =
69                  GearWithOriginalRankOrders.newGearWithOriginalRankOrder(gear);
70          gearToView.setCaracteristics(caracteristics);
71  
72          if (log.isInfoEnabled()) {
73              log.info("Will edit gear " + decorate(gearToView) +
74                       " with " + gearToView.getCaracteristics().size() + " caracteristics.");
75          }
76          editor.getModel().setGear(gearToView);
77  
78          getUI().getMainPanelLayout().setSelected(EditCruiseUIHandler.GEAR_CARACTERISTICS_CARD);
79      }
80  }