1 package fr.ifremer.quadrige3.ui.swing.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.ui.swing.content.AbstractMainUIHandler; 28 29 /** 30 * Action to keep but reload the current screen, after action execution. 31 * 32 * @author Benoit Lavenier <benoit.lavenier@e-is.pro> 33 */ 34 public abstract class AbstractReloadCurrentScreenAction extends AbstractChangeScreenAction { 35 36 37 private boolean skipScreenReload = false; 38 39 /** 40 * <p>Constructor for AbstractReloadCurrentScreenAction.</p> 41 * 42 * @param handler a {@link AbstractMainUIHandler} object. 43 * @param hideBody a boolean. 44 */ 45 protected AbstractReloadCurrentScreenAction(AbstractMainUIHandler handler, 46 boolean hideBody) { 47 super(handler, hideBody, null /*empty screen*/); 48 } 49 50 /** 51 * <p>Setter for the field <code>skipScreenReload</code>.</p> 52 * 53 * @param skipScreenReload a boolean. 54 */ 55 public void setSkipScreenReload(boolean skipScreenReload) { 56 this.skipScreenReload = skipScreenReload; 57 } 58 59 /** 60 * <p>isSkipScreenReload.</p> 61 * 62 * @return a boolean. 63 */ 64 public boolean isSkipScreenReload() { 65 return skipScreenReload; 66 } 67 68 /** {@inheritDoc} */ 69 @Override 70 public boolean prepareAction() throws Exception { 71 // Send the current screen, before super() 72 setScreen(getContext().getScreen()); 73 74 return super.prepareAction(); 75 } 76 77 /** {@inheritDoc} */ 78 @Override 79 public final void doAction() throws Exception { 80 doActionBeforeReload(); 81 82 if (!skipScreenReload) { 83 super.doAction(); 84 } 85 } 86 87 @Override 88 protected void releaseAction() { 89 super.releaseAction(); 90 91 skipScreenReload = false; 92 } 93 94 /** 95 * <p>doActionBeforeReload.</p> 96 * 97 * @throws Exception if any. 98 */ 99 public abstract void doActionBeforeReload() throws Exception; 100 101 }