View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.campaign.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.campaign.CampaignsUI;
29  import fr.ifremer.dali.ui.swing.content.manage.campaign.CampaignsUIModel;
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.
35   */
36  public class ClearAction extends AbstractCheckModelAction<CampaignsMenuUIModel, CampaignsMenuUI, CampaignsMenuUIHandler> {
37  
38  	/**
39  	 * Constructor.
40  	 *
41  	 * @param handler Controller
42  	 */
43  	public ClearAction(final CampaignsMenuUIHandler 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().getStartDateCombo().setSelectedItem(null);
54  		getUI().getEndDateCombo().setSelectedItem(null);
55  
56      	// Suppression des donnees dans les tableaux
57          if (getLocalModel() != null && getLocalModel().getCampaignsTableUIModel() != null)
58          	getLocalModel().getCampaignsTableUIModel().setBeans(null);
59  	}
60  
61  	/** {@inheritDoc} */
62  	@Override
63  	protected Class<? extends AbstractDaliSaveAction> getSaveActionClass() {
64  		return SaveAction.class;
65  	}
66  
67  	/** {@inheritDoc} */
68  	@Override
69  	protected boolean isModelModify() {
70          final CampaignsUIModel model = getLocalModel();
71          return model != null && model.isModify();
72      }
73  
74  	/** {@inheritDoc} */
75  	@Override
76  	protected void setModelModify(boolean modelModify) {
77  		CampaignsUIModel model = getLocalModel();
78  		if (model != null) {
79  			model.setModify(modelModify);
80  		}
81  	}
82  
83  	/** {@inheritDoc} */
84  	@Override
85  	protected boolean isModelValid() {
86          final CampaignsUIModel model = getLocalModel();
87          return model == null || model.isValid();
88      }
89  
90  	/** {@inheritDoc} */
91  	@Override
92  	protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
93  		return getHandler().getCampaignsUI().getHandler();
94  	}
95  
96  	private CampaignsUIModel getLocalModel() {
97  		final CampaignsUI ui = getHandler().getCampaignsUI();
98  		if (ui != null) {
99  			return ui.getModel();
100 		}
101 		return null;
102 	}
103 
104 }