View Javadoc
1   /**
2    * This file Copyright (c) 2013-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.api.action;
35  
36  import info.magnolia.annotation.deprecation.MgnlDeprecated;
37  import info.magnolia.commands.CommandsManager;
38  
39  import java.util.HashMap;
40  import java.util.Map;
41  
42  import org.apache.commons.lang3.builder.ToStringBuilder;
43  
44  /**
45   * A basic action definition useful for actions that delegates to commands.
46   */
47  public class CommandActionDefinition extends ConfiguredActionDefinition {
48  
49      private String command;
50      private String catalog = CommandsManager.DEFAULT_CATALOG;
51      private boolean asynchronous = false;
52      private int delay = 1;
53      private boolean isParallel = true;
54      private int timeToWait = 5000;
55      private boolean notifyUser = true;
56      private boolean alwaysShowSuccessMessage = false;
57  
58      private Map<String, Object> params = new HashMap<String, Object>();
59  
60      public String getCommand() {
61          return command;
62      }
63  
64      public void setCommand(String command) {
65          this.command = command;
66      }
67  
68      /**
69       * @return {@link CommandsManager#DEFAULT_CATALOG} if not set otherwise.
70       */
71      public String getCatalog() {
72          return catalog;
73      }
74  
75      public void setCatalog(String catalog) {
76          this.catalog = catalog;
77      }
78  
79      public void setParams(Map<String, Object> params) {
80          this.params = params;
81      }
82  
83      public Map<String, Object> getParams() {
84          return params;
85      }
86  
87      @Override
88      public String toString() {
89          return ToStringBuilder.reflectionToString(this);
90      }
91  
92      /**
93       * Defines whether this action should try to run asynchronously, e.g. to avoid blocking the UI.
94       */
95      public boolean isAsynchronous() {
96          return asynchronous;
97      }
98  
99      public void setAsynchronous(boolean asynchronous) {
100         this.asynchronous = asynchronous;
101     }
102 
103     /**
104      * Defines the delay (in seconds) after which the command should start, if asynchronous. Default is 1s.
105      * 
106      * @see #isAsynchronous()
107      */
108     public int getDelay() {
109         return delay;
110     }
111 
112     public void setDelay(int delay) {
113         this.delay = delay;
114     }
115 
116     /**
117      * Defines whether the command may be executed in parallel for multiple items, if asynchronous. Default is <code>true</code>.
118      * 
119      * @see #isAsynchronous()
120      * @deprecated since 6.2. This property is not supported in new framework. Any action can be executed in parallel. Use scheduler module instead to run non parallel jobs.
121      */
122     @Deprecated
123     public boolean isParallel() {
124         return isParallel;
125     }
126 
127     /**
128      * @deprecated since 6.2. This property is not supported in new framework. Any action can be executed in parallel. Use scheduler module instead to run non parallel jobs.
129      */
130     @MgnlDeprecated(since = "6.2", description = "This property is not supported in new framework. Any action can be executed in parallel. Use scheduler module instead to run non parallel jobs.")
131     @Deprecated
132     public void setParallel(boolean isParallel) {
133         this.isParallel = isParallel;
134     }
135 
136     /**
137      * Defines how long (in milliseconds) the UI should remain blocked until notifying user that the action will complete in the background, if asynchronous. Default is 5000ms.
138      * 
139      * @see #isAsynchronous()
140      */
141     public int getTimeToWait() {
142         return timeToWait;
143     }
144 
145     public void setTimeToWait(int timeToWait) {
146         this.timeToWait = timeToWait;
147     }
148 
149     /**
150      * Defines whether the action should notify the user in the Pulse, if asynchronous and if it completes in the background. Default is <code>true</code>.
151      * 
152      * @see #isAsynchronous()
153      */
154     public boolean isNotifyUser() {
155         return notifyUser;
156     }
157 
158     public void setNotifyUser(boolean notifyUser) {
159         this.notifyUser = notifyUser;
160     }
161 
162     /**
163      * Defines whether the action should always show the success message, even although the action takes less than #timeToWait.
164      */
165     public boolean isAlwaysShowSuccessMessage() {
166         return alwaysShowSuccessMessage;
167     }
168 
169     public void setAlwaysShowSuccessMessage(boolean alwaysShowSuccessMessage) {
170         this.alwaysShowSuccessMessage = alwaysShowSuccessMessage;
171     }
172 }