View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.context.contextslist;
2   
3   /*
4    * #%L
5    * Dali :: 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  
27  import fr.ifremer.dali.dto.configuration.context.ContextDTO;
28  import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
29  import fr.ifremer.dali.ui.swing.content.manage.context.ManageContextsUI;
30  import fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil;
31  
32  import java.io.File;
33  import java.util.List;
34  
35  import static org.nuiton.i18n.I18n.t;
36  
37  /**
38   * Action pour le remplacement d'un lieu local par un lieu national
39   */
40  public class ImportContextAction extends AbstractDaliAction<ManageContextsListTableUIModel, ManageContextsListTableUI, ManageContextsListTableUIHandler> {
41  
42      private List<ContextDTO> importedContexts;
43      
44      private File importFile;
45      
46  	/**
47  	 * Constructor.
48  	 *
49  	 * @param handler Controlleur
50  	 */
51  	public ImportContextAction(ManageContextsListTableUIHandler handler) {
52  		super(handler, false);
53  	}
54  
55  	/** {@inheritDoc} */
56  	@Override
57      public boolean prepareAction() throws Exception {
58          importFile = null;
59          if (super.prepareAction()) {
60              // get importFile
61              importFile = chooseFile(t("dali.action.context.import.title"),
62                                                  t("dali.action.common.chooseFile.buttonLabel"),
63                                                  "^.*\\.dat", t("dali.common.file.dat"));
64              
65          }
66          return importFile != null && importFile.exists();
67      }
68  
69  	/** {@inheritDoc} */
70  	@Override
71  	public void doAction() throws Exception {
72          importedContexts = getContext().getContextService().importContexts(importFile);
73  	}
74  
75      /** {@inheritDoc} */
76      @Override
77      public void postSuccessAction() {
78          getModel().addBeans(importedContexts);
79          // fix Mantis #30776
80          ((ManageContextsUI) ApplicationUIUtil.getParentUI(getUI())).getManageContextsListMenuUI().getHandler().reloadComboBox();
81      }
82  }