1 package fr.ifremer.tutti.ui.swing.content.operation.fishing.actions;
2
3 /*
4 * #%L
5 * Tutti :: UI
6 * %%
7 * Copyright (C) 2012 - 2014 Ifremer
8 * %%
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (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 General Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/gpl-3.0.html>.
22 * #L%
23 */
24
25 import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport;
26 import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUI;
27 import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIHandler;
28 import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUIModel;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 /**
33 * Cancels the edition of a fishing operation and potentially switch to another tab.
34 *
35 * @author Kevin Morin - kmorin@codelutin.com
36 * @since 1.0
37 */
38 public class CancelEditFishingOperationAction extends LongActionSupport<EditFishingOperationUIModel, EditFishingOperationUI, EditFishingOperationUIHandler> {
39
40 /** Logger. */
41 private static final Log log = LogFactory.getLog(SaveFishingOperationAction.class);
42
43 /**
44 * Delegate edit action.
45 *
46 * @since 1.0
47 */
48 protected EditFishingOperationAction editAction;
49
50 public CancelEditFishingOperationAction(EditFishingOperationUIHandler handler) {
51 super(handler, true);
52 }
53
54 public EditFishingOperationAction getEditAction() {
55 if (editAction == null) {
56 editAction = getContext().getActionFactory().createLogicAction(
57 getHandler().getParentUi().getHandler(),
58 EditFishingOperationAction.class);
59 }
60 return editAction;
61 }
62
63 @Override
64 public void doAction() throws Exception {
65
66 EditFishingOperationAction action = getEditAction();
67
68 if (getModel().isCreate()) {
69 if (log.isInfoEnabled()) {
70 log.info("Cancel creation for fishingOperation");
71 }
72 // cancel to create a new fishingOperation
73 action.setFishingOperation(null);
74 getActionEngine().runInternalAction(action);
75
76 } else {
77
78 if (log.isInfoEnabled()) {
79 log.info("Can edition of fishingOperation");
80 }
81
82 // re-edit current fishing operation (but do not perform any check)
83 action.setCheckPreviousEdit(false);
84 action.setFishingOperation(getModel().getFishingOperation());
85 action.setInternalAction(true);
86 getActionEngine().runInternalAction(action);
87 }
88
89 //FIXME-TC Make sure this works again
90 // // if called directly from the EditFishingOperationUIHandler:
91 // // the user does not want to save the modifications before
92 // // selecting another tab, we must reload the current tab before setting
93 // // the new index of the tab pane
94 // if (event.getSource() != null
95 // && event.getSource().getClass().isAssignableFrom(EditFishingOperationUIHandler.class)) {
96 //
97 // int newIndex = event.getID();
98 // parentHandler.getTabPanel().setSelectedIndex(newIndex);
99 // }
100 }
101
102 // @Override
103 // public void postSuccessAction() {
104 // super.postSuccessAction();
105 // getEditAction().displayValidationErrors();
106 // }
107 }