View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local.replace;
2   
3   /*
4    * #%L
5    * Reef DB :: 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.reefdb.dto.referential.SamplingEquipmentDTO;
27  import fr.ifremer.reefdb.service.referential.ReferentialService;
28  import fr.ifremer.reefdb.ui.swing.content.manage.referential.replace.AbstractReplaceAction;
29  import fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.ManageSamplingEquipmentsUI;
30  
31  import javax.swing.*;
32  
33  import static org.nuiton.i18n.I18n.t;
34  
35  /**
36   * Created on 7/6/14.
37   */
38  public class ReplaceSamplingEquipmentAction extends AbstractReplaceAction<SamplingEquipmentDTO, ReplaceSamplingEquipmentUIModel, ReplaceSamplingEquipmentUI, ReplaceSamplingEquipmentUIHandler> {
39  
40      /**
41       * <p>Constructor for ReplaceSamplingEquipmentAction.</p>
42       *
43       * @param handler a {@link fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local.replace.ReplaceSamplingEquipmentUIHandler} object.
44       */
45      public ReplaceSamplingEquipmentAction(ReplaceSamplingEquipmentUIHandler handler) {
46          super(handler);
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      protected String getReferentialLabel() {
52          return t("reefdb.property.samplingEquipment");
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      protected boolean prepareReplaceReferential(ReferentialService service, SamplingEquipmentDTO source, SamplingEquipmentDTO target) {
58  
59          if (service.isSamplingEquipmentUsedInValidatedData(source.getId())) {
60              String decoratedSource = decorate(source);
61              if (getContext().getDialogHelper().showConfirmDialog(getReplaceUI(), t("reefdb.replaceReferential.used.validatedData.message", decoratedSource, decoratedSource),
62                      getReplaceUI().getTitle(), JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
63                  return false;
64              }
65              setDelete(false);
66          }
67  
68          return true;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      protected void replaceReferential(ReferentialService service, SamplingEquipmentDTO source, SamplingEquipmentDTO target, boolean delete) {
74  
75          service.replaceSamplingEquipment(source, target, delete);
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      protected void resetCaches() {
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public void postSuccessAction() {
86          super.postSuccessAction();
87  
88          final ManageSamplingEquipmentsUI ui = (ManageSamplingEquipmentsUI) getContext().getMainUI().getHandler().getCurrentBody();
89          // reload table
90          if (ui != null) {
91              SwingUtilities.invokeLater(() -> getActionEngine().runAction(ui.getSamplingEquipmentsLocalUI().getSamplingEquipmentsLocalMenuUI().getSearchButton()));
92          }
93  
94      }
95  }