View Javadoc
1   package fr.ifremer.quadrige3.ui.swing.synchro.action;
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.vo.SynchroProgressionStatus;
28  import fr.ifremer.quadrige3.ui.swing.action.AbstractWorkerAction;
29  import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUI;
30  import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIContext;
31  import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIHandler;
32  import org.apache.commons.lang3.StringUtils;
33  import org.apache.commons.logging.Log;
34  import org.apache.commons.logging.LogFactory;
35  
36  import java.net.URI;
37  import java.net.URISyntaxException;
38  import java.net.URL;
39  
40  /**
41   * Abstract Synchronization Action
42   *
43   * @author Ludovic Pecquot <ludovic.pecquot@e-is.pro>
44   */
45  public abstract class AbstractSynchroAction extends AbstractWorkerAction<SynchroUIContext, SynchroUI, SynchroUIHandler> {
46  
47      private static final Log log = LogFactory.getLog(AbstractSynchroAction.class);
48  
49      private URI baseUri;
50  
51      /**
52       * <p>Constructor for AbstractSynchroAction.</p>
53       *
54       * @param handler a {@link SynchroUIHandler} object.
55       */
56      public AbstractSynchroAction(SynchroUIHandler handler) {
57          super(handler);
58      }
59  
60      URI getBaseUri() {
61          return baseUri;
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public boolean initAction() {
67  
68          URL baseUrl = getConfig().getSynchronizationSiteUrl();
69          try {
70              baseUri = baseUrl.toURI();
71          } catch (URISyntaxException ex) {
72              failedAction(ex);
73              return false;
74          }
75  
76          // by default by set by
77          getModel().setServerSide(false);
78  
79          return true;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public void failedAction(Throwable ex) {
85  
86          String message = ex.getLocalizedMessage();
87          if (StringUtils.isBlank(message)) {
88              message = ex.toString();
89          }
90          log.error(message, ex);
91          getHandler().report(message);
92          getModel().setStatus(SynchroProgressionStatus.FAILED);
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public void disposeAction() {
98          // if something to dispose after work
99      }
100 
101 }