PivotAction.java
01 /*
02  * Copyright 2008-2014 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *     http://www.apache.org/licenses/LICENSE-2.0
09  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package griffon.pivot.support;
17 
18 import griffon.core.CallableWithArgs;
19 import org.apache.pivot.wtk.Action;
20 import org.apache.pivot.wtk.Component;
21 
22 import static java.util.Objects.requireNonNull;
23 
24 /**
25  @author Andres Almiray
26  */
27 public class PivotAction extends Action {
28     private String name;
29     private String description;
30     private CallableWithArgs<Void> callable;
31 
32     public PivotAction() {
33         this(null);
34     }
35 
36     public PivotAction(CallableWithArgs<Void> callable) {
37         this.callable = callable;
38     }
39 
40     public String getName() {
41         return name;
42     }
43 
44     public void setName(String name) {
45         this.name = name;
46     }
47 
48     public String getDescription() {
49         return description;
50     }
51 
52     public void setDescription(String description) {
53         this.description = description;
54     }
55 
56     public CallableWithArgs<Void> getCallable() {
57         return callable;
58     }
59 
60     public void setCallable(CallableWithArgs<Void> callable) {
61         this.callable = callable;
62     }
63 
64     public String toString() {
65         return "Action[" + name + ", " + description + "]";
66     }
67 
68     @Override
69     public void perform(Component component) {
70         requireNonNull(callable, "Argument 'callable' must not be null for " this);
71         callable.call(component);
72     }
73 }