View Javadoc
1   package fr.ifremer.dali.ui.swing.action;
2   
3   /*-
4    * #%L
5    * Dali :: UI
6    * %%
7    * Copyright (C) 2014 - 2017 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Affero General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU Affero General Public License
20   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
22   */
23  
24  import fr.ifremer.dali.ui.swing.util.DaliUI;
25  import fr.ifremer.quadrige3.ui.swing.AbstractUIHandler;
26  import fr.ifremer.quadrige3.ui.swing.model.AbstractBeanUIModel;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  /**
32   * @author peck7 on 04/07/2017.
33   */
34  public abstract class AbstractDaliSaveAction<M extends AbstractBeanUIModel, UI extends DaliUI<M, ?>, H extends AbstractUIHandler<M, UI>>
35          extends AbstractDaliAction<M, UI, H> {
36  
37      private boolean fromChangeScreenAction = false;
38      private boolean fromCheckModelAction = false;
39      private boolean allowChangeScreen = true;
40  
41      /**
42       * <p>Constructor for AbstractAction.</p>
43       *
44       * @param handler  a H object.
45       * @param hideBody a boolean.
46       */
47      public AbstractDaliSaveAction(H handler, boolean hideBody) {
48          super(handler, hideBody);
49      }
50  
51      public boolean isFromChangeScreenAction() {
52          return fromChangeScreenAction;
53      }
54  
55      public void setFromChangeScreenAction(boolean fromChangeScreenAction) {
56          this.fromChangeScreenAction = fromChangeScreenAction;
57      }
58  
59      public boolean isFromCheckModelAction() {
60          return fromCheckModelAction;
61      }
62  
63      public void setFromCheckModelAction(boolean fromCheckModelAction) {
64          this.fromCheckModelAction = fromCheckModelAction;
65      }
66  
67      public boolean isAllowChangeScreen() {
68          return allowChangeScreen;
69      }
70  
71      public void setAllowChangeScreen(boolean allowChangeScreen) {
72          this.allowChangeScreen = allowChangeScreen;
73      }
74  
75      @Override
76      public boolean prepareAction() throws Exception {
77          fromChangeScreenAction = false;
78          fromCheckModelAction = false;
79          allowChangeScreen = true;
80          return super.prepareAction();
81      }
82  
83      // Override this method to gather models to set as not modified at the end of action
84      protected List<AbstractBeanUIModel> getModelsToModify() {
85          return new ArrayList<>();
86      }
87  
88      @Override
89      public void postSuccessAction() {
90          super.postSuccessAction();
91  
92          // Set each model as not modified
93          getModelsToModify().forEach(model -> model.setModify(false));
94  
95          // Set main model as not modified
96          getModel().setModify(false);
97      }
98  }