View Javadoc
1   package fr.ifremer.quadrige3.ui.swing.synchro.resolver;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 UI Common
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 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  
27  import fr.ifremer.quadrige3.synchro.service.client.NotExportableRowStatus;
28  import fr.ifremer.quadrige3.synchro.service.client.NotExportableRowStrategy;
29  import fr.ifremer.quadrige3.synchro.service.client.SynchroNotExportableRowResolver;
30  import fr.ifremer.quadrige3.ui.swing.DialogHelper;
31  
32  import javax.swing.JOptionPane;
33  import javax.swing.SwingUtilities;
34  
35  import static org.nuiton.i18n.I18n.t;
36  
37  /**
38   * <p>SynchroNotExportableRowUIResolver class.</p>
39   *
40   * @author Lionel Touseau <lionel.touseau@e-is.pro>
41   */
42  public class SynchroNotExportableRowUIResolver implements SynchroNotExportableRowResolver {
43  
44  
45      private final DialogHelper dialogHelper;
46  
47      /**
48       * <p>Constructor for SynchroNotExportableRowUIResolver.</p>
49       *
50       * @param dialogHelper a {@link DialogHelper} object.
51       */
52      public SynchroNotExportableRowUIResolver(DialogHelper dialogHelper) {
53          this.dialogHelper = dialogHelper;
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public NotExportableRowStrategy getStrategy(final NotExportableRowStatus status, final String rejectMessage) {
59  
60          NotExportableRowStrategy rejectedRowStrategy = NotExportableRowStrategy.CANCEL;
61          int dialogResult;
62  
63          // Ask user to show to keep or delete his data
64          if (status == NotExportableRowStatus.RECORDED_BY_USER) {
65  
66              dialogResult = dialogHelper.showConfirmDialog(
67                      t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_USER.message"),
68                      rejectMessage,
69                      t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_USER.help"),
70                      t("quadrige3.action.synchro.export.notExportable.title"),
71                      JOptionPane.YES_NO_CANCEL_OPTION);
72              switch (dialogResult) {
73                  case JOptionPane.YES_OPTION: // = OK_OPTION
74                      rejectedRowStrategy = NotExportableRowStrategy.KEEP_LOCAL;
75                      break;
76                  case JOptionPane.NO_OPTION:
77                      rejectedRowStrategy = NotExportableRowStrategy.DELETE;
78                      break;
79                  case JOptionPane.CANCEL_OPTION:
80                      rejectedRowStrategy = NotExportableRowStrategy.CANCEL;
81                      break;
82              }
83          }
84  
85          // Display not exportable data to user
86          else if (status == NotExportableRowStatus.RECORDED_BY_OTHER) {
87  
88              // Display as non-blocking warning dialog
89              SwingUtilities.invokeLater(() -> dialogHelper.showWarningDialog(
90                      t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_OTHER.message"),
91                      rejectMessage,
92                      t("quadrige3.action.synchro.export.notExportable.RECORDED_BY_OTHER.help"),
93                      t("quadrige3.action.synchro.export.notExportable.title")));
94  
95              rejectedRowStrategy = NotExportableRowStrategy.KEEP_LOCAL;
96          }
97  
98          // Display not exportable data to user
99          else if (status == NotExportableRowStatus.DIRTY_AND_OLD) {
100 
101             // Display a non-blocking warning dialog
102             SwingUtilities.invokeLater(() -> dialogHelper.showWarningDialog(
103                     t("quadrige3.action.synchro.export.notExportable.DIRTY_AND_OLD.message"),
104                     rejectMessage,
105                     t("quadrige3.action.synchro.export.notExportable.DIRTY_AND_OLD.help"),
106                     t("quadrige3.action.synchro.export.notExportable.title")));
107 
108             rejectedRowStrategy = NotExportableRowStrategy.KEEP_LOCAL;
109         }
110 
111         return rejectedRowStrategy;
112     }
113 
114 }