View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.program.menu;
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  import fr.ifremer.dali.ui.swing.action.AbstractCheckModelAction;
27  import fr.ifremer.dali.ui.swing.action.AbstractDaliSaveAction;
28  import fr.ifremer.dali.ui.swing.content.manage.program.ProgramsUI;
29  import fr.ifremer.dali.ui.swing.content.manage.program.ProgramsUIModel;
30  import fr.ifremer.dali.ui.swing.content.manage.program.SaveAction;
31  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
32  
33  /**
34   * Action permettant d effacer la recherche les mesures.
35   */
36  public class ClearAction extends AbstractCheckModelAction<ProgramsMenuUIModel, ProgramsMenuUI, ProgramsMenuUIHandler> {
37  
38  	/**
39  	 * Constructor.
40  	 *
41  	 * @param handler Controller
42  	 */
43  	public ClearAction(final ProgramsMenuUIHandler handler) {
44  		super(handler, false);
45  	}
46  
47  	/** {@inheritDoc} */
48  	@Override
49  	public void doAction() throws Exception {
50  		
51  		getModel().clear();
52          // remove selected item directly because model binding can't works here
53  		getUI().getProgramMnemonicCombo().setSelectedItem(null);
54  		getUI().getProgramCodeCombo().setSelectedItem(null);
55  
56      	// Suppression des informations du contexte
57      	getContext().setSelectedProgramCode(null);
58      	getContext().setSelectedLocationId(null);
59      	
60      	// Suppression des donnees dans les tableaux
61  		ProgramsUI ui = getHandler().getProgramsUI();
62  		if (ui != null) {
63  			ui.getModel().getProgramsUIModel().clear();
64  			ui.getModel().getStrategiesUIModel().clear();
65  			ui.getModel().getLocationsUIModel().clear();
66  			ui.getModel().getPmfmsUIModel().clear();
67  		}
68  	}
69  
70  	/** {@inheritDoc} */
71  	@Override
72  	protected Class<? extends AbstractDaliSaveAction> getSaveActionClass() {
73  		return SaveAction.class;
74  	}
75  
76  	/** {@inheritDoc} */
77  	@Override
78  	protected boolean isModelModify() {
79          final ProgramsUIModel model = getLocalModel();
80          return model != null && model.isModify();
81      }
82  
83  	/** {@inheritDoc} */
84  	@Override
85  	protected void setModelModify(boolean modelModify) {
86  		ProgramsUIModel model = getLocalModel();
87  		if (model != null) {
88  			model.setModify(modelModify);
89  		}
90  	}
91  
92  	/** {@inheritDoc} */
93  	@Override
94  	protected boolean isModelValid() {
95          final ProgramsUIModel model = getLocalModel();
96          return model == null || model.isValid();
97      }
98  
99  	/** {@inheritDoc} */
100 	@Override
101 	protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
102 		return getHandler().getProgramsUI().getHandler();
103 	}
104 
105 	private ProgramsUIModel getLocalModel() {
106 		final ProgramsUI ui = getHandler().getProgramsUI();
107 		if (ui != null) {
108 			return ui.getModel();
109 		}
110 		return null;
111 	}
112 
113 }